Ted, the text editor
The initial implementation of the text editor compiled with no great
difficulty. The I/O routines written for the Ratfor preprocessor were
used and the pattern matching routines were extracted from the FIND and
CHANGE programs.
The limitations of this implementation soon became obvious - all text
is held in a linked list in memory, and no attempt is made to reclaim
the space used by lines that are deleted or changed.
I decided to make a version based on the "scratch file" implementation of
the editor described in the book, with some significant changes:
- A linked list of "line" datastructures is held in memory, each structure
holding the length of the matching text line and a pointer to the text.
- For small text files the text is held in the same array as the linked
list, towards the end of the array.
- The text is held packed 3 bytes to the 24 bit word, routines
GFPACK8 and
GFUNPACK8 are used to pack and
unpack the text.
- As lines are deleted from the file (and all changes are considered
a deletion of the old line followed by the insertion of the new line) the
per-line datastructures are moved to a free list so they can be re-used, and
holes appear in the space used to hold the text.
- When a line is inserted, if there is no space left in the memory
buffer a garbage collection
is run to recover lost space in the text. (Text is copied in the buffer using the
routine GFMOVE which uses the hardware
MOVE instruction.)
- If the garbage collection doesn't recover enough space in the buffer
then the text is copied out to a scratch file, freeing up the buffer to
hold more line data structures.
- The text file is implemented as a George *DA (random access) file with
512 word (4 block) buckets. When the text is held in the scratch files the
text pointers in the line datastructure point to the disk bucket and offset
that holds the text.
- In scratch file mode the last 512 words of the buffer hold the disk
bucket currently being written and the 512 words before that hold the
last disk bucket read from the file. The rest of the buffer holds the
line structures.
The heart of the implementation consists of two routines, findtxt and
spacefor:
findtxt
findtxt returns the address in the buffer for a given line. If the
text is being held in the buffer its simple, but if the text is in the scratch
file there are three cases:
- The text is in the block currently being written - it's address is
returned. (The block being written is held in the top of the buffer).
- The text is in the block last read - it's address is returned (the last
block read is held in the next 512 words of the buffer).
- Otherwise the appropriate block is read into the read part of the buffer and its address is returned.
spacefor
spacefor allocates space in the buffer to hold a new line.
- If the text is currently being held in memory and there is enough
space available its address is returned.
- If there is not enough space in memory a garbage collection is launched.
If the garbage collection frees enough space then it is returned, otherwise
the text is copied to the scratch file.
- If the text is in the scratch file and there is enough space in the block
currently being written it is returned.
- Otherwise the block is written out to the scratch file, making enough
space available.
Installation
To install ted download the NEWCOPYIN source tape,
(5250003,EDITTAPE), then:
- Copy the tape image to your tapes directory.
- On George, create a new directory, and make it the current directory:
10.46.01← MK EDIT
10.46.02← DY EDIT
- Use NEWCOPYIN to read the file NEWCOPYINPAR from the tape, then copy
in all the files listed in NEWCOPYINPAR:
10.46.03← NEWCOPYIN (5250003),TRAPOPEN
← NEWCOPYINPAR
← ****
...
10.46.04← NEWCOPYIN (5250003),TRAPOPEN,*CR NEWCOPYINPAR
...
10.46.05←
- Run the macro MAKEEDIT (in a background job if you feel like it).
10.46.06← RJ EDITJOB,MAKEEDIT
- When the compilation has finished log in as user :LIB and run the macro
INSTALL in the directory:
10.46.07← LN :LIB,EDITMOP
PASSWORD← XXXX
10.46.08← DY :XXXX.EDIT
10.46.09← INSTALL
- Now log in as MACROS and re-run the install script:
10.46.07← LN :MACROS,EDITMOP
PASSWORD← XXXX
10.46.08← DY :XXXX.EDIT
10.46.09← INSTALL
That's it, now the editor is installed.
The macro TED takes the file to be edited as the first argument (which may
be omitted to start TED with an empty buffer) and optionaly an edit script
as the 2nd argument.