nbr-mbas.txt <-- filename of this file (other files are for the library) Brian C Dugle <-- author 6002 Carrindale Ct Burke, VA 22015 (703) 569-3036 Okay to release address and phone *** Note t editor *** Al carriag retur symbol ar ' i th text d searc an replac t pu i th typesetter' code Contro character fo illustratio i th tex us circumfle o care (shift-6 followe b th capita letter Pleas leav codin line a formatte (i possible an prin thos section i fixe pitc (monospace?) Searc fo "^N.. t fin comment i th fil fo yo t ai i startin an endin monospace Thes comment shoul b delete (a shoul thes notes befor sendin t th printer. Question Ar yo plannin t pu ou an mor specifi guidanc o formattin o article contributed I so I' interested. .. *** Actual Article Starts Here *** A Simple MBASIC Preprocessor by Brian Dugle Severa month ago wrot a articl fo th FOGHOR abou usin WordSta fo writin MBASI program (Vo IV N 11 Au 1985) I i mentione tha automati numberin fo BASI progra wa m nex subject Well i yo hav bee waitin fo it her i is Thi articl wil describ BASI progra whic read a un-numbere sourc fil an write numbere fil fro it Thi woul b prett trivia i ther wer n 'GOTOs an n 'GOSUBs (eithe ver unlikel o no ver usefu fo programmin i BASIC!) bu w wil handl conversio o name label t lin number a well Further w won' pas o an remar line sinc progra documentatio wil remai i th origina un- numbere listing. First wh MBASIC On reaso i tha MBASI program ar eas t wor with The ca b debugge interactivel (o eve "hacke together") an the ar on o th mor portabl kind o program around A a illustratio o MBASIC' portability recentl wrot circl drawin progra fo a offic a wor tha ha th sam printe a d a home Ther wa on differenc though thei compute i a IB PC an min i a Osborne MBASI o th Ozz an BASI o th P bot com fro th sam hom (MicroSoft an too advantag o tha fact wa no doin scree graphic (obviousl machin dependent) an ther wer coupl o difference (lik clearin th screen) bu 9 percen o th progra ra th sam o bot machines ( eve too i i o dis courtes o Uniform!) S muc fo portability Th othe thin fin ver usefu wit MBASI i bein abl t ad 'STOP statemen fo debuggin i a havin trouble Whe th brea messag appears ca easil investigat value o variable b 'PRINTing the i immediat mod t fin ou wha i causin th problem Then i ther i n proble a tha point ca 'CONTinue'. BASI leave lo t b desire i term o structuring Th nee fo lin number everywher i absolutel pain Yo ma b askin wh haven' switche t CBASI then--wel hav don som wor wit i too bu i i quit differen fro MBASI and i m opinion almos th wors o bot world fo th casua progammer CBASI i no interactive; eac tim chang i mad yo hav t recompile And hav ha som problem i gettin thing t wor th wa though the should Someon wit mor rigorou approac woul undoubtedl avoi mos o thes problems. S wha i m answer thin tha thos o yo BASI devotee wh d no wan t bu cop o TURB an lear Pasca shoul rea on BASI wil neve b a clea lookin a th mai bloc o Pasca program an NB (th progra w ar abou t write mus b ru separatel o th fil jus lik compilin CBASI program bu th advantage o writin larg progra withou lin number mak i worthwhile. Th firs ste i t buil you progra fro th to down No tha sound lik I' spoutin th origina programmer' buzz- word bu believ th to dow approac i fundamenta requiremen fo gettin workin progra tha doe wha yo wan done To dow mean sketchin pla fo doin th jo i regula ol English then wit mor detai a eac level explainin eac ste o th plan Whil yo ar a it wh no d you sketchin wit WordSta i (non-document mode? I help t thin bi i term o logica statement i sketchin ou you plan Som ke word tha describ decision tha mus b mad an action tha mus b take i gettin fro star t en wil b ver helpful bu wit th magi o WordStar al thing ca b changed Onc yo hav th proble an it solutio describe a th genera level yo ca the g t th en o th fil an star describin th detai leve procedure tha wer state i phras o tw a first. Th onl proble wit thi i tha yo hav don al thi writing bu yo can' us an o i becaus ther aren' an lin number i there Wel han i there becaus th poin o thi articl i t us thi techniqu t writ progra tha solve th problem Th followin i sketc o pseud cod outlin o progra whic wil numbe th line o progra an conver label t lin number fo us. initialize variables open program file pass one initialize the line counter while not eof read a line if it is blank or just a remark, don't count it otherwise, save the line in an array if the line begins with a label, add the label and its line number to a list increment line number end while close program file pass two open output file reset line number to start for each line saved if it is a label line, make it a remark and print it otherwise add a line number at the beginning if it has a remark on the end, ignore that part look for labels in the line i found loo u i th lis an replac wit th appropriate line number keep looking at the line until there are no more labels add the line to the output file increment line number end while close output file print a list of the labels end I doesn' loo to muc lik MBASI yet bu i ha possibilities An i wil allo u t writ futur program wit WordStar muc bette ide tha th ol MBASI lin editor I doe no tak muc imaginatio o effor t translat th sketc abov into: ..start monospace, delete this line! Listing of NBR.ASC 'NBR is a MicroSoft BASIC-80 (r) basic program that adds line ' numbers to a file 'labels of the form "[label]" are converted to the appropriate ' line number ver$ = "1.24, 10 Nov 85" REM copyright 1985 by Brian Dugle 6002 Carrindale Ct Burke, VA 22015 (703) 569-3036 REM This program may be used by any individual for non-commercial purposes; it may not be sold alone or as part of a group of "public domain" programs 'NOTE!! ' lines that end with a colon must be terminated with a linefeed ' (^P^J in WordStar) to continue on the next physical line-- ' this also applies to 'if' statements continued on multiple ' lines, ie, end physical lines that continue on the next line ' with a LINEFEED, not a RETURN... ' Lines continued in this manner are still limited to a total ' of 255 chars (including LFs, TABs, etc), this program does ' not check for this error, it crashes!! 'define constants for variable type, size of arrays... defint a-z: tblsz = 50: codesz = 150: dim lblname$ (tblsz), lblval (tblsz), progline$ (codesz) 'functions - boolean def fnisodd (n) = ( (n and 1) = 1 ) def fniseven (n) = ( (n and 1) = 0 ) def fniswhitespace (c) = ( instr (whitespace$, c) > 0 ) def fnisremline (l$) = ( left$ (l$, 1) = rmk$ ) def fnisblankline (l$) = ( len (l$) = 0 ) def fnislabelline (l$) = ( left$ (l$, 1) = lblstcode$ ) ' other functions... def fnlnum (n) = n * incr + startnum 'logical values and ascii constants false = 0: true = not false: blank$ = chr$ (32): tab$ = chr$ (9): lf$ = chr$ (10): cr$ = chr$ (13): quote$ = chr$ (34): cl$ = chr$ (26) 'program parameters and initialized variables startnum = 100: incr = 10: infile = 1: outfile = 2 rmk$ = "'": lblstcode$ = "[": lblendcode$ = "]": maxlblnum = 0: whitespace$ = blank$ + tab$ '___________________________________________________main program print cl$: print "nbr.bas vers "; ver$; " (c) Brian Dugle" [get filename] input "Enter the program name: ", progname$ upr$ = progname$: gosub [make upper]: progname$ = upr$: infilname$ = progname$ + ".ASC": outfilname$ = progname$ + ".NUM": symfilname$ = progname$ + ".SYM" '............................................pass one pass = 1 on error goto [open error] open "I", infile, infilname$ 'ln keeps track of lines in output ".NUM" file, sourceln counts input file lines for use in error messages ln = 0: sourceln = 1: print "Free memory ="; fre (0) while not eof (infile) and (ln <= codesz) ' ...keep user up to date on progress... print cr$;: print using "pass 1, source line ### mem = #####"; sourceln; fre (0); '...get a line and check if it should be kept for output line input # infile, progline$ (ln): if fnisremline (progline$ (ln)) or fnisblankline (progline$ (ln)) then [next pass1 line] '...if the line is not a remark and is not blank, then check to see if the line starts with a label, if so then add to list of labels... 'Note! remarks made with REM will stay in the file... lblptr = instr (progline$ (ln), lblstcode$): if lblptr = 1 then gosub [eval label] ln = ln + 1 [next pass1 line] 'Note! arriving at this label directly skips incrementing line number but source line is incr'd sourceln = sourceln + 1 wend lastln = ln - 1 'possible error, codesz terminated input--if so tell user if not eof (infile) and ln >= codesz then print "Source file too big, ran out of romm at"; ln; "lines": print "Change the variable 'codesz' and try again...": end close infile '............................................pass two pass = 2 open "O", outfile, outfilname$ for ln = 0 to lastln ' progress check... print cr$;: print using "pass 2, prog line ##### mem = #####"; fnlnum (ln); fre (0); 'reformat line 'if line is a label location, only action required is to make it a remark, skip everything else if fnislabelline ( progline$ (ln) ) then progline$ (ln) = str$ (fnlnum (ln)) + tab$ + "' " + progline$ (ln): goto [print line] 'add the line number to progline$ (ln) and add tabs following linefeeds to maintain indenting progline$ (ln) = str$ (fnlnum (ln)) + tab$ + progline$ (ln): lfpos = instr (progline$ (ln), lf$): while lfpos <> 0: c$ = mid$ (progline$ (ln), lfpos+1, 1): if c$ = cr$ then lfpos = lfpos + 1 progline$ (ln) = left$ (progline$ (ln), lfpos) + tab$ + mid$ (progline$ (ln), lfpos+1): lfpos = instr (lfpos+1, progline$ (ln), lf$): wend 'set quote positions 'search progline$ (ln) for quotes (chr$(34)), save position of each quote char in quotepos$ 'positions are one byte values saved in a string variable qpos = instr (progline$ (ln), quote$): quotepos$ = "" while qpos <> 0: quotepos$ = quotepos$ + chr$ (qpos): qpos = instr (qpos+1, progline$ (ln), quote$): wend if fnisodd (len (quotepos$)) then errmsg$ = "Quotes not paired": gosub [print errmsg] else quotepos$ = quotepos$ + chr$ (255) 'delete trailing remarks in progline$ (ln) start by finding first rmk$ that is not in a quoted string and return its position in remptr remptr = instr (progline$ (ln), rmk$): while remptr > 0: ptr = remptr: gosub [check ptr in quotes]: if ptrinquotes then remptr = instr (remptr+1, progline$ (ln), rmk$) wend 'if remptr is found, then delete trailing remark and whitespace from end of line if remptr > 0 then progline$ (ln) = left$ (progline$ (ln), remptr - 1): p = len (progline$ (ln)): while fniswhitespace ( mid$ (progline$ (ln), p, 1) ): p = p - 1: wend: progline$ (ln) = left$ (progline$ (ln), p) 'search for labels, convert to line numbers, insert in line and print to output file numlbls = 0: lblptr = instr (progline$ (ln), lblstcode$): while lblptr > 0: ptr = lblptr: gosub [check ptr in quotes]: if not ptrinquotes then gosub [save label num] lblptr = instr (lblptr+1, progline$ (ln), lblstcode$): wend: gosub [insert label nums] [print line] 'print the current line and then delete it to make more workspace print # outfile, progline$ (ln): progline$ (ln) = "" next ln '............................................finish up close outfile 'put the symbol table in a disk file that can be LISTed from MBASIC... open "O", outfile, symfilname$: print # outfile, "1 'Label listing of: " + progname$ + ".BAS": for i = 0 to maxlblnum-1: print # outfile, str$ (lblval (i)); " '[" + lblname$ (i) + "]": next close: print: end '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [make upper] 'pass a string to the routine in upr$ 'routine checks each char and, if lower case, converts it to ' upper case 'result returned in upr$ for c = 1 to len (upr$): cupr$ = mid$ (upr$, c, 1) ' ...if cupr$ is lower case, convert it and insert into upr$... if (cupr$ >= "a") and (cupr$ <= "z") then cupr$ = chr$ ( asc (cupr$) - 32 ): upr$ = left$ (upr$, c-1) + cupr$ + mid$ (upr$, c+1) next c return '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [open error] 'error on attempt to open input file if err = 53 then print "Error, file: " infilname$ " not found, check spelling": resume [get filename] else on error goto 0 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [eval label] 'pass 1--extract a label from a line when lblptr = 1, ie, ' line starts with a label 'if it is not already in the list, add it to the list gosub [get label]: if lblerr then errmsg$ = "Incorrect label format": gosub [print errmsg]: goto [end eval label] gosub [match label]: if inlist then gosub [lbl dbl def] else gosub [add to list] [end eval label] return '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [lbl dbl def] 'error, found label already in list during pass one errmsg$ = "Label '[" + lbl$ + "]' is redefined in line" + str$ (ln) + ", value is" + str$ (lblval (n)): gosub [print errmsg]: return '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [add to list] 'pass one--add a new label to the list 'make label value the next line, remark line will not be the ' target of the goto or gosub lblname$ (maxlblnum) = lbl$: lblval (maxlblnum) = fnlnum (ln + 1): maxlblnum = maxlblnum + 1: return '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [check ptr in quotes] 'remark and label identifiers are not significant when in ' quoted strings 'this routine checks ptr to see if it is within a quoted string 'uses quotepos$ 'returns boolean ptrinquotes if ptr > 255 then errmsg$ = "Pointer value too high, " + str$ (ptr): gosub [print errmsg]: stop qnum = 1: qpos = asc (quotepos$) '...ASC function returns ascii code of first char in a string... while ptr > qpos: qnum = qnum + 1: qpos = asc (mid$ (quotepos$, qnum, 1)): wend ptrinquotes = fniseven (qnum) return '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [save label num] 'pass two--change a label to its value 'arrive here with "lblptr" pointing to start of a label in ' "progline$ (ln)" 'find label in list and save value & position to replace or 'print error: undefined label gosub [get label]: if lblerr then errmsg$ = "Incorrect label format at pos" + str$ (lblptr): gosub [print errmsg]: goto [end save label num] gosub [match label]: if not inlist then errmsg$ = "Undefined label '[" + lbl$ + "]'": gosub [print errmsg]: goto [end save label num] 'found a good label, save position & value, bump counter labelpos (numlbls) = lblptr: labelval (numlbls) = lblval (n): numlbls = numlbls + 1 [end save label num] return '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [insert label nums] 'numlbls is the number of labels found in this line 'they must be replaced from the far end first so that the position ' of each insertion does not change 'array labelval () holds the label value to insert 'array labelpos () holds the pointer, where to insert it ' both arrays are set to 10 subscripts by default... for lp = numlbls-1 to 0 step -1 endlblptr = instr (labelpos (lp), progline$ (ln), lblendcode$): progline$ (ln) = left$ (progline$ (ln), (labelpos (lp) - 1)) + str$ ( labelval (lp) ) + mid$ (progline$ (ln), endlblptr + 1) next lp return '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [get label] 'call with lblptr pointing to lblstcode$ in progline$ (ln) 'return with label name in lbl$, error in lblerr, lblptr not ' changed endlblptr = instr (lblptr, progline$ (ln), lblendcode$): lblerr = (endlblptr = 0): if not lblerr then lbl$ = mid$ ( progline$ (ln), (lblptr + 1), (endlblptr - lblptr -1) ) else lbl$ = "" return '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [match label] 'find label in label list, return result in boolean "inlist" ' if in list, return subscript in "n" inlist = false: n = -1: while (n < maxlblnum) and not inlist: n = n + 1: inlist = (lbl$ = lblname$ (n)): wend: return '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [print errmsg] 'message passed in "errmsg$" 'prints to screen and outfile if pass = 1 then print: print "Error: "; errmsg$ else if pass = 2 then print # outfile, errmsg$ return '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ..back to normal type setting Dependin o ho tha listin wa treate b th typesetters yo shoul hav som ide o wha hav bee talkin about I too severa step t g fro th firs sketc outlin t th listin above bu th abilit t chang thing globally searc throughou th listing etc wa ke t makin i muc easier Wit n lin numbers majo structura change suc a movin al th subroutine t th beginnin (wher MBASI i repute t fin the faster ar eas t d wit bloc mov i WordStar The (fo thi example jus ad 'got [start] a th beginnin an labe '[start] wher th initializatio no begins an ru i throug NB again. Ther ma b somethin naggin i th bac o you mind-- lik ho d w ge ther th firs time perhaps I' gla yo asked Th ke t pullin yoursel u b you bootstrap i thi cas i th little-use PI [N2 parameter Digita Researc reall though o everythin here N add lin number t th fron o eac lin o file Fro there i i manua operatio t ru throug th listin (i WordSta non-documen mode onc mor t eliminat al blan line an globall search- and-replac eac labe wit it lin number Althoug i take longer sugges no usin th "withou asking optio (n o thi one Tha wa yo ca leav th labe wher i belong a th beginnin o eac routine. Th step fo thi proces ar reasonabl i yo remembe yo n longe hav t d thi onc yo ge th NB progra running I thi progra i adde t th FO library the yo ma no eve hav t d i a all Bu wil describ wha di anyway First us PI t ad th lin numbers: A>pip nbr.num=nbr.asc[n2] No fo slightl stick part I yo hav type thi progra listin i faithfully yo undoubtedl pu colon a th en o man o th lines Thes multipl physica line ar t b treate a singl logica lin b th MBASI interpreter T continu on logica lin o th nex physica line th physica lin mus en wit ^P^ whe i WordStar o ^ alon i MBASIC' ow editor Yo wil se tha WordSta indicate line terminate b linefee wit "J i th statu colum o th righ sid o you scree a describe i th Au 8 article. Thes line shoul b terminate wit linefee fo MBASIC bu no fo PIP' N mode PI wil conside the al separat lines T ge aroun this jus ra throug th fil an eliminate th extraneou lin number adde b PI whil wa replacin th label wit thei numbers Optionally yo coul leav al multipl statement o on physica lin o jus leav ou th colons Th fewe lin number yo have th faste th progra wil run s compoun statement ar goo idea withi reason (An besides i i onl fo thi on tim anyway...) Thi work fin unti yo ge t som o thos I THE ELS statements--MBASI use th <-- search for lf-cr REPLACE WITH? ^P^J<-- replace with just lf OPTIONS? gn^S <-- here is the ^S I was talking about ..back to normal Withou th ^ yo woul probabl no wan t bother th searc an replac take LON TIME Wit th displa updat turne of an th whol proga alread i memor i i almos instantaneous On thing normall i yo follo searc o search-and-replac sequenc wit ^Qp WordSta take yo bac t th poin fro whic th comman wa issued--i doe no wor wit th ^ optio becaus th las characte type (th ^S i locate a th en o th fil a fa a WordSta i concerned I yo d wan t retur t you star point us ^ a th speed-u characte instea o ^S Whe th search-and-replac operatio ends yo wil b a th en o th fil wit ^ (quic commands actio pending Jus hi th 'P ke fo retur t you previou locatio i th file! Finally bi abou filenam convention use i th program arbitraril decide tha th origina un-numbere fil shoul b .ASC th produc o NBR.BA woul b .NUM an th symbo listin woul b .SYM Onc i i finall debugged yo shoul LOA th .NU fil wit MBASI an SAV i a tokenize file tha i SAV i withou th ",A option Th tokenize fil load muc mor quickl tha a asci file I yo simpl 'SAV "PROGNAME" thi las time MBASI wil ad th '.BAS fo you. Tha jus abou bring m t th en o thi article Thi progra coul mak us o som enhancements an encourag yo t experimen an tak i fro here I th interes o simplicity lef thi versio o th progra prett basic bu on obviou additio woul b t ad wa t handl file to bi t fi i memory di thi wit versio 1. an a sendin i alon fo th library Anothe usefu modificatio woul b a explici "continu lin code tha woul allo writin th sourc wit VDO smal fas edito availabl fro th FO librar (min i versio 2A think) us i fo man things bu fin th lac o tru search-and-replac an bloc mov function somewha limiting Eve better i woul b nic t hav th progra compiled d no ow BASCOM s canno hel there bu I' thinkin abou writin i i TURB t mak i quick Yo ma not th displa o memor remainin i th progra progres lines-- use i t tes variou scheme t mak th interprete progra ru faste an lef i i fo you amazement. Thi wa bi chunk don' kno i ou kin edito ha an roo left bu a goin t ad th produc o th progra liste abov next s yo ca se th result Th progra doe wor o itself tha ha bee mos o m testin o i a thi time M addres an phon numbe ar i th listin i yo fin an bug o hav an individua questions. ..start monospace (if you have any room left) Listing of NBR.BAS 100 VER$ = "1.24, 10 Nov 85" 110 REM copyright 1985 by Brian Dugle 6002 Carrindale Ct Burke, VA 22015 (703) 569-3036 120 REM This program may be used by any individual for non-commercial purposes; it may not be sold alone or as part of a group of "public domain" programs 130 DEFINT A-Z: TBLSZ = 50: CODESZ = 150: DIM LBLNAME$ (TBLSZ), LBLVAL (TBLSZ), PROGLINE$ (CODESZ) 140 DEF FNISODD (N) = ( (N AND 1) = 1 ) 150 DEF FNISEVEN (N) = ( (N AND 1) = 0 ) 160 DEF FNISWHITESPACE (C) = ( INSTR (WHITESPACE$, C) > 0 ) 170 DEF FNISREMLINE (L$) = ( LEFT$ (L$, 1) = RMK$ ) 180 DEF FNISBLANKLINE (L$) = ( LEN (L$) = 0 ) 190 DEF FNISLABELLINE (L$) = ( LEFT$ (L$, 1) = LBLSTCODE$ ) 200 DEF FNLNUM (N) = N * INCR + STARTNUM 210 FALSE = 0: TRUE = NOT FALSE: BLANK$ = CHR$ (32): TAB$ = CHR$ (9): LF$ = CHR$ (10): CR$ = CHR$ (13): QUOTE$ = CHR$ (34): CL$ = CHR$ (26) 220 STARTNUM = 100: INCR = 10: INFILE = 1: OUTFILE = 2 230 RMK$ = "'": LBLSTCODE$ = "[": LBLENDCODE$ = "]": MAXLBLNUM = 0: WHITESPACE$ = BLANK$ + TAB$ 240 PRINT CL$: PRINT "nbr.bas vers "; VER$; " (c) Brian Dugle" 250 ' [get filename] 260 INPUT "Enter the program name: ", PROGNAME$ 270 UPR$ = PROGNAME$: GOSUB 650: PROGNAME$ = UPR$: INFILNAME$ = PROGNAME$ + ".ASC": OUTFILNAME$ = PROGNAME$ + ".NUM": SYMFILNAME$ = PROGNAME$ + ".SYM" 280 PASS = 1 290 ON ERROR GOTO 700 300 OPEN "I", INFILE, INFILNAME$ 310 LN = 0: SOURCELN = 1: PRINT "Free memory ="; FRE (0) 320 WHILE NOT EOF (INFILE) AND (LN <= CODESZ) 330 PRINT CR$;: PRINT USING "pass 1, source line ### mem = #####"; SOURCELN; FRE (0); 340 LINE INPUT # INFILE, PROGLINE$ (LN): IF FNISREMLINE (PROGLINE$ (LN)) OR FNISBLANKLINE (PROGLINE$ (LN)) THEN 380 350 LBLPTR = INSTR (PROGLINE$ (LN), LBLSTCODE$): IF LBLPTR = 1 THEN GOSUB 720 360 LN = LN + 1 370 ' [next pass1 line] 380 SOURCELN = SOURCELN + 1 390 WEND 400 LASTLN = LN - 1 410 IF NOT EOF (INFILE) AND LN >= CODESZ THEN PRINT "Source file too big, ran out of romm at"; LN; "lines": PRINT "Change the variable 'codesz' and try again...": END 420 CLOSE INFILE 430 PASS = 2 440 OPEN "O", OUTFILE, OUTFILNAME$ 450 FOR LN = 0 TO LASTLN 460 PRINT CR$;: PRINT USING "pass 2, prog line ##### mem = #####"; FNLNUM (LN); FRE (0); 470 IF FNISLABELLINE ( PROGLINE$ (LN) ) THEN PROGLINE$ (LN) = STR$ (FNLNUM (LN)) + TAB$ + "' " + PROGLINE$ (LN): GOTO 590 480 PROGLINE$ (LN) = STR$ (FNLNUM (LN)) + TAB$ + PROGLINE$ (LN): LFPOS = INSTR (PROGLINE$ (LN), LF$): WHILE LFPOS <> 0: C$ = MID$ (PROGLINE$ (LN), LFPOS+1, 1): IF C$ = CR$ THEN LFPOS = LFPOS + 1 490 PROGLINE$ (LN) = LEFT$ (PROGLINE$ (LN), LFPOS) + TAB$ + MID$ (PROGLINE$ (LN), LFPOS+1): LFPOS = INSTR (LFPOS+1, PROGLINE$ (LN), LF$): WEND 500 QPOS = INSTR (PROGLINE$ (LN), QUOTE$): QUOTEPOS$ = "" 510 WHILE QPOS <> 0: QUOTEPOS$ = QUOTEPOS$ + CHR$ (QPOS): QPOS = INSTR (QPOS+1, PROGLINE$ (LN), QUOTE$): WEND 520 IF FNISODD (LEN (QUOTEPOS$)) THEN ERRMSG$ = "Quotes not paired": GOSUB 1030 ELSE QUOTEPOS$ = QUOTEPOS$ + CHR$ (255) 530 REMPTR = INSTR (PROGLINE$ (LN), RMK$): WHILE REMPTR > 0: PTR = REMPTR: GOSUB 810: IF PTRINQUOTES THEN REMPTR = INSTR (REMPTR+1, PROGLINE$ (LN), RMK$) 540 WEND 550 IF REMPTR > 0 THEN PROGLINE$ (LN) = LEFT$ (PROGLINE$ (LN), REMPTR - 1): P = LEN (PROGLINE$ (LN)): WHILE FNISWHITESPACE ( MID$ (PROGLINE$ (LN), P, 1) ): P = P - 1: WEND: PROGLINE$ (LN) = LEFT$ (PROGLINE$ (LN), P) 560 NUMLBLS = 0: LBLPTR = INSTR (PROGLINE$ (LN), LBLSTCODE$): WHILE LBLPTR > 0: PTR = LBLPTR: GOSUB 810: IF NOT PTRINQUOTES THEN GOSUB 870 570 LBLPTR = INSTR (LBLPTR+1, PROGLINE$ (LN), LBLSTCODE$): WEND: GOSUB 930 580 ' [print line] 590 PRINT # OUTFILE, PROGLINE$ (LN): PROGLINE$ (LN) = "" 600 NEXT LN 610 CLOSE OUTFILE 620 OPEN "O", OUTFILE, SYMFILNAME$: PRINT # OUTFILE, "1 'Label listing of: " + PROGNAME$ + ".BAS": FOR I = 0 TO MAXLBLNUM-1: PRINT # OUTFILE, STR$ (LBLVAL (I)); " '[" + LBLNAME$ (I) + "]": NEXT 630 CLOSE: PRINT: END 640 ' [make upper] 650 FOR C = 1 TO LEN (UPR$): CUPR$ = MID$ (UPR$, C, 1) 660 IF (CUPR$ >= "a") AND (CUPR$ <= "z") THEN CUPR$ = CHR$ ( ASC (CUPR$) - 32 ): UPR$ = LEFT$ (UPR$, C-1) + CUPR$ + MID$ (UPR$, C+1) 670 NEXT C 680 RETURN 690 ' [open error] 700 IF ERR = 53 THEN PRINT "Error, file: " INFILNAME$ " not found, check spelling": RESUME 260 ELSE ON ERROR GOTO 0 710 ' [eval label] 720 GOSUB 980: IF LBLERR THEN ERRMSG$ = "Incorrect label format": GOSUB 1030: GOTO 750 730 GOSUB 1010: IF INLIST THEN GOSUB 770 ELSE GOSUB 790 740 ' [end eval label] 750 RETURN 760 ' [lbl dbl def] 770 ERRMSG$ = "Label '[" + LBL$ + "]' is redefined in line" + STR$ (LN) + ", value is" + STR$ (LBLVAL (N)): GOSUB 1030: RETURN 780 ' [add to list] 790 LBLNAME$ (MAXLBLNUM) = LBL$: LBLVAL (MAXLBLNUM) = FNLNUM (LN + 1): MAXLBLNUM = MAXLBLNUM + 1: RETURN 800 ' [check ptr in quotes] 810 IF PTR > 255 THEN ERRMSG$ = "Pointer value too high, " + STR$ (PTR): GOSUB 1030: STOP 820 QNUM = 1: QPOS = ASC (QUOTEPOS$) 830 WHILE PTR > QPOS: QNUM = QNUM + 1: QPOS = ASC (MID$ (QUOTEPOS$, QNUM, 1)): WEND 840 PTRINQUOTES = FNISEVEN (QNUM) 850 RETURN 860 ' [save label num] 870 GOSUB 980: IF LBLERR THEN ERRMSG$ = "Incorrect label format at pos" + STR$ (LBLPTR): GOSUB 1030: GOTO 910 880 GOSUB 1010: IF NOT INLIST THEN ERRMSG$ = "Undefined label '[" + LBL$ + "]'": GOSUB 1030: GOTO 910 890 LABELPOS (NUMLBLS) = LBLPTR: LABELVAL (NUMLBLS) = LBLVAL (N): NUMLBLS = NUMLBLS + 1 900 ' [end save label num] 910 RETURN 920 ' [insert label nums] 930 FOR LP = NUMLBLS-1 TO 0 STEP -1 940 ENDLBLPTR = INSTR (LABELPOS (LP), PROGLINE$ (LN), LBLENDCODE$): PROGLINE$ (LN) = LEFT$ (PROGLINE$ (LN), (LABELPOS (LP) - 1)) + STR$ ( LABELVAL (LP) ) + MID$ (PROGLINE$ (LN), ENDLBLPTR + 1) 950 NEXT LP 960 RETURN 970 ' [get label] 980 ENDLBLPTR = INSTR (LBLPTR, PROGLINE$ (LN), LBLENDCODE$): LBLERR = (ENDLBLPTR = 0): IF NOT LBLERR THEN LBL$ = MID$ ( PROGLINE$ (LN), (LBLPTR + 1), (ENDLBLPTR - LBLPTR -1) ) ELSE LBL$ = "" 990 RETURN 1000 ' [match label] 1010 INLIST = FALSE: N = -1: WHILE (N < MAXLBLNUM) AND NOT INLIST: N = N + 1: INLIST = (LBL$ = LBLNAME$ (N)): WEND: RETURN 1020 ' [print errmsg] 1030 IF PASS = 1 THEN PRINT: PRINT "Error: "; ERRMSG$ ELSE IF PASS = 2 THEN PRINT # OUTFILE, ERRMSG$ 1040 RETURN ..back to normal for a couple lines Listing of NBR.SYM (Not tha sinc eac lin o thi fil i numbered yo ca LOAD it LIS it an LLIS i fro MBASIC I doe no RU ver wel though...) ..start monospace, last comment line 1 'Label listing of: NBR124.BAS 260 '[get filename] 380 '[next pass1 line] 590 '[print line] 650 '[make upper] 700 '[open error] 720 '[eval label] 750 '[end eval label] 770 '[lbl dbl def] 790 '[add to list] 810 '[check ptr in quotes] 870 '[save label num] 910 '[end save label num] 930 '[insert label nums] 980 '[get label] 1010 '[match label] 1030 '[print errmsg]