5 REM  MBXREF.BAS  MBASIC 5.2 [CP/M ver] Cross Reference Utility
6 REM  Downloaded from Prodigy Systems CBBS  5/17/81  T.E.M.
8 E$=CHR$(27):CLR$=E$+"E":PRINT CLR$
10 PRINT TAB(20);"MICROSOFT BASIC CROSS REFERENCE UTILITY."
20 PRINT:PRINT TAB(20);"LISTS ALL VARIABLES AND REFERENCED LINE #S."
23 PRINT:PRINT TAB(20);"MBASIC FILES MUST BE ASCII FOR THIS PROGRAM."
26 PRINT:PRINT TAB(20);"ENTER ONE OR MORE FILE NAMES, THEN JUST RETURN"
29 PRINT:PRINT TAB(20);"TO END THE LIST OF FILENAMES."
32 PRINT:PRINT TAB(20);"   ---> BE SURE LINE PRINTER IS READY."
50 '
60 CLEAR 3000 :DEFINT I-J : LW=80 : WIDTH 132
70 ON ERROR GOTO 1480
80 DIM	RW$(126), PT%(25), F$(10)
90 I=450 : DIM	VNXT%(540), V$(540), FRST%(450), LST%(450), RFL%(2250), NXT%(2250)
120 ' ...RESERVED WORDS - - - -
130 DATA ABS,AND,ASC,AS,ATN,AUTO,CDBL,CHR$,CINT,CLEAR,CLOSE,CONSOLE,CONT
140 DATA COS,CSNG,CVD,CVI,CVS,DATA
150 DATA DEFDBL,DEFINT,DEFSNG,DEFSTR,DEFUSR,DEF,DELETE,DIM,DSKI$,DSKO$,DSKF
160 DATA EDIT,ELSE,END,EOF,EQV,ERASE,ERL,ERR,EXP,FIELD,FILES,FIX,FOR
170 DATA FRE,GET,GOSUB,GOTO,HEX$
180 DATA IF,IMP,INPUT,INP,INSTR,INT,KILL,LEFT$,LEN,LET,LINE
190 DATA LIST,LLIST,LOAD,LOC,LOF,LOG,LPRINT,LSET,MERGE,MID$,MKD$,MKI$
200 DATA MKS$,MOD,MOUNT,NAME,NEW,NEXT,NOT,NULL,OCT$,ON,OPEN,OR,OUT
210 DATA PEEK,POKE,POS,PRINT,PUT
220 DATA READ,REM,RENUM,RESET,RESTORE,RESUME,RETURN,RIGHT$,RND,RSET,RUN
230 DATA SAVE,SGN,SIN,SPACE$,SPC(,SQR,STEP,STOP,STR$,STRING$,SWAP
240 DATA TAB(,TAN,THEN,TO,TROFF,TRON,UNLOAD
250 DATA USING,USR,VAL,VARPTR,WAIT,WIDTH,XOR,"\"
260 '
270 '...FILL ARRAY WITH RESERVED WORDS
280 '
290 RW=0
300 READ RW$
310 RW=RW+1 : RW$(RW)=RW$ : IF RW$="\" THEN 350
320 I=ASC(RW$)-ASC("A") : IF PT%(I)=0 THEN PT%(I)=RW
330 GOTO 300
340 '
350 FOR I=1 TO 25 : IF PT%(I)=0 THEN PT%(I)=RW
360 NEXT I
370 '
380 '...GET LIST OF NAMES
390 '
400 FX=0
410 PRINT : PRINT TAB(20);"   ---> ASCII SAVED PROGRAM #" FX+1 " = "; : LINE INPUT L$
420 IF L$="" THEN IF FX<1 THEN 570 ELSE 480
440 NAME L$ AS L$
450 FX=FX+1 : F$(FX)=L$
460 GOTO 410
470 '
480 PRINT:PRINT TAB(20);: INPUT "   ---> DATE = "; D$
483 PRINT:PRINT TAB(20);"NOW INDICATE WHETHER YOU WISH:"
485 PRINT TAB(25);"- A PRINTED CROSS-REFERENCE LISTING(S)"
486 PRINT TAB(25);"- A PRINTED PROGRAM SOURCE LISTING(S)"
487 PRINT TAB(25);"......OR BOTH."
490 PRINT:PRINT TAB(20);: INPUT "1) CROSS REFERENCE   2) LIST   3) BOTH "; M
500 '
510 '...PROCESS LIST OF NAME FILES
520 '
530 FOR F=1 TO FX
540 CLOSE : OPEN "I",1,F$(F) : PRG$="'"+F$(F)+"'   -   "+D$ : GOSUB 610
550 NEXT F
560 LPRINT STRING$(65-LZ,CHR$(10))
570 END
580 '
590 '...INITIALIZE CROSS REFERENCE
600 '
610 LC=0 : BC=0 : PZ=0 : V$="" : C$="" : VC=91 : RC=-1
620 FOR I=1 TO 91 : VNXT%(I)=-1 : NEXT I
630 IF M>1 THEN GOSUB 1520
640 '
650 '...INPUT LINE AND EXTRACT LINE NUMBER
660 '
670 IF EOF(1) THEN 1200
680 LINE INPUT #1, L$ : IF M>1 THEN GOSUB 1430 : IF M=2 THEN 670
690 LG=LEN(L$) : BRNCH=0 : ER$="" : LC=LC+1 : BC=BC+LG
700 LP=INSTR(L$," ") : LN=VAL(LEFT$(L$,LP)) : PRINT LN,
710 IF LN>32767 THEN LN=LN-65536!
720 '
730 '...PARSE REST OF LINE
740 '
750 LP=LP+1 : IF LP>LG THEN GOSUB 1010 : GOTO 670
760 C$=MID$(L$,LP,1)
770 IF C$>="A" AND C$<="Z" THEN 890 ELSE IF C$>="0" AND C$<="9" THEN 1150
780 IF C$=" " THEN 750 ELSE IF C$<>"," THEN BRNCH=0
790 IF C$=CHR$(34) THEN GOSUB 1010 : LP=INSTR(LP+1,L$,C$) : IF LP>0 THEN 750 ELSE 670
800 IF C$="'" THEN GOSUB 1010 : GOTO 670
810 IF C$="&" THEN GOSUB 1010 : V$=C$ : GOTO 750
820 IF C$="$" OR C$="!" OR C$="%" OR C$="#" THEN GOSUB 1130 : GOTO 750
830 IF C$="(" THEN GOSUB 1130
840 GOSUB 1010 : IF C$<>"," THEN ER$=""
850 GOTO 750
860 '
870 '...TEST FOR COMMAND
880 '
890 C=ASC(C$) : P=PT%(C-ASC("A")) : BRNCH=0
900 IF C<ASC(RW$(P)) THEN 1160
910 IF INSTR(LP,L$,RW$(P))<>LP THEN P=P+1 : GOTO 900
920 GOSUB 1010 : RW$=RW$(P)
930 IF RW$="DATA" THEN LP=INSTR(LP,L$,":") : IF LP>0 THEN 750 ELSE 670
940 IF RW$="REM" THEN 670
950 IF RW$="GOTO" OR RW$="GOSUB" OR RW$="THEN" OR RW$="ELSE" OR RW$="RESUME" THEN BRNCH=1
960 IF RW$="ERASE" THEN ER$="(" ELSE ER$=""
970 LP=LP+LEN(RW$)-1 : GOTO 750
980 '
990 '...END VARIABLE
1000 '
1010 IF V$="" THEN RETURN
1020 IF V$>="A" THEN V$=V$+ER$ : C=ASC(V$)+1 ELSE IF V$>="0" THEN V$=RIGHT$("    "+V$,5) : C=VAL(LEFT$(V$,2)) ELSE 1090
1030 IL=-1 : I=C
1040 IF V$>V$(I) THEN IL=I : I=VNXT%(I) : IF I>0 THEN 1040 ELSE 1060
1050 IF V$=V$(I) THEN J=LST%(I-91) : IF RFL%(J)=LN THEN 1090 ELSE RC=RC+1 : NXT%(J)=RC : GOTO 1080
1060 VC=VC+1 : IF IL>=0 THEN VNXT%(IL)=VC
1070 V$(VC)=V$ : VNXT%(VC)=I : RC=RC+1 : FRST%(VC-91)=RC : I=VC
1080 RFL%(RC)=LN : NXT%(RC)=-1 : LST%(I-91)=RC
1090 V$="" : RETURN
1100 '
1110 '...EXPAND VARIABLE
1120 '
1130 IF V$<>"" THEN V$=V$+C$
1140 RETURN
1150 IF V$="" AND BRNCH=0 THEN 750
1160 V$=V$+C$ : GOTO 750
1170 '
1180 '...LIST VARIABLES
1190 '
1200 IF M=2 THEN RETURN
1210 PZ=0 : GOSUB 1400
1220 FOR J=0 TO 91 : V=J
1230 V=VNXT%(V) : IF V<=0 THEN 1340
1240 IF LZ>56 THEN GOSUB 1400 ELSE SZ=SZ+1 : IF SZ=3 THEN GOSUB 1410
1250 RZ=0 : I=FRST%(V-91) : LPRINT V$(V);
1260 IF RZ=0 THEN LPRINT TAB(16);
1270 LN=RFL%(I) : IF LN<0 THEN LN=LN+65536!
1280 LPRINT USING "    #####";LN,
1290 RZ=RZ+1
1300 IF RZ>6 THEN RZ=0 : LPRINT : LZ=LZ+1 : IF LZ>56 THEN GOSUB 1400
1310 I=NXT%(I) : IF I>0 THEN 1260
1320 IF RZ>0 THEN LPRINT : LZ=LZ+1
1330 GOTO 1230
1340 NEXT J
1350 '
1360 LPRINT STRING$(80,"=")
1370 LPRINT "LINES: " LC "     BYTES: " BC "     SYMBOLS: " VC-91 "     REFERENCES: " RC+1
1380 LZ=LZ+2 : RETURN
1390 '
1400 GOSUB 1520 : LPRINT "SYMBOL" TAB(20) "REFERENCE LINE" : LZ=LZ+1
1410 LPRINT STRING$(80,"-") : LZ=LZ+1 : SZ=0 : RETURN
1420 '
1430 X=1
1440 IF LZ>60 OR RIGHT$(L$,3)="'PG" THEN GOSUB 1520
1450 Y=INSTR(X,L$,CHR$(10)) : IF Y>0 THEN LPRINT MID$(L$,X,Y-X) : LZ=LZ+1 : X=Y+1 : GOTO 1450
1460 LPRINT MID$(L$,X,LW) : LZ=LZ+1 : X=X+LW : IF X<LEN(L$) THEN 1460 ELSE RETURN
1470 '
1480 IF ERR=53 THEN PRINT : PRINT "FILE NOT FOUND" : RESUME 410
1490 IF ERR=58 THEN RESUME 450
1500 ON ERROR GOTO 0
1510 '
1520 LPRINT STRING$(65-LZ,CHR$(10))
1530 PZ=PZ+1 : LPRINT TAB(72) "PAGE" PZ
1540 LPRINT PRG$ : LPRINT
1550 LZ=3 : RETURN : REM ------- END OF PROGRAM --------

1530 PZ=PZ+1 : LPRINT TAB(72) "PAGE" PZ
1540 LPRINT