Post by tsh73 on Jun 18, 2021 20:40:19 GMT
(resurfaced at
justbasiccom.proboards.com/thread/685/using-line-numbers
)
As you probably know, REMLINE.BAS is original program from Microsoft
disigned to remove unused line numbers
(really handy then converting some older BASIC with line numbers to JB)
Original program called REMLINE.BAS, my copy size 12 318 bytes, 398 lines
Starts with LOOONG comment (41 lines!)
And indeed it needs some heavy adapting to JB
I pretty sure someone already did that - but I apparently do not have it.
Here is code from www.qb64.net adapted to JB
(it is much smaller, 92 lines, 3064 bytes.)
Under the code attribution is written
While testing, I found one problem with it:
it does not supports things like
- so on this case, it preserved first number (770) but deleted other two.
Anyway JB does not support this construction either, so if you encounter this, you will have to rewrite it somehow.
Here it is
Since it attempts to rewrite source program, having backup is a wise move.
justbasiccom.proboards.com/thread/685/using-line-numbers
)
As you probably know, REMLINE.BAS is original program from Microsoft
disigned to remove unused line numbers
(really handy then converting some older BASIC with line numbers to JB)
Original program called REMLINE.BAS, my copy size 12 318 bytes, 398 lines
Starts with LOOONG comment (41 lines!)
'
' Microsoft RemLine - Line Number Removal Utility
' Copyright (C) Microsoft Corporation 1985-1990
'
' REMLINE.BAS is a program to remove line numbers from Microsoft Basic
' Programs. It removes only those line numbers that are not the object
' of one of the following statements: GOSUB, RETURN, GOTO, THEN, ELSE,
' RESUME, RESTORE, or RUN.
'
And indeed it needs some heavy adapting to JB
I pretty sure someone already did that - but I apparently do not have it.
Here is code from www.qb64.net adapted to JB
(it is much smaller, 92 lines, 3064 bytes.)
Under the code attribution is written
Code courtesy of Pete from the Network 54 Qbasic Forum
While testing, I found one problem with it:
it does not supports things like
ON ME(J) GOSUB 770,720,640
- so on this case, it preserved first number (770) but deleted other two.
Anyway JB does not support this construction either, so if you encounter this, you will have to rewrite it somehow.
Here it is
Since it attempts to rewrite source program, having backup is a wise move.
'from
'http://www.qb64.net/wiki/index-php/Line_number/
' Code courtesy of Pete from the Network 54 Qbasic Forum
'adaptation to JB by tsh73, may 2021
CLS
REDIM linenumber(100000)
PRINT "This Program removes unnecessary line numbers.": PRINT
INPUT "Name of file: "; filename$: PRINT
OPEN filename$ FOR INPUT AS #1
DO UNTIL EOF(#1)
LINE INPUT #1, a$
REM Get rid of quotes and REM statements.
DO while 1
IF INSTR(a$, CHR$(34)) <> 0 THEN
IF INSTR(a$, CHR$(34), INSTR(a$, CHR$(34)) + 1 ) = 0 THEN EXIT DO: REM Mismatched quotes. Illegal code.
a$ = MID$(a$, 1, INSTR(a$, CHR$(34)) - 1) + MID$(a$, INSTR(a$, CHR$(34), INSTR(a$, CHR$(34)) + 1) + 1)
ELSE
EXIT DO
END IF
LOOP
IF INSTR( upper$(a$), "REM ") <> 0 THEN a$ = MID$(a$, 1, INSTR( upper$(a$), "REM "))
IF INSTR( upper$(a$), "' ") <> 0 THEN a$ = MID$(a$, 1, INSTR(a$, "' "))
DO while 1
flag = 0
REM Break down compound statements and get line numbers.
IF INSTR(a$, "GOTO ") <> 0 THEN flag = 1: n = INSTR(a$, "GOTO ") + 5: GOSUB [tracknumber]
IF INSTR(a$, "GOSUB ") <> 0 THEN flag = 1: n = INSTR(a$, "GOSUB ") + 6: GOSUB [tracknumber]
IF INSTR(a$, "THEN ") <> 0 THEN flag = 1: n = INSTR(a$, "THEN ") + 5: GOSUB [tracknumber]
IF INSTR(a$, "ELSE ") <> 0 THEN flag = 1: n = INSTR(a$, "ELSE ") + 5: GOSUB [tracknumber]
IF INSTR(a$, "RUN ") <> 0 THEN flag = 1: n = INSTR(a$, "RUN ") + 4: GOSUB [tracknumber]
IF INSTR(a$, "RESUME ") <> 0 THEN flag = 1: n = INSTR(a$, "RESUME ") + 7: GOSUB [tracknumber]
IF INSTR(a$, "RETURN ") <> 0 THEN flag = 1: n = INSTR(a$, "RETURN ") + 7: GOSUB [tracknumber]
IF flag = 0 THEN EXIT DO ELSE a$ = MID$(a$, n)
LOOP
LOOP
PRINT "Number of line-numbered statements kept:"; count
CLOSE #1
OPEN filename$ FOR INPUT AS #1
OPEN "filename.tmp" FOR OUTPUT AS #2
DO UNTIL EOF(#1)
LINE INPUT #1, a$
flag = 0
IF VAL(MID$(a$, 1, 1)) <> 0 THEN
FOR i = 1 TO count
IF VAL(a$) = linenumber(i) THEN flag = 1: EXIT FOR
NEXT
IF flag = 0 THEN a$ = MID$(a$, INSTR(a$, " ") + 1)
END IF
PRINT #2, a$
LOOP
CLOSE #1
CLOSE #2
run "notepad.exe filename.tmp"
PRINT
PRINT "Back up original file as .org and give edited file original file name? [Y/N]"
DO while 1
'b$ = upper$(INKEY$)
b$ = upper$(input$(1))
SELECT CASE b$
'CASE CHR$(27): SYSTEM 'does not provide ESC
CASE "N"
'ON ERROR GOTO [resnxt]
'KILL "filename.tmp"
'ON ERROR GOTO 0
call tryKill "filename.tmp"
PRINT
PRINT "Temporary "+ CHR$(34) + "filename.tmp" + CHR$(34) + " was removed and no changes were made to original file."
PRINT
PRINT "Press any key to end."
EXIT DO
CASE "Y"
'ON ERROR GOTO [resnxt]
'KILL MID$(filename$, 1, INSTR(filename$, ".") - 1) + ".org"
'ON ERROR GOTO 0
call tryKill MID$(filename$, 1, INSTR(filename$, ".") - 1) + ".org"
NAME filename$ AS MID$(filename$, 1, INSTR(filename$, ".") - 1) + ".org"
NAME "filename.tmp" AS filename$
PRINT : PRINT "File conversion completed. Press any key to end."
EXIT DO
END SELECT
LOOP
'SLEEP
'SYSTEM
end
[tracknumber]
DO while 1
count = count + 1
linenumber(count) = VAL(MID$(a$, n))
IF INSTR(a$, "ON") <> 0 AND INSTR(a$, "GOSUB") <> 0 OR INSTR(a$, "ON") <> 0 AND INSTR(a$, "GOTO") <> 0 THEN
FOR i = n TO LEN(a$)
IF VAL(MID$(a$, i, 1)) = 0 AND MID$(a$, i, 1) <> "0" AND MID$(a$, i, 1) <> "," AND MID$(a$, i, 1) <> " " THEN EXIT FOR
IF MID$(a$, i, 2) = ", " THEN n = i + 1: EXIT FOR
NEXT
IF n <> i + 1 THEN EXIT DO
ELSE
EXIT DO
END IF
LOOP
RETURN
'[resnxt]
'RESUME NEXT
sub tryKill fileName$
on error goto [err]
kill fileName$
exit sub
[err]
print "ERR: failed to kill a file ";fileName$
end sub