REFORMAT - BASIC REFORMATTER 26 May 2010 This program takes an Altair BASIC Program, saved in Ascii, as input. REFORMAT outputs a version of the input program that is more readable. REFORMAT has been optimized by CRUNCHER. REFJUN1.TXT is the crunched REFORMAT reformatted by REFORMAT. Tom Sanderson www.virtualaltair.com 10 ' 11 ' 12 ' 13 ' 19 ' 20 CLEAR12000 30 ONERRORGOTO65000' 40 DEFINTA-Z' 50 PRINT:PRINT"BASIC REFORMATTER":PRINT 60 GOSUB1000' 70 GOSUB2000' 80 GOSUB3000' 90 GOSUB4000' 100 PRINT:PRINT"END OF REFORMATTING":PRINT 110 ONERRORGOTO0' 120 CLEAR200' 999 END 1000 ' 1010 LC=0' 1020 PS=65' 1030 RS=60' 1040 PT=4' 1050 LF$=CHR$(10)' 1060 CH$="EOS"' 1070 OL$=""' 1080 CR$=CHR$(13)' 1090 QT$=CHR$(34)' 1100 KEY$="N"' 1999 RETURN 2000 ' 2010 PRINT:INPUT"ENTER THE INPUT FILE NAME. ";IN$:PRINT 2020 AF$="Y" 2030 PRINT:INPUT"WAS THIS FILE SAVED WITH THE 'A' OPTION? (ENTER N FOR N O OR RETURN FOR YES) ";AF$:PRINT 2038 IFAF$="NO"THENAF$="N" 2039 IFAF$="YES"THENAF$="Y" 2040 IFAF$="Y"THENGOTO2050ELSEIFAF$<>"N"THENGOTO2030 2045 PRINT:PRINT"SAVE THE FILE USING THE 'A' OPTION AND TRY AGAIN.":PRIN T 2050 ID=1' 2060 INPUT" ENTER INPUT DISK NUMBER (DEFAULT = 1) ";ID 2070 OPEN"I",#1,IN$,ID 2080 LPRINT:LPRINT:LPRINT"**** FILE ";IN$;" ON DISK ";ID;"REFORMATTED":L PRINT:LPRINT:LC=LC+5 2999 RETURN 3000 ' 3010 GOSUB8000' 3015 IFCH$="EOF"THENGOTO3999 3020 GOSUB22000' 3030 GOSUB10000' 3040 GOTO3010' 3999 RETURN 4000 ' 4010 CLOSE1' 4020 GOSUB5000' 4999 RETURN 5000 ' 5010 FORI=LCTOPSSTEP1:LPRINT:NEXTI' 5020 LC=0' 5999 RETURN 6000 ' 6010 IFLC0THENIR $=RIGHT$(IR$,SL) 8999 RETURN 9000 ' 9001 GOSUB14000' 9002 GOSUB15000' 9003 RETURN 9004 ' 9005 ' 9006 IFCH$="'"THENGOSUB13000:RETURN' 9007 ' 9008 IFCH$=QT$THENGOSUB12000:RETURN' 9009 ' 9010 IFCH$=LF$THENLC=LC+1:RETURN' 9019 ' 9020 IFCH$=":"THENLPRINTOL$:LC=LC+1:GOSUB6000:OL$="":CH$=":"+SPACE$(LL-1 ):RETURN 9025 ' 9030 IFCH$="+"THENCH$=" + ":RETURN 9040 IFCH$=";"THENCH$="; ":RETURN 9050 IFCH$=","THENCH$=", ":RETURN 9060 IFCH$="-"THENCH$=" - ":RETURN 9065 ' 9070 NC$=LEFT$(IR$,1)' 9080 IFCH$="="THENOL$=OL$+" "+CH$:CH$=" ":IF(NC$=">")OR(NC$="<")THENGOSU B8000:OL$=OL$+CH$:CH$=" "ELSERETURN:RETURN 9090 IFCH$="<"THENOL$=OL$+" "+CH$:CH$=" ":IF(NC$=">")OR(NC$="=")THENGOSU B8000:OL$=OL$+CH$:CH$=" "ELSERETURN:RETURN 9100 IFCH$=">"THENOL$=OL$+" "+CH$:CH$=" ":IFNC$="="THENGOSUB8000:OL$=OL$ +CH$:CH$=" "ELSERETURN:RETURN 9999 RETURN 10000 ' 10010 IFCH$<>"EOS"THENOL$=OL$+CH$ELSELPRINTOL$:LC=LC+1:GOSUB6000:OL$="" 10999 RETURN 11000 ' 11001 OUT8,15 11002 SL=LEN(IR$) 11010 '' 11015 IFIR$=""THENRETURN 11020 LN$=LEFT$(IR$,INSTR(IR$," ")) 11030 LL=LEN(LN$) 11040 OL$=OL$+LN$ 11050 SL=SL-LL 11060 IR$=RIGHT$(IR$,SL) 11999 RETURN 12000 ' 12010 OL$=OL$+CH$' 12020 GOSUB8000' 12030 IFCH$="EOS"THENERROR(100):RETURN' 12040 IFCH$<>QT$THENGOTO12010 12999 RETURN 13000 ' 13010 OL$=OL$+CH$' 13020 GOSUB8000' 13030 IFCH$<>"EOS"THENGOTO13010 13999 RETURN 14000 ' 14010 IFSL<2THENRETURN 14020 IF(CH$+LEFT$(IR$,2))="REM"THENGOSUB13000' 14030 IFSL<3THENRETURN 14040 T4$=CH$+LEFT$(IR$,3)' 14050 IFT4$="THEN"THENOL$=OL$+" ":RETURN' 14060 IFT4$="ELSE"THENOL$=OL$+" ":RETURN' 14070 IFT4$="DATA"THENGOSUB13000:RETURN' 14080 IFT4$="STEP"THENOL$=OL$+" ":RETURN' 14999 RETURN 15000 ' 15010 OL=LEN(OL$) 15020 IFOL<1THENRETURN 15030 T2$=RIGHT$(OL$,1)+CH$ 15040 GOSUB16000' 15045 IFKEY$="Y"THENGOTO15990 15050 IFOL<2THENRETURN 15060 T3$=RIGHT$(OL$,2)+CH$ 15070 GOSUB17000' 15075 IFKEY$="Y"THENGOTO15990 15080 IFOL<3THENRETURN 15090 T4$=RIGHT$(OL$,3)+CH$ 15100 GOSUB18000' 15105 IFKEY$="Y"THENGOTO15990 15110 IFOL<4THENRETURN 15120 T5$=RIGHT$(OL$,4)+CH$ 15130 GOSUB19000' 15135 IFKEY$="Y"THENGOTO15990 15140 IFOL<5THENRETURN 15150 T6$=RIGHT$(OL$,5)+CH$ 15160 GOSUB20000' 15165 IFKEY$="Y"THENGOTO15990 15170 IFOL<6THENRETURN 15180 T7$=RIGHT$(OL$,6)+CH$ 15190 GOSUB21000 15195 IFKEY$="Y"THENGOTO15990 15990 KEY$="N" 15999 RETURN 16000 ' 16010 IFT2$="IF"THENGOTO16500 16490 RETURN 16500 CH$=CH$+" " 16999 RETURN 17000 ' 17010 IFT3$="FOR"THENGOTO17500 17020 IFT3$="DIM"THENGOTO17500 17030 IFT3$="AND"THENGOTO17500 17040 IFT3$="GET"THENGOTO17500 17050 IFT3$="PUT"THENGOTO17500 17060 IFT3$="NOT"THENGOTO17500 17070 IFT3$="LET"THENGOTO17500 17080 IFT3$="OUT"THENGOTO17500 17490 RETURN 17500 CH$=CH$+" " 17510 KEY$="Y" 17999 RETURN 18000 ' 18010 IFT4$="GOTO"THENGOTO18500 18020 IFT4$="THEN"THENGOTO18500 18030 IFT4$="ELSE"THENGOTO18500 18040 IFT4$="STEP"THENGOTO18500 18050 IFT4$="LOAD"THENGOTO18500 18060 IFT4$="NEXT"THENGOTO18500 18070 IFT4$="POKE"THENGOTO18500 18080 IFT4$="PEEK"THENGOTO18500 18090 IFT4$="READ"THENGOTO18500 18100 IFT4$="WAIT"THENGOTO18500 18110 IFT4$="OPEN"THENGOTO18500 18120 IFT4$="LINE"THENGOTO18500 18130 IFT4$="LSET"THENGOTO18500 18140 IFT4$="RSET"THENGOTO18500 18150 IFT4$="SWAP"THENGOTO18500 18490 RETURN 18500 CH$=CH$+" " 18510 KEY$="Y" 18999 RETURN 19000 ' 19010 IFT5$="CLEAR"THENGOTO19500 19020 IFT5$="ERROR"THENGOTO19500 19030 IFT5$="GOSUB"THENGOTO19500 19040 IFT5$="PRINT"THENGOTO19500 19050 IFT5$="WIDTH"THENGOTO19500 19060 IFT5$="CLOSE"THENGOTO19500 19070 IFT5$="ERASE"THENGOTO19500 19080 IFT5$="USING"THENGOTO19500 19090 IFT5$="MOUNT"THENGOTO19500 19100 IFT5$="INPUT"THENGOTO19500 19110 IFT5$="FIELD"THENGOTO19500 19490 RETURN 19500 CH$=CH$+" " 19510 KEY$="Y" 19999 RETURN 20000 ' 20010 IFT6$="LPRINT"THENGOTO20500 20020 IFT6$="RESUME"THENGOTO20500 20030 IFT6$="UNLOAD"THENGOTO20500 20040 IFT6$="DEFDBL"THENGOTO20500 20050 IFT6$="DEFINT"THENGOTO20500 20060 IFT6$="DEFSNG"THENGOTO20500 20070 IFT6$="DEFSTR"THENGOTO20500 20490 RETURN 20500 CH$=CH$+" " 20510 KEY$="Y" 20999 RETURN 21000 ' 21010 IFT7$="CONSOLE"THENGOTO21500 21490 RETURN 21500 CH$=CH$+" " 21510 KEY$="Y" 21999 RETURN 22000 ' 22010 IFCH$=" "THENGOSUB8000:GOTO22010' 22020 IF((CH$<"A")OR(CH$>"z")OR(CH$>"Z")AND(CH$<"a"))THENGOSUB9004ELSEGO SUB9000 22999 RETURN 65000 ' 65010 IFERR<>100THENGOTO65020 65011 PRINT:PRINT"**** UNMATCHED QUOTES IN THE LINE BELOW.":PRINT 65012 LPRINT:LPRINT"**** UNMATCHED QUOTES IN THE LINE BELOW.":LPRINT:LC= LC+3 65013 RESUME12999 65020 IF(ERL<>11020)OR(ERR<>5)THENGOTO65030 65021 PRINT:PRINT"**** NO LINE NUMBER FOUND IN LINE BELOW.":PRINTIR$:PRI NT 65022 LPRINT:LPRINT"**** NO LINE NUMBER FOUND IN THE LINE BELOW.":LPRINT IR$:LPRINT:LC=LC+4 65023 SL=0:RESUME11999 65030 '' 65080 PRINT" **** ERROR NUMBER ";ERR;" IN LINE ";ERL 65090 RESUME90' 65099 RETURN