*BSD News Article 9906


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA6783 ; Fri, 15 Jan 93 10:32:45 EST
Xref: sserve comp.unix.bsd:9963 alt.sources:4987
Path: sserve!manuel.anu.edu.au!munnari.oz.au!uunet!usc!sol.ctr.columbia.edu!ira.uka.de!Germany.EU.net!hcshh!hm
From: hm@hcshh.hcs.de (Hellmuth Michaelis)
Newsgroups: comp.unix.bsd,alt.sources
Subject: [386BSD] pcvt 2.00 - VT220 console driver (part 05/11)
Summary: 386BSD 0.1 VT220 console device driver source code
Keywords: 386BSD console driver VT220
Message-ID: <1621@hcshh.hcs.de>
Date: 15 Jan 93 13:02:28 GMT
Followup-To: comp.unix.bsd
Organization: HCS GmbH, Hamburg, Europe
Lines: 2439

Submitted-by: hm@hcshh.hcs.de (Hellmuth Michaelis)
Archive-name: pcvt-2.00/part05

---- Cut Here and unpack ----
#!/bin/sh
# This is part 05 of pcvt-2.00
if touch 2>&1 | fgrep '[-amc]' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= Support/uemacs/dot-emacsrc ==============
if test ! -d 'Support/uemacs'; then
    echo "x - creating directory Support/uemacs"
    mkdir 'Support/uemacs'
fi
if test X"$1" != X"-c" -a -f 'Support/uemacs/dot-emacsrc'; then
	echo "File already exists: skipping 'Support/uemacs/dot-emacsrc'"
else
echo "x - extracting Support/uemacs/dot-emacsrc (Text)"
sed 's/^X//' << 'SHAR_EOF' > Support/uemacs/dot-emacsrc &&
X;---------------------------------------------------------------------------
X;
X;	Startup file for MicroEMACS 3.8b, 3.10, 3.11a
X;	---------------------------------------------
X;
X;	written by Hellmuth Michaelis 1989,1990,1991,1992
X;		 Eggerstedtstr. 28
X;		 2000 Hamburg 50	(hm@hcshh.hcs.de)
X;
X;	updated: 18-02-89 -hm
X;		for os-9/68k with HP-Terminals & lookalikes
X;		tested with hp2624/hp150/hp2392/hp7009x/cumulus/zentec8392 
X;	updated: 08-12-89 -hm
X;		for HP-UX emacs 3.10
X;		tested with cumulus terminals ( == hp 700/94 )
X;	updated: 29-01-90 -hm
X;		last-edit-date macro
X;	updated: 07-10-91 -hm
X;		uemacs 3.11, debugging, polishing ..
X;
X;	edit-date: [Sun Aug 16 15:56:50 1992]
X;	Edit-Vers: [17]
X;
Xset $discmd FALSE
Xwrite-message "[Setting up Function-Key Menu system ....]"
X;
X;====== HELP SYSTEM =============================
X;	enter help system
X1 store-macro
X	set $discmd FALSE
X	bind-to-key execute-macro-2 FN1
X	1 label-function-key "  EXIT    HELP  "
X	bind-to-key execute-macro-3 FN2
X	2 label-function-key "                "
X	bind-to-key execute-macro-3 FN3
X	3 label-function-key "                "
X	bind-to-key execute-macro-3 FN4
X	4 label-function-key "                "
X	bind-to-key execute-macro-3 FN5
X	5 label-function-key "                "
X	bind-to-key execute-macro-3 FN6
X	6 label-function-key "                "
X	bind-to-key execute-macro-4 FN7
X	7 label-function-key "  prev    scrn  "
X	bind-to-key execute-macro-5 FN8
X	8 label-function-key "  next    scrn  "
X	1 next-window
X	help
X	8 resize-window
X	add-mode "red"
X	beginning-of-file
X	2 forward-character
X	clear-message-line
X	set $discmd TRUE
X!endm
X
X;	exit help
X2 store-macro
X	execute-macro-6	
X	delete-window
X	clear-message-line
X!endm
X
X;	macro 3 =  don't allow these commands === GENERAL PURPOSE ===
X3	store-macro
X	write-message "[ KEY HAS NO FUNCTION !! ]"
X!endm
X
X;	previous help page
X4 store-macro
X	beginning-of-line
X	search-reverse "=>"
X	1 redraw-display
X	2 forward-character
X!endm
X
X;	next help page
X5 store-macro
X	beginning-of-line
X	2 forward-character
X	search-forward "=>"
X	1 redraw-display
X!endm
X;=========== MAIN MENU FUNCTION KEYS & MISC ========
X;	set main function key labels
X6 store-macro
X	set $discmd FALSE
X	bind-to-key execute-macro-1 FN1
X	!force 1 label-function-key "  HELP    FILE  "
X	bind-to-key execute-macro-7 FN2
X	!force 2 label-function-key "  WORD   MOV/DEL"
X	bind-to-key execute-macro-8 FN3
X	!force 3 label-function-key "  HPUX    SPEC  "
X	bind-to-key execute-macro-9 FN4
X	!force 4 label-function-key " WINDOW   CMDS  "
X	bind-to-key execute-macro-10 FN5
X	!force 5 label-function-key " SEARCH  REPLACE"
X	bind-to-key execute-macro-11 FN6
X	!force 6 label-function-key "  MISC    CMDS  "
X	bind-to-key execute-macro-12 FN7
X	!force 7 label-function-key " REGION   CMDS  "
X	bind-to-key exit-emacs FN8
X	!force 8 label-function-key "  EXIT    EMACS "
X	clear-message-line
X	set $discmd TRUE
X!endm
X;========= WORD FUNCTIONS ======================
X;	build word-keys menu
X7 store-macro
X	set $discmd FALSE
X	bind-to-key previous-word FN1
X	1 label-function-key "  WORD  move <--"
X	bind-to-key next-word FN2
X	2 label-function-key "  WORD  move -->"
X	bind-to-key delete-previous-word FN3
X	3 label-function-key "  WORD  del  <--"
X	bind-to-key delete-next-word FN4
X	4 label-function-key "  WORD  del  -->"
X	bind-to-key case-word-capitalize FN5
X	5 label-function-key "  WORD  capitalz"
X	bind-to-key case-word-lower FN6
X	6 label-function-key "  WORD  lowrcase"
X	bind-to-key case-word-upper FN7
X	7 label-function-key "  WORD  upprcase"
X	bind-to-key execute-macro-6 FN8
X	8 label-function-key "  EXIT  TO  MAIN"
X	clear-message-line
X	set $discmd TRUE
X!endm
X;========== OP-SYS ACCESS & COMMAND EXEC =============
X8 store-macro
X	set $discmd FALSE
X	bind-to-key shell-command FN1
X	1 label-function-key "  HPUX  cmndline"
X	bind-to-key i-shell FN2
X	2 label-function-key "  HPUX    shell "
X	bind-to-key add-mode FN3
X	3 label-function-key "  ADD     MODE  "
X	bind-to-key delete-mode FN4
X	4 label-function-key " DELETE   MODE  "
X	bind-to-key execute-macro-14 FN5
X	5 label-function-key " MACRO    PAGE  "
X	bind-to-key execute-named-command FN6
X	6 label-function-key "  EXEC    cmnd  "
X	bind-to-key execute-file FN7
X	7 label-function-key "  EXEC    file  "
X	bind-to-key execute-macro-6 FN8
X	8 label-function-key "  EXIT  TO  MAIN"
X	clear-message-line
X	set $discmd TRUE
X!endm
X;========== WINDOW MANAGEMENT ===========================
X9 store-macro
X	set $discmd FALSE
X	bind-to-key next-window FN1
X	1 label-function-key "  NEXT   window "
X	bind-to-key previous-window FN2
X	2 label-function-key "  PREV   window "
X	bind-to-key delete-window FN3
X	3 label-function-key "  DEL   cur wind"
X	bind-to-key delete-other-windows FN4
X	4 label-function-key "  DEL   oth wind"
X	bind-to-key split-current-window FN5
X	5 label-function-key "  SPLIT  window "
X	bind-to-key shrink-window FN6
X	6 label-function-key " SHRINK  window "
X	bind-to-key grow-window FN7
X	7 label-function-key " ENLARGE window "
X	bind-to-key execute-macro-6 FN8
X	8 label-function-key "  EXIT  TO  MAIN"
X	clear-message-line
X	set $discmd TRUE
X!endm
X;========== SEARCH/REPLACE =============================
X10 store-macro
X	set $discmd FALSE
X	bind-to-key search-forward FN1
X	1 label-function-key " SEARCH  forward"
X	bind-to-key search-reverse FN2
X	2 label-function-key " SEARCH backward"
X	bind-to-key replace-string FN3
X	3 label-function-key " SEARCH &replace"
X	bind-to-key query-replace-string FN4
X	4 label-function-key "SRCHRPLC w/query"
X	bind-to-key hunt-forward FN5
X	5 label-function-key " REPEAT  src fwd"
X	bind-to-key hunt-backward FN6
X	6 label-function-key " REPEAT src back"
X	bind-to-key execute-macro-3 FN7
X	7 label-function-key "                "
X	bind-to-key execute-macro-6 FN8
X	8 label-function-key "  EXIT  TO  MAIN"
X	clear-message-line
X	set $discmd TRUE
X!endm
X;========== MISC CMDS ===================================
X11 store-macro
X	set $discmd FALSE
X	bind-to-key goto-matching-fence FN1
X	1 label-function-key "  GOTO  C-fence "
X	bind-to-key goto-line FN2
X	2 label-function-key "  GOTO    line  "
X	bind-to-key set FN3
X	3 label-function-key "  SET   variable"
X	bind-to-key buffer-position FN4
X	4 label-function-key "  SHOW  position"
X	bind-to-key begin-macro FN5
X	5 label-function-key " START   macro  "
X	bind-to-key end-macro FN6
X	6 label-function-key "  END    macro  "
X	bind-to-key execute-macro FN7
X	7 label-function-key "  EXEC   macro  "
X	bind-to-key execute-macro-6 FN8
X	8 label-function-key "  EXIT  TO  MAIN"
X	clear-message-line
X	set $discmd TRUE
X!endm
X;========== REGION CMDS ===================================
X12 store-macro
X	set $discmd FALSE
X	bind-to-key set-mark FN1
X	1 label-function-key "  SET     mark  "
X	bind-to-key exchange-point-and-mark FN2
X	2 label-function-key "  XCHG  pnt&mark"
X	bind-to-key kill-region FN3
X	3 label-function-key "  KILL   region "
X	bind-to-key copy-region FN4
X	4 label-function-key "  COPY   region "
X	bind-to-key case-region-lower FN5
X	5 label-function-key "LOWRCASE region "
X	bind-to-key case-region-upper FN6
X	6 label-function-key "UPPRCASE region "
X	bind-to-key execute-macro-3 FN7
X	7 label-function-key "                "
X	bind-to-key execute-macro-6 FN8
X	8 label-function-key "  EXIT  TO  MAIN"
X	clear-message-line
X	set $discmd TRUE
X!endm
X
X;====================================================
X;	Set up auto CMODE
X;====================================================
X40	store-macro
X	set %rctmp &sin $cfname "."
X	!if &equ %rctmp 0
X		!return
X	!endif
X	set %rctmp &mid $cfname &add %rctmp 1 5
X	!if &or &seq %rctmp "c" &seq %rctmp "h"
X		add-mode "cmode"
X	!endif
X!endm
Xset $readhook execute-macro-40
X
X;==============================================
X;	Load a new page
X;==============================================
X14	store-macro
X	!if &seq &find newpage.cmd ""
X		write-message "[Can not find NEWPAGE.CMD]"
X	!else
X		execute-file newpage.cmd
X	!endif
X!endm
X
X;=================================================
X;==== END OF SETUP, START EMACS... ===============
X;=================================================
Xexecute-macro-6
X;
Xadd-mode EXACT
Xadd-global-mode EXACT
X;
Xset $discmd TRUE
X;
X;>>> EDITDATE.CMD - adjust the edit date and edit number
X;
X;	The edit date is the date that the file was last editted on. The
X;	edit number is just an incrementing number that gets bumped whenever
X;	the file is editted.
X;
X;	Formats of the edit date and edit number field are:
X;
X;		Edit-Date: [Wed Aug 01 10:05:13 199]
X;		Edit-Vers: [0]
X;
X;	You should also put the two above lines at the top of your
X;	emacs.rc file so that whenever you edit it they wlll get
X;	updated!
X;
X;	updates:
X;		- save current position
X;		- save current search string
X;		- reset exact mode while searching for "Edit-Date: []"
X;
X22	store-macro
X	9 set-mark
X;	write-message "[Checking if buffer is in VIEW mode]"
X	!if &equal &band $cmode 16 0
X		set %MODESAVE $cmode
X		set %LASTSRCH $search
X		set $cmode &band $cmode &bnot 8
X		write-message "[Looking for Edit-Date: []]"
X		beginning-of-file
X		!force search-forward &cat "Edit-Date: " "["
X		!if &seq $status TRUE
X			0 set-mark
X			search-forward "]"
X			1 backward-character
X			kill-region
X			insert-string $time
X		!endif
X		write-message "[Looking for Edit-Vers: []]"
X		!force search-forward &cat "Edit-Vers: " "["
X		!if &seq $status TRUE
X			0 set-mark
X			search-forward "]"
X			1 backward-character
X			kill-region
X			insert-string &add $kill 1
X		!endif
X		beginning-of-file
X		clear-message-line
X		set $cmode %MODESAVE
X		set $search %LASTSRCH
X	!endif
X9 exchange-point-and-mark
X!endm
X;
Xset $writehook execute-macro-22
SHAR_EOF
$TOUCH -am 0112125693 Support/uemacs/dot-emacsrc &&
chmod 0640 Support/uemacs/dot-emacsrc ||
echo "restore of Support/uemacs/dot-emacsrc failed"
set `wc -c Support/uemacs/dot-emacsrc`;Wc_c=$1
if test "$Wc_c" != "9469"; then
	echo original size 9469, current size $Wc_c
