From sail.labs.tek.com!ogicse!harvard!genrad.com!somewhere!mlf@sequent.UUCP Mon Jan 21 13:27:01 1991
Received: from sail.labs.tek.com (sail.TEK) by squirrel.labs.tek.com (5.4/7.1)
	id AA06374; Mon, 21 Jan 91 13:26:59 PST
Received: from tekchips.LABS.TEK.COM (tekchips.TEK) by sail.labs.tek.com (4.0/7.1)
	id AA08597; Mon, 21 Jan 91 13:24:39 PST
Received: by tekchips.LABS.TEK.COM (5.51/6.24)
	id AA26909; Mon, 21 Jan 91 13:26:36 PST
Received: from tektronix.TEK.COM (tektronix.TEK) by sail.labs.tek.com (4.0/7.1)
	id AA08581; Mon, 21 Jan 91 13:24:10 PST
Received: by tektronix.TEK.COM (5.51/7.1)
	id AA20776; Mon, 21 Jan 91 13:25:51 PST
Received: by sequent.sequent.com (5.61/1.34)
	id AA18762; Mon, 21 Jan 91 13:02:33 -0800
Received: by cse.ogi.edu
	(5.61+eap+OGI_1.1.named/IDA-1.2.8+OGI_1.12) id AA07704; Mon, 21 Jan 91 12:47:41 -0800
Received: by harvard.harvard.edu (5.54/a0.25)
	(for sequent!tektronix!crl.labs.tek.com!markh) id AA01670; Mon, 21 Jan 91 15:46:59 EST
Received: by genrad.com (5.57)
	id AA20687; Mon, 21 Jan 91 10:50:37 -0500
Received: by genrad.com (5.57)
	id AA20674; Mon, 21 Jan 91 10:50:25 -0500
Date: Mon, 21 Jan 91 10:50:25 -0500
From: sail.labs.tek.com!ogicse!genrad.com!mlf@sequent.UUCP (Matt Fichtenbaum)
Message-Id: <9101211550.AA20674@genrad.com>
To: crl.labs.tek.com!markh@ogicse.UUCP
Subject: Teco, part 1 of 5
Status: OR

Hi, Mark,

    Thanks for the kind words.  I'm glad to hear you're making use of
TECO; there are still a few of us left in the world.  Four more messages,
each containing the usual C-source files separated by lines beginning
with ####, follow.  These contain my latest source.

    As for bugs:  I (unfortunately) knew about the EQ empty-string bug,
which cost me an hour's lost work once.  Interesting about the form-feed
switch.  One of my other "customers" tells me that Q*, the filespec buffer,
should also be part of the file structure, so that switching between
primary and secondary input streams keeps the relevant file name available.
I've not done any of that yet.  He also claims a subtle bug in the Otag$ code,
and that a few commands don't properly consume arguments (resetting esp->op to
OP_START and clearing the flags).  I've, of course, gotten around to fixing
none of this. :-)

    Instead, my recent TECO activity has been a result of my having acquired
an MS-DOS machine at home and porting TECO to it in order to (a) have it
available, and (b) learn relevant PC and DOS stuff.  Funny you should comment
on the screen code (thanks, again, for the kindness): in writing the corres-
ponding PC code, I still haven't included all the incremental-redraw niceness
that the Ultrix version has.  There's not quite the same incentive when one has
direct access to video refresh memory.

    Anyway, I added support, in the PC version, for the keyboard function
keys and the mouse.  Then I began to miss same at work, so I added support
for VT-100 function keys.  Following are a section of changes to the "teco.doc"
document describing them, plus a skeleton ".tecorc" file illustrating their
use.

    The function-key mechanism uses the Unix "select" function to find escape
sequences that come in within a certain time, so it should well be adaptible
to Sun keyboards (which also generate escape sequences, though different, for
their function keys).  See the following document fragment for details on the
rest.

    Good luck.  Let me know if I can help, or if you'd like the DOS version.

P.S.  I, too, once considered variable-length cells to minimize moving char's
around for insert and delete.  I was going to add a "count" field to the cell
header, make insert and delete work with partial cells (delete trims the cell
containing the start of the deletion, makes a left-justified copy of the cell
ending the deletion, and leaves the rest the same; insert trims the start cell,
left-justifies the first cell afterwards, and adds new cells), make set_pointer
work with partial cells (sum "counts" rather than dividing by CELLSIZE), and
think of some clever scheme for where and when to garbage-collect.  But it
hasn't happened yet.  Let me know what you do.

Matt

---------------------------------------------
Document describing function keys


   nFL		Command to move pointer "n" display lines up or down, to the
		character on the new line at the same column position as the
		character at the original position.  (If the display window
		is not enabled, this command is treated as the "L" command).
