home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Jason Aller Floppy Collection
/
101.img
/
QB45-1.ZIP
/
REMLINE.BAS
(
.txt
)
< prev
next >
Wrap
QuickBASIC Tokenized Source
|
1988-09-08
|
12KB
|
210 lines
GetToken
Search
Delim
StrSpn
InString
Separator
StrBrk
IsDigit
Char%
GetFileNames
BuildTable
GenOutFile
InitKeyTable
TRUE:
falseG
MaxLines
LineTable
LineCount
Seps,
InputFile
OutputFile
TmpFile
KeyWordCount
KeyWordTable
KeyData
FileErr1
FileErr2
InLin
token
KeyIndex
LineNumber
FoundNumber
index
BegPos
SaveStr
NewPos
Count
KeyWord
CharAsc
Microsoft RemLine - Line Number Removal Utility
Copyright (C) Microsoft Corporation - 1985, 1986, 1987
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.s
REMLINE is run by typings
REMLINE [<input> [, <output>]]e
where <input> is the name of the file to be processed and <output>E
is the name of the file or device to receive the reformatted output.
If no extension is given, .BAS is assumed (except for output devices).
If file names are not given, REMLINE prompts for file names. If both)
file names are the same, REMLINE saves the original file with the
extension .BAK.
REMLINE makes several assumptions about the program:f
1. It must be correct syntactically, and must run in BASICA ort
GWBASIC interpreter.t
2. There is a 400 line limit. To process larger files, change
MaxLines constant.l
3. The first number encountered on a line is considered a line
number; thus some continuation lines (in a compiler specificn
constructiion) may not be handled correctly.o
4. REMLINE can handle simple statements that test the ERL function
using relational operators such as =, <, and >. For example,
the following statement is handled correctly:
IF ERL = 100 THEN END
Line 100 is not removed from the source code. However, more
complex expressions that contain the +, -, AND, OR, XOR, EQV,
MOD, or IMP operators may not be handled correctly. For example,o
in the following statement REMLINE does not recognize line 105e
as a referenced line number and removes it from the source code:
IF ERL + 5 = 105 THEN END
If you do not like the way REMLINE formats its output, you can modify
the output lines in SUB GenOutFile. An example is shown in comments.y
Function and Subprogram declarations.
Global and constant datad
Keyword search data
THEN, ELSE, GOSUB, GOTO, RESUME, RETURN, RESTORE, RUN, ERL, ""
Start of module-level program codeE
,:=<>()d%
Working"
. . .
CON"q
Invalid file name"
New input file name (ENTER to terminate):
Output file name (ENTER to print to screen) :"
GetToken
GetToken$:
Extracts tokens from a string. A token is a word that is surroundedP
by separators, such as spaces or commas. Tokens are extracted ande
analyzed when parsing sentences or commands. To use the GetToken$e
function, pass the string to be parsed on the first call, then pass
a null string on subsequent calls until the function returns a null
to indicate that the entire string has been parsed.n
Input:d
Search$ = string to search
Delim$ = String of separators
Output:
GetToken$ = next token
Note that SaveStr$ and BegPos must be static from call to calla
(other variables are only static for efficiency).
If first call, make a copy of the stringi
Find the start of the next tokene
Set position to start of token
If no new token, quit and return null
Find end of token
Set position to end of token
If no end of token, return set to end a value
Cut token out of search string
Set new starting position
StrSpn
StrSpn:
Searches InString$ to find the first character that is not one ofn
those in Separator$. Returns the index of that character. This
function can be used to find the start of a token.
Input:i
InString$ = string to search
Separator$ = characters to search fort
Output:
StrSpn = index to first nonmatch in InString$ or 0 if all match
Look for start of a token (character that isn't a delimiter).
StrBrk
StrBrk:
Searches InString$ to find the first character from among those in
Separator$. Returns the index of that character. This function can
be used to find the end of a token.a
Input:e
InString$ = string to search
Separator$ = characters to search for
Output:
StrBrk = index to first match in InString$ or 0 if none matchn
Look for end of token (first character that is a delimiter).c
IsDigit
IsDigit:
Returns true if character passed is a decimal digit. Since any
BASIC token starting with a digit is a number, the function only
needs to check the first digit. Doesn't check for negative numbers,
but that's not needed here.g
Input:h
Char$ - initial character of string to check
Output:
IsDigit - true if within 0 - 9
GetFileNames
GetFileNames:
Gets a file name from COMMAND$ or by prompting the user.
Input:a
Used Command$ or user inputN
Output:
Defines InputFiles$ and OutputFiles$
Microsoft RemLine: Line Number Removal Utility"
(.BAS assumed if no extension given)"
Input file name (ENTER to terminate):
Output file name (ENTER to print to screen): "
Output file name (ENTER to print to screen): "
CON";
SCRN;
PRN";
COM1;
COM2;
LPT1;
LPT2;
LPT3;
BuildTable
BuildTable:
Examines the entire text file looking for line numbers that are
the object of GOTO, GOSUB, etc. As each is found, it is entered
into a table of line numbers. The table is used during a second
pass (see GenOutFile), when all line numbers not in the listo
are removed.n
Input:r
Uses globals KeyWordTable$, KeyWordCount, and Seps$
Output:
Modefies LineTable! and LineCount
Get line and first tokend
See if token is keyword
Get possible line number after keywordo
Check each token to see if it is a line numberd
(the LOOP is necessary for the multiple numbers
of ON GOSUB or ON GOTO). A non-numeric token will
terminate search.
Get next token
GenOutFile
GenOutFile:
Generates an output file with unreferenced line numbers removed.
Input:a
Uses globals LineTable!, LineCount, and Seps$n
Output:
Processed file
Speed up by eliminating comma and colon (can't separate first token)s
"d%
Get first token and process if it is a line numbera
See if line number is in table of referenced line numbers
Modify line strings
You can replace the previous lines with your owne
code to reformat output. For example, try these lines:e
TmpPos1 = StrSpn(InLin$, Sep$) + LEN(Token$)
TmpPos2 = TmpPos1 + StrSpn(MID$(InLin$, TmpPos1), Sep$)e
IF FoundNumber THEN
InLin$ = LEFT$(InLin$, TmpPos1 - 1) + CHR$(9) + MID$(InLin$, TmpPos2)
InLin$ = CHR$(9) + MID$(InLin$, TmpPos2)R
END IF
Print line to file or console (PRINT is faster than console device)
InitKeyTable
InitKeyTable:
Initializes a keyword table. Keywords must be recognized so that
line numbers can be distinguished from numeric constants.s
Input:n
Uses KeyData
Output:
Modifies global array KeyWordTable$r