tcsh with editor (again) (3 of 7)

Paul Placeway paul at osu-dbs.UUCP
Sat Apr 21 04:34:56 AEST 1984


(I'm trying again for everyone who missed some of it)

The following code is my changes to Ken Greer's tcsh.  I have added a visual
mini-editor to the shell, and cleaned up the expansion routines some what.
note that this is the 4.1 version.  When we get 4.2 up I'll repost the new
changes.

Please send any changes back to me so that I can update our version.

Note: this is part 3 of 7, you need all of the parts to make tcsh.

					Paul W. Placeway
					The Ohio State University
					(UUCP: cbosgd!osu-dbs!paul)
					(CSNet: paul at ohio-state)

================ cut here ================
: This is a shar archive.  Extract with sh, not csh.
echo x - TCSH.README
cat > TCSH.README << '!Funky!Stuff!'
------------------------------------------------------------------
C-shell with tenex-style file name recognition (and more).

I've included the full source of the changed files here.
If you've made local changes to your C shell, use diff
to see what I've done. 

If you fix any bugs or make improvements, please send them
back to me!   (Please note bug mentioned in manual tcsh.1!! -
NB: that has been fixed --fjl)

                        Ken Greer
                        Hewlett-Packard
                        Computer Research Center
                        Palo Alto, Ca. 94301

                        ucbvax!hplabs!kg     (on uucp)
                        kg at hplabs            (on CSNET)
                        kg.hplabs at udel-relay (on ARPANET)
                        (415) 857-8801       (on MA-BELL NET)


The following files have been added or changed:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sh.c (changed):
1) The code to print out the shell prompt was moved into
   a procedure "printprompt" from the previous in-line code.
   The routine "tenex" (in tenex.c) calls it.
2) Added an "autologout" facility.  No action at prompt level
   for one hour logs you out.  Time controlled by shell variable
   "autologout" set to minutes.  An unset or setting to 0 turns
   autologout off.
--------------
sh.lex.c (changed):
Added code to call "tenex" routine when reading from terminal.
--------------
tenex.c (new):
The file name recognition code.
--------------
tcsh.1 (new):
Man entry for changes made.
--------------
makefile (changed):
Changed to load with tenex.o.  Output executable called "tcsh".
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NOTES:
1) To make autologout useful on dialups, add to getty
   at line 190:
            ioctl(0, TIOCHPCL, 0);              /* Hang up on close */
   (This should be there anyway to hangup up the modem on logout.)

2) If you run "tcsh" as a login shell, login won't know to set you
   up with the new tty driver. Here's my login.c fix with
   < = oldlogin, > = newlogin...

