Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-04 - 43,50334/tops9t.gno
There are no other files named tops9t.gno in the archive.
%switch qz false
%if qz
%nocontrolc
%nextlesson pub("TOPQ");
%ifend qz
%order
%text
TECO as a programming language.
==============================

TECO is in reality a programming language in which you can
write executable text editing routines. However, such capabilities
in general go beyond the scope of this introductory course.

The simplest case of a program is a loop. A loop in TECO can be used
if you want to do the same editing action at several places in the text.
You do not have to type in the string of the same TECO command
more than once if you use a loop.
%text
Writing iterative loops with TECO.
=================================

A loop consists of a number, the character "<", a TECO command
string and finally the character ">".

Example: "3<FS $  $>$$" indicates a loop. The number 3 tells
TECO to execute the command string inside the "<" ">" brackets
three times. Once in each iteration, a space is found and
changed to two spaces.

Thus, the command example above will, if it is applied to
"this text line, change the line to:"
"this  text  line,  change the line to:"
%question comment dangerous motorcar;
Write the shortest TECO command string to find the next five
occurences of "MOTORCAR" and change it to "DANGEROUS VEHICLE".
%noextra
%order
%right 5<FSmotorcardangerous vehicle>
%right 5<FNmotorcardangerous vehicle>
%right 5<FSmotorcardangerous vehicle>
%right 5<FNmotorcardangerous vehicle>
%extra
%wrong skip
If you want to skip this question, then write "%" first.
%wrong "
You should not include any double apostrophe ('"') in your answer.
%wrong vehicle>
You forgot the ESCAPE after "VEHICLE".
%wrong $dangerous vehicle
There must be an ESCAPE before "DANGEROUS VEHICLE".
%wrong 5< >
Between the brackets, write the command string "FSMOTORCAR$DANGEROUS VEHICLE$"
to find the word "MOTORCAR" and change it once in each iteration.
%wrong < >
Since you should make the same thing five times, you should put a
digit five("5") in front of the "<".
%lack >
There is no right bracket ">".
If you want to repeat the same TECO command string more than once,
then you should use the loop-brackets "<" and ">".
%lack <
There is no left bracket "<".
If you want to repeat the same TECO command string more than once,
then you should use the loop-brackets "<" and ">".
%lack FS
Use the "FS" command. The format of that command is:
"FS... search string ...$... substitution string ...$" to find
the search string and substitute the substitution string.
%lack  
There should be two "ESCAPE"s after "FS". The first "ESCAPE"
ends the search string, and the second "ESCAPE" ends the
substitution string.
%wrong
You did not include any loop brackets "<" and ">" in your answer.
Put them around the command which is to be executed more than
once.
%wrong
%same
%wrong
%question comment important;
Write the shortest TECO command to change the text
"IMPORTANT" to "I M P O R T A N T".
Assume that the pointer initially is at the beginning of
the text to be changed.
%noextra
%right 8<c i >
%right 8<c i >
%extra
%neutral 8 < 1c i  >
If there is no integer number before "C" then "1" is default.
You can therefore write "C" instead of "1C" to get a shorter
command string.
%goto repeat
%neutral 8 < 1c i  >
%same
%wrong 1c
%same
%wrong "
You should not include any double apostrophe ('"') in your answer.
%wrong S
There is no need to use a search command. You only need to use
the "C" and "I" commands of TECO.
%wrong N
%same
%wrong <ci >
Write "8" in front of "<" since you should insert 8 spaces.
%wrong <ci >
You forgot the ESCAPE ending the parameter to the "I" command.
%wrong < >
Inside the loop, you do two things. First you advance one character
using the "C" command, then you insert a space using the "I" command.
%lack < >
Your answer did not include any loop bracket pair "<"...">".
%wrong
You must make a loop eight times, and in each iteration
skip one character and then insert a blank.
%same
%wrong
%text
You do not have to put any number at all in front of the
loop brackets. If there is no such number, the loop continues
infinitely. However, there are commands you can put inside the
loop to stop it. One common such command is the ";" command,
which stops the loop at the end of the text file.