fi
fi
# ============= Support/uemacs/emacs.hlp ==============
if test X"$1" != X"-c" -a -f 'Support/uemacs/emacs.hlp'; then
	echo "File already exists: skipping 'Support/uemacs/emacs.hlp'"
else
echo "x - extracting Support/uemacs/emacs.hlp (Text)"
sed 's/^X//' << 'SHAR_EOF' > Support/uemacs/emacs.hlp &&
X=>		MicroEMACS 3.11 Help screens		(03/19/89)
X
X	M-  means to use the <ESC> key prior to using another key
X	^A  means to use the control key at the same time as the A key
X
X^V or [Pg Dn]	  Scroll down		M-< or <HOME>	Begining of file
X^Z or [Pg Up]	  Scroll up		M-> or <END>	End of file
X
X-----------------------------------------------------------------------
X=>		(1) MOVING THE CURSOR
X
X^F  Forward character	M-F    Forward word		Keypad arrows
X^B  Backward character	M-B    Backward word		are active!
X^A  Front of line	M-G    Goto a line
X^E  End of line		
X^N  Next line		M-N    Front of paragraph
X^P  Previous line	M-P    End of paragraph
X-----------------------------------------------------------------------
X=>		(2) DELETING & INSERTING
X
X<--		Delete previous character
X^D or <DELETE>	Delete next character
X^C or <INSERT>	Insert a space
XM-<--		Delete previous word
XM-D		Delete next word
X^K		Close (delete) to end of line
X-----------------------------------------------------------------------
X=>		(2a) MORE DELETING & INSERTING
X
X<RETURN>   Insert a newline		<TAB>  Advance to next tab stop
X^J	   Insert a newline and indent	M-^W   Delete paragraph
X^O	   Open (insert) line
X^W	   Delete region between mark (set using M-<spacebar>) and cursor
XM-W	   Copy region to kill buffer
X^X^O	   Delete blank lines around cursor
X-----------------------------------------------------------------------
X=>		(3) SEARCHING
X
X^S	Search forward from cursor position.
X^R	Reverse search from cursor position.
X^XS	Forward incremental search
X^XR	Reverse incremental search
X<ALT> S	Search for the next occurence of the last string (IBM-PC only)
X<ALT> R	Search for the last occurence of the last string (IBM-PC only)
X-----------------------------------------------------------------------
X=>		(4) REPLACING
X
XM-R   Replace all instances of first typed-in string with second
X	  typed-in string.  End each string with ESC.
XM-^R  Replace with query.  Answer with:
X	^G  cancel		   .   exit to entry point
X	!   replace the rest		Y    replace & continue
X	?   Get a list of options	N   no replacement & continue
X-----------------------------------------------------------------------
X=>		(5) CAPITALIZING & TRANSPOSING
X
XM-U	UPPERCASE word
XM-C	Capitalize word 	    ^T	    Transpose characters
XM-L	lowercase word
X^X^L	lowercase region
X^X^U	uppercase region
X^Q	Quote next entry, so that control codes may be entered into text
X-----------------------------------------------------------------------
X=>		(6) REGIONS & THE KILL BUFFER
X
XM-<spacebar>	set MARK at current position
X^X^X		eXchange mark and cursor
X
XA REGION will then be continuously-defined as the area between the mark and
Xthe current cursor position.  The KILL BUFFER is the text which has been
Xmost recently saved or deleted.
X-----------------------------------------------------------------------
X=>		(7) COPYING AND MOVING
X
X^W  Delete (Wipe) region		M-W	copy region to KILL buffer
X^Y  Yankback save buffer at cursor
XGenerally, the procedure for copying or moving text is:
X    1)	Mark a REGION using M-<spacebar> at beginning and cursor at end.
X    2)	Delete it (with ^W) or copy it (with M-W) into the KILL buffer.
X    3)	Move the cursor to the desired location and yank it back (with ^Y).
X-----------------------------------------------------------------------
X=>		(8) MODES OF OPERATION
X^XM	Add mode in buffer		M-M    Add global mode
X^X^M	Delete mode in buffer		M-^M   Delete global mode
XOVER		Replaces (overwrites) rather than inserts characters
XWRAP		Turns on word wrap (automatic newlines)
XVIEW		Allows viewing file without insertion and deletion
XCMODE		Automatic indenting for C program entry
XEXACT/MAGIC	Changes how search and replace commands work (see next page)
X-----------------------------------------------------------------------
X=>		(9) SEARCH AND REPLACE MODES
X
XEXACT	Uppper/lower case is not ignored in searches
XMAGIC	Regular pattern matching characters are active
X    .	Matches any one character
X    *	Matches any any number of the preceding character
X    ^	Beginning of line	 [ ]   Character class enclosure
X    $	End of line		 \     Quote next character
X-----------------------------------------------------------------------
X=>		(10) ON-SCREEN FORMATTING
X
X^XF		Set fill column
XMn-<tab>	Set tab spacing to n charecters between tabs stops
XM-Q		Format paragraph so that text lies between margins
X^X=		Position report -- displays line number, char count,
X				   file size and character under cursor
XM-^C		Count words/lines/chars in marked region
X-----------------------------------------------------------------------
X=>		(11) MULTIPLE WINDOWS
X
XMany WINDOWS may be active at once on the screen.  All windows may show
Xdifferent parts of the same buffer, or each may display a different one.
X^X2	Split the current window in two	^XO	Change to next window
X^X0	delete current window		^XP	Change to previous window
X^X1	delete all other windows	M-^V	Page down next window
X					M-^Z	Page up other window
X-----------------------------------------------------------------------
X=>		(12) CONTROLLING WINDOWS AND THE SCREEN
X
X^X^	Enlarge current window	 M-<n> ^XW   Resize window to <n> lines
X^X^Z	Shrink current window
X^X^N	Move window down
X^X^P	Move window up
XM-^L	Reposition window
X^L	Refresh the screen
X-----------------------------------------------------------------------
X=>		(13) MULTIPLE BUFFERS
XA BUFFER is a named area containing a document being edited.  Many buffers
Xmay be activated at once.
X^XB	Switch to another buffer.  <CR> = use just-previous buffer
X^XX	Switch to next buffer in buffer list
XM-^N	Change name of current buffer
X^XK	Delete a non-displayed buffer.
X^X^B	Display buffer directory in a window
X-----------------------------------------------------------------------
X=>		(14) READING FROM DISK
X
X^X^F	Find file; read into a new buffer created from filename.
X	(This is the usual way to begin editing a new file.)
X^X^R	Read file into current buffer, erasing its previous contents.
X	No new buffer will be created.
X^X^I	Insert file into current buffer at cursor's location.
X^X^V	Find a file to make current in VIEW mode
X-----------------------------------------------------------------------
X=>		(15) SAVING BUFFERS AND REGIONS TO DISK
X
X^X^S	Save current buffer to disk
X^X^W	Write current buffer to disk
X^XN	Change file name of current buffer
XM-Z	Write out all changed buffers and exit MicroEMACS
X^X<	Make everything outside the current region invisable
X^X>	Restore invisible text
X-----------------------------------------------------------------------
X=>		(16) ACCESSING THE OPERATING SYSTEM
X
X^X!	Send one command to the operating system and return
X^X@	Pipe DOS command results to buffer
X^X#	Filter buffer through DOS filter program
X^XC	Start a new command processor under MicroEMACS
X^XD	Suspend MicroEMACS into the background (UNIX BSD4.2 only)
X^X^C	Exit MicroEMACS
X-----------------------------------------------------------------------
X=>		(17) KEY BINDINGS AND COMMANDS
X
XM-K	Bind a key to a command        M-A  Describe a class of commands
XM-^K	Unbind a key from a command
X^X?	Describe command bound to a key
XM-X	Execute a named (and possibly unbound) command
X{Describe-bindings}
X	Display a list of all commands and key bindings to a buffer
X-----------------------------------------------------------------------
X=>		(18) COMMAND EXECUTION
XCommands can be specified as command lines in the form:
X	<optional repeat count> {command-name} <optional arguments>
X{Execute-command-line}	execute a typed in command line
X{Execute-buffer}	executes commands lines in a buffer
X{Execute-file}		executes command lines from a file
X{clear-message-line}	clears the message line during execution
X   M-~			clears the modified flag for a buffer
X-----------------------------------------------------------------------
X=>		(19) MACRO EXECUTION
X
X^X(	Start recording keyboard macro
X^X)	Stop recording keyboard macro
X^XE	Execute keyboard macro
XM-<n> {store-macro}	Start recording named macro
X      !endm		Stop recording named macro
X{execute-macro-n}	Execute macro n (where n is from 1 to 20)
X-----------------------------------------------------------------------
X=>		(20) SPECIAL KEYS
X
X^G		Cancel current command and return to top level of processing.
X^U or		Universal repeat.  May be followed by an integer (default = 4)
XM-<digit>	and repeats the next command that many times.
XM-X		Execute a named (and possibly unbound) command
X
X
X
SHAR_EOF
$TOUCH -am 0112125693 Support/uemacs/emacs.hlp &&
chmod 0640 Support/uemacs/emacs.hlp ||
echo "restore of Support/uemacs/emacs.hlp failed"
set `wc -c Support/uemacs/emacs.hlp`;Wc_c=$1
if test "$Wc_c" != "8365"; then
	echo original size 8365, current size $Wc_c
