Classic Computer Magazine Archive ANTIC VOL. 3, NO. 9 / JANUARY 1985

the toolbox

BASIC SEARCHER

"Global search" for programmers

by SCOTT SHECK


BASIC Searcher finds the lines containing any command, operator, function or variable in your BASIC program.  The program works on all Atari computers of any memory size.  Antic Disk subscribers, follow the directions in the article.

Global search is one of the most useful editing functions found in good word processing software.  Now you can make use of the same powerful editing tool when you're revising or debugging your own BASIC programs.
   BASIC Searcher is a utility that can find all the lines containing any BASIC command, operator, function or variable in your program.  It is compatible with BASIC XL (O.S.S.) and can be used with any BASIC program having line numbers below 31900.
   First, type in the program listing, check it with TYPO II, and LIST it to disk using LIST "D:SEARCH.LST". Cassette owners should type LIST "C:"

HOW TO USE BASIC SEARCHER
Once the computer has a BASIC program in memory, type ENTER "D: SEARCH.LST or "ENTER C:" to merge your program with BASIC Searcher.  Your program MUST be in memory before you ENTER the BASIC Searcher program!
   Next, type GOTO 31900.  After a brief pause, a list of your program's variables will appear on the screen.  Occasionally, this list 'will include variables which no longer exist.  This occurs because BASIC Searcher references your program's Variable Name Table which, in the case of a SAVED file, may have retained previously deleted variables.  To clear the Variable Name Table, LIST your program to disk or cassette, type NEW, and ENTER your program again.
   Each variable in the list will be accompanied by a reference number.  To locate a particular variable in your program, type in its corresponding reference number and press [RETURN].
   Now, type [S] to have your results printed on the screen, or [P] to have your output sent to a printer.
   The program will print an "END OF SEARCH" message when it's through.  If you want to perform another search, type [Y].  If not, type [N] and BASIC Searcher will erase itself from your program.
   BASIC Searcher can also find BASIC reserved words, constants and character strings. just type in a reference number from the accompanying Table.  If you were looking for every occurence of the POKE command, for example, you'd type in [31] and press [RETURN].
   Although BASIC Searcher will find all references to specific variables, it cannot isolate individual constants or character strings.  If you're searching for constants (reference number 14) or strings (number 15), BASIC Searcher will print out all references to every constant or string in your program.

HOW IT WORKS
BASIC Searcher looks for tokens, the one-byte codes which the Atari's BASIC interpreter uses to represent reserved words, variables and other pieces of information.
   Tokens for BASIC reserved words are represented by ATASCII characters 0 through 84.  The computer represents your program's variables with ATASCII characters 128 through 255. (This is why a program may not have more than 128 variables.)
   As the computer interprets a BASIC program, each variable is assigned a token, beginning with ATASCII 128, and this token is appended to the Variable Name Table.  At the same time, the variable's name is added to the Variable Name List, and its value is stored in the Variable Value Table.  The computer uses these tables to keep track of your program's variables.  BASIC Searcher looks through the Variable Name Table and the Variable Name List when analyzing your program.

REFERENCE NUMBER TABLE

0 REM
1 DATA
2 INPUT
3 COLOR
4 LIST
5 ENTER
6 LET
7 IF
8 FOR
9 NEXT
10 GOTO
11 GO TO
12 GOSUB
13 TRAP
14 all constants or BYE
15 all strings or CONT
16 COM
17 CLOSE
18 CLR or ,
19 DEG or $
20 DIM or :
21 END or ;
22 NEW
23 OPEN
24 LOAD
25 SAVE or TO
26 STATUS or STEP
27 NOTE or THEN
28 POINT or #
29 XIO or <= [arithmetic]
30 ON or <>
31 POKE or >=
32 PRINT or <
33 RAD or >
34 READ or =
35 RESTORE or
36 RETURN or *
37 RUN or +
38 STOP or -
39 POP or /
40 ? or NOT
41 GET or OR
42 PUT or AND
43 GRAPHICS or (
44 PLOT or )
45 POSITION or = [arithmetic]
46 DOS or = [strings]
47 DRAWTO or <= [strings]
48 SETCOLOR or <>
49 LOCATE or <=
50 SOUND or <
51 LPRINT or >
52 CSAVE or =
53 CLOAD or + [unary]
54 Implied LET or -
55 ERROR [syntax] or ( [strings]
56 ( [arrays]
57 ( [DIM arrays]
58 ( [functions]
59 ( [DIM strings]
60 , [arrays]
61 STR$
62 CHR$
63 USR
64 ASC
65 VAL
66 LEN
67 ADR
68 ATN
69 COS
70 PEEK
71 SIN
72 RND
73 FRE
74 EXP
75 LOG
76 CLOG
77 SQR
78 SGN
79 ABS
80 INT
81 PADDLE
82 STICK
83 PTRIG
84 STRIG

Scott Sheck is one of the most creative and prolific utility programmers appearing in Antic. Last month's issue featured his "Word Storage Space Saver," an almost fiendishly clever method of reducing memory waste in text storage.