Example "<FNWORK$HAPPINESS$;>$$" will search through all pages
of the whole text file and change every occurence of "WORK" to
"HAPPINESS".
%text if latescore > 1 then
You are doing fine!
%question comment print lines with "ELSE";
Write the shortest TECO command string which will search through
the whole text file from the pointer to the end of the file.
Every time that the word "ELSE" occurs in the text, the whole
line is to be output to the terminal.
%noextra
%right <Nelse0t;t>
%right <Nelse0t;t>
%right <Nelse;0tt>
%right <Nelse;0tt>
%right <Nelse0tt;>
%right <Nelse0tt;>
%extra
%wrong 0lt
"0LT" will print the whole line. But since the "L" positions
the pointer at the beginning of the line, the next loop iteration
will find the same "ELSE" again infinitely, instead of moving to
the next "ELSE" in the text.
%wrong <NELSE0tt>
You forgot the ";" after "NELSE$" which is necessary to stop the
program going into an infinite loop.
%wrong FN
Use the "N", not the "FN" command, since you do not want to
substitute anything this time.
%lack < >
There are no loop brackets, "<" and ">" surrounding the iteration
loop, that is surrounding that part of the command string which
you want to do many times.
%wrong Nelse;
After "NELSE$;" you write "0TT" to print the whole line
with "ELSE" in it.
%wrong Nelse
After finding "ELSE" you write ";" to leave the loop when
no more "ELSE" can be found in the text.
%wrong < >
Inside < > you first put "NELSE$" to find a line with "ELSE"
in it, and then you write a "T" command to print that line.
%text
Q-registers for temporary data storage.
======================================

TECO like most other programming languages has variable cells
in which you can store information for later use. These cells
are called Q-register and they have one-character names:
either one of the letters A-Z or one of the digits 0-9.

Two common uses for Q-registers are

a) To store a complex TECO command string in them which you
want to execute many times.

b) To store text in them which you want to move from one place
in the text to another place, or which you want to insert at more
than one place in the text.
%text
Macros = saved TECO command strings.
===================================

If you want to store a TECO command string in a Q-register, you
write "*" followed by the Q-register name, immediately after
executing the command string that you want to store in the
Q-register.

Example: You want to look, one at a time, on all lines containing
the word "ERROR". The first time you write the command string
"NERROR$0TT$$". Immediately after that you write
"*M" to store this command string in the Q-register M.
The next time you just write "MM$$" which means "execute
the TECO command string in Q-register M, that is exactly as
if you had written "NERROR$0TT$$" once more.

Every time thereafter, when you search through the file for
more occurences of the word "ERROR" you only have to type
"MM$$".
%question comment find begin and skip;
Write the shortest TECO command string to do the following:
a) Find the next occurence(skipping pages if necessary)
   of the word "BEGIN".
