A Line-Oriented Text Editor
A compiler, unlike the BASIC interpreter in your personal computer converts program source statements written in an English-like language, into a format acceptable for execution by your computer. This article deals not with compilers, but with a general purpose utility that is used to create and maintain the program source language statements that are input to compilers.
While designing the TINY PASCAL System for the PET and APPLE II it became apparent very early in the development stage that we would need a utility program to maintain the PASCAL source language statements. The utility we wrote for this purpose is called the LINE EDITOR (LED).
The LED is line-oriented as opposed to word-oriented. As such, it cannot be considered a true word processor although it does provide many of the same capabilities as many of the other commercially available word processors. In fact, a slightly modified version of the LED was used to create this article. Although we wrote the LED to maintain program source statements, its usefulness is by no means limited to that application.
The LED is a line oriented text editor. The entire source program must be in memory while the user is modifying it. Modifications allowed include appending source to the end of the text, inserting lines of text into the middle of existing text, changing occurance of a character string to another string, and printing the text to a hardcopy device. After creating or modifying the text, the user may then save it onto tape or diskette. Some of the key points to note when using the LED are:
each line is numbered
each line can contain up to 80 characters
when entering a line, the line must be terminated by RETURN key
a maximum of 500 lines of text may be entered (this is subject to the memory capacity of your particular computer)
as lines are inserted or deleted from the source program, the remaining lines are automatically renumbered
a line of source may extend more than one screen line on your crt
The following are the descriptions of each of the commands:
'F' enter FILER portion of LED
This command allows you to use the LOAD or SAVE commands which are described below:
'L' load file from tape or diskette
This command allows you to load a previously edited source program. The source program may have been saved on tape or diskette. After keying 'L' the LED will prompt you for the name of the source program. Key in the filename and depress RETURN. Do not key in the suffix '.SOURCE'. If you decide that you really don't want to load a file, then enter a null line instead of a filename. At this point you will be asked if the file was saved on tape or diskette (for the PET version of LED). Type 'T' or 'D' as appropriate. If the source program is on tape, then you must put the source file tape into cassette #1. For either tape or diskette, the filename that is keyed in must match the filename that is on the storage medium.
'S' save file onto tape or diskette
This command allows you to save the current source program onto tape or diskette.
After keying 'S', the LED will prompt you for, the name of the file to be saved. Key in the filename and then depress RETURN. The filename is limited to twelve characters. The suffix '.SOURCE' will be added to the filename by the LED. If you decide that you really don't want to save a file, then enter a null line instead of a filename.
At this point you will be asked if you want to save the file onto tape or diskette (for PET version of the LED). Type 'T' or 'D' as appropriate. If the source is to be saved onto tape, then you must put the tape into cassette #1.
***Note that tape is supported only in the PET version.
'A' append the end of source
This command allows you to add lines to the end of the current source program. If you have not loaded any source program, then this command will allow you to create a new source program. You may append one or as many lines as you desire. To signal the end of append mode press RETURN when the cursor is sitting at the first character after the line number prompt (null line).
'C' change string
This command allows you to change an existing string to a new string. It will make changes to either a single line or to a range of lines. Indicate a single line by keying in its line number followed by RETURN. Indicate a range of lines by keying the line number of the first line to be searched followed by '-' and finally followed by the line number of the last line to be searched followed by RETURN. You will then be prompted for the change string. The format for the changed string is:
+ from-string + to-string +
+ is a delimiter—any character may be used but it must not be contained in either the from-string or the to-string.
from-string is the string of characters which are to be replaced
to-string is the string of characters which are to replace the from-string in the original source line
in the above example all occurances of 'abc' will be replaced by 'xyz'.
in the above example all occurances of 'abc' will be eliminated (replaced by nulls).
'D' delete line or range
This command allows you to delete a line or a range of lines from the source program in memory.
DELETE range(low,high)- > 80
will delete line 80
DELETE range(low,high)- > 80-90
will delete lines 80 thru 90
DELETE range(low-high)- > -20
will delete all lines thru 20
'I' insert lines into source program
This command will allow you to insert lines into the existing source program. LED will prompt you for the line number before which you want to insert the new source statements. You may enter one or as many new lines as you desire. Follow each line with RETURN. To signal the end of INSERT mode press RETURN when the cursor is setting at the first character in the line (null).
'L' list source program
This command allows you to list a line or range of lines.
LIST range(low-high)- > 80
will list line 80
LIST range(low-high)- > 80-100
will list lines 80 thru 100
LIST range(low-high)- > -20
will list all lines thru 20
LIST range(low-high)- > null
will list all lines
With the LIST command only the following features are available:
RUN/STOP key - suspends the listing awaiting the depression of the RETURN key.
SPACE BAR - scrolls the listing one line at a time
OFF/RVS key - slows the speeds of the listing
ESC key - suspends the listing awaiting the depression of the RETURN key.
RETURN KEY - reverts to normal speed listing after ESC
SPACE BAR - slows the speed of the listing
'M' menu display
This command allows you to see a more complete explanation of the commands than the abbreviated version which prompts you.
'P' print source program
This command allows you to print a line or range of lines to a hardcopy printer. The PET is supported thru the IEEE interface as device 4. The APPLE II is supported thru slot 2. The range specifications are identical as LIST.
'Q' quit LED
This command allows you to gracefully exit from the LED. The LED gives you a chance to change your mind so that if you accidentally keyed 'Q', then you will have another opportunity to save your source file.
'R' replace a line
This command allows you to replace a single line only. After keying in the line number to be replaced, the LED will prompt you with that line number. Key in the replacement text and press return.
REPLACE -line#- > 108
allows you to replace line 108
The listing which follows is the version of the LED for the PET/CBM machines. The version for the APPLE II is very similar to the PET/CBM version and runs under APPLESOFT. The major differences between the two versions are in the routines that handle the disk and printer I/O.