Classic Computer Magazine Archive ANTIC VOL. 3, NO. 4 / AUGUST 1984

the toolbox

RENAMER

A simple way to rename Atari BASIC variables

By WILLIAM W. HOUGH

SYNOPSIS
This utility program lets you rename variables in a BASIC program.  RENAMER requires Atari BASIC and 3500 bytes of RAM, in addition to the program being altered.  It runs on all Atari computers.

Recently, a friend asked if I knew how to rename variables in Atari BASIC programs.  I suggested that it would be easy to do with a word processor such as Text Wizard or AtariWriter.  Simply LIST the program to disk or cassette and enter it as text into the word processor.  The global-search-and-replace function makes quick work of changing all occurances of a variable.
   Unfortunately, my friend didn't use any of these word processors on his cassette-based system. (AtariWriter is designed to be used with cassette systems -ANTIC ED.) After some thought, I attacked the problem directly.  Using a co-resident program to change variable names in the variable name table, the modified program can be RUN or SAVED without LISTing, modifying the text and ENTERing the listed program.  The result, RENAMER, accompanies this article.
   The RENAMER program appends new variable names to the variable name table, then copies the table into a string.  The new name is switched with the old name, and the string is copied back into the variable name table.  The RENAMER program must be LISTed on either cassette or disk.  First, LOAD your BASIC program and compare it with RENAMER for conflicting line numbers.  Renumber as necessary.  ENTER the RENAMER program after you've loaded your BASIC program.  To begin, type GOTO 27500.
   You'll notice a pause while the program loads a machine-language routine into ZMOVE$.  This routine transfers the variable name table to and from the strings ZVNT1$ and ZVNT2$.  All variables in RENAMER begin with the letter "Z" to minimize their chances of being renamed, although it does no harm if they are.  You must tell RENAMER whether you're changing the name of a numeric variable, an array or a string.  Next, type the variable's old name, and then its new name.  String variables do not need the " $ " identifier, since you've already identified them.
   The Atari forced-read mode appends new variables to the variable name table.  If the new name you've entered already exists, the RENAMER reports the duplication to you, and asks whether the name change is intentional.  If so, type "Y", and the change is made.  In this case, the name will appear twice in the table: once in its original form, and once in its new form.  This is possible because the variables don't use the same token, and may not have the same value.
   Every variable used in a BASIC program is assigned its own token.  Tokens are one-byte representations of variables that are used to save space in memory.  The token is assigned when the variable is first used.  This token is also tied to the variable's corresponding value in the variable value table.  The RENAMER program "puts a new label" on a token.  The value the token refers to, and the way a program handles the token remain the same.  RENAMER can give every variable in a program the same name without affecting the operation of the program.  However, such programs should not be LISTed to a cassette or disk; they must be SAVED.
   The RENAMER program uses 13 different variable names (start with Z) which are added to the variable name table.  To get rid of the extra names, and to save programming space, follow this procedure: LIST the program to tape or disk, type NEW and ENTER the LISTed program, and SAVE it.  This should be done after every renaming session.
   Occasionally, if you're renaming a variable with a name that already exists, and the new name is very long, you won't be able to rename the variable.  If this happens, you'll be notified, and asked if you want to rename another variable.
   Dialogue with RENAMER requires a simple yes or no response.  A capital "Y" means "Yes." Any other keyboard response is taken as "No." An example of a Yes/No question is: "Do you want to change another variable?" This occurs after each successful pass, or when the old variable name entered isn't in the table.  If you don't want to change any more variable names, you're asked if you want to delete the RENAMER program.  The final routine deletes every line in the RENAMER program from your program in memory by entering RENAMER's line numbers in the forced-read mode.

POTENTIAL PROBLEMS
When working with a long program with many variables, RENAMER may generate an ERROR 4 message.  ERROR 4 indicates the program has exceeded the computer's limit of 128 variable names.  This can occur while the renaming program is being ENTERed, or while RENAMER is running.  To correct this, LIST the original program to cassette or disk, type NEW and ENTER it again.  This clears unused names from the variable name table.  If this is unsuccessful, use RENAMER on itself.  Change the Z-name variables of RENAMER to variable names already used in your main program.  This fools BASIC into "thinking" you are using fewer variables.  After renaming the "Z" variables, LIST the RENAMER program back to cassette/disk, LOAD/ENTER your main program, then ENTER the new RENAMER last.
   One other possible problem deserves mention.  BASIC will only accept up to three lines of code with the same line number.  If your original program already contains long lines of code, and your new variable names are longer than your old names, this three-line limit may be exceeded.  This is only a problem when you attempt to correct or change one of these long lines.  If you do this, the line is truncated when the RETURN key is pressed.  If you want to edit such a line, you must break it into two lines with separate line numbers first.
   Remember, you must LOAD your main BASIC program before ENTERing the RENAMER program.  RENAMER will not function properly otherwise.

William W Hough, an engineer with degrees from Northwestern and Stanford, has been interested in microcomputers for a relatively short time, but mastering the Atari has become a principal leisure-time activity for him. Bill also is the author of a logic game, Brainboggler, which is available through Educational Software, Inc.

Listing: RENAMER.LST Download / View