b) Move to the end of the line in which "BEGIN" was found.
c) Insert the text "COMMENT".
d) Print the line up to and including the inserted word.
Include the two final ESCAPES in your answer.
%noextra
%right NBEGINL2RICOMMENT0T
%right NBEGINL2RICOMMENT0T *m
I did not ask you to insert the command string into Q-register "M",
but I accept that answer, since I intended to ask you to do that later.
%goto noasterisk
%right NBEGINL2RICOMMENT0T *m 
%same
%extra
%wrong skip
To skip to the end of a line, write L2R. To skip this question,
write %.
%wrong sbegin
The "S" search command is used to search within a page and the
"N" to search skipping page boundaries. In your case, "N" should
be used.
%wrong *
Do not insert the command string into any Q-register with the "*"
command yet, I will ask you to do that later.
%wrong 0tt
"0TT" means print the whole current line.
"0T" means print the current line up to the pointer.
Therefore, if you know that the pointer is at the end
of a line, you can print the whole line with both "0TT"
and "0T". But since you were asked to write the shortest
possible TECO command string, you should use "0T" and not "0TT".
%wrong FN
Do not use the "FN" command. That command substitutes something
for the found string, which was not required. Use the "N" command
instead.
%wrong NBEGINL2RICOMMENT0T
After "0T" you should write the two final ESCAPES.
%wrong NBEGINL2RICOMMENT
After "ICOMMENT$" you write "0T" to print the line up to the pointer.
%wrong NBEGINL2RICOMMENT
You forgot the ESCAPE after "ICOMMENT".
%wrong NBEGINL2R
After putting the pointer at the end of the line you insert the
text comment by writing "ICOMMENT$".
%wrong NBEGINL
To move two characters backward, from the beginning of the
next line to the end of the previous line, you write "2R".
%wrong NBEGIN
A simple way of finding the end of a line is
to move to the beginning of the next line with the "L" command,
and then move past the two characters CARRIAGE RETURN and LINE
FEED which are always found between one line and the next line.
%wrong NBEGIN S
The shortest way of finding the end of the line is not to
use a search command. Instead, you simply write "L2R" which
will first move to the beginning of the next line ("L")
and then move backwards past the LINE FEED and CARRIAGE RETURN
to the end of the previous line.
%wrong NBEGIN N
%same
%wrong NBEGIN
%same
%wrong NBEGIN
You forgot the ESCAPE after "BEGIN" to finish the search request.
%lack nbegin
To search for "BEGIN" you write the search command "N" followed
by the string "BEGIN" that you are searching for.
%lack nbegin
First you write "NBEGIN$" to find the next occurence of the word
"BEGIN".
%wrong
%same
%wrong
Yes, this is a very difficult exercise when TECO
is so new for you. But just try something to begin with,
and the program will help you get along.
%same
%wrong
%same
%question comment save command in q-register;
Now you know that you want to execute that command string
many times. What do you write to save it in Q-register M?
%noextra
%right *M
%right *M
%extra
%wrong mm
You only need write the Q-register name "M" once in your command string.
%lack m
Your answer does not contain the Q-register name "M".
%lack *
A hint: Use the "*" command of TECO.
%wrong
First write "*" and then the name of the Q-register.
%wrong
The correct answer is "*M$$".
%text if percent < 50 and latescore > 3 then
This is a very difficult lesson, but you are clever and stubborn.
%text if percent >= 50 then
You are a tough man (or woman). I think that these questions
were a little too easy for you...
%question comment execute q-register-stored command string; noasterisk:
And if you want to execute the command string once more.
What do you write to execute a command string which is saved
in Q-register M.
%noextra
%right MM
%right MM
%wrong MM
Why did you write one but not two ESCAPEs? That ESCAPE in itself
does nothing.
%extra
%wrong *
The "*" is used to store something in a Q-register, not to use what
is stored in the Q-register. Do not write any "*".
%wrong MM
Your answer is right except for the extra characters in it.
%algol extratest;
%wrong
A hint: Use the "M" command of TECO.
%wrong
%same
%wrong
The correct answer is "MM$$".
%text
Using Q-registers to store and move text segments.
=================================================

To insert text from the file into a Q-register you write "nXi" where
n is the number of lines to insert and i is the name of the
Q-register.

You can then move the contents of the Q-register back to the
file again by writing "Gi" where i is the Q-register name.

Example:
You have the text
"AAAA
CCCC
BBBB
" and want to get the lines in alphabetical order. This can
be done with the TECO command string "L1XAKLGA$$". Try to
understand why!!!
%text
You will find more information about TECO in the manuals
"Introduction to TECO" and "TECO programmers reference manual".
%text summary:
Summary
=======

TECO Command	Effect
------------	------
n<commands enclosed in brackets>
		The commands will be executed n times.
*m		Store the last command string in Q-register m.
Mm		Execute the contents of Q-register m.
nXm		Move n lines of text into Q-register m.
Gm		Put the contents of Q-register m into
		the text at the pointer.
%algol pause;
%end