Pretty_bas

See all articles from QL_DOC n1
Author(s): Réal Gagnon
Publication: QL_DOC
Pub Details: QL_DOC n1 (Issue 1)
Date: January 1988
Pages: 4-6

In English: PRETTY_BAS, a SuperBASIC utility that rewrites a program file with its listing indented to show the structure of procedures, loops and IF blocks. A before-and-after example shows the effect, and the full listing (marked "enhanced version -mtl") follows; it asks for a source file and an optional destination name.

The article below is in French, as printed in QL_DOC n1 (January 1988).


PRETTY_BAS est un programme qui transforme vos programmes en les rendant plus lisibles. Ceci est fait avec l’indentation du “listing”. Ainsi si nous prenons le programme suivant:

10 DEFine PROCedure prog
20 FOR i=0 TO 5
30 test
40 END FOR i
50 END DEFine
60 :
100 DEFine PROCedure test
110 IF i=5
120 PRINT "C'est la fin"
130 ELSE
140 PRINT i
160 END DEFine

PRETTY_BAS le transformera de la façon suivante:

10 DEFine PROCedure prog
20 FOR i=0 TO 5
30 test
40 END FOR i
50 END DEFine
60 :
100 DEFine PROCedure test
110 IF i=5
120 PRINT "C'est la fin!"
130 ELSE
140 PRINT i
150 END IF
160 END DEFine

Pour démarrer le programme faites LRUN xxxx_PRETTY_BAS. La première question à répondre est le nom du programme à transformer, ensuite le nom du nouveau programme, si on desire tout simplement garder le même nom, on tape ENTER. Voilà c’est tout! Il est important de mettre le nom du “device” ( flp1_, mdv1_, … ) lorsque l’on donne le nom du fichier.

100 REMark PRETTY PRINT ROUTINE
110 REMark enhanced version -mtl
120 :
130 DEFine PROCedure update
140 DELETE flp1_pretty_bas
150 SAVE flp1_pretty_bas
160 END DEFine
170 :
180 WINDOW 512,256,0,0
190 PAPER 0:CLS
200 CSIZE 2,1: PRINT ' **PRETTY_LIST**': CSIZE 0,0
210 WINDOW 220,175,115,42: PAPER 32: CLS
220 PAPER 0: INK 7
230 OPEN#5,con_200x50a125x50: PAPER#5,2: BORDER#5,1,7: INK#5,0: CLS#5
240 OPEN#6,scr_400X50a40x105: PAPER#6,4: BORDER#6,2,2: INK#6,0: CLS#6
250 OPEN#7,scr_400x50a40x160: PAPER#7,7: BORDER#7,2,4: INK#7,0: CLS#7
260 :
270 INPUT#5,'SOURCE (ex. mdv1_prog_bas) ?',source$
280 INPUT#5,'DESTINATION ( ENTER si le même)?',dest$
290 :
300 IF (dest$ = '' OR dest$ = source$ )
310 dest$ = source$
320 source$ = source$ & '_temp'
330 COPY dest$ TO source$
340 DELETE dest$
350 temp = 1
360 ELSE
370 temp = 0
380 END IF
390 OPEN_IN #3,source$
400 DELETE dest$
410 OPEN_NEW #4,dest$
420 spc = 1
430 REPeat loop
440 IF EOF(#3) THEN EXIT loop
450 INPUT #3,line$
460 PRINT#6,line$
470 num line$
480 before = 0: after = 0
490 spaces line$
500 spc = spc - before
510 IF spc < 0 : spc = 0
520 PRINT #4,FILL$(' ',spc);line$
530 PRINT#7,FILL$(' ',spc);line$
540 spc = spc + after
550 END REPeat loop
560 CLOSE #3
570 CLOSE #4
580 CLOSE#5: CLOSE#6: CLOSE#7
590 IF temp THEN DELETE source$
600 STOP
610 :
620 DEFine PROCedure num(a$)
630 LOCal n$,i
640 n$ = ' ' : i = 1
650 REPeat loop2
660 IF a$(i) <> ' ' THEN EXIT loop2
670 i = i + 1
680 END REPeat loop2
690 REPeat loop3
700 IF a$(i) <'0' OR a$(i) >'9' THEN EXIT loop3
710 n$ = n$ & a$(i)
720 i = i + 1
730 END REPeat loop3
740 PRINT #4,FILL$(' ',6 - LEN(n$));n$;
750 PRINT#7,FILL$(' ',6 - LEN(n$));n$;
760 REPeat loop4
770 IF a$(i)<> ' ' THEN EXIT loop4
780 i = i + 1
790 END REPeat loop4
800 a$ = a$(i TO )
810 END DEFine
820 :
830 DEFine PROCedure spaces(l$)
840 LOCal n,colon,tmin,stmt$
850 RESTORE
860 FOR n = 1 TO 10
870 READ stmt$
880 IF l$(1 TO LEN(stmt$)) = stmt$ THEN EXIT n
890 END FOR n
900 colon = ':' INSTR l$
910 IF colon = LEN(l$) THEN colon = 0
920 SELect ON n
930 = 1,2
940 diff 1,1
950 IF colon THEN spaces l$(':' INSTR l$ + 1 TO)
960 = 3 TO 6
970 IF NOT colon THEN diff 0,2
980 =7
990 tmin = 'THEN' INSTR l$
1000 IF tmin THEN tmin = LEN(l$) > tmin + 4
1010 IF NOT ( colon OR tmin ) THEN diff 0,2
1020 =8 : diff 2,2
1030 = 9 : diff 2,0
1040 END SELect
1050 END DEFine
1060 :
1070 DEFine PROCedure diff(a,b)
1080 before = before + a
1090 after = after + b
1100 END DEFine
1110 :
1120 DATA '=','ON','REPeat','FOR','DEFine'
1130 DATA 'SELect','IF','ELSE','END','*'
1140 END DEFine

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.