1 'MBEAUT.BAS MBASIC BEAUTIFIER FOR MBASIC VER 5.XX CP/M 2 'DERIVED FROM "FORMAT.BAS" FROM GFRN DATA EXCH (GARDEN GROVE) 3 'DOWNLOADED 5/19/82 AND NAE CHANGED TO AVOID CONFUSING WITH 4 'DISK INIT PROGRAMS. T. MC CORMICK. 6 GOTO 10 7 SAVE "MBEAUT.BAS",A:STOP 10 ' 20 ' 30 ' This program will beautify MBASIC (,A Ascii saved) 40 ' programs. It will not disturb source statement lines which 50 ' contain a colon (":") after an " IF " statement since 60 ' MBASIC logic would thereby be altered. Also the "IF" 70 ' must be properly delimited by spaces both in front, 80 ' and in back. (i.e. ) 90 ' 100 ' In addition to the above the prog. also 'SEGMENTS' 110 ' the input file by looking for the following key words: 120 ' ON ... GOTO 130 ' GOTO 140 ' RETURN 150 ' END 160 ' When (if) it finds one of these, it inserts two remark 170 ' lines--one of which contains a series of dashes. 180 ' 190 ' The prog. also indents 'FOR ... NEXT' loops as well 200 ' as all 'IF' statements. 210 ' 220 ' Please note that all of this expands the original 230 ' size so that the output file can become quite large if the 240 ' input file was heavily packed with multiple statements and 250 ' subroutines! 260 ' 270 ' THIS PROGRAM WILL NOT ALTER THE ORIGINAL FILE!! 280 ' 290 ' 300 ' N O T E S 310 ' 320 ' This program obtains its line number by checking 330 ' for the presence of a space between the line number and 340 ' the start of the statement. This space must be present! 350 ' 360 ' The variables MAX and MAX4 are set to the mamaximum 370 ' sizes of the input arrays. The numbers picked are arbitrary 380 ' and may be changed to suit your system requirements. (The 390 ' array sizes given in the DIM statement are constants since 400 ' BASCOM doesn't like variables in its DIM's) 410 ' 420 ' Since this program creates new line numbers by adding 430 ' one to the last known line number, it is advisable to renumber 440 ' the original program. This is to ensure that enough room 450 ' exists to add the new numbers. 460 ' 470 ' cml 480 ' 490 ' --------------------------------------------------------------------- 500 ' 510 R$=" '" 520 R1$=" ' --------------------------------------------------------------" 530 MAX = 100 540 MAX4 = 4*MAX 550 COLS=1 560 F=0 570 DIM M$(400),IN$(100) 572 FOR I=1 TO 25 : PRINT: NEXT I 595 INPUT "SOURCE FILE NAME ? ",W$ 600 INPUT "OUTPUT FILE NAME ? ",W1$ 610 PRINT 620 OPEN "I",#1,W$ 630 OPEN "O",#2,W1$ 640 N=0 650 M=0 660 FOR K=0 TO MAX 670 IF EOF(1) < 0 THEN 720 680 LINE INPUT #1,L$ 690 IN$(K)=L$ 700 L$="" 710 NEXT K 720 IF EOF(1) < 0 THEN ENDS=1 ELSE ENDS=0 730 IF ENDS=1 THEN MAX=K-1 740 L$=IN$(M) 750 L=LEN(L$) 760 M$(N)="" 770 I=INSTR(L$," ") 780 N$=LEFT$(L$,I-1) 790 NUM=VAL(N$) 800 IF INSTR(L$,":")=0 THEN 820 ELSE 810 810 IF MID$(L$,I+1,3)="'" THEN 820 ELSE 840 820 M$(N)=L$ 830 GOTO 1200 840 NUM=VAL(N$) 850 PRINT USING"* #####";NUM; 860 COLS=COLS+1 870 IF COLS > 10 THEN 880 ELSE 900 880 PRINT 890 COLS=1 900 M$(N)=N$ 910 Q=0 920 SP=0 930 FOR J = I TO L 940 IF MID$(L$,J,1)=CHR$(34) THEN Q=Q+1 950 IF Q=1 THEN 1150 960 IF Q=2 THEN Q=0 970 IF MID$(L$,J,1)=":" THEN 980 ELSE 1150 980 L1$="" 990 L1$=MID$(L$,I,J-I) 1000 IF INSTR(L1$," IF ") > 0 THEN 1150 ELSE 1010 1010 M$(N)=M$(N)+CHR$(13) 1020 GOSUB 1340 1030 N=N+1 1040 M$(N)="" 1050 NUM=NUM+1 1060 N$=STR$(NUM) 1070 IS=1 1080 IF MID$(N$,IS,1) = " " THEN 1090 ELSE 1110 1090 IS=IS+1 1100 GOTO 1080 1110 N$=MID$(N$,IS) 1120 M$(N)=N$+" " 1130 SP=1 1140 GOTO 1180 1150 IF SP=1 AND MID$(L$,J,1)=" " THEN 1180 ELSE 1160 1160 SP=0 1170 M$(N)=M$(N)+MID$(L$,J,1) 1180 NEXT J 1190 M$(N)=M$(N)+CHR$(13) 1200 GOSUB 1340 1210 N=N+1 1220 M=M+1 1230 IF M > MAX OR N > MAX4 THEN 1240 ELSE 740 1240 FOR N1=0 TO N-1 1250 IF M$(N1)="" THEN 1280 1260 GOSUB 1560 1270 PRINT #2,M$(N1) 1280 NEXT N1 1290 IF ENDS=0 THEN 640 1300 CLOSE 1310 END 1320 ' ---------------------------------------------------------------- 1330 ' 1340 ' 1350 I1=INSTR(M$(N)," ") + 1 1360 IF I1=1 THEN RETURN 1370 IF MID$(M$(N),I1,1)= " " THEN 1380 ELSE 1400 1380 I1=I1+1 1390 GOTO 1370 1400 IF MID$(M$(N),I1,5) = "GOTO " THEN 1450 1410 IF MID$(M$(N),I1,3)="ON " AND INSTR(I1,M$(N)," GOTO ") >0 THEN 1450 1420 IF MID$(M$(N),I1,6) = "RETURN" THEN 1450 1430 IF MID$(M$(N),I1,3) = "END" THEN 1450 1440 RETURN 1450 NUM=NUM+1 1460 N2$=STR$(NUM) 1470 N2$=MID$(N2$,2) 1480 NUM=NUM+1 1490 N3$=STR$(NUM) 1500 N3$=MID$(N3$,2) 1510 N=N+1 1520 M$(N)=N2$+R1$+CHR$(13) 1530 N=N+1 1540 M$(N)=N3$+R$+CHR$(13) 1550 RETURN 1560 I=INSTR(M$(N1)," ") 1570 IF MID$(M$(N1),I,1)=" " THEN 1580 ELSE 1600 1580 I=I+1 1590 GOTO 1570 1600 IF MID$(M$(N1),I,3) = "IF " THEN 1740 1610 IF MID$(M$(N1),I,4) = "FOR " THEN 1650 1620 IF MID$(M$(N1),I,5) = "NEXT " THEN 1670 1630 IF F=3 THEN 1710 1640 RETURN 1650 F=3 1660 GOTO 1680 1670 F=0 1680 IS=INSTR(M$(N1)," ") 1690 M$(N1)=LEFT$(M$(N1),IS) + " " + MID$(M$(N1),IS+1) 1700 RETURN 1710 IS=INSTR(M$(N1)," ") 1720 M$(N1)= LEFT$(M$(N1),IS) + " " + MID$(M$(N1),IS +1) 1730 RETURN 1740 IS=INSTR(M$(N1)," ") 1750 M$(N1)=LEFT$(M$(N1),IS) + " " + MID$(M$(N1),IS+1) 1760 RETURN M$(N1),IS +1) 1730 RETURN 1740 IS=INSTR(M$(N1)," ") 1750 M$(N1)=LEFT$(M$(N1),IS) + " " + MID$(M$(N1),IS