fi
fi
# ============= Support/uemacs/unix.c-3.11a ==============
if test X"$1" != X"-c" -a -f 'Support/uemacs/unix.c-3.11a'; then
	echo "File already exists: skipping 'Support/uemacs/unix.c-3.11a'"
else
echo "x - extracting Support/uemacs/unix.c-3.11a (Text)"
sed 's/^X//' << 'SHAR_EOF' > Support/uemacs/unix.c-3.11a &&
X/*---------------------------------------------------------------------------*
X *
X *	Last Edit-Date: [Sun Aug 16 16:00:28 1992]
X *
X *	HP-Terminal Handling written by
X *		Hellmuth Michaelis, Hamburg, Germany
X *	e-mail: hm@hcshh.hcs.de tel: +49-40-559030
X *
X *	-hm	updating from emacs 3.10 to 3.11 beta
X *		- standout not erased by overwrite display handling
X *		- function key handling
X *		- function key labeling handling
X *		- keyboard open & close routines
X *		- function key label & contents backup store
X *
X *	-hm	updating to emacs version 3.11/3.11a
X *	-hm	modifying termcap table
X *	-hm	fkey-labels for 386bsd virtual ansi-2392 terminal
X *
X *---------------------------------------------------------------------------*/
X
X/**
X	New features:
X
X	1. Timeouts waiting on a function key have been changed from
X	35000 to 500000 microseconds.
X
X	2. Additional keymapping entries can be made from the command
X	language by issuing a 'set $palette xxx'.  The format of
X	xxx is a string as follows:
X		"KEYMAP keybinding escape-sequence".
X	To add "<ESC><[><A>" as a keybinding of FNN, issue:
X		"KEYMAP FNN ^[[A".
X	Note that the escape character!  It is a read escape character
X	and it's pretty difficult to enter.
X
X	3. Colors are supported.  Under AIX the colors will be pulled
X	in automaticly.  For other environments, you can either add
X	the termcap entries, C0 to D7.  Or the colors may be defined
X	using the command language by issuing a 'set $palette xxx'
X	command.  The format of xxx is a string as follows:
X		"CLRMAP # escape-sequence".
X	The number is a number from 0 to 15, where 0 to 7 is the
X	foreground colors, and 8 to 15 as background colors.
X	To add foreground color 0 for ansi terminals, issue:
X		"CLRMAP 0 ^[[30m".
X	
X	'Porting notes:
X
X	I have tried to create this file so that it should work
X	as well as possible without changes on your part.
X
X	However, if something does go wrong, read the following
X	helpful hints:
X
X	1. On SUN-OS4, there is a problem trying to include both
X	the termio.h and ioctl.h files.  I wish Sun would get their
X	act together.  Even though you get lots of redefined messages,
X	it shouldn't cause any problems with the final object.
X
X	2. In the type-ahead detection code, the individual UNIX
X	system either has a FIONREAD or a FIORDCHK ioctl call.
X	Hopefully, your system uses one of them and this be detected
X	correctly without any intervention.
X
X	3. Also lookout for directory handling.  The SCO Xenix system
X	is the weirdest I've seen, requiring a special load file
X	(see below).  Some machine call the result of a readdir() call
X	a "struct direct" or "struct dirent".  Includes files are
X	named differently depending of the O/S.  If your system doesn't
X	have an opendir()/closedir()/readdir() library call, then
X	you should use the public domain utility "ndir".
X
X	To compile:
X		Compile all files normally.
X	To link:
X		Select one of the following operating systems:
X			SCO Xenix:
X				use "-ltermcap" and "-lx";
X			SUN 3 and 4:
X				use "-ltermcap";
X			IBM-RT, IBM-AIX, ATT UNIX, Altos UNIX, Interactive:
X				use "-lcurses".
X**/
X
X/** Include files **/
X#include <stdio.h>			/* Standard I/O definitions	*/
X#include "estruct.h"			/* Emacs definitions		*/
X
X/** Do nothing routine **/
Xint scnothing()
X{
X	return(0);
X}
X
X/** Only compile for UNIX machines **/
X#if BSD || USG || SMOS || HPUX || SUN || XENIX || AVIION
X
X/* for 386BSD 0.0new (-hm) */
X#if BSD386
X#define USE_OLD_TTY
X#endif
X
X/** Include files **/
X#include "eproto.h"			/* Function definitions		*/
X#include "edef.h"			/* Global variable definitions	*/
X#include "elang.h"			/* Language definitions		*/
X
X/** Kill predefined **/
X#undef CTRL				/* Problems with CTRL		*/
X
X/** Overall include files **/
X#include <sys/types.h>			/* System type definitions	*/
X#include <sys/stat.h>			/* File status definitions	*/
X#include <sys/ioctl.h>			/* I/O control definitions	*/
X
X/** Additional include files **/
X#if BSD
X#include <sys/time.h>			/* Timer definitions		*/
X#endif /* BSD */
X#if BSD || SUN || HPUX || AVIION
X#include <signal.h>			/* Signal definitions		*/
X#endif /* BSD || SUN || HPUX || AVIION */
X#if USG || SMOS || HPUX || SUN || XENIX
X#include <termio.h>			/* Terminal I/O definitions	*/
X#endif /* USG || SMOS || HPUX || SUN || XENIX */
X#if AVIION
X#include <termios.h>			/* Terminal I/O definitions	*/
X#endif /* AVIION */
X#if CURSES
X#include <curses.h>			/* Curses screen output		*/
X#undef WINDOW				/* Oh no!			*/
X#endif /* CURSES */
X
X/** Completion include files **/
X/** Directory accessing: Try and figure this out... if you can! **/
X#if BSD
X#include <sys/dir.h>			/* Directory entry definitions	*/
X#define DIRENTRY	direct
X#endif /* BSD */
X#if XENIX || VAT
X#include <sys/ndir.h>			/* Directory entry definitions	*/
X#define DIRENTRY	direct
X#endif /* XENIX */
X#if (USG && !VAT) || SMOS || HPUX || SUN || AVIION
X#include <dirent.h>			/* Directory entry definitions	*/
X#define DIRENTRY	dirent
X#endif /* USG || SMOS || HPUX || SUN || AVIION */
X
X/** Restore predefined definitions **/
X#undef CTRL				/* Restore CTRL			*/
X#define CTRL 0x0100
X
X/** Parameters **/
X#define NKEYENT		300		/* Number of keymap entries	*/
X#define NINCHAR		64		/* Input buffer size		*/
X#define NOUTCHAR	256		/* Output buffer size		*/
X#if TERMCAP
X#define NCAPBUF		1024		/* Termcap storage size		*/
X#endif /* TERMCAP */
X#define MARGIN		8		/* Margin size			*/
X#define SCRSIZ		64		/* Scroll for margin		*/
X#define NPAUSE		10		/* # times thru update to pause */
X
X/** CONSTANTS **/
X#define TIMEOUT		255		/* No character available	*/
X
X/** Type definitions **/
Xstruct keyent {				/* Key mapping entry		*/
X	struct keyent * samlvl;		/* Character on same level	*/
X	struct keyent * nxtlvl;		/* Character on next level	*/
X	unsigned char ch;		/* Character			*/
X	int code;			/* Resulting keycode		*/
X};
X#if TERMCAP
Xstruct capbind {			/* Capability binding entry	*/
X	char * name;			/* Termcap name			*/
X	char * store;			/* Storage variable		*/
X};
Xstruct keybind {			/* Keybinding entry		*/
X	char * name;			/* Termcap name			*/
X	int value;			/* Binding value		*/
X};
Xchar *reset = (char*) NULL;		/* reset string kjc */
X#endif /* TERMCAP */
X
X/** Local variables **/
X#if BSD
Xstatic struct sgttyb cursgtty;		/* Current modes		*/
Xstatic struct sgttyb oldsgtty;		/* Original modes		*/
Xstatic struct tchars oldtchars;		/* Current tchars		*/
Xstatic struct ltchars oldlchars;	/* Current ltchars		*/
Xstatic char blank[6] =			/* Blank out character set	*/
X	{ -1, -1, -1, -1, -1, -1 };
X#endif /* BSD */
X#if USG || SMOS || HPUX || SUN || XENIX
Xstatic struct termio curterm;		/* Current modes		*/
Xstatic struct termio oldterm;		/* Original modes		*/
X#endif /* USG || SMOS || HPUX || SUN || XENIX */
X#if AVIION
Xstatic struct termios curterm;		/* Current modes		*/
Xstatic struct termios oldterm;		/* Original modes		*/
X#endif /* AVIION */
X#if TERMCAP
Xstatic char tcapbuf[NCAPBUF];		/* Termcap character storage	*/
X#define CAP_CL		0		/* Clear to end of page		*/
X#define CAP_CM		1		/* Cursor motion		*/
X#define CAP_CE		2		/* Clear to end of line		*/
X#define CAP_SE		3		/* Standout ends		*/
X#define CAP_SO		4		/* Standout (reverse video)	*/
X#define CAP_IS		5		/* Initialize screen		*/
X#define CAP_KS		6		/* Keypad mode starts		*/
X#define CAP_KE		7		/* Keypad mode ends		*/
X#define CAP_VB		8		/* Visible bell			*/
X#if COLOR
X#define CAP_C0		9		/* Foreground color #0		*/
X#define CAP_C1		10		/* Foreground color #1		*/
X#define CAP_C2		11		/* Foreground color #2		*/
X#define CAP_C3		12		/* Foreground color #3		*/
X#define CAP_C4		13		/* Foreground color #4		*/
X#define CAP_C5		14		/* Foreground color #5		*/
X#define CAP_C6		15		/* Foreground color #6		*/
X#define CAP_C7		16		/* Foreground color #7		*/
X#define CAP_D0		17		/* Background color #0		*/
X#define CAP_D1		18		/* Background color #1		*/
X#define CAP_D2		19		/* Background color #2		*/
X#define CAP_D3		20		/* Background color #3		*/
X#define CAP_D4		21		/* Background color #4		*/
X#define CAP_D5		22		/* Background color #5		*/
X#define CAP_D6		23		/* Background color #6		*/
X#define CAP_D7		24		/* Background color #7		*/
X#endif /* COLOR */
Xstatic struct capbind capbind[] = {	/* Capability binding list	*/
X	{ "cl" },			/* Clear to end of page		*/
X	{ "cm" },			/* Cursor motion		*/
X	{ "ce" },			/* Clear to end of line		*/
X	{ "se" },			/* Standout ends		*/
X	{ "so" },			/* Standout (reverse video)	*/
X	{ "is" },			/* Initialize screen		*/
X	{ "ks" },			/* Keypad mode starts		*/
X	{ "ke" },			/* Keypad mode ends		*/
X	{ "vb" },			/* Visible bell			*/
X#if COLOR
X	{ "c0" },			/* Foreground color #0		*/
X	{ "c1" },			/* Foreground color #1		*/
X	{ "c2" },			/* Foreground color #2		*/
X	{ "c3" },			/* Foreground color #3		*/
X	{ "c4" },			/* Foreground color #4		*/
X	{ "c5" },			/* Foreground color #5		*/
X	{ "c6" },			/* Foreground color #6		*/
X	{ "c7" },			/* Foreground color #7		*/
X	{ "d0" },			/* Background color #0		*/
X	{ "d1" },			/* Background color #1		*/
X	{ "d2" },			/* Background color #2		*/
X	{ "d3" },			/* Background color #3		*/
X	{ "d4" },			/* Background color #4		*/
X	{ "d5" },			/* Background color #5		*/
X	{ "d6" },			/* Background color #6		*/
X	{ "d7" }			/* Background color #7		*/
X#endif /* COLOR */
X};
X#if COLOR
Xstatic int cfcolor = -1;		/* Current forground color	*/
Xstatic int cbcolor = -1;		/* Current background color	*/
X#endif /* COLOR */
Xstatic struct keybind keybind[] = {	/* Keybinding list		*/
X	{ "bt", SHFT|CTRL|'i' },	/* Back-tab key			*/
X	{ "k1", SPEC|'1' },		/* F1 key			*/
X	{ "k2", SPEC|'2' },		/* F2 key			*/
X	{ "k3", SPEC|'3' },		/* F3 key			*/
X	{ "k4", SPEC|'4' },		/* F4 key			*/
X	{ "k5", SPEC|'5' },		/* F5 key			*/
X	{ "k6", SPEC|'6' },		/* F6 key			*/
X	{ "k7", SPEC|'7' },		/* F7 key			*/
X	{ "k8", SPEC|'8' },		/* F8 key			*/
X	{ "k9", SPEC|'9' },		/* F9 key			*/
X	{ "k0", SPEC|'0' },		/* F0 or F10 key		*/
X 	{ "k;", SPEC|'0' },		/* F0 or F10 key	(kjc)	*/
X	{ "kA", CTRL|'O' },		/* Insert line key		*/
X	{ "kb", CTRL|'H' },		/* Backspace key		*/
X	{ "kC", CTRL|'L' },		/* Clear screen key		*/
X	{ "kD", CTRL|'D' },		/* Delete character key		*/
X	{ "kd", CTRL|'N' },		/* Down arrow key		*/
X	{ "kE", CTRL|'K' },		/* Clear to end of line key	*/
X	{ "kF", CTLX|0x0e},		/* Scroll forward key	(hm)	*/
X	{ "kH", META|'>' },		/* Home down key		*/
X 	{ "@7", META|'>' },		/* Home down key	(kjc)	*/
X	{ "kh", META|'<' },		/* Home key			*/
X	{ "kI", CTRL|'C' },		/* Insert character key		*/
X	{ "kL", CTRL|'K' },		/* Delete line key		*/
X	{ "kl", CTRL|'B' },		/* Left arrow key		*/
X	{ "kN", CTRL|'V' },		/* Next page key		*/
X	{ "kP", CTRL|'Z' },		/* Previous page key		*/
X	{ "kR", CTLX|0x10},		/* Scroll backward key	(hm)	*/
X	{ "kr", CTRL|'F' },		/* Right arrow key		*/
X	{ "ku", CTRL|'P' }		/* Up arrow key			*/
X};
X#endif /* TERMCAP */
Xstatic int inbuf[NINCHAR];		/* Input buffer			*/
Xstatic int * inbufh =			/* Head of input buffer		*/
X	inbuf;
Xstatic int * inbuft =			/* Tail of input buffer		*/
X	inbuf;
X#if TERMCAP
Xstatic unsigned char outbuf[NOUTCHAR];	/* Output buffer		*/
Xstatic unsigned char * outbuft = 	/* Output buffer tail		*/
X	outbuf;
X#endif /* TERMCAP */
Xstatic unsigned char keyseq[256];	/* Prefix escape sequence table	*/
Xstatic struct keyent keymap[NKEYENT];	/* Key map			*/
Xstatic struct keyent * nxtkey =		/* Next free key entry		*/
X	keymap;
Xstatic DIR *dirptr = NULL;		/* Current directory stream	*/
Xstatic char path[NFILEN];		/* Path of file to find		*/
Xstatic char rbuf[NFILEN];		/* Return file buffer		*/
Xstatic char *nameptr;			/* Ptr past end of path in rbuf	*/
X
X/** Terminal definition block **/
Xint scopen(), scclose(), ttgetc(), ttputc(), ttflush();
Xint scmove(), sceeol(), sceeop(), scbeep(), screv();
Xint sckopen(), sckclos();
X#if COLOR
Xint scfcol(), scbcol();
X#endif /* COLOR */
XTERM term = {
X	60,				/* Maximum number of rows	*/
X	0,				/* Current number of rows	*/
X	132,				/* Maximum number of columns	*/
X	0,				/* Current number of columns	*/
X	MARGIN,				/* Margin for extending lines	*/
X	SCRSIZ,				/* Scroll size for extending	*/
X	0, 0,				/* upper left corner default screen */
X	NPAUSE,				/* # times thru update to pause	*/
X	scopen,				/* Open terminal routine	*/
X	scclose,			/* Close terminal routine	*/
X	sckopen,			/* Open keyboard routine	*/
X	sckclos,			/* Close keyboard routine	*/
X	ttgetc,				/* Get character routine	*/
X	ttputc,				/* Put character routine	*/
X	ttflush,			/* Flush output routine		*/
X	scmove,				/* Move cursor routine		*/
X	sceeol,				/* Erase to end of line routine	*/
X	sceeop,				/* Erase to end of page routine	*/
X	sceeop,				/* Clear the desktop		*/
X	scbeep,				/* Beep! routine		*/
X	screv,				/* Set reverse video routine	*/
X	scnothing,			/* Set resolution routine	*/
X#if COLOR
X	scfcol,				/* Set forground color routine	*/
X	scbcol				/* Set background color routine	*/
X#endif /* COLOR */
X};
X
Xint hpterm;			/* flag braindead hp-terminal ... */
Xint hpfkey;			/* flag terminal has hp-like fkey-labels */
X
X/** Open terminal device **/
Xint ttopen()
X{
X#if BSD
X	/* Get tty modes */
X	if (ioctl(0, TIOCGETP, &oldsgtty) ||
X		ioctl(0, TIOCGETC, &oldtchars) ||
X		ioctl(0, TIOCGLTC, &oldlchars))
X		return(-1);
X
X	/* Save to original mode variables */
X	cursgtty = oldsgtty;
X
X	/* Set new modes */
X	cursgtty.sg_flags |= CBREAK;
X	cursgtty.sg_flags &= ~(ECHO|CRMOD);
X
X	/* Set tty modes */
X	if (ioctl(0, TIOCSETP, &cursgtty) ||
X		ioctl(0, TIOCSETC, blank) ||
X		ioctl(0, TIOCSLTC, blank))
X		return(-1);
X#endif /* BSD */
X#if USG || SMOS || HPUX || SUN || XENIX
X
X#if SMOS
X	/* Extended settings; 890619mhs A3 */
X	set_parm(0,-1,-1);
X#endif /* SMOS */
X
X	/* Get modes */
X	if (ioctl(0, TCGETA, &oldterm)) {
X		perror("Cannot TCGETA");
X		return(-1);
X	}
X
X	/* Save to original mode variable */
X	curterm = oldterm;
X
X	/* Set new modes */
X/*	curterm.c_iflag &= ~(INLCR|ICRNL|IGNCR); /* no ^S and ^Q possible !*/
X	curterm.c_iflag &= ~(INLCR|ICRNL|IGNCR|IXON|IXOFF);
X	curterm.c_lflag &= ~(ICANON|ISIG|ECHO);
X	curterm.c_cc[VMIN] = 1;
X	curterm.c_cc[VTIME] = 0;
X
X#if SMOS
X	/****THIS IS A BIG GUESS ON MY PART... the code changed
X	  too much between versions for me to be sure this will work - DML */
X
X	/* Allow multiple (dual) sessions if already enabled */
X	curterm.c_lflag = oldterm.c_lflag & ISIG;
X
X	/* Use old SWTCH char if necessary */
X	if (curterm.c_lflag != 0)
X		curterm.c_cc[VSWTCH] = oldterm.c_cc[VSWTCH];
X
X	/* Copy VTI settings	*/
X	curterm.c_cc[VTBIT] = oldterm.c_cc[VTBIT];
X
X	/* Extended settings; 890619mhs A3 */
X	set_parm(0,-1,-1);
X#endif /* SMOS */
X
X	/* Set tty mode */
X	if (ioctl(0, TCSETA, &curterm)) {
X		perror("Cannot TCSETA");
X		return(-1);
X	}
X#endif /* USG || SMOS || HPUX || SUN || XENIX */
X#if AVIION
X	/* Get modes */
X	if (tcgetattr(0, &oldterm)) {
X		perror("Cannot tcgetattr");
X		return(-1);
X	}
X
X	/* Save to original mode variable */
X	curterm = oldterm;
X
X	/* Set new modes */
X	curterm.c_iflag &= ~(INLCR|ICRNL|IGNCR);
X	curterm.c_lflag &= ~(ICANON|ISIG|ECHO);
X	curterm.c_cc[VMIN] = 1;
X	curterm.c_cc[VTIME] = 0;
X
X#if AVIION
X	/* Set line discipline for Data General */
X	curterm.c_line = 0;
X#endif /* AVIION */
X
X	/* Set tty mode */
X	if (tcsetattr(0, TCSANOW, &curterm)) {
X		perror("Cannot tcsetattr");
X		return(-1);
X	}
X#endif /* AVIION */
X
X	/* Success */
X	return(0);
X}
X
X/** Close terminal device **/
Xint ttclose()
X{
X	/* Restore original terminal modes */
X	if (reset != (char*)NULL)
X		write(1, reset, strlen(reset));
X
X#if BSD
X	if (ioctl(0, TIOCSETP, &oldsgtty) ||
X		ioctl(0, TIOCSETC, &oldtchars) ||
X		ioctl(0, TIOCSLTC, &oldlchars))
X		return(-1);
X#endif /* BSD */
X
X#if USG || SMOS || HPUX || SUN || XENIX
X#if SMOS
X	/* Extended settings; 890619mhs A3 */
X	set_parm(0,-1,-1);
X#endif /* SMOS */
X	if (ioctl(0, TCSETA, &oldterm))
X		return(-1);
X#endif /* USG || SMOS || HPUX || SUN || XENIX */
X
X#if AVIION
X	/* Set tty mode */
X	if (tcsetattr(0, TCSANOW, &oldterm))
X		return(-1);
X#endif /* AVIION */
X
X	/* Success */
X	return(0);
X}
X
X/** Flush output buffer to display **/
Xint ttflush()
X{
X#if TERMCAP
X	int len;
X
X	/* Compute length of write */
X	len = outbuft - outbuf;
X	if (len == 0)
X		return(0);
X
X	/* Reset buffer position */
X	outbuft = outbuf;
X
X	/* Perform write to screen */
X	return(write(1, outbuf, len) != len);
X#endif /* TERMCAP */
X
X#if CURSES
X	refresh();
X#endif /* CURSES */
X
X#ifndef TERMCAP		/* otherwise we get a "statement not reached" .. */
X	return(0);
X#endif
X}
X
X/** Put character onto display **/
Xint ttputc(ch)
Xchar ch;				/* Character to display		*/
X{
X#if TERMCAP
X	/* Check for buffer full */
X	if (outbuft == &outbuf[sizeof(outbuf)])
X		ttflush();
X
X	/* Add to buffer */
X	*outbuft++ = ch;
X#endif /* TERMCAP */
X
X#if CURSES
X	/* Put character on screen */
X	addch(ch);
X#endif /* CURSES */
X
X	return(0);
X}
X
X/** Add character sequence to keycode entry **/
Xvoid addkey(seq, fn)
Xunsigned char * seq;			/* Character sequence		*/
Xint fn;					/* Resulting keycode		*/
X{
X	int first;
X	struct keyent * cur, * nxtcur;
X
X	/* Skip on null sequences */
X	if (!seq)
X		return;
X
X	/* Skip single character sequences */
X	if (strlen(seq) < 2)
X		return;
X
X	/* If no keys defined, go directly to insert mode */
X	first = 1;
X	if (nxtkey != keymap) {
X		
X		/* Start at top of key map */
X		cur = keymap;
X		
X		/* Loop until matches exhast */
X		while (*seq) {
X			
X			/* Do we match current character */
X			if (*seq == cur->ch) {
X				
X				/* Advance to next level */
X				seq++;
X				cur = cur->nxtlvl;
X				first = 0;
X			} else {
X				
X				/* Try next character on same level */
X				nxtcur = cur->samlvl;
X				
X				/* Stop if no more */
X				if (nxtcur)
X					cur = nxtcur;
X				else
X					break;
X			}
X		}
X	}
X	
X	/* Check for room in keymap */
X	if (strlen(seq) > NKEYENT - (nxtkey - keymap))
X		return;
X		
X	/* If first character in sequence is inserted, add to prefix table */
X	if (first)
X		keyseq[*seq] = 1;
X		
X	/* If characters are left over, insert them into list */
X	for (first = 1; *seq; first = 0) {
X		
X		/* Make new entry */
X		nxtkey->ch = *seq++;
X		nxtkey->code = fn;
X		
X		/* If root, nothing to do */
X		if (nxtkey != keymap) {
X			
X			/* Set first to samlvl, others to nxtlvl */
X			if (first)
X				cur->samlvl = nxtkey;
X			else
X				cur->nxtlvl = nxtkey;
X		}
X
X		/* Advance to next key */
X		cur = nxtkey++;
X	}
X}
X
X/** Grab input characters, with wait **/
Xunsigned char grabwait()
X{
X#if BSD
X	unsigned char ch;
X
X	/* Perform read */
X	if (read(0, &ch, 1) != 1) {
X		puts("** Horrible read error occured **");
X		exit(1);
X	}
X	return(ch);
X#endif /* BSD */
X#if USG || SMOS || HPUX || SUN || XENIX || AVIION
X	unsigned char ch;
X
X	/* Change mode, if necessary */
X	if (curterm.c_cc[VTIME]) {
X		curterm.c_cc[VMIN] = 1;
X		curterm.c_cc[VTIME] = 0;
X#if USG || SMOS || HPUX || SUN || XENIX
X		ioctl(0, TCSETA, &curterm);
X#endif /* USG || SMOS || HPUX || SUN || XENIX */
X#if AVIION
X		tcsetattr(0, TCSANOW, &curterm);
X#endif /* AVIION */		
X	}
X
X	/* Perform read */
X	if (read(0, &ch, 1) != 1) {
X		puts("** Horrible read error occured **");
X		exit(1);
X	}
X
X	/* Return new character */
X	return(ch);
X#endif /* USG || SMOS || HPUX || SUN || XENIX || AVIION */
X}
X
X/** Grab input characters, short wait **/
Xunsigned char grabnowait()
X{
X#if BSD
X	static struct timeval timout = { 0, 500000L };
X	int count, r;
X
X	/* Select input */
X	r = 1;
X	count = select(1, &r, NULL, NULL, &timout);
X	if (count == 0)
X		return(TIMEOUT);
X	if (count < 0) {
X		puts("** Horrible select error occured **");
X		exit(1);
X	}
X
X	/* Perform read */
X	return(grabwait());
X#endif /* BSD */
X#if USG || SMOS || HPUX || SUN || XENIX || AVIION
X	int count;
X	unsigned char ch;
X
X	/* Change mode, if necessary */
X	if (curterm.c_cc[VTIME] == 0) {
X		curterm.c_cc[VMIN] = 0;
X		curterm.c_cc[VTIME] = 5;
X#if USG || SMOS || HPUX || SUN || XENIX
X		ioctl(0, TCSETA, &curterm);
X#endif /* USG || SMOS || HPUX || SUN || XENIX */
X#if AVIION
X		tcsetattr(0, TCSANOW, &curterm);
X#endif /* AVIION */		
X	}
X
X	/* Perform read */
X	count = read(0, &ch, 1);
X	if (count < 0) {
X		puts("** Horrible read error occured **");
X		exit(1);
X	}
X	if (count == 0)
X		return(TIMEOUT);
X
X	/* Return new character */
X	return(ch);
X#endif /* USG || SMOS || HPUX || SUN || XENIX || AVIION */
X}
X
X/** Queue input character **/
Xvoid qin(ch)
Xint ch;					/* Character to add		*/
X{
X	/* Check for overflow */
X	if (inbuft == &inbuf[sizeof(inbuf)]) {
X		
X		/* Annoy user */
X		scbeep();
X		return;
X	}
X	
X	/* Add character */
X	*inbuft++ = ch;
X}
X
X/** Cook input characters **/
Xvoid cook()
X{
X	unsigned char ch;
X	struct keyent * cur;
X	
X	/* Get first character untimed */
X	ch = grabwait();
X	qin(ch);
X	
X	/* Skip if the key isn't a special leading escape sequence */
X	if (keyseq[ch] == 0)
X		return;
X
X	/* Start at root of keymap */
X	cur = keymap;
X
X	/* Loop until keymap exhasts */
X	while (cur) {
X
X		/* Did we find a matching character */
X		if (cur->ch == ch) {
X
X			/* Is this the end */
X			if (cur->nxtlvl == NULL) {
X
X				/* Replace all character with new sequence */
X				inbuft = inbuf;
X				qin(cur->code);
X				return;
X			} else {
X				/* Advance to next level */
X				cur = cur->nxtlvl;
X			
X				/* Get next character, timed */
X				ch = grabnowait();
X				if (ch == TIMEOUT)
X					return;
X
X				/* Queue character */
X				qin(ch);
X			}
X		} else
X			/* Try next character on same level */
X			cur = cur->samlvl;
X	}
X}
X
X/** Return cooked characters **/
Xint ttgetc()
X{
X	int ch;
X
X	/* Loop until character found */
X	while (1) {
X	
X		/* Get input from buffer, if available */
X		if (inbufh != inbuft) {
X			ch = *inbufh++;
X			if (inbufh == inbuft)
X				inbufh = inbuft = inbuf;
X			break;
X		} else
X
X			/* Fill input buffer */
X			cook();
X	}
X	
X	/* Return next character */
X	return(ch);
X}
X
X#if TYPEAH
Xint typahead()
X{
X	int count;
X
X	/* See if internal buffer is non-empty */
X	if (inbufh != inbuft)
X		return(1);
X
X	/* Now check with system */
X#ifdef FIONREAD  /* Watch out!  This could bite you! */
X	/* Get number of pending characters */
X	if (ioctl(0, FIONREAD, &count))
X		return(0);
X	return(count);
X#else /* not FIONREAD */
X#ifdef VAT
X	return(0);
X#else /* not VAT */
X	/* Ask hardware for count */
X	count = ioctl(0, FIORDCHK, 0);
X	if (count < 0)
X		return(0);
X	return(count);
X#endif	/* VAT */
X#endif /* FIONREAD */
X}
X#endif /* TYPEAH */
X
X#if TERMCAP
X/** Put out sequence, with padding **/
Xvoid putpad(seq)
Xchar * seq;				/* Character sequence		*/
X{
X	/* Check for null */
X	if (!seq)
X		return;
X
X	/* Call on termcap to send sequence */
X	tputs(seq, 1, ttputc);
X}
X#endif /* TERMCAP */
X
X/** Initialize screen package **/
Xint scopen()
X{
X#if TERMCAP
X	char * cp, tcbuf[1024];
X	int status;
X	struct capbind * cb;
X	struct keybind * kp;
X
X	char * getenv(), * tgetstr();
X
X#ifndef VAT
X#define TGETSTR(a,b)	tgetstr((a), (b))
X#else
X#define TGETSTR(a,b)	tgetstr((a), *(b))
X#endif
X
X#if HPUX || VAT
X	/* HP-UX doesn't seem to have these in the termcap library */
X	char PC, * UP;
X	short ospeed;
X#else /* not HPUX */
X	extern char PC, * UP;
X	extern short ospeed;
X#endif /* HPUX */
X
X	/* Get terminal type */
X	cp = getenv("TERM");
X	if (!cp) {
X		puts("Environment variable \"TERM\" not define!");
X		exit(1);
X	}
X
X	/* Try to load termcap */
X	status = tgetent(tcbuf, cp);
X	if (status == -1) {
X		puts("Cannot open termcap file");
X		exit(1);
X	}
X	if (status == 0) {
X		printf("No entry for terminal type \"%s\"\n", cp);
X		exit(1);
X	}
X
X	/* Get size from termcap */
X	term.t_nrow = tgetnum("li") - 1;
X	term.t_ncol = tgetnum("co");
X	if (term.t_nrow < 3 || term.t_ncol < 3) {
X		puts("Screen size is too small!");
X		exit(1);
X	}
X
X	/* Start grabbing termcap commands */
X	cp = tcapbuf;
X
X	/* Get the reset string */
X	reset = TGETSTR("is", &cp);
X
X	/* Get the pad character */
X	if (tgetstr("pc", &cp))
X		PC = tcapbuf[0];
X
X	/* Get up line capability */
X	UP = TGETSTR("up", &cp);
X
X	/* Get other capabilities */
X	cb = capbind;
X	while (cb < &capbind[sizeof(capbind)/sizeof(*capbind)]) {
X		cb->store = TGETSTR(cb->name, &cp);
X		cb++;
X	}
X
X	/* Check for minimum */
X	if (!capbind[CAP_CL].store && (!capbind[CAP_CM].store || !UP)) {
X		puts("This terminal doesn't have enough power to run microEmacs!");
X		exit(1);
X	}
X
X	/* Set reverse video and erase to end of line */
X	if (capbind[CAP_SO].store && capbind[CAP_SE].store)
X		revexist = TRUE;
X	if (!capbind[CAP_CE].store)
X		eolexist = FALSE;
X
X	/* Get keybindings */
X	kp = keybind;
X	while (kp < &keybind[sizeof(keybind)/sizeof(*keybind)]) {
X		addkey(TGETSTR(kp->name, &cp), kp->value);
X		kp++;
X	}
X
X	hpterm = tgetflag("xs");	/* working on HP-Terminal ??? -hm */
X	hpfkey = tgetflag("Xs");	/* hp-like fkey-labels */
X
X	/* Open terminal device */
X	if (ttopen()) {
X		puts("Cannot open terminal");
X		exit(1);
X	}
X
X	/* Set speed for padding sequences */
X#if BSD
X	ospeed = cursgtty.sg_ospeed;
X#endif /* BSD */
X#if USG || SMOS || HPUX || SUN || XENIX
X	ospeed = curterm.c_cflag & CBAUD;
X#endif /* USG || SMOS || HPUX || SUN || XENIX */
X#if AVIION
X	ospeed = cfgetospeed(&curterm);
X#endif /* AVIION */
X	
X	/* Send out initialization sequences */
X	putpad(capbind[CAP_IS].store);
X/*	putpad(capbind[CAP_KS].store);  /* -hm */
X	sckopen();			/* -hm */
X#endif /* TERMCAP */
X
X#if CURSES
X	/* Initialize screen */
X	initscr();
X
X	/* Set size of screen */
X	term.t_nrow = LINES - 1;
X	term.t_ncol = COLS;
X
X	/* Open terminal device */
X	if (ttopen()) {
X		puts("Cannot open terminal");
X		exit(1);
X	}
X#endif /* CURSES */
X
X	/* Success */
X	return(0);
X}
X
X/** Close screen package **/
Xint scclose()
X{
X#if TERMCAP
X	/* Turn off keypad mode */
X/*	putpad(capbind[CAP_KE].store);	/* -hm */
X	sckclos();			/* -hm */
X	/* Close terminal device */
X	ttclose();
X#endif /* TERMCAP */
X
X#if CURSES
X	/* Turn off curses */
X	endwin();
X
X	/* Close terminal device */
X	ttclose();
X#endif /* CURSES */
X	/* Success */
X	return(0);
X}
X
X/* open keyboard -hm */
Xint sckopen()
X{
X#ifdef TERMCAP
X	putpad(capbind[CAP_KS].store);
X	ttflush();
X	dis_ufk();
X#endif
X}
X
X/* close keyboard -hm */
Xint sckclos()
X{
X#ifdef TERMCAP
X	putpad(capbind[CAP_KE].store);
X	ttflush();
X	dis_sfk();
X#endif
X}
X
X/** Move cursor **/
Xint scmove(row, col)
Xint row;				/* Row number			*/
Xint col;				/* Column number		*/
X{
X	char *tgoto();
X#if TERMCAP
X	/* Call on termcap to create move sequence */
X	putpad(tgoto(capbind[CAP_CM].store, col, row));
X#endif /* TERMCAP */
X
X#if CURSES
X	move(row, col);
X#endif /* CURSES */
X
X	/* Success */
X	return(0);
X}
X
X/** Erase to end of line **/
Xint sceeol()
X{
X#if TERMCAP
X	/* Send erase sequence */
X	putpad(capbind[CAP_CE].store);
X#endif /* TERMCAP */
X
X#if CURSES
X	clrtoeol();
X#endif /* CURSES */
X
X	/* Success */
X	return(0);
X}
X
X/** Clear screen **/
Xint sceeop()
X{
X#if TERMCAP
X#if COLOR
X	scfcol(gfcolor);
X	scbcol(gbcolor);
X#endif /* COLOR */
X	/* Send clear sequence */
X	putpad(capbind[CAP_CL].store);
X#endif /* TERMCAP */
X
X#if CURSES
X	erase();
X#endif /* CURSES */
X
X
X	/* Success */
X	return(0);
X}
X
X/** Set reverse video state **/
Xint screv(state)
Xint state;				/* New state			*/
X{
X#if TERMCAP
X#if COLOR
X	int ftmp, btmp;		/* temporaries for colors */
X#endif /* COLOR */
X
X	/* Set reverse video state */
X	putpad(state ? capbind[CAP_SO].store : capbind[CAP_SE].store);
X
X#if COLOR
X	if (state == FALSE) {
X		ftmp = cfcolor;
X		btmp = cbcolor;
X		cfcolor = -1;
X		cbcolor = -1;
X		scfcol(ftmp);
X		scbcol(btmp);
X	}
X#endif /* COLOR */
X#endif /* TERMCAP */
X
X#if CURSES
X	if (state)
X		standout();
X	else
X		standend();
X#endif /* CURSES */
X
X	/* Success */
X	return(0);
X}
X
X/** Beep **/
Xscbeep()
X{
X#if TERMCAP
X#if !NOISY
X	/* Send out visible bell, if it exists */
X	if (capbind[CAP_VB].store)
X		putpad(capbind[CAP_VB].store);
X	else
X#endif /* not NOISY */
X		/* The old standby method */
X		ttputc('\7');
X#endif /* TERMCAP */
X
X#if CURSES
X	addch('\7');		/* FIX THIS! beep() and flash comes up undefined */
X#endif /* CURSES */
X
X	/* Success */
X	return(0);
X}
X
X#if COLOR
X/** Set foreground color **/
Xint scfcol(color)
Xint color;		/* Color to set			*/
X{
X#if TERMCAP
X	/* Skip if already the correct color */
X	if (color == cfcolor)
X		return(0);
X
X	/* Skip if color isn't defined */
X	if (!capbind[CAP_C0].store)
X		return(0);
X
X	/* Send out color sequence */
X	putpad(capbind[CAP_C0 + (color & 7)].store);
X
X	/* Set current color */
X	cfcolor = color;
X#endif /* TERMCAP */
X
X#if CURSES
X	/* ? */
X#endif /* CURSES */
X	return(0);
X}
X
X/** Set background color **/
Xint scbcol(color)
Xint color;			/* Color to set			*/
X{
X#if TERMCAP
X	/* Skip if already the correct color */
X	if (color == cbcolor)
X		return(0);
X
X	/* Skip if color isn't defined */
X	if (!capbind[CAP_C0].store)
X		return(0);
X
X	/* Send out color sequence */
X	putpad(capbind[CAP_D0 + (color & 7)].store);
X
X	/* Set current color */
X        cbcolor = color;
X#endif /* TERMCAP */
X
X#if CURSES
X	/* ? */
X#endif /* CURSES */
X	return(0);
X}
X#endif /* COLOR */
X
X/** Set palette **/
Xint spal(cmd)
Xchar * cmd;				/* Palette command		*/
X{
X	int code, dokeymap;
X	char * cp;
X
X	/* Check for keymapping command */
X	if (strncmp(cmd, "KEYMAP ", 7) == 0)
X		dokeymap = 1;
X	else
X#if TERMCAP
X#if COLOR
X	if (strncmp(cmd, "CLRMAP ", 7) == 0)
X		dokeymap = 0;
X	else
X#endif /* COLOR */
X#endif /* TERMCAP */
X		return(0);
X	cmd += 7;
X
X	/* Look for space */
X	for (cp = cmd; *cp != '\0'; cp++)
X		if (*cp == ' ') {
X			*cp++ = '\0';
X			break;
X		}
X	if (*cp == '\0')
X		return(1);
X
X	/* Perform operation */
X	if (dokeymap) {
X
X		/* Convert to keycode */
X		code = stock(cmd);
X
X		/* Add to tree */
X		addkey(cp, code);
X	}
X#if TERMCAP
X#if COLOR
X	else {
X
X		/* Convert to color number */
X		code = atoi(cmd);
X		if (code < 0 || code > 15)
X			return(1);
X
X		/* Move color code to capability structure */
X		capbind[CAP_C0 + code].store = malloc(strlen(cp) + 1);
X		if (capbind[CAP_C0 + code].store)
X			strcpy(capbind[CAP_C0 + code].store, cp);
X	}
X#endif /* COLOR */
X#endif /* TERMCAP */
X	return(0);
X}
X
X#if BSD || SUN || HPUX || AVIION
X/* Surely more than just BSD systems do this */
X
X/** Perform a stop signal **/
Xint bktoshell(f, n)
X{
X	/* Reset the terminal and go to the last line */
X	vttidy();
X	
X	/* Okay, stop... */
X	kill(getpid(), SIGTSTP);
X
X	/* We should now be back here after resuming */
X
X	/* Reopen the screen and redraw */
X	scopen();
X	curwp->w_flag = WFHARD;
X	sgarbf = TRUE;
X
X	/* Success */
X	return(0);
X}
X
X#endif /* BSD || SUN || HPUX || AVIION */
X
X/** Get time of day **/
Xchar * timeset()
X{
X	long int buf; /* Should be time_t */
X	char * sp, * cp;
X
X	char * ctime();
X
X	/* Get system time */
X	time(&buf);
X
X	/* Pass system time to converter */
X	sp = ctime(&buf);
X
X	/* Eat newline character */
X	for (cp = sp; *cp; cp++)
X		if (*cp == '\n') {
X			*cp = '\0';
X			break;
X		}
X	return(sp);
X}
X
X#if USG || SMOS || HPUX || XENIX
X/** Rename a file **/
Xint rename(file1, file2)
Xchar * file1;				/* Old file name		*/
Xchar * file2;				/* New file name		*/
X{
X	struct stat buf1;
X	struct stat buf2;
X
X	/* No good if source file doesn't exist */
X	if (stat(file1, &buf1))
X		return(-1);
X
X	/* Check for target */
X	if (stat(file2, &buf2) == 0) {
X
X		/* See if file is the same */
X		if (buf1.st_dev == buf2.st_dev &&
X			buf1.st_ino == buf2.st_ino)
X
X			/* Not necessary to rename file */
X			return(0);
X	}
X
X	/* Get rid of target */
X	unlink(file2);
X
X	/* Link two files together */
X	if (link(file1, file2))
X		return(-1);
X
X	/* Unlink original file */
X	return(unlink(file1));
X}
X#endif /* USG || SMOS || HPUX || XENIX */
X
X/** Callout to system to perform command **/
Xint callout(cmd)
Xchar * cmd;				/* Command to execute		*/
X{
X	int status;
X
X	/* Close down */
X	scmove(term.t_nrow, 0);
X	ttflush();
X	sckclos();	/* -hm */
X	ttclose();
X
X	/* Do command */
X	status = system(cmd) == 0;
X
X	/* Restart system */
X        sgarbf = TRUE;
X	sckopen();	/* -hm */
X	if (ttopen()) {
X		puts("** Error reopening terminal device **");
X		exit(1);
X	}
X
X	/* Success */
X        return(status);
X}
X
X/** Create subshell **/
Xint spawncli(f, n)
Xint f;					/* Flags			*/
Xint n;					/* Argument count		*/
X{
X	char * sh;
X
X	char * getenv();
X
X	/* Don't allow this command if restricted */
X	if (restflag)
X		return(resterr());
X
X	/* Get shell path */
X	sh = getenv("SHELL");
X	if (!sh)
X#if BSD || SUN
X		sh = "/bin/csh";
X#endif /* BSD || SUN */
X#if USG || SMOS || HPUX || XENIX || AVIION
X		sh = "/bin/sh";
X#endif /* USG || SMOS || HPUX || XENIX || AVIION */
X
X	/* Do shell */
X	return(callout(sh));
X}
X
X/** Spawn a command **/
Xint spawn(f, n)
Xint f;					/* Flags			*/
Xint n;					/* Argument count		*/
X{
X	char line[NLINE];
X	int s;
X
X	/* Don't allow this command if restricted */
X	if (restflag)
X		return(resterr());
X
X	/* Get command line */
X	s = mlreply("!", line, NLINE);
X	if (!s)
X		return(s);
X
X	/* Perform the command */
X	s = callout(line);
X
X	/* if we are interactive, pause here */
X	if (clexec == FALSE) {
X	        mlwrite("[End]");
X		ttflush();
X		ttgetc();
X        }
X        return(s);
X}
X
X/** Execute program **/
Xint execprg(f, n)
Xint f;					/* Flags			*/
Xint n;					/* Argument count		*/
X{
X	/* Same as spawn */
X	return(spawn(f, n));
X}
X
X/** Pipe output of program to buffer **/
Xint pipecmd(f, n)
Xint f;					/* Flags			*/
Xint n;					/* Argument count		*/
X{
X	char line[NLINE];
X	int s;
X	BUFFER * bp;
X	WINDOW * wp;
X	static char filnam[] = "command";
X
X	/* Don't allow this command if restricted */
X	if (restflag)
X		return(resterr());
X
X	/* Get pipe-in command */
X	s = mlreply("@", line, NLINE);
X	if (!s)
X		return(s);
X
X	/* Get rid of the command output buffer if it exists */
X	bp = bfind(filnam, FALSE, 0);
X	if (bp) {
X		/* Try to make sure we are off screen */
X		wp = wheadp;
X		while (wp) {
X			if (wp->w_bufp == bp) {
X				onlywind(FALSE, 1);
X				break;
X			}
X			wp = wp->w_wndp;
X		}
X		if (!zotbuf(bp))
X			return(0);
X	}
X
X	/* Add output specification */
X	strcat(line, ">");
X	strcat(line, filnam);
X
X	/* Do command */
X	s = callout(line);
X	if (!s)
X		return(s);
X
X	/* Split the current window to make room for the command output */
X	if (!splitwind(FALSE, 1))
X		return(0);
X
X	/* ...and read the stuff in */
X	if (!getfile(filnam, FALSE))
X		return(0);
X
X	/* Make this window in VIEW mode, update all mode lines */
X	curwp->w_bufp->b_mode |= MDVIEW;
X	wp = wheadp;
X	while (wp) {
X		wp->w_flag |= WFMODE;
X		wp = wp->w_wndp;
X	}
X
X	/* ...and get rid of the temporary file */
X	unlink(filnam);
X	return(1);
X}
X
X/** Filter buffer through command **/
Xint filter(f, n)
Xint f;					/* Flags			*/
Xint n;					/* Argument count		*/
X{
X	char line[NLINE], tmpnam[NFILEN];
X	int s;
X	BUFFER * bp;
X	static char bname1[] = "fltinp";
X	static char filnam1[] = "fltinp";
X	static char filnam2[] = "fltout";
X
X	/* Don't allow this command if restricted */
X	if (restflag)
X		return(resterr());
X
X	/* Don't allow filtering of VIEW mode buffer */
X	if (curbp->b_mode & MDVIEW)
X		return(rdonly());
X
X	/* Get the filter name and its args */
X	s = mlreply("#", line, NLINE);
X	if (!s)
X		return(s);
X
X	/* Setup the proper file names */
X	bp = curbp;
X	strcpy(tmpnam, bp->b_fname);	/* Save the original name */
X	strcpy(bp->b_fname, bname1);	/* Set it to our new one */
X
X	/* Write it out, checking for errors */
X	if (!writeout(filnam1, "w")) {
X		mlwrite("[Cannot write filter file]");
X		strcpy(bp->b_fname, tmpnam);
X		return(0);
X	}
X
X	/* Setup input and output */
X	strcat(line," <fltinp >fltout");
X
X	/* Perform command */
X	s = callout(line);
X
X	/* If successful, read in file */
X	if (s) {
X		s = readin(filnam2, FALSE);
X		if (s)
X			/* Mark buffer as changed */
X			bp->b_flag |= BFCHG;
X	}
X			
X
X	/* Reset file name */
X	strcpy(bp->b_fname, tmpnam);
X
X	/* and get rid of the temporary file */
X	unlink(filnam1);
X	unlink(filnam2);
X
X	/* Show status */
X	if (!s)
X		mlwrite("[Execution failed]");
X	return(s);
X}
X
X/** Get first filename from pattern **/
Xchar *getffile(fspec)
Xchar *fspec;				/* Filename specification	*/
X{
X	int index, point, extflag;
X
X	/* First parse the file path off the file spec */
X	strcpy(path, fspec);
X	index = strlen(path) - 1;
X	while (index >= 0 && (path[index] != '/' &&
X		path[index] != '\\' && path[index] != ':'))
X		--index;
X	path[index+1] = '\0';
X
X
X	/* Check for an extension */
X	point = strlen(fspec) - 1;
X	extflag = FALSE;
X	while (point >= 0) {
X		if (fspec[point] == '.') {
X			extflag = TRUE;
X			break;
X		}
X		point--;
X	}
X
X	/* Open the directory pointer */
X	if (dirptr) {
X		closedir(dirptr);
X		dirptr = NULL;
X	}
X
X	dirptr = opendir((path[0] == '\0') ? "./" : path);
X
X	if (!dirptr)
X		return(NULL);
X
X	strcpy(rbuf, path);
X	nameptr = &rbuf[strlen(rbuf)];
X
X	/* ...and call for the first file */
X	return(getnfile());
X}
X
X/** Get next filename from pattern **/
Xchar *getnfile()
X{
X	int index;
X	struct DIRENTRY * dp;
X	struct stat fstat;
X
X	/* ...and call for the next file */
X	do {
X		dp = readdir(dirptr);
X		if (!dp)
X			return(NULL);
X
X		/* Check to make sure we skip all weird entries except directories */
X		strcpy(nameptr, dp->d_name);
X
X	} while (stat(rbuf, &fstat) &&
X		((fstat.st_mode & S_IFMT) && (S_IFREG || S_IFDIR)) == 0);
X
X	/* if this entry is a directory name, say so */
X	if ((fstat.st_mode & S_IFMT) == S_IFDIR)
X		strcat(rbuf, DIRSEPSTR);
X
X	/* Return the next file name! */
X	return(rbuf);
X}
X
X#if FLABEL
X/*---------------------------------------------------------------------------*
X
X      handle the function keys and function key labels on HP-Terminals
X      -----------------------------------------------------------------
X
X          Hellmuth Michaelis 1989,1990,1991
X	  Eggerstedtstr. 28
X	  2000 Hamburg 50
X	  Germany			e-mail: hm@hcshh.hcs.de
X	  
X *---------------------------------------------------------------------------*/
X 
Xstatic unsigned char flabstor[8][50];		/* label & xmit backup store */
Xstatic char flabstof[8] = {0,0,0,0,0,0,0,0};	/* filled flag */
X
Xint fnclabel(f, n)		/* label a function key */
Xint f;		/* argument supplied ?? */
Xint n;		/* function key number 1...8 on hp-terminals */
X{
X 	char lbl[20];	/* label string buffer */
X 	char xmit[5];	/* transmitted string ( ESC 'p'...'w' ) */
X 	char buf[80];	/* writeout buffer */
X 	int i;		/* general purpose index */
X 	int status;	/* return status */
X 
X 	if(!hpterm && !hpfkey)/* check if we are connected to an hp-terminal */
X 		return(FALSE);
X 	
X 	if (f == FALSE) 
X 	{
X 		mlwrite("%Need function key number");
X 		return(FALSE);
X 	}
X 
X 	/* and it must be a legal key number */
X 
X 	if (n < 1 || n > 8) 
X 	{
X 		mlwrite("%Function key number out of range");
X 		return(FALSE);
X 	}
X 
X 	/* get the string to send */
X 
X 	lbl[0] = '\0';	/* we don't now the label yet */
X 	
X 	if((status = mlreply("Enter Label String: ", lbl, 19)) != TRUE)
X 		return(status);
X 
X 	lbl[16] = '\0';
X 
X 	if((i = strlen(lbl)) > 16)
X 		i = 16;
X 
X 	xmit[0] = 0x1b;
X 	xmit[1] = 'o' + n;
X 	xmit[2] = '\0';
X 
X 	sprintf(flabstor[n-1],"%c&f0a%dk%dd2L%s%s",(char)0x1b,n,i,lbl,xmit);
X 	write(1,flabstor[n-1],strlen(flabstor[n-1]));
X 	flabstof[n-1] = 1;
X 	
X 	sprintf(buf,"%c&jB",(char)0x1b);
X 	write(1,buf,strlen(buf));	
X
X	return(TRUE);
X} 
X
X/* display user function key labels */
Xstatic dis_ufk()
X{
X	int i = 0;
X	char buf[16];
X	
X	if(!hpterm && !hpfkey)
X		return;
X
X 	do
X 	{	
X 		if(flabstof[i])
X 			write(1,flabstor[i],strlen(flabstor[i]));
X 	}
X 	while(i++ < 8);
X 	sprintf(buf,"%c&jB",(char)0x1b);
X 	write(1,buf,strlen(buf));	
X}
X 
X/* display system function key labels */
Xstatic dis_sfk()
X{
X 	char buf[16];
X 	
X 	if(!hpterm && !hpfkey)
X 		return;
X 	sprintf(buf,"%c&jA",(char)0x1b);
X 	write(1,buf,strlen(buf));	
X}
X#endif /* FLABEL */
X
X
X#if XENIX && FILOCK
Xint mkdir(name, mode)
Xchar *name;	/* name of directory to create */
Xint mode;	/* umask for creation (which we blissfully ignore...) */
X{
X	char buf[80];
X
X	strcpy(buf, "mkdir ");
X	strcat(buf, name);
X	strcat(buf, " > /dev/null 2>&1");
X	return(system(buf));
X}
X
Xint rmdir(name)
Xchar *name;	/* name of directory to delete */
X{
X	char buf[80];
X
X	strcpy(buf,"rmdir ");
X	strcat(buf, name);
X	strcat(buf, " > /dev/null 2>&1");
X	return(system(buf));
X}
X#endif /* XENIX & FILOCK */
X
X#endif /* BSD || USG || SMOS || HPUX || SUN || XENIX || AVIION */
SHAR_EOF
$TOUCH -am 0112125693 Support/uemacs/unix.c-3.11a &&
chmod 0640 Support/uemacs/unix.c-3.11a ||
echo "restore of Support/uemacs/unix.c-3.11a failed"
set `wc -c Support/uemacs/unix.c-3.11a`;Wc_c=$1
if test "$Wc_c" != "38978"; then
	echo original size 38978, current size $Wc_c
