And "with the little help of my..." 15 lines plain(+TK2)SuperBasic FuNction, never bother about line numbers or renumbering :
AddLineNumbers_bas
Code: Select all
11 DEFine FuNction add_line_numbers(f$,first,interval)
12 input_file$ = dev$ & f$ & "_txt"
13 output_file$ = dev$ & f$ & "_bas"
14 OPEN_IN#5,input_file$
15 OPEN_OVER#6,output_file$
16 l = first : i = interval
17 REPeat number
18 INPUT#5,l$ : k = LEN(l$) : IF k > 1 THEN
19 IF CODE(l$(k))=13 THEN k = k-1
20 IF k > 0 THEN PRINT#6,IDEC$(l,5,0);" ";l$( 1 TO k )
21 ELSE i = 0 : END IF
22 IF EOF(#5) THEN EXIT number : ELSE l = l+i : i = interval
23 END REPeat number
24 CLOSE#6 : CLOSE#5 : RETurn l
25 END DEFine add_line_numbers
Give it a file name of a SuperBasic program without line numbers prefixed by a DEV$ and suffixed with "_txt" and it wil create (or overwrite) a line-numbered SuperBasic program file on the same DEV$ and suffixed with "_bas" : with given first line and interval. I coded it as a FuNction so that it could return the last line number.
Now suppose that you have split a SuperBasic program PROG into let's say 4 modules called PROG1..PROG4, in files without line numbers, because you may change or modify some modules while developping the program.
So,"with the little help of your..." SuperBasic file without line numbers (here in its simplest "_text" form !)
MakeProg_txt
Code: Select all
Linc = 10
R = add_line_numbers("Prog1",100,Linc)
MERGE DEV$ & "Prog1_bas"
R = add_line_numbers("Prog2",R+Linc,Linc)
MERGE DEV$ & "Prog2_bas"
R = add_line_numbers("Prog3",R+Linc,Linc)
MERGE DEV$ & "Prog3_bas"
R = add_line_numbers("Prog4",R+Linc,Linc)
MERGE DEV$ & "Prog4_bas"
PRINT R : STOP
You put it through the add_line_numbers to get a corresponding "_bas" file, you merge it and then run it to fetch all the (un-numbered) SuperBasic source modules of PROG1..PROG4, put them through the add_line_numbers and merge them together on the spot.
MakeProg_bas
Code: Select all
1 Linc = 10
2 R = add_line_numbers("Prog1",100,Linc)
3 MERGE DEV$ & "Prog1_bas"
4 R = add_line_numbers("Prog2",R+Linc,Linc)
5 MERGE DEV$ & "Prog2_bas"
6 R = add_line_numbers("Prog3",R+Linc,Linc)
7 MERGE DEV$ & "Prog3_bas"
8 R = add_line_numbers("Prog4",R+Linc,Linc)
9 MERGE DEV$ & "Prog4_bas"
10 PRINT R : STOP
All automatically ! No problem, even if the size of some modules varied.
And to do it again and again(in this simple case), you may just save all that you need in this file :
MakeProg_etc
Code: Select all
1 Linc = 10
2 R = add_line_numbers("Prog1",100,Linc)
3 MERGE DEV$ & "Prog1_bas"
4 R = add_line_numbers("Prog2",R+Linc,Linc)
5 MERGE DEV$ & "Prog2_bas"
6 R = add_line_numbers("Prog3",R+Linc,Linc)
7 MERGE DEV$ & "Prog3_bas"
8 R = add_line_numbers("Prog4",R+Linc,Linc)
9 MERGE DEV$ & "Prog4_bas"
10 PRINT R : STOP
11 DEFine FuNction add_line_numbers(f$,first,interval)
12 input_file$ = DEV$ & f$ & "_txt"
13 output_file$ = DEV$ & f$ & "_bas"
14 OPEN_IN#5,input_file$
15 OPEN_OVER#6,output_file$
16 l = first : i = interval
17 REPeat number
18 INPUT#5,l$ : k = LEN(l$) : IF k > 1 THEN
19 IF CODE(l$(k))=13 THEN k = k-1
20 IF k > 0 THEN PRINT#6,IDEC$(l,5,0);" ";l$( 1 TO k )
21 ELSE i = 0 : END IF
22 IF EOF(#5) THEN EXIT number : ELSE l = l+i : i = interval
23 END REPeat number
24 CLOSE#6 : CLOSE#5 : RETurn l
25 END DEFine add_line_numbers
However, you understand that "MakeProg" is just another SuperBasic program that may be adapted to more complex situations, using all the power of the SuperBasic langage (conditionnal line adding and merging, etc.).
Note also that the add_line_numbers "_bas" shown above came itself from a "_txt" file maybe with blank lines or spurious CR characters all automatically removed but that the indentations were conserved. This file actually :
AddLineNumbers_txt
Code: Select all
DEFine FuNction add_line_numbers(f$,first,interval)
input_file$ = dev$ & f$ & "_txt"
output_file$ = dev$ & f$ & "_bas"
OPEN_IN#5,input_file$
OPEN_OVER#6,output_file$
l = first : i = interval
REPeat number
INPUT#5,l$ : k = LEN(l$) : IF k > 1 THEN
IF CODE(l$(k))=13 THEN k = k-1
IF k > 0 THEN PRINT#6,IDEC$(l,5,0);" ";l$( 1 TO k )
ELSE i = 0 : END IF
IF EOF(#5) THEN EXIT number : ELSE l = l+i : i = interval
END REPeat number
CLOSE#6 : CLOSE#5 : RETurn l
END DEFine add_line_numbers
When selecting this code and try to view it in a QL, you will see the CR characters before they are erased by the add_line_numbers FuNction. The blank lines are supressed too.