Has anyone here ever used TECO?
TECO is an old editor that was originally designed to ease the editing and loading of paper tapes. Hence, it stands for Tape Editor and COrrector.
It was not only an editor, but a full scale programming language. At one point in about 1980 or 1981, it suddenly struck me that it wouldn't be particularly difficult to write the entire system startup procedures for the RSTS/E operating system as a TECO macro. Imagine booting a minicomputer to a text editor macro to mount the disk drives, start the various systems and services, and then enable everyone to log on.
Several years ago I wrote a simple line editor, LED, that operated on a single line at a time. It was a quick hack that took maybe 5 or 6 hours for the whole program. For each line in an input stream, whether from standard input or a file or from any other source, it would apply the same exact sequence of commands to every line in the stream. A command line to scan a directory listing for files ending with '.txt' and rename the files with a '.text' extension would be
ls | led "_#Cs?.txt?.text?g0imv \"#Pi\" \"#gi\"" | ksh
on a UNIX or Linux computer. On Windows, it might be
dir /b | led "_#Cs?.txt?.text?g0irename \"#\"\"#gi\"" | cmd
In the command string given:
_# - Sets the delimiter to '#'. If it is clear where one command ends and the next begins, there is no need to use the delimiter.
C - Copy the buffer
s?.txt?.text? - Change all instances of .txt in the file name to .text. I assume that there is no files named something like x.txt.txt.txt. Note that the first letter after the s is a delimiter to mark the old and new strings. The command delimiter cannot appear anywhere in there.
g0 - Go back to the start of the buffer.
imv \"# - Insert a 'mv "' at the start of the buffer. Note that we have to use the '#' delimiter here. Otherwise the editor wouldn't know where the next command began.
P - Paste the data copied earlier back into the buffer
imv \" \"# - Inserts an ending quote, a space, and another quote. The quotes are necessary in case there are strings within the file name.
g - Go to the end of the string. Note that g0 goes to the start, g1 to the second character, ... . A g by itself says to go to the end of the string
i\" - Inserts a closing double quote. Note that we don't need a delimiter because the command line ends there.
Thus, a file name of this is a sample file.txt would result in the command
mv "this is a sample file.txt" "this is a sample file.text"
being passed to the ksh shell in this example.
If I did this often, I could even store the commands in a file named txttotext.led and invoke with
ls | led @txttotext.led | ksh
Note that the quotes around the command line aren't necessary because there are no spaces imbedded in this command line. If it were txt to text.led, it would need to be "@txt to text.led" in the command line.
It's a fairly powerful little editor.
Anyway, I was looking for a copy of my source code and can't find it anywhere! I know I have it backed up to CDs or DVDs, but I have thousands of backup disks and don't feel like looking back through them. There were a lot of things I need to add anyway so I'm thinking of just rewriting the entire program to make it more useful.
First, there are times in a program where I need to make some changes to data and would like to be able to use LED to massage data. For a simplistic example, I might want to make a string all lowercase and remove all occurrences of the letter 'a'. It's easy enough to use a loop to go through the string one character at a time and make each character lowercase while deleting 'a's as I go, but as an alternate, it would be nice to do something like:
led edobj( "lg0s/a//" ) // save a procedure
cout << edobj( "TexT" ) << endl ;
cout << edobj( "The quick brown fox jumps over the lazy brown dog." ) << endl ;
Another thing that I would like is to handle regular expressions. At the time I wrote the original LED, I didn't thinking about handling regular expressions.
The third thing is that it doesn't cross lines. The current version can't join two lines or do anything crossing line boundaries with the exception of being able to print out two or more lines in the command string by inserting a '\n' into the buffer with the insert command. So I'm thinking of making it able to load an entire stream or file into memory and then applying the edit commands on all at once. Currently, it just reads a line, edits the line, writes the line, and repeat as necessary.
One approach could be to get a copy of TECO (actually I already have a copy) and extend it. It's very tempting considering the power of TECO. Finally, I could rewrite LED to use TECO commands and make sure that I can add more commands whenever I need them.
The option that I am strongly leaning toward is to rewrite LED to more or less match the commands as they are now (the simplest option) but make it more extensible. One possibility is to put a count modifier in front of the command. For example, '10ia#' would insert 'aaaaaaaaaa' in the stream at the current cursor position and '-5j' would jump to a cursor position five characters sooner. Currently, if there is a number it is seen as part of the previous command, so that would require some changes.
That said, I always liked TECO and so it is tempted to switch to TECO commands.
Note that I posted a copy of LED somewhere years ago for someone to use, but if there are any programs called LED that you can find with Google, it is very doubtful that they are my LED.
Anyway, any suggestions or advice?