Operating instructions

Search/Change
in
Applesoft
It
is
often useful to
be
able to search a file for a par·
ticular string and then to change the string for a new
one. This paper presents a Search/Change capability for
Applesoft.
J.D. Childress
5108 Springlake Way
Baltimore, MD 21212
)
A program to produce a cross-
reference table for all the variables in a
program under development is a useful
tool; such a table enables one
to
deter-
mine whether and where a variable label
has
been used.
Unfortunately,
a
variable's cross-reference program in
BASIC is not available in the literature
although the development of one was
recently reported
by
William and Alice
Englander,
Nybb/es:
BAS/C
Cross-
Reference Tab/e Generator, Byte,
v4,
4:190 (April
79).
About as useful in pro·
gram development though not as neat
for complete documentation purposes is
the FIND program of Jim Butterfield,
/n-
side
PET
BAS/C,
MICRO,
8:39,
(December78-January
79).
Butterfield's
paper inspired the present SEARCH/-
FIND program, one
that
does the same
function as Butterfield's but also, allows
one
to
change the found item (within
limits).
SEARCH/CHANGE is about seven
times
as
long
(1.5
Kbytes)
as
Butterfield's FIND and runs at about half
the speed.
It
takes about
2.5
minutes
to
search
8.5
Kbytes.
On
the plus side, the
extra length and sacrifice in speed buys
1.
the option not
to
search or
only
to
search strings,
2.
the option
to
have listed the
lines that contain the sought
item, and
3.
the option
to
replace the
sought item
by
anything
of
equal
length.
January, 1980
Because
of
the limitation on length in
the CHANGE function, this feature is not
really a general purpose program editing
tool. Nevertheless, it is quite useful in
dressing up variable labels or changing,
say, a real variable to
an
integer variable.
Demonstration
To
do
a
search/change,
the
SEARCH/CHANGE program must be
ap-
pended to the program to
be
searched.
Either use the merge feature
of
the 3.2
DOS
renumbering program or
the
machine language APPEND program
and
proceedure
given
by
Chuck
Carpenter,
Renumber
App/esoft, MICRO
12:45 (May
79).
Once the programs are
wed, enter the search item as line 1 and
the change item, if any, as line
2.
Then a
RUN
63000 starts the works.
To demonstrate the workings of
SEARCH/CHANGE,
we
use the rather
nonsensical program listed in Figure
1.
We enter the search item
DOG
as line 1
and run 63000. The print-out
of
this run
is
given in Fig.
2.
Every appearance
of
the
three consecutive letters
DOG
is listed.
Had we asked for the lines
to
be
listed, a
given line would have been listed only
once.
We
can search for anything; Fig.
3(a)
shows the result
of
a search for
equal signs. However, we do have
to
be
careful
of
Applesoft's reserved words.
MICRO
--
The 6502 Journal
Figure
3(b)
shows what happens if
we
try
to search for
CAT.
Applesoft recognizes
the reserved word
AT
in CAT. This makes
clear the need of having the program list
for verification the search and change
items.
The reserved word problem is a
relatively minor nuisance. A little in·
genuity can get us around it.
In
the CAT
case,
we
could search for
CA;
if that
gave too many other items, we could
then search for
TS
and only consider the
lines that appear in both lists.
The CHANGE function, as weil as
the line listing feature, is demonstrated
in
Fig.
4.
Again caution is wise. What
if
we
had already used the
DGS
label
in
our
program? There would be no way later
that
we
could separate the old
DGS
from
the new
DGS.
If in doubt
in
changing a
label, first make a search to see
if
the
new label is already being used.
In
changing the variable label from
DOG
to
DGS,
we
did not want to change
the word
DOG
inside strings, hence did
not search strings. The capability
of
not
searching strings or only searching str-
ings provides all the flexibility
we
ever
need.
We note that
we
can only change
an
item to one equal in length (as AP·
PLESOFT sees the length). Extra length
in the change item entered as line 2 is ig·
nored.
If
the replacement is shorter than
20:55