140c140
<               if (!strcmp(pwd->pw_shell, "/bin/csh")) {
---
>               if (cshell (pwd->pw_shell)) {
364a365,379
> }
> 
> /*
>  * return TRUE if the shell is the C shell.
>  * Algorithm: TRUE if "csh" appears anywhere in string.
>  */
> cshell (shell)
> char *shell;
> {
>     register char *p;
>     extern char *index ();
>     for (p = shell; p = index (p, 'c'); p++)
>       if (strncmp (p, "csh", 3) == 0)
>           return (TRUE);
>     return (FALSE);
------------------------------------------------------------------
!Funky!Stuff!
echo x - READ_TOO
cat > READ_TOO << '!Funky!Stuff!'
Lepreau's notes:

1. Here's a minor change I made to kg's tenex.c.  You may want
        to change the value to simething else, perhaps depending if you
        have auto-wrap on your terminals.

Use the full 80 columns for alternatives display.
Should probably do a getwidth ioctl and use that instead...

176c176
<     columns = 78 / maxwidth;
---
>     columns = 80 / maxwidth;


2. makefile.orig is kg's original.
   makefile is the above plus some local Utah flags, minus a real SCCS, and set
        up to install tcsh as linked to csh.

3. The man page should mention the "autologout" shell variable.
!Funky!Stuff!
echo x - READ_THREE
cat > READ_THREE << '!Funky!Stuff!'
Placeway's notes:

1. An editor has been added to tcsh which is called by twenex().  The
routines for packing things back into the tty driver have been removed since
the editor does that stuff itself.

2. The makefile has been changed to make tcsh (not linked to csh) and put it
in /usr/bin.  /u0/osu is the local changes directory.  Our man(1) command
searches multiple paths, that's why tcsh.1 gets put there.  The make copy
command is used to save a working set of sources in our local directory.

3. I *think* that I have documented all the changes to tcsh in the manual
pages.

4. The editor's handling of up/down the history list isn't perfect, because
the orignal shells handling wasn't.  *sigh*

----------------------------------------------------------------

If you make any changes or additions, please send them to me so that I can
update my own version.

					Paul W. Placeway
					The Ohio State University IRCC
					(UUCP: cbosgd!osu-dbs!paul)
					(CSNet: paul at ohio-state)
					(Phone: (614) 422-0915)
!Funky!Stuff!
echo x - tcsh.1
cat > tcsh.1 << '!Funky!Stuff!'
.TH TCSH 1 Ohio-State
.SH NAME
tcsh \- C shell with file name completion and command line editing
.SH SYNOPSIS
chsh username /bin/tcsh    -- to get it
.SH DESCRIPTION
.I Tcsh
is an enhanced version of the Berkeley UNIX C shell
.I csh (1).
It behaves exactly like the C shell,
except for the added utilities of:
.PP
.in +6
.ti -3
1) Editing of the command line using control characters.
.sp
.ti -3
2) Interactive command, file name and user name completion.
.sp
.ti -3
3) File/Directory/User list in the middle of a typed command.
.sp
.ti -3
4) Lookup of command documentation in the middle of a typed command.
.sp
.ti -3
5) Visual step up/down through the history list.
.sp
.ti -3
6) Automatic logout after long amounts of idle time.
.in -6
.PP
.SH "FILE NAME COMPLETION"
In typing file names as arguments to commands,
it is no longer necessary to type a complete name,
only a unique abbreviation is necessary.
When you type an ESCAPE to
.I tcsh
it will complete the file name for you,
echoing the full name on the terminal.
If the file name prefix you typed matches no file name, the terminal
bell is enunciated.
The file name may be partially completed if the prefix matches several
longer file names.  If this is the case, the name is extended up to
the ambiguous deviation, and the bell is enunciated.
.PP
.I Example
.PP
In the following example, assume the plus character ``+''
is where the user typed the ESCAPE key.
Assume the current directory contained the files:
.sp
.nf
   DSC        bin        cmd       lib        memos
   DSC.NEW    chaosnet   cmtest    mail       netnews
   bench      class      dev       mbox       new
.fi
.sp
The command:
.sp
                > vi ch+
.sp
would cause 
.I tcsh
to complete the command with the name chaosnet.  If instead, the
user had typed:
.sp
                > vi D+
.sp
.I tcsh
would have extended the name to DSC and enunciated the terminal bell, 
indicating partial completion.
.PP
File name completion works equally well when other directories are addressed.
Additionally, 
.I tcsh 
understands the C shell tilde (~) convention for home directories.
Thus,
.sp
                > cd ~speech/data/fr+
.sp
does what one might expect.  This may also be used to expand login names only.
Thus,
.sp
                > cd ~sy+
.sp
does a 
.I cd
to the 
.I synthesis
directory.
.SH "COMMAND NAME RECOGNITION"
Command name recognition and completion
works in the same manner as file name recognition
and completion above.
The current value of the environment variable \fBPATH\fR is used
in searching for the command.
For example
.sp
		> newa+
.sp
might expand to
.sp
		> newaliases
.sp
Also,
.sp
		> new?
.sp
would list all commands (along PATH) that begin with "new".
.SH "FILE/DIRECTORY LIST"
At any point in typing a command, you may request "what files are available".
Thus, when you have typed, perhaps:
.sp
                > cd ~speech/data/fritz/
.sp
you may wish to know what files or subdirectories exist (in ~speech/data/fritz),
without, of course, aborting the command you are typing.
Typing the character Question mark (?), will list the files available.
The files are listed in multicolumn format, sorted column-wise .
Directories and executable files are indicated with a trailing `/' and `*',
respectively.
Once printed, the command is re-echoed for you to complete.
.PP
Additionally, one may want to know which files match a prefix.
If the user had typed:
.sp
                > cd ~speech/data/fr?
.sp
all files and subdirectories whose prefix was
``fr'' would be printed.  Notice that the example before was simply
a degenerate case of this with a null trailing file name. 
(The null string is a prefix of all strings.)
Notice also, that
a trailing slash is required to pass to a new directory for 
both file name completion and listing.
.PP
The degenerate
.sp
                > ~?
