Beebug


Utility Editor

 
Published in Beebug Volume 2 Number 1

Utility Editor

When developing a program, much time can be wasted scanning the listing to locate a specific procedure, function or character string that needs to be changed. The program listed with this article is a mini editor, which can be loaded into the computer along with your development program, to allow you to:

  1. List all occurrences of a specific string, including search for Basic Keywords.
  2. Change all occurrences of a specific string to any new string that is equal or shorter in length than the original string, thus allowing you globally to change variable names.
  3. List the starting line number and name of each procedure used.
  4. List the starting line number and name of each function used.

Basic Keywords

As you have probably heard, when the computer sStores a program in its memory, it converts all Basic Keywords (such as If, PRINT, SOUND, GOTO ...etc) into tokens. What this means is that rather than store all these, sometimes long, and frequently repeated words actually as they are spelt, it simply stores each of them as a 1 byte code (token).

This leads to much more economical use of storage space. However, it does result in a problem for string search programs; quite simply, searching for say, "Print" is a waste of time, as it has been stored in memory as 241. (see User Guide page 484)

A special feature of this editor is that option 1 will allow' you to search for any string, including a keyword, if you wish. This is achieved by special procedures which use the table at &806D (&8871 in BASIC II) in ROM to perform a conversion of the keyword in the string that you specify.

Limitations

The editor is stored for convenience just below Mode 7 HIMEM. Consequently running a development program which uses a Mode other than 7, with the -editor also in memory, will overwrite the editor. This is no real problem as it is not necessary to run the user program while the editor is in situ, and in any case, the editor is easily reloaded. It should be noted that the string replace (option 2), will not locate or replace keywords.

Even with these minor restrictions the editor is a very useful tool, especially if you do not have the use of a printer with which to produce full program listings for inspection.

Program Details

The program is in fact a combination of several procedures, sent in mainly by two members. We are most grateful to T. Burgess for the first (PROCREPL) and to P Otto for (PROCLISTT, PROCLISTP and PROCLISTF).

The procedures have been combined and are accessed via a menu, to create a single more powerful editor. However, if you decide that you are interested say, in only one of the procedures, they are easily separated.

To Set Up The Editor

Type in the editor as listed. To enable two programs to be in memory at the same time (the editor and the program you will use it. on), the editor is stored at the top of available memory, out of the way. Obviously the actual location of this will differ between 16k and 32k machines. Therefore, if you have a 16k machine, alter line 10 to:

10 *KEY0PAGE=&3000|MRUN|M

Note that the default value of PAGE on the BBC machine is &1900 when a disc interface is fitted to the computer , (rather than &E00 on cassette-based machines).

If you have a disc system then change line 20 to:

20 page=&1900

Once you have typed in the program check your version against the original listing, given at the end of this article, and then save a copy to tape or disc, under the file name "EDITOR" .

To Use The Editor

  1. If you have a 16k machine type: PAGE=&3000 (RETURN) If you have a 32k machine type PAGE=&7000 (RETURN)
  2. Load and run the program using CHAIN"EDITOR". Running it will immediately set the red function key (f0) ready for later use.
  3. Now press ESCAPE. This will stop the editor from running further.
  4. Press function key 1. You are now ready to load in your development program in the normal way.
  5. To invoke the editor use function key 0, which will take you to the editor menu.
  6. Having finished using the editor select option 5 to continue with your program.

About The Editor

When you run the editor you will be presented with a menu offering the five options. To choose an option simply use the relevant key, as indicated. All other entries are locked out. If you enter 1 or 2 you will be prompted for a search string. Simply enter your string and then press return. Option 2 will also prompt you for a replace string which you key-in in the same way.

As already mentioned, option 1 will allow you to search for strings including a keyword. To tell the computer that the relevant part of the string is a keyword, it must be enclosed in 2 slashes (/). eg:

To search for PRINT "HELLO"

enter /PRINT/ "HELLO"

To search for REPEAT

enter /REPEAT/

To search for A%=A%+1 :NEXT B%

enter A%=A%+1 :/NEXT/ B%

As you see you must enter the search string exactly as it exists in the program, but adding / symbols around the keyword, if there is one.

Only one keyword may be searched for in any one string.

If the program can not find the keyword specified it will print an error message, and continue the search with the string exactly as you entered it.

If you choose options 3 or 4 no prompts are required and the search for procedures or functions is initiated immediately.

Having displayed the relevant line numbers (if there are any to display) the editor will prompt you to press RETURN, upon which the menu will be redisplayed, ready for your next command. To return to your development program select option 5.

Note: All options put the display in "paged mode". This prevents the located line numbers from being displayed, only to scroll off the top of the screen. If a full screen is displayed, pressing "shift" will display the next screenful.

If You Have Problems

If upon running the editor you get an error message indicating that the computer has run out of room (eg. DIM space), it probably means that your version of the program has become longer than the original.

This may be due to accidentally adding extra spaces. If this is so you can very easily overcome this by reloading the program slightly lower in memory (eg. &6F00 for 32k and &2F00 for 16k machines). If you have to do this, don't forget to alter line 10 to reflect the new start address.

Error Messages

Error try again
This is only issued by option 2 and indicates either that you have attempted to replace a string by a longer string, which is not allowed, or that the editor cannot find the program to edit.

Invalid Keyword
This is displayed by option 1 and indicates that you have attempted to search for a Basic Keyword which has not been found in the table. eg /PRNT/ . If this is specified as a search argument in option 1, the error message will be given. The search will continue, however, for the actual string /PRNT/. i.e. no conversion will take place.

About The Keyword Conversion

The keyword table replacement routine will only be able to locate the keywords exactly as they are stored in the ROM memory. You will find it useful to know that the token for INSTR assumes the first bracket, and so should be searched for as /INSTR(/. This also applies for LEFT$, which is searched for as /LEFT$(/, MID$ which is /MID$(/, POINT which is /POINT(/, RIGHT$ which is /RIGHT$(/, STRING$ which is /STRING$ (/ and TAB which is /TAB(/.

The following keywords are stored twice in the table, only the first entry is accessed by the conversion program. These are: PAGE, PTR, TIME, LOMEM, HIMEM.

If a search is requested for a string containing a keyword and nothing else, after conversion, the program will be searching for a single byte (the token). It is possible that this byte may occur in a different context within the program, eg as part of a line number.

If this is the case, the program will erroneously report a line number. This happens in practice very rarely, and only on searches for strings containing just a keyword and nothing else.

Searching for GOTO followed by a line number, eg /GOTO/200 will not work. This is beceause the line number after a GOTO, is stored by the computer in coded form too.

A Tip For Users With Disc Systems

You may find it more convenient to load and run this program from another program. This will save you having to set PAGE every time you decide to load the editor again. To this end save the main program as "EDITOR" and save the following two line program as "EDSTART".

10 PAGE=&7000
20 CHAIN "EDITOR"

So now to load and run the editor you need only to enter, CHAIN "EDSTART"

Note: Do not forget to customise the program to your machine if you have a 16k or disc system, as described above.

Finally, note that the variable 'page' occurs at several points in the program, and that it must be typed in lower case.

Adrian Calcraft