--------

   EZ		word with some unrelated one-bit flags, as follows:

	32768	0: Function key support is disabled.
		1: Function key support is enabled (see Function Keys, below).

--------

Function key support

     TECO includes provisions to use the PC keyboard's function and cursor keys.
Function keys may immediately invoke TECO macros and/or insert text into the
command string; this mechanism allows the TECO user to implement a variety of
single-key immediate editor operations.

     Function keys are enabled by setting the "32768" bit in variable EZ.  They
operate as follows.  TECO includes is an additional set of 36 Q-registers,
called Q`0..Q`9 and Q`A..Q`Z.  Each function key has one of these registers
associated with it, as described in this table:

	KEY			Q-reg		----code read by ^T-----------
	Keypad 0..9		Q`A..Q`J	hex 100..109	octal 400..411
	Cursor up,down		Q`K, Q`L	hex 10a, 10b	octal 412, 413
	Cursor left, right	Q`M, Q`N	hex 10c, 10d	octal 414, 415
	PF1..PF4		Q`O..Q`R	hex 10e..111	octal 420, 421
	Keypad -		Q`S		hex 112		octal 422
	Keypad ,		Q`T		hex 113		octal 423
	Keypad .		Q`U		hex 114		octal 424
	Keypad ENTER		Q`V		hex 115		octal 425

The function key's operation depends on the value in the associated Q-register's
numeric part, as follows:

	16	0: This function key is not active.
		1: This function key is active.

	32	0: The associated register's text part contains a TECO macro 
		   that is executed immediately.  The macro may contain any
		   valid TECO commands.
		1: The macro contains text that is inserted into the current
		   command string.

	64	0: This function key is active anytime.
		1: This key is active only at the beginning of a command line,
		   i.e., before any command characters have been entered.

	128	0: This function key operates normally.
		1: After this key's associated macro is executed, the functions
		   associated with register Q`0 are performed as controlled by
		   the numeric part of Q`0.  A function-key macro can use this
		   facility to insert text into the current command string by
		   (1) writing the text into register Q`0, (2) setting the "16"
		   and "32" bits in Q`0, and (3) setting the "128" bit in the
		   register associated with the function key..

    Function keys are not active while TECO is executing commands, only while
TECO is accepting a command string from the keyboard.  The registers Q`0..Q`9
and Q`A..Q`Z may be used as normal Q-registers when function keys are not
enabled.

     Function keys also produce codes that can be read using the ^T command.
When a function key is struck, ^T reads a value as shown in the table, above.

-------------------------------------------
My VT-100 keypad layout

|--------|--------|--------|---------
| Up     | Down   | Left   | Right  |
| row    | row    | char   | char   |
|       ^|       v|       <|       >|
|--------|--------|--------|---------

|--------|--------|--------|--------|
| Delete |        | ew^Eq* | Toggle |
|        |        |        | seeall |
|     PF1|     PF2|     PF3|     PF4|
|--------|--------|--------|--------|
| Page   | Line   | Buffer |        |
| up     | up     | #1     |        |
|       7|       8|       9|       -|
|--------|--------|--------|--------|
| Page   | Line   | Buffer |        |
| down   | down   | #2     |        |
|       4|       5|       6|       ,|
|--------|--------|--------|--------|
| Search | Search | ^Pc    |        |
| again  | back   |        |        |
|       1|       2|       3|        |
|--------|--------|--------|        |
|                 |  Auto- | Insert |
|      <$><$>     | indent | mode   |
|                0|       .|     ENT|
|-----------------|--------|--------|


---------------------------------------------
Skeleton .tecorc

! teco startup file 12/18/90 09.54 !
! invoke te -vfF8erw [+nnn] [@file] [file] [file2] !
! -v screen off (default on) !
! -f formfeed ends page (default no) !
! -F disables VT100 function keys (default on) !
! -8 tabs every 8 chars (default 4) !
! -e erfile$ ewfile2$ if file2, else erfile$ ewfile$ !
! -r erfile$ only !
! -w ewfile$ only !
! +nnn use unix line convention, start at line nnn !
! @file do eifile$, leave rest of line in qz for macro !

@ei// hk 70+128ez gz 0j 0ux 0uz 0,0xx 0,0xy
<:s "u zj 0;' ::s-;    ! scan option flags !
 <.-z"e 0;'
  0a-^^f"e 2,0ez
  | 0a-^^8"e 4,0ez
  | 0a-^^e"e qz&120+1uz
  | 0a-^^r"e qz&120+2uz
  | 0a-^^w"e qz&120+4uz
  | 0a-^^v"e qz#8uz
  | 0a-^^F"e qz#64uz
  | 0a-^^ "e 0;
  | @^A/Invalid option / 0a^T 13^T 10^T hkekex '''''''' 1c>>

::s+"s 0,32ez \ux ::s   qx"g -1%x''    ! if +nnn option spec'd save line count !