.sp
will print a full list of login names on the current system.
.PP
The behavior of the completion can be changed by setting the shell variable
.I recexact.
This makes an exact command be expanded rather than just ringing the bell.
For example, assume the current directory has two subdirectorys
called foo and food, then with
.I recexact
set the following could be done:
.sp
		> cd fo+
.br
to ...
.br
		> cd foo+
.br
to ...
.br
		> cd foo/
.sp
rather than beeping on the second escape.
.SH EDITING
The shell edits the command line using a (slightly changed) emacs format.
It does so by setting the terminal to `CBREAK' mode and getting a single
character at a time.
The following is a list of which control characters do what.
.PP
.in +6
.ti -4
.sp
^@  (NUL) Prints a help file on the current command (usually a man page).
This help file is found by searching the path list HPATH for files of the
form foo.help, foo.1, foo.8, or foo.6 in that order (assuming that 
the current command is foo).  The file is just printed, not paged in any
way.  This is because ^@ is meant to be used to look up short help files,
not manual pages.
.ti -4
.sp
^A  Moves the cursor to the beginning of the line (after the prompt)
.ti -4
.sp
^B  Moves the cursor back one space.  Beeps if it is already in column one.
.ti -4
.sp
^C  Sends a SIGINTR to the current process (from the tty driver)
.ti -4
.sp
^D  Deletes the character that is over the cursor.
.ti -4
.sp
^E  Moves the cursor to the end of the line.
.ti -4
.sp
^F  Moves the cursor forward one space.  Beeps if at the end of the line.
.ti -4
.sp
^G  Erase entire line and start over.
.ti -4
.sp
^H  (BS) Yanks back the last command typed (ignoring empty lines) the same way
that ^Y does for saved text.  This is useful if you muff a command and want
to correct it.  Its also nice for re-doing the last command.
.ti -4
.sp
^I  (TAB) Inserts a tab character
.ti -4
.sp
^J  (LF) Moves the cursor to the end of the line, inserts a newline
character, and sends the line.
.ti -4
.sp
^K  Delete all characters from the current cursor position to the end
inclusive and save them in a special buffer to be called back later (see ^Y).
.ti -4
.sp
^L  Clear the screen and redisplay the line
.ti -4
.sp
^M  (RETURN) Same as ^J
.ti -4
.sp
^N  Move to the next following word.
A word is a contigous string of one of the characters A-Z, a-z, 0-9, *, ?,
\-, ., or _.
.ti -4
.sp
^O  Flush tty output until the next tty input request (tty driver).
.ti -4
.sp
^P  Same as ^N but go backwards. I.e. previous word.
.ti -4
.sp
^Q  Restart output. (see ^S)
.ti -4
.sp
^R  Redisplay the current line and move the cursor to it's original place.
.ti -4
.sp
^S  Stop the tty's output.
.ti -4
.sp
^T  Transpose previous two characters.
.ti -4
.sp
^U  Same as ^K but kill to the beginning of the line exclusive.
.ti -4
.sp
^V  Insert the next character regardless of it's meaning (quote it).
.ti -4
.sp
^W  Delete the previous word.
.ti -4
.sp
^X  Delete the next word (see ^W).
.ti -4
.sp
^Y  Yank the characters saved (by ^K or ^U) as if they were typed on the
keyboard.
.ti -4
.sp
^Z  Send a SIGTSTP (stop) to the current process (tty driver).
.ti -4
.sp
^[  (ESC) Try to complete the typed in command or file name (see ?).
.ti -4
.sp
^\\  send a SIGQUIT (quit and dump core) to the current process (tty driver)
.ti -4
.sp
^]  Send a SIGTSTP when the program attempts to read the ^]. (tty driver)
This is usually immediately because of cbreak mode, but the assignment is left
so that cooked mode uses it.
.ti -4
.sp
^_  Put an end of file mark at the end and send the line. (tty driver)  This
either exits a pushed shell or gives you a warning about how to log out.
.ti -4
.sp
?   (question mark) Show the possible choices for completing commands.
It does this by
putting a ? at the end of the line and sending it without echoing a
newline.  The completer then does it's stuff and sends the line back.
.ti -4
.sp
^?  (DELETE) Delete the character immediately to the left of the cursor.
Beeps if the cursor is at the beginning of the line.
.ti -4
.sp
ALL OTHERS  All other characters insert themselves into the line.
.in -6
.PP
There is a new shell command, 
.B bind,
that allows the user to redefine what any key does.
If given two arguments 
.B bind
binds the function (first argument) to the given key (second argument).
the key may be either the direct character or a carret-<letter> combination,
which is converted to control-<letter>.
If given one argument
.B bind
tells you what that key does.
If you give bind the lone argument of 'defaults', it resets each key to its
default value (see the above list).
The folowing are legal functions:
.PP
.in +6
.nf
function                default key
--------                -----------
auto_insert             all printables
backward_char           ^B
backward_word           ^P
beginning_of_line       ^A
clear_screen            ^L
delete_char_backward    ^?
delete_char_forward     ^D
delete_word_backward    ^W
delete_word_forward     ^X
end_of_line             ^E
send_eof                ^_
forward_char            ^F
forward_word            ^N
helpme                  ^@
kill_to_beginning       ^U
kill_to_end             ^K
nl_send_line            ^J, ^M
quote_next              ^V
redisplay               ^R
complete                ^[
list_options            ?
start_over              ^G
transpose_chars         ^T
yank_killbuffer         ^Y
yank_last_input         ^H
tty_dsusp               ^]
tty_flush_output        ^O
tty_sigintr             ^C
tty_sigquit             ^\\
tty_sigtsusp            ^Z
tty_start_output        ^Q
tty_stop_output         ^S
.in -6
.fi
.PP
The folowing functions are also provided, but not bound by default.
The history functions step up and down through the history list by placing
the next or previous line in the editor line.  The contents of the current
line are saved, but editing changes do not effect any commands that are up
the list.
These functions are normaly bound to ^P and ^N (previous and next).
.PP
.in +6
.nf
function
--------
down_history
up_history
.in -6
.fi
.PP
If the bind command is given no arguments, all the current bindings are
listed.
.SH "OTHER THINGS"
There is also a new shell variable called
.I shlvl
Which is equal to the number of shells which the user has pushed (where one
is the login shell).
This is done by maintaining the environment variable
.I SHLVL
and incrementing it whenever a new shell is started.
.PP
The automatic logout time is controled by the variable
.I autologout
who's value is the number of minutes of inactivity will be allowed before
automaticly loging the user out.  When that many minutes have been reached,
the shell prints "autologout" and dies (without executing ~/.logout).
.SH FYI
This shell uses cbreak mode but takes typed-ahead characters anyway.
You can still use
.I stty(1)
to set some of the modes of your terminal (but not bindings).
.PP
This shell will restore your tty to a sane mode if it appears to
return from some command in raw, cbreak, or noecho mode.
.SH FILES
~/.tcshrc -- TC-shell startup file
.SH ENVORONMENT
HPATH -- path to look for command documentation
.br
SHLVL -- the number of shell levels pushed (handled be the shell)
.br
TERM -- used to tell how to handle the terminal
.SH "SHELL VARIABLES"
shlvl, term -- see above
.br
recexact -- recognize exact matches even if they are ambigous
.SH SEE ALSO
csh (1), chsh (1)
.SH BUGS
Currently it has many bugs.
.PP
Startup of the shell can be very slow.
.PP
The editor will occasionally get confused as to what it thinks is on the
screen if a tab character is deleted in the middle of a line.
.PP
Any other bugs should be sent to Paul Placeway (osu-dbs!paul or
paul at ohio-state).
.SH AUTHOR
Paul Placeway, OSU IRCC wrote the editor and is supporting tcsh at OSU.
.sp
Ken Greer, HP Labs wrote the command completion.
.sp
Mike Ellis, Fairchild, added command name recognition/completion.
!Funky!Stuff!
echo x - makefile
cat > makefile << '!Funky!Stuff!'
#
#	makefile	4.1	10/9/80
#
# C Shell with process control; VM/UNIX VAX Makefile
# Bill Joy UC Berkeley; Jim Kulp IIASA, Austria
#
CFLAGS=	-O -DTELL -DVMUNIX -Ddebug -DVFORK -I
XSTR=	/usr/ucb/xstr
ED=	-ed
AS=	-as
RM=	-rm
CXREF=	/usr/ucb/cxref
CTAGS=	/usr/ucb/ctags
LIBES=	-ljobs -ltermcap
DESTDIR= /u1/paul
SRCDEST= /u1/paul/src/tcsh/COPY
DESTMAN= /u1/paul/man/man1
# strings.o must be last in OBJS since it can change when
# previous files compile
OBJS=	sh.o sh.dol.o sh.err.o sh.exec.o sh.exp.o sh.func.o sh.glob.o \
	sh.hist.o sh.lex.o sh.misc.o sh.parse.o sh.print.o sh.sem.o sh.set.o \
	sh.proc.o sh.dir.o sh.time.o alloc.o sh.init.o printf.o \
	tw.help.o tw.main.o tw.init.o tw.parse.o sh.nfunc.o dir14.o inputl.o \
	strings.o doprnt.o

# for use in copying a good version to a safe place

SRCS=	sh.c sh.dol.c sh.err.c sh.exec.c sh.exp.c sh.func.c sh.glob.c \
	sh.hist.c sh.lex.c sh.misc.c sh.parse.c sh.print.c sh.sem.c sh.set.c \
	sh.proc.c sh.dir.c sh.time.c alloc.c sh.init.c printf.c sh.nfunc.c \
	dir14.c doprnt.c dir.h sh.dir.h sh.h sh.local.h inputl.c \
	sh.proc.h makefile READ_THREE READ_TOO TODO TCSH.README inputl.h \
	tcsh.1 tw.help.c tw.main.c tw.init.c tw.parse.c tw.h

# Special massaging of C files for sharing of strings
.c.o:
	${CC} -E ${CFLAGS} $*.c | ${XSTR} -c -
	${CC} -c ${CFLAGS} x.c 
	mv x.o $*.o

tcsh: ${OBJS} sh.local.h
	rm -f tcsh
	cc ${OBJS} -o tcsh ${LIBES}

csh.prof: ${OBJS} sh.prof.o sh.local.h mcrt0.o
	rm -f csh.prof
	ld -X mcrt0.o ${OBJS} -o csh.prof ${LIBES} -lc

sh.o.prof:
	cp sh.c sh.prof.c
	cc -c ${CFLAGS} -DPROF sh.prof.c

.DEFAULT:
	${SCCS} get $<

# need an old doprnt, whose output we can trap
doprnt.o: doprnt.c
	cc -E doprnt.c > doprnt.s
	as -o doprnt.o doprnt.s
	rm -f doprnt.s

# strings.o and sh.init.o are specially processed to be shared
strings.o: strings
	${XSTR}
	${CC} -c -R xs.c
	mv xs.o strings.o

sh.init.o:
	${CC} -E ${CFLAGS} sh.init.c | ${XSTR} -c -
	${CC} ${CFLAGS} -c -R x.c
	mv x.o sh.init.o
	
lint:
	lint ${CFLAGS} sh*.c inputl.c tw*.c

print:
	@pr READ_ME
	@pr makefile makefile.*
	@(size -l a.out; size *.o) | pr -h SIZES
	@${CXREF} sh*.c | pr -h XREF
	@ls -l | pr 
	@pr sh*.h [a-rt-z]*.h sh*.c alloc.c

vprint:
	@pr -l84 READ_ME TODO
	@pr -l84 makefile makefile.*
	@(size -l a.out; size *.o) | pr -l84 -h SIZES
	@${CXREF} sh*.c | pr -l84 -h XREF
	@ls -l | pr -l84
	@${CXREF} sh*.c | pr -l84 -h XREF
	@pr -l84 sh*.h [a-rt-z]*.h sh*.c alloc.c

vgrind:
	@cp /dev/null index
	@for i in *.h; do vgrind -t -h "C Shell" $$i >/crp/bill/csh/$$i.t; done
	@for i in *.c; do vgrind -t -h "C Shell" $$i >/crp/bill/csh/$$i.t; done
	@vgrind -t -x -h Index index >/crp/bill/csh/index.t

install: tcsh sh.local.h
	rm -f ${DESTDIR}/bin/tcsh
	cp tcsh ${DESTDIR}/bin/tcsh
#	cp tcsh.1 ${DESTMAN}

clean:
	${RM} -f a.out strings x.c xs.c tcsh
	${RM} -f *.o sh.prof.c

copy: ${SRCS}
	cp ${SRCS} ${SRCDEST}

tags:	/tmp
	${CTAGS} sh*.c
!Funky!Stuff!



More information about the Comp.sources.unix mailing list