fi
fi
# ============= Support/fonts/vt100pc.814.uu ==============
if test ! -d 'Support/fonts'; then
    echo "x - creating directory Support/fonts"
    mkdir 'Support/fonts'
fi
if test X"$1" != X"-c" -a -f 'Support/fonts/vt100pc.814.uu'; then
	echo "File already exists: skipping 'Support/fonts/vt100pc.814.uu'"
else
echo "x - extracting Support/fonts/vt100pc.814.uu (Text)"
sed 's/^X//' << 'SHAR_EOF' > Support/fonts/vt100pc.814.uu &&
Xbegin 660 vt100pc.814
XM`$1D5$Q$`"`@("`^````/$`X!'@`(B(^(B(````\0#@$>``B%`@4(@```'Q`
XM>$!\`"(4"!0B````?$!X0'P`/@@("`@```!\0'A`?``<(B(J'`(``#A$?$1$
XM`"0H,"@D````>$1X1'@`("`@(#X```!X1'A$>``>(!P"/````$1$?$1$`#X(
XM"`@(````0$!`0'P`/B`\("````!$1$0H$``^"`@("````'Q`>$!``#X@/"`@
XM````/$!`0#P`/"(\)"(````\0#@$>``<(B(B'````#Q`.`1X`!P("`@<````
XM>$1$1'@`("`@(#X```!X1$1$>``$#`0$#@```'A$1$1X`!PB#!`^````>$1$
XM1'@`'`(,`AP```!X1$1$>``$"!(^`@```$1D5$Q$`"(D."0B````/$`X!'@`
XM(A0("`@```!\0'A`?``\(CPB/````#Q`0$`\`"(R*B8B````?$!X0'P`(C8J
XM(B(````\0#@$>``B(B(B'````'Q`>$!\`!X@("`>````?$!X0$``'B`<`CP`
XM```\0$Q$/``>(!P"/````'A$>$A$`!X@'`(\````1$1$1#@`'B`<`CP`````
XM```````````````````8/#P\&!@`&!@`````8V-C(@``````````````-C9_
XM-C8V?S8V````#`P^8V%@/@-#8SX,#```````86,&#!@S8P``````'#8V'#MN
XM9F8[`````#`P,&````````````````P8,#`P,#`8#```````&`P&!@8&!@P8
XM`````````&8\_SQF```````````8&!C_&!@8````````````````&!@8,```
XM````````_P`````````````````````8&````````0,&#!@P8$`````````^
XM8V=O>W-C8SX```````P</`P,#`P,/P``````/F,#!@P8,&-_```````^8P,#
XM'@,#8SX```````8.'C9F?P8&#P``````?V!@8'X#`V,^```````<,&!@?F-C
XM8SX``````']C`P8,&!@8&```````/F-C8SYC8V,^```````^8V-C/P,#!CP`
XM```````8&````!@8`````````!@8````&!@P```````&#!@P8#`8#`8`````
XM`````'X``'X`````````8#`8#`8,&#!@```````^8V,&#`P`#`P``````#YC
XM8V]O;VY@/@``````"!PV8V-_8V-C``````!^,S,S/C,S,WX``````!XS86!@
XM8&$S'@``````?#8S,S,S,S9\``````!_,3$T/#0Q,7\``````'\Q,30\-#`P
XM>```````'C-A8&!O8S,=``````!C8V-C?V-C8V,``````#P8&!@8&!@8/```
XM````#P8&!@8&9F8\``````!S,S8V/#8V,W,``````'@P,#`P,#$Q?P``````
XMP^?_V\/#P\/#``````!C<WM_;V=C8V,``````!PV8V-C8V,V'```````?C,S
XM,SXP,#!X```````^8V-C8VMO/@8'`````'XS,S,^-C,S<P``````/F-C,!P&
XM8V,^``````#_F9D8&!@8&#P``````&-C8V-C8V-C/@``````P\/#P\/#9CP8
XM``````##P\/#V]O_9F8``````,/#9CP8/&;#PP``````P\/#9CP8&!@\````
XM``#_@X8,&#!AP?\``````#PP,#`P,#`P/```````0&!P.!P.!P,!```````\
XM#`P,#`P,##P````('#9C`````````````````````````````/\`&!@,````
XM`````````````````#P&/F9F.P``````<#`P/#8S,S-N```````````^8V!@
XM8SX```````X&!AXV9F9F.P``````````/F-_8&,^```````<-C(P?#`P,'@`
XM`````````#MF9F8^!F8\````<#`P-CLS,S-S```````,#``<#`P,#!X`````
XM``8&``X&!@8&9F8\````<#`P,S8\-C-S```````<#`P,#`P,#!X`````````
XM`.;_V]O;VP``````````;C,S,S,S```````````^8V-C8SX``````````&XS
XM,S,^,#!X````````.V9F9CX&!@\```````!N.S,P,'@``````````#YC.`YC
XM/@``````"!@8?A@8&!L.``````````!F9F9F9CL``````````,/#PV8\&```
XM````````P\/;V_]F``````````!C-AP<-F,``````````&-C8V,_`P8\````
XM````?V8,&#-_```````.&!@8<!@8&`X``````!@8&!@`&!@8&```````<!@8
XM&`X8&!AP```````[;@``````````````J@"J`*H`J@"J`*H`J@``/&;"P,#"
XM9CP,!GP```#,S`#,S,S,S'8`````#!@P`'S&_L#&?``````0.&P`>`Q\S,QV
XM``````#,S`!X#'S,S'8`````8#`8`'@,?,S,=@`````X;#@`>`Q\S,QV````
XM`````'C,P,QX&`QX````$#AL`'S&_L#&?```````S,P`?,;^P,9\`````&`P
XM&`!\QO[`QGP``````,S,`'`P,#`P>``````P>,P`<#`P,#!X`````,!@,`!P
XM,#`P,'@`````QL80.&S&QO[&Q@```#AL.``X;,;&_L;&````&#!@`/YB8'Q@
XM8OX`````````;+H2?I"8?@``````/FS,S/[,S,S.`````!`X;`!\QL;&QGP`
XM`````,;&`'S&QL;&?`````!@,!@`?,;&QL9\`````#!XS`#,S,S,S'8`````
XM8#`8`,S,S,S,=@``````QL8`QL;&QGX&#'@``,;&.&S&QL;&;#@`````QL8`
XMQL;&QL;&?``````("'[(R,C(?@@(`````#AL9&#P8&!@YOP``````,9L.!#^
XM$/X0$`````#XS,SXQ,S>S,SF`````!PT,#`P_#`P,#"PX```&#!@`'@,?,S,
XM=@`````,&#``.!@8&!@\`````!@P8`!\QL;&QGP`````&#!@`,S,S,S,=@``
XM````=MP`W&9F9F9F````=MP`QN;V_M[.QL8`````/&QL/@!^```````````X
XM;&PX`'P````````````P,``P,&#&QGP```````````!_8&!@````````````
XM`'\!`0$``````,#`QLS8,&#<A@P8/@``P,#&S-@P9LZ:/@8&````&!@`&!@\
XM/#P8`````````#9LV&PV````````````V&PV;-@``````"*((H@BB"*((H@B
XMB"*(JE2J5*I4JE2J5*I4JE2Z[KKNNNZZ[KKNNNZZ[A@8&!@8&!@8&!@8&!@8
XM&!@8&!@8&/@8&!@8&!@8&!@8&/@8^!@8&!@8&#8V-C8V-C;V-C8V-C8V````
XM`````/XV-C8V-C8``````/@8^!@8&!@8&#8V-C8V]@;V-C8V-C8V-C8V-C8V
XM-C8V-C8V-C8``````/X&]C8V-C8V-C8V-C8V]@;^````````-C8V-C8V-OX`
XM```````8&!@8&/@8^`````````````````#X&!@8&!@8&!@8&!@8&!\`````
XM```8&!@8&!@8_P````````````````#_&!@8&!@8&!@8&!@8&!\8&!@8&!@`
XM````````_P```````!@8&!@8&!C_&!@8&!@8&!@8&!@?&!\8&!@8&!@V-C8V
XM-C8V-S8V-C8V-C8V-C8V-S`_```````````````_,#<V-C8V-C8V-C8V-O<`
XM_P``````````````_P#W-C8V-C8V-C8V-C8W,#<V-C8V-C8``````/\`_P``
XM`````#8V-C8V]P#W-C8V-C8V&!@8&!C_`/\````````V-C8V-C8V_P``````
XM````````_P#_&!@8&!@8`````````/\V-C8V-C8V-C8V-C8V/P```````!@8
XM&!@8'Q@?```````````````?&!\8&!@8&!@`````````/S8V-C8V-C8V-C8V
XM-C;_-C8V-C8V&!@8&!C_&/\8&!@8&!@8&!@8&!@8^``````````````````?
XM&!@8&!@8__________________\`````````__________#P\/#P\/#P\/#P
XM\/#P#P\/#P\/#P\/#P\/#P__________````````````````=MS8V-QV````
XM`````'S&_,;&_,#`0````/[&QL#`P,#`P`````````#^;&QL;&QL``````#^
XMQF`P&#!@QOX``````````'[8V-C8<`````````!F9F9F?&!@P````````';<
XM&!@8&!@``````/PP>,S,S'@P_```````.&S&QO[&QFPX```````X;,;&QFQL
XM;.X``````#Q@,!A\S,S,>```````````?-;6?``````````&#'S.UN9\8,``
XM`````#A@P,#XP,!@.````````'S&QL;&QL;&````````_@``_@``_@``````
XM`#`P,/PP,#``_```````8#`8#!@P8`#\```````8,&#`8#`8`/P```````X:
XM&A@8&!@8&!@8&!@8&!@8&!@86%AP```````P,```_```,#``````````=MP`
XM=MP```````!PV-AP````````````````````&!@`````````````````&```
XM```````>&!@8&!C8V'@X`````-AL;&QL;```````````<-@P8,CX````````
X=```````^/CX^/CX`````````````````````````
X`
Xend
SHAR_EOF
$TOUCH -am 0112125693 Support/fonts/vt100pc.814.uu &&
chmod 0640 Support/fonts/vt100pc.814.uu ||
echo "restore of Support/fonts/vt100pc.814.uu failed"
set `wc -c Support/fonts/vt100pc.814.uu`;Wc_c=$1
if test "$Wc_c" != "4968"; then
	echo original size 4968, current size $Wc_c
fi
fi
echo "End of part 5, continue with part 6"
exit 0
-- 
hellmuth michaelis    HCS Hanseatischer Computerservice GmbH   hamburg, europe
hm@hcshh.hcs.de              tel: +49/40/55903-170         fax: +49/40/5591486