<.-z;        ! scan file args !
 ::s  ::s@"s
  .uy :s "s 1r | zj' qy,.xw ::s  .,zxzhk 0;  ! indir file !
 | .uy :s "s 1r | zj'
  :qx"e qy,.xx 0,.k     ! one file arg !
  | :qy"e qy,.xy 0,.k   ! two file args !
  | @^A/Too many files specified/ 13^T 10^T hkekex'''   ! more than 2 !
>

hk
qz&8"e :qw"e 5,7:w''

:qx"e qz&7"n @^A/(No file specified)/ 13^T 10^T '
| qz&6"n      ! -r or -w only one file allowed !
  :qy"n @^A/Too many files specified/ 13^T 10^T hkekex
  | qz&2"n :erqx"u @^A/File not found: / :g* 13^T 10^T hkekex' y | ewqx ''   ! -r or -w !
| :qy"n :erqx"u @^A/File not found: / :g* 13^T 10^T hkekex' ewqy y      ! 2 files: ERfirst, EWsecond !
  | qz&1"n :erqx "u @^A/File not found: / :g* 13^T 10^T hkekex'ewqx y   ! 1 file: ER,EW if -e !
    | :ebqx "u @^A/File not found: / :g* 13^T 10^T hkekex' y ' ' ' '       ! EB otherwise !

0j qxl 0ux 0,0xx 0,0xy

! if @file spec'd do it !
:qw"n :@ei/qw/"u :@ei/qw.tec/"u
 @^A/file not found: / :gx 13^T 10^T hkekex'' 0,0xw ^C '

0,0xz

qz&64"e      ! if -F arg not present !
 !define function keys!
 0,32768ez                      ! enable function keys !
 0,1et=1,0et               ! <ESC><=>  keypad in function key mode !
 @^u`a## @:^u`a## 32+16u`a                           !K0 - <esc><esc>!
 @^u`b#@s// # 16u`b                                    !K1 - s$ !
 @^u`c#-2@s// # 16u`c                                  !K2 - -2s$ !
 @^u`d#^Pc# 16u`d                                      !K3 - ^Pc !
 @^u`e#ee"e 2:w-(7:w)-(8:w)-1l | 8:w-1l '# 16u`e       !K4 - down display-area size lines!
 @^u`h#ee"e 1-(2:w)+(7:w)+(8:w)l | 1-(8:w)l '# 16u`h   !K7 - back display-area size lines!
 @^u`i#-1l# 16u`i                                      !K8 - up one line!
 @^u`f#1l# 16u`f                                       !K5 - down one line!
 @^u`j#0ee# 16u`j                                      !K9 - primary buffer!
 @^u`g#1ee# 16u`g                                      !K6 - secondary buffer!
 @^u`o#.-z"n 1d'# 16u`o                                !PF1 - delete 1 char!
 @^u`q#ewq*# 32+16u`q                               !PF3 - open current file for write!
 @^u`r#3:w"e 1,3:w | 0,3:w'# 16u`r                     !PF4 - toggle seeall !
 @^u`m#."g1r'# 16u`m                                   !left arrow - back one char!
 @^u`n#.-z"l1c'# 16u`n                                 !right arrow - ahead one char!
 @^u`k#-1fl'# 16u`k                                    !up arrow - up one line!
 @^u`l#1fl# 16u`l                                      !down arrow - down one line!
 @^u`u%(-2&q`v)#(q`v+1&1)u`v% 16u`u                    !K. - toggle autoindent insert mode !
  @:^u`u%q`v&2"n 13 INSERT MODE   q`v&1"n AUTOINDENT |            ''%

 ! insert: insert mode macro !
 !    ENTER toggles insert mode !
 ! cases are - delete, LF, default, ENTER, UP, DN, UP ROW, DN ROW, LEFT, RIGHT, FKEY !
 @^u`v%
  [0 [1 [2 etu2 0,8et
  INSERT MODE
  q`v#2u`v q`v&1"n  AUTOINDENT'
  <u0 q0-127"e ."n -1a-10"e -2a-13"e -2d | -1d' | -1d''
    | q0-10"e 10i q`v&1"n-2a-13"e -1lss 1r 0x0 1l g0''
    | q0-127"l q0i
    | q0-277"e 0;
    | q0-266"e -1fl
    | q0-267"e 1fl
    | q0-264"e -1l
    | q0-261"e 1l
    | q0-268"e ."n-1c'
    | q0-269"e .-z"l 1c'
    | q0&256"n
        q0&127+^^au1 ^u0q` q1:^u0 :^u0&48-16"em` q1:^u0 ^^':^u0 m0
 ''''''''''' >
  q2et ]2 ]1 ]0 -3&q`vu`v
  13                                        13
 % 16u`v
'

0uz

