-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patha_source.awk
1554 lines (1054 loc) · 40.1 KB
/
a_source.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Hobby Cross-Assembler (HXA) V0.201 - User Source File Management
# (c) 2004-2013 by Anton Treuenfels
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# ---------------------------------
# by Anton Treuenfels
# 5248 Horizon Dr
# Fridley, MN 55421
# e-mail: atreuenfels@earthlink.net
# source language: Thompson AWK 4.0
# first created: 05/16/03
# last revision: 09/09/13
# public function prefix: "SRC"
# -------------------
# file descriptors
local inFile, outFile
# source tracking
local currFile
local currLine
local currMaster
local masterLine
local saveMaster
# file inclusion stack
local incStkFile, incStkLine, incStkPos
local incDepth = 0
# files used
local fileMaster, fileName, fileLine
local fileCnt
local readOnce # files tagged as "read once only"
# input text storage
local listSource # flag: list source text ?
local listExpand # flag: list expansion text ?
local currText # last source line read
local expandText # saved source lines (from expansions)
local sourceText # saved source lines (from files)
# source listing control
local listCtrl # list control options
local trueFlag
local falseFlag
local rootFlag
local takenFlag = TRUE # default for conditional branches
local listLineNum = 0 # flag: show leading line number (also count)
# source cross-reference
local xrefHistory # cross-reference history
local xrefListLine # listing line (as opposed to source line)
# source listing format control
local pageMax = 255 # max page width, length
local pagWid # page width (zero = no upper limit)
local pagLen # page length (zero = no upper limit)
local lineSpc # line spacing
local topMrg, lftMrg # top and left margins
local botMrg, rgtMrg # bottom and right margins
local pageFormat # non-default values
local txtWid # printable width (if applicable)
local pageLine # line number on page
local pageBot # last printable line on page
local breakMin # minimum left breakpoint for long lines
local lftIndent # leading indent spaces to create left margin
local listLineNumFmt # leading line number
# -------------------
# set line counts to zero
# - when masterLine is zero, any errors found are not associated
# with any source line, eg., a file read/write error
# - when currLine is non-zero, it is possible for the source line number
# of an error to *be* currLine (not always, but often enough to be useful)
local function zerolinecnts() { masterLine = currLine = 0 }
# get master line number
global function SRCgetmaster() { return( masterLine ) }
# set master line number
global function SRCsetmaster(this) { masterLine = this }
# save/restore master line number
# - during periods of temporary re-setting, which are used to report
# errors associated with earlier master lines but only discovered now
global function SRCsavemaster() { saveMaster = masterLine }
global function SRCresetmaster() { masterLine = saveMaster }
# -------------------
# set list save flags
# - during the first pass some data is saved solely for listing purposes
# - but if it can be determined that no listing of a line is possible,
# some of that data can be safely ignored (ie., not saved)
# - for now we are mostly concerned about:
# - expansion lines, which by default aren't listed, where our concern
# is mostly about the text itself
# - false conditional branches, which by default aren't listed, where
# our concern is mostly about tracking which branch is which
# - either way, even if we do not save these lines initially we will save
# them later if we determine that code and/or error reporting happens
local function setlistflag() {
listSource = listCtrl[ "OBJECT" ] && listCtrl[ "SOURCE" ] \
&& ( !incDepth || listCtrl["INCLUDES"] )
listExpand = listSource && listCtrl[ "MACROS" ]
}
# set page-related list defaults
local function setpagedefault() {
pagWid = 75
pagLen = 0
topMrg = rgtMrg = botMrg = lftMrg = 0
lineSpc = 1
}
INIT {
# list flags: default:
# object: master object code list flag TRUE
# source: list source code TRUE
# includes: list include files TRUE
# macros: list macro expansions FALSE
# untaken: list untaken conditional branches FALSE
# allequ: local and variable label equates FALSE
# labels: master symbol table list flag TRUE
# autos: list auto-generated labels FALSE
# xref: macro/global label cross reference FALSE
# segments: master segment map list flag TRUE
# stats: master stats list flag FALSE
# linenums: master list line numbering flag FALSE
# linewrap: master line wrapping flag TRUE
# all: "meta" flag (sets all others) don't care
CKpopulateNdx( listCtrl, \
"OBJECT SOURCE INCLUDES LABELS SEGMENTS LINEWRAP", TRUE )
CKpopulateNdx( listCtrl, \
"MACROS UNTAKEN AUTOS XREF STATS LINENUMS ALLEQU ALL", FALSE )
setlistflag()
zerolinecnts()
setpagedefault()
}
# -----------------------------
# get text of line (slightly faster if text known to be from file)
global function SRCtextf(ndx) { return( sourceText[ndx] ) }
# get text of line (from file or expansion)
global function SRCtext(ndx) {
return( ndx in sourceText ? sourceText[ndx] : expandText[ndx] )
}
# -----------------------------
# make sure current source line is saved
# - may be needed later for listing or error reporting purposes
# - on second pass (when we're not reading source) only error reporting
# calls this when expression resolution fails - but any such expression
# must have generated data during first pass and so will already be saved
global function SRCremember() {
# line not already saved ?
# - can only happen when expanding macros whose text is not
# going to be listed
# - if caller saves return value this newly-saved line
# can be "forgotten" later
if ( MACexpanding() && !(masterLine in expandText) ) {
expandText[ masterLine ] = currText
return( masterLine )
}
# line saved already (and so un-deletable)
return( -masterLine )
}
# set source line index to saved value
global function SRCrecall(ndx) {
return( ndx > 0 ? ndx : -ndx )
}
# delete saved source line
# - if possible, then not needed for any future use (no data generated)
global function SRCforget(ndx) {
if ( ndx > 0 )
delete( expandText[ndx] )
}
# -----------------------------
# find master line number of nearest previous user source line
# - ie., the nearest previous non-expansion line
global function SRCnearest(master) {
# can we report the most recent source line read ?
if ( currLine && (currMaster <= master) )
return( currMaster )
# search for it
while ( !(master in sourceText) )
--master
return( master )
}
# get the index of the master file record of a given master line number
local function masterfile(master) {
local i
# - fileMaster[1] = 0 and master > 0, so this search
# should always succeed
# - if only one source file or first pass error call, search is quick
# since we always want the current file (first one looked at)
# - if more than one file we might look at more than most recent
# file during (1) second pass error call or (2) recovery of the name of
# the first file read (for default output file names)
for ( i = fileCnt; i > 0; --i ) {
if ( master > fileMaster[i] )
return( i )
}
UMnoway( "MASTERFILE" )
}
# get the source file name given a master line (user or macro)
global function SRCfile(master) {
return( fileName[masterfile(master)] )
}
# find source line number nearest given master by counting them
local function nearestsource(ndx, master, linenum) {
while ( ndx++ < master ) {
if ( ndx in sourceText )
linenum++
}
return( linenum )
}
# get the source file line number given a master line (user or macro)
global function SRCline(master) {
local i
# can we report the most recent source line read ?
if ( currLine && (currMaster <= master) )
return( currLine )
# okay, count source lines (always works, but slower)
i = masterfile( master )
return( nearestsource(fileMaster[i], master, fileLine[i]) )
}
# -----------------------------
# fetch next source line
global function SRCnextline() {
# is an expansion block active ?
# - if so, we know the next line will be non-null (so there will be
# only one fetch) and "attached" to the last program source line
if ( MACexpanding() ) {
currText = MACgetline()
++masterLine
if ( listExpand )
expandText[ masterLine ] = currText
}
# is there a line in the current source file ?
else {
do {
if ( (getline(currText) < inFile) <= 0 )
return( "" )
# save all text read from file(s)
sourceText[ ++masterLine ] = currText
++currLine
# skip blank and comment lines
} while ( currText ~ CKignoreLine )
# save for possible error reporting
currMaster = masterLine
}
# remove comment at end of line (if any)
# - comment starts if first char of second or later field is ";"
# - we do a "fast" check followed by a "thorough" check if necessary
if ( index(currText, ";") && match(currText, /[ \t]+;/) )
return( substr(currText, 1, RSTART - 1) )
return( currText )
}
# -----------------------------
# set list control change flag
# - only one change can happen per one source line
local function setlistctrl(value, flag) {
if ( flag )
trueFlag[ masterLine ] = value
else
falseFlag[ masterLine ] = value
}
# set conditional branch result
# - in order to cut down on storing unnecessary data:
# (a) we record only if there has actually been a change, and
# (b) even then only if the current line could possibly be listed
# (which it can't if it isn't stored, which is the default for expansions)
global function SRCsetcond(flag) {
if ( flag != takenFlag ) {
takenFlag = flag
if ( listSource && ((masterLine in sourceText) || listExpand) )
setlistctrl( "IFCOND", flag )
}
}
# show EQUATE value in object section ?
global function SRCshowequ(label) {
return( (label ~ SYMglbLabel) || listCtrl["ALLEQU"] )
}
# -----------------------------
# Assembly 'Include' files
# -----------------------------
# set current source file
global function SRCsetfile(name, line, pos) {
if ( inFile )
close( inFile )
# try to open file for reading
# - negative line number flags open for binary read
if ( (inFile = CKfopen(name, (line >= 0) ? "rt" : "rb")) ) {
# position file pointer
# - first byte of file is at offset zero
if ( pos > 0 )
fseek( inFile, pos )
# record for error-reporting
# - note masterLine and currLine are one less than
# first actual line in new file
fileName[ ++fileCnt ] = currFile = toupper( name )
fileLine[ fileCnt ] = currLine = line
fileMaster[ fileCnt ] = SRCgetmaster()
}
# successful if non-zero
return( inFile )
}
# set root file flag
local function setrootflag(state) {
rootFlag[ masterLine ] = state
setlistflag()
}
# is include stack non-empty ?
# - if so, restore topmost source file
global function SRCpopfile() {
# - note that if we can't restore topmost file,
# we keep trying until we run out of them
while ( (incDepth > 0) && CKtopblock(CKincBlk) ) {
CKoldscope()
if ( --incDepth == 0 )
setrootflag( TRUE )
if ( \
SRCsetfile(incStkFile[incDepth], \
incStkLine[incDepth], \
incStkPos[incDepth] \
) \
)
return( TRUE )
}
return( FALSE )
}
# push source file info
local function pushfile(name, line, pos) {
incStkFile[ incDepth ] = name
incStkLine[ incDepth ] = line
incStkPos[ incDepth ] = pos
if ( ++incDepth == 1 )
setrootflag( FALSE )
CKnewscope( CKincBlk )
}
# handle "INCLUDE" psop
# - INCLUDE filename
# - we do this in a way that lets us take advantage of another
# function's error-handling during source file switching
global function SRCdoinclude(name) {
# used within an expansion block ?
# - not allowed because expansions have read priority over files,
# so next line would come from expansion and not the included file
if ( MACexpanding() ) {
UMerror( "BadInExp" )
return
}
# tagged as READONCE ?
name = toupper( name )
if ( name in readOnce )
return
# stack current file
pushfile( currFile, currLine, ftell(inFile) )
# stack include file
pushfile( name, 0, 0 )
# "restore" include file
SRCpopfile()
}
# handle "INCBIN" pseudo op
# - INCBIN filename [[, count] [, start]]
global function SRCdoincbin(name, cnt, beg) {
local data
# stack current file
pushfile( currFile, currLine, ftell(inFile) )
# try to open include file
if ( SRCsetfile(name, -1, beg) ) {
# default is to take entire file
if ( cnt < 1 )
cnt = filesize( name )
# - should there be a warning if cnt > filesize() - beg ?
# read until end of file or have count
while ( !feof(inFile) && (cnt > 0) ) {
data = fread( cnt > 512 ? 512 : cnt, inFile )
cnt -= length( data )
CGsavestr( data )
}
}
# restore current file
SRCpopfile()
}
# warn about circular or previous inclusions
local function alreadyincluded(this) {
UMwarn( this == currFile ? "CircInc" : "PrevInc", this )
}
# handle "READONCE" psop
# - READONCE
global function SRCdoreadonce() {
local i
local fname
local stillactive
if ( !(currFile in readOnce) ) {
# okay, don't start reading this file again
readOnce[ currFile ] = ".T."
# we can only get here if 'currFile' has never been completely read
# - because if it had, READONCE would already have been processed
# - so 'currFile' has been read from its start to the point READONCE
# appears
# - it is best if 'currFile' has not INCLUDED any other files prior
# to READONCE, but even so it is not necessarily a problem unless
# - 1) any inclusions by 'currFile' are themselves not yet fully read
# - 2) AND such an inclusion itself managed to INCLUDE 'currFile'
# - 3) AND managed to reach the READONCE while the original read
# of 'currFile' did not
# - 4) AND something happened which should not have
# - if all that occured we might like to provide a clue why
# is the (1)-(3) sequence happening now ?
# - we can't tell anything about (4), though
stillactive = FALSE
for ( i = 0; i < incDepth; i++ ) {
fname = incStkFile[ i ]
if ( stillactive )
alreadyincluded( fname )
else
stillactive = (fname == currFile)
}
if ( stillactive )
alreadyincluded( currFile )
# has the current file INCLUDED anything before now ?
# - it is possible to deliberately arrange things so that READONCE
# occurs after any inclusions are complete but then prevents
# future inclusions necessary to produce the 'expected' result
# - and if it can be done deliberately it can be done accidentally
# - we only show that an inclusion has happened, as we cannot
# distinguish between 'calls' and 'returns' in the files read list
else {
for ( i = 1; i < fileCnt; i++ ) {
fname = fileName[ i ]
if ( fname == currFile ) {
alreadyincluded( fileName[i+1] )
break
}
# check for duplicate base names
# - might be a different path to same file
# - might the same file in a different location
# - might be a different file in a different location
# - a more elaborate check would use file sizes, times, etc
# - it is possible for a duplicate base name to also be
# in the include stack, but we only check here so as to
# avoid multiple warnings for one name
else if ( CKbasename(fname) == CKbasename(currFile) )
UMwarn( "PrevInc", fname )
}
}
}
}
# -------------------
# handle "END" psop
# root file:
# - [label] END [startaddr] (monolithic)
# - END [startaddr] (segmented)
# - ignores all following text in root file
# - halts pass one
# include file:
# - [label] END (monolithic)
# - END (segmented)
# - ignores all following text in include file (if no other open block)
# - halts pass one (if open block of another type active)
global function SRCdoend(addr) {
# open block(s) ?
# - will be flagged as errors if pass one terminates
if ( CKblockstacked() )
UMwarn( "OddUse" )
# within root file ?
if ( !incDepth )
CGsetstart( addr )
# within include file
else {
# can't set start address here
if ( addr )
UMignored( addr )
# not within an open block of another type within include file ?
if ( CKtopblocktype() == CKincBlk ) {
if ( SRCpopfile() )
return
}
# open block of another type (or could not restore previous file)
}
# killing any expansion blocks stops reading from them...
MACkillexpansion()
# ...and closing current file stops reading from it
close( inFile )
}
# -----------------------------
# turn listing option(s) on/off
# - unknown flags are silently ignored
local function setlistopt(flags, state) {
local i, j, ndx
local optlist
for ( i = CKsplitfield(flags, optlist, CKfieldSep); i > 0; --i ) {
ndx = optlist[ i ]
if ( ndx == "ALL" ) {
for ( j in listCtrl )
listCtrl[ j ] = state
}
else if ( ndx in listCtrl )
listCtrl[ ndx ] = state
}
}
# handle "LIST--" psops
# - LIST-- [option [[,option]..]]
global function SRCdolistopt(type, optcnt, optlist) {
local i
local opt, state
# if no option given, default to OBJECT list flag
# - ie., can choose to list only sections of code
if ( !optcnt )
opt = "OBJECT"
# otherwise verify options are legal
else {
for ( i = 1; i <= optcnt; i++ ) {
opt = optlist[ i ] = toupper( optlist[i] )
if ( !(opt in listCtrl) )
UMignored( opt )
}
opt = CKjoinfields( optlist )
}
# we'll process option flags now so any master list switches given
# will be in effect at start of listing
state = ( type == "LISTON" )
setlistopt( opt, state )
# we'll also save flags so we can process list switches
# again when we're actually performing list
# - correct SEGMENTS flag in particular must be protected
setlistctrl( opt, state )
# update expansion text save flag
setlistflag()
}
# -----------------------------
# Listing File Support
# -----------------------------
# A page:
# +---pagWid-----------------------------------+
# | | |
# | Margin Area topMrg |
# pagLen | |
# | +---txtWid-------------+ |
# | | | |
# | | Printable Area | |
# | txtLen | |
# | | | |
# |--lftMrg--| |--rgtMrg--|
# | | | |
# | | | |
# | | | |
# | | | |
# | | | |
# | +----------------------+ |
# | | |
# | botMrg |
# | | |
# +--------------------------------------------+
# set page format value
# - an error here prevents listing output (as all errors do)
local function setformat(ndx, new, old, min, max) {
# new val in range and really new ?
if ( CKinrange(new, min, max) ) {
if ( CKunique(new, ndx, pageFormat) )
return( new )
}
# new val is out-of-range or same as previously set
return( old )
}
# check if page format has any printable area
# - width requires that at least the first character of an output line
# actually be output regardless of whatever might be added to that line
# as it is broken up to be output on multiple lines (line numbers, etc.)
# - length requires that at least one line can be output on each page
# - if page width or length is zero, output along that dimension always
# succeeds because these are flags that mean "as much as necessary"
local function badpage(wid, len) {
local badwid, badlen
badwid = pagWid && ( wid < 1 )
if ( badwid )
UMwarn( "BadPgWid", wid )
badlen = pagLen && ( len < 1 )
if ( badlen )
UMwarn( "BadPgLen", len )
return( badwid || badlen )
}
# check page area
# - depending on the order in which page size and margins are set,
# any warning might not ultimately matter, but if one does we want to
# know which line did it
local function checkarea() {
badpage( pagWid - lftMrg - rgtMrg, pagLen - topMrg - botMrg )
}
# handle "PAGESIZE" psop
# - PAGESIZE width [, length]
global function SRCdopagesize(pwid, plen) {
pagWid = setformat( "PWID", pwid, pagWid, 0, pageMax )
pagLen = setformat( "PLEN", plen, pagLen, 0, pageMax )
checkarea()
}
# handle "MARGINS" psop
# - MARGINS top, lft [, bot[, rgt]]
global function SRCdomargins(top, lft, bot, rgt) {
local max
max = pageMax - 1
topMrg = setformat( "MTOP", top, topMrg, 0, max )
lftMrg = setformat( "MLFT", lft, lftMrg, 0, max )
botMrg = setformat( "MBOT", bot, botMrg, 0, max )
rgtMrg = setformat( "MRGT", rgt, rgtMrg, 0, max )
checkarea()
}
# handle "LINESPACE" psop
# - LINESPACE val
global function SRCdolinespace(val) {
lineSpc = setformat( "LSPC", val, lineSpc, 1, pageMax - 1 )
}
# handle "PAGE" psop
# - PAGE
global function SRCdopage() { pageFormat[ SRCgetmaster() ] = ".T." }
# -----------------------------
# set minimum break point for long lines
local function setbreakmin(this) {
breakMin = this
# verify derived page values "work"
# - an error here is fatal because the output device may not be
# compatible with either wrong values or a re-setting of default values,
# eg., output "file" is "PRN" under MS-DOS
if ( badpage(txtWid - breakMin, pageBot - topMrg) )
UMfatal( "BadPage" )
}
# possible "OBJECT" section line formats
# <- lftIndent -><linetype><- object -><- text ->
# <- lftIndent -><linetype><- spaces -><- text ->
# <- lftIndent -><linetype><- linenum -><- object -><- text ->
# <- lftIndent -><linetype><- linenum -><- spaces -><- text ->
# | |
# left margin right margin
# set additional page values derived from user-settable values
local function makeformats(linecnt) {
local digits
# printable area
pageBot = pagLen - botMrg
txtWid = pagWid - lftMrg - rgtMrg
# indent all lines from left edge ?
if ( lftMrg )
lftIndent = strdup( " ", lftMrg )
# show line numbers in listing ?
if ( listCtrl["LINENUMS"] ) {
# set count (doubles as flag; how handy!)
listLineNum = 1
# how many digits shall we display ?
# - based only on "OBJECT" section line count, but most often will
# have a leading zero, which ought to accomodate all other sections
# - log() yields natural log, not base 10 log
digits = int( log(linecnt)/log(10) + 2 )
# create format for showing line numbers
listLineNumFmt = "%0" digits "d "
# account for line numbers in printable width
txtWid -= digits + 1
}
# an indent for non-object-generating source lines and those
# broken due to length
# - we have to wait until 'txtWid' is set before we can do this because
# there is a "reality check" involved
# - object: type addr hex hex hex hex src: "?XXXX XX XX XX XX src"
# - no object: (blank) src: " src"
# ----!----!----!----!----!
setbreakmin( PCgetformatlen() + 15 )
}
# --------------------------------
local function min(val1, val2) { return( val1 < val2 ? val1 : val2 ) }
# output blank line(s)
local function skipline(cnt) {
while ( cnt-- > 0 )
print "" > outFile
}
# output text
# - adds left indent and line number (if any)
# - adds newline
# - handles pagination
local function putline(this) {