X11R3 xterm on 6000 (BIG message 5336 lines)

/100000 root at johnbob.uucp
Sat Nov 10 08:37:35 AEST 1990


Here are the files that need to be changed to compile
the X11R3 MIT xterm on the 6000.  (I would post diff files but have
no way to verify that they work)

You will need the rest of the source to compile xterm.  A Makefile is
included but for anything fancy you will have to build a new one.


John Harvey	Austin, Texas
AT HOME  ...!sequoia!johnbob!jph  OR
...!uunet!cs.utexas.edu!execu!sequoia!johnbob!jph
AT WORK  johnbob at ausvmq  OR  john at johnbob  OR  johnbob at austin
         @cs.utexas.edu:ibmchs!auschs!johnbob.austin.ibm.com!john  OR
...!uunet!cs.utexas.edu!ibmaus!auschs!johnbob.austin.ibm.com!john
The full path is needed for network hopping.
I don't speak for anybody.  Not even myself.




---- Cut Here and unpack ----
#!/bin/sh
# This is a shell archive (shar 3.10)
# made 11/09/1990 19:24 UTC by root at AIX 
# Source directory /athens/r3v3xterm
#
# existing files will NOT be overwritten
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   1336 -rw-r--r-- DECkeysym.h
#  22817 -rw-r--r-- Makefile
#  40619 -rw-r--r-- Tekproc.c
#   7287 -rw-r--r-- input.c
#  67831 -rw-r--r-- main.c
#
touch 2>&1 | fgrep '[-amc]' > /tmp/s3_touch$$
if [ -s /tmp/s3_touch$$ ]
then
	TOUCH=can
else
	TOUCH=cannot
fi
rm -f /tmp/s3_touch$$
# ============= DECkeysym.h ==============
if test -f DECkeysym.h; then echo "File DECkeysym.h exists"; else
sed 's/^X//' << 'SHAR_EOF' > DECkeysym.h &&
X/* $XConsortium: DECkeysym.h,v 1.2 88/09/06 15:55:54 jim Exp $ */
X
X/***********************************************************
XCopyright 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
Xand the Massachusetts Institute of Technology, Cambridge, Massachusetts.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its 
Xdocumentation for any purpose and without fee is hereby granted, 
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in 
Xsupporting documentation, and that the names of Digital or MIT not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.  
X
XDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X#define DXK_Remove	0x1000FF00   /* Remove */
SHAR_EOF
chmod 0644 DECkeysym.h || echo "restore of DECkeysym.h fails"
if [ $TOUCH = can ]
then
    touch -am 1109131490 DECkeysym.h
fi
fi
# ============= Makefile ==============
if test -f Makefile; then echo "File Makefile exists"; else
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X#
X#
X#	Makefile for a program
X#
X#	After changing this makefile do a 'make depend'.
X#
X
XPROGRAM		= xterm
XINSTALLDIR	= .
X
XSRCS		=	\
X	TekPrsTbl.c	\
X	Tekproc.c	\
X	VTPrsTbl.c	\
X	button.c	\
X	charproc.c	\
X	cursor.c	\
X	data.c	\
X	input.c	\
X	main.c	\
X	menu.c	\
X	misc.c	\
X	screen.c	\
X	scrollbar.c	\
X	tabs.c	\
X	util.c
XOBJS		=	\
X	TekPrsTbl.o	\
X	Tekproc.o	\
X	VTPrsTbl.o	\
X	button.o	\
X	charproc.o	\
X	cursor.o	\
X	data.o	\
X	input.o	\
X	main.o	\
X	menu.o	\
X	misc.o	\
X	screen.o	\
X	scrollbar.o	\
X	tabs.o	\
X	util.o
XLINTOBJS	=	\
X	TekPrsTbl.ln	\
X	Tekproc.ln	\
X	VTPrsTbl.ln	\
X	button.ln	\
X	charproc.ln	\
X	cursor.ln	\
X	data.ln	\
X	input.ln	\
X	main.ln	\
X	menu.ln	\
X	misc.ln	\
X	screen.ln	\
X	scrollbar.ln	\
X	tabs.ln	\
X	util.ln
XHDRS		=
X
X
XSHELL		= /bin/sh
XCC		= cc
XLINT		= lint
X
XINCLUDES	= -I/usr/lpp/X11/Xamples/lib/Xaw
XLIBS		= /usr/lpp/X11/Xamples/lib/Xaw/libXaw.a /usr/lpp/X11/Xamples/lib/Xmu/libXmu.a -lXt -lX11 -lcurses
XLINTLIBS	=
XDEFINES		= -D_BSD -DMODEMENU -DUTMP -DBcopy=bcopy -DAIXV3
XSYS_CFLAGS	=
XCPPFLAGS	= $(DEFINES) $(INCLUDES)
XCFLAGS		= $(DEFINES) $(SYS_CFLAGS) $(INCLUDES)
XLINTFLAGS	= $(DEFINES) $(INCLUDES)
X
X.SUFFIXES: .o .h .c .ln
X
X.c.o:
X	$(CC) $(CFLAGS) -c $*.c
X
X.c.ln:
X	$(LINT) $(LINTFLAGS) -c $*.c
X
Xall:	$(PROGRAM)
X	@echo ''
X
Xinstall:	$(INSTALLDIR)/$(PROGRAM)
X
X$(INSTALLDIR)/$(PROGRAM): $(PROGRAM)
X	@if [ "$(INSTALLDIR)" = "." ] ; \
X	then \
X	    echo $(PROGRAM) lives here. ; \
X	    echo 'I should never be reached anyway.' ; \
X	else \
X	    rm -f $(INSTALLDIR)/$(PROGRAM) ; \
X	    echo mv $(PROGRAM) $(INSTALLDIR)/$(PROGRAM) ; \
X	    mv $(PROGRAM) $(INSTALLDIR)/$(PROGRAM) ; \
X	    touch $(PROGRAM) ; \
X	    touch $(INSTALLDIR)/$(PROGRAM) ; \
X	fi
X
X$(PROGRAM): $(OBJS)
X	$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
X
Xlint: $(LINTOBJS)
X	$(LINT) $(LINTFLAGS) $(LINTOBJS) $(LINTLIBS)
X
Xdepend: Makefile
X	@source="$(SRCS)" ; \
X	script=.ed.script ; \
X	marker="## DON'T DELETE THIS LINE" ; \
X	warning=" 'make depend' depends on it" ; \
X	warning2="## DO NOT add stuff here -- it will go away" ; \
X	echo "/^$$marker/,\$$d" > $$script ; \
X	echo '$$' >> $$script ; \
X	echo 'a' >> $$script ; \
X	echo $$marker $$warning >> $$script ; \
X	for f in $$source  ; \
X	do \
X	    fo=`echo $$f | sed 's/\.c$$/.o/'` ; \
X	    echo $$fo':' ; \
X	    ds=` cc -E $(CPPFLAGS) $$f | grep '^# 1 ' | cut -d'"' -f2 | sort | uniq ` ; \
X	    echo $$fo: $$ds | sed 's/ /	\\ 	/g' | tr ' ' '\012' >> $$script ; \
X	done ; \
X	echo $$marker $$warning >> $$script ; \
X	echo $$warning2 >> $$script ; \
X	echo '.' >> $$script ; \
X	echo 'w' >> $$script ; \
X	echo 'q' >> $$script ; \
X	cp Makefile Makefile.bak ; \
X	ed Makefile < $$script > /dev/null ; \
X	rm -f $$script
X	touch depend
X
Xnoex: clean
X	rm -f $(PROGRAM)
X
Xclean: 
X	rm -f *.ln *.o core *~
X
X## DON'T DELETE THIS LINE 'make depend' depends on it
XTekPrsTbl.o:	\
X	./Tekparse.h	\
X	/usr/include/X11/copyright.h	\
X	TekPrsTbl.c
XTekproc.o:	\
X	./Tekparse.h	\
X	./data.h	\
X	./error.h	\
X	./menu.h	\
X	./ptyx.h	\
X	/usr/include/NLchar.h	\
X	/usr/include/NLctype.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/Shell.h	\
X	/usr/include/X11/StringDefs.h	\
X	/usr/include/X11/Vendor.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xatom.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/ctype.h	\
X	/usr/include/errno.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/pwd.h	\
X	/usr/include/setjmp.h	\
X	/usr/include/sgtty.h	\
X	/usr/include/standards.h	\
X	/usr/include/stdio.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/NLchar.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/errno.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/ioctl.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/localedef.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/ttychars.h	\
X	/usr/include/sys/ttydev.h	\
X	/usr/include/sys/types.h	\
X	/usr/include/time.h	\
X	Tekproc.c
XVTPrsTbl.o:	\
X	./VTparse.h	\
X	/usr/include/X11/copyright.h	\
X	VTPrsTbl.c
Xbutton.o:	\
X	./data.h	\
X	./error.h	\
X	./menu.h	\
X	./ptyx.h	\
X	/usr/include/NLchar.h	\
X	/usr/include/NLctype.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xatom.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xmu.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/ctype.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/setjmp.h	\
X	/usr/include/signal.h	\
X	/usr/include/standards.h	\
X	/usr/include/stdio.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/NLchar.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/localedef.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/types.h	\
X	button.c
Xcharproc.o:	\
X	./VTparse.h	\
X	./data.h	\
X	./error.h	\
X	./main.h	\
X	./menu.h	\
X	./ptyx.h	\
X	/usr/include/NLchar.h	\
X	/usr/include/NLctype.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/StringDefs.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/ctype.h	\
X	/usr/include/errno.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/setjmp.h	\
X	/usr/include/sgtty.h	\
X	/usr/include/standards.h	\
X	/usr/include/stdio.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/NLchar.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/errno.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/ioctl.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/localedef.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/ttychars.h	\
X	/usr/include/sys/ttydev.h	\
X	/usr/include/sys/types.h	\
X	charproc.c
Xcursor.o:	\
X	./ptyx.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/standards.h	\
X	/usr/include/stdio.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/ioctl.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/ttychars.h	\
X	/usr/include/sys/ttydev.h	\
X	/usr/include/sys/types.h	\
X	cursor.c
Xdata.o:	\
X	./data.h	\
X	./ptyx.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/setjmp.h	\
X	/usr/include/standards.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/types.h	\
X	data.c
Xinput.o:	\
X	./DECkeysym.h	\
X	./ptyx.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/X11/keysym.h	\
X	/usr/include/X11/keysymdef.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/standards.h	\
X	/usr/include/stdio.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/types.h	\
X	input.c
Xmain.o:	\
X	./data.h	\
X	./error.h	\
X	./main.h	\
X	./ptyx.h	\
X	/usr/include/NLchar.h	\
X	/usr/include/NLctype.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/Shell.h	\
X	/usr/include/X11/StringDefs.h	\
X	/usr/include/X11/Vendor.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/ctype.h	\
X	/usr/include/errno.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/pwd.h	\
X	/usr/include/setjmp.h	\
X	/usr/include/sgtty.h	\
X	/usr/include/signal.h	\
X	/usr/include/standards.h	\
X	/usr/include/stdio.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/NLchar.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/errno.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/ioctl.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/localedef.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/m_wait.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/resource.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/termio.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/ttmap.h	\
X	/usr/include/sys/ttychars.h	\
X	/usr/include/sys/ttydev.h	\
X	/usr/include/sys/types.h	\
X	/usr/include/sys/wait.h	\
X	/usr/include/termios.h	\
X	/usr/include/utmp.h	\
X	main.c
Xmenu.o:	\
X	./data.h	\
X	./menu.h	\
X	./ptyx.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/Shell.h	\
X	/usr/include/X11/StringDefs.h	\
X	/usr/include/X11/Vendor.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xatom.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/X11/cursorfont.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/setjmp.h	\
X	/usr/include/standards.h	\
X	/usr/include/stdio.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/types.h	\
X	menu.c
Xmisc.o:	\
X	./data.h	\
X	./error.h	\
X	./gray.ic	\
X	./ptyx.h	\
X	./wait.ic	\
X	./waitmask.ic	\
X	/usr/include/NLchar.h	\
X	/usr/include/NLctype.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/Shell.h	\
X	/usr/include/X11/Vendor.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xatom.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/X11/cursorfont.h	\
X	/usr/include/ctype.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/pwd.h	\
X	/usr/include/setjmp.h	\
X	/usr/include/signal.h	\
X	/usr/include/standards.h	\
X	/usr/include/stdio.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/NLchar.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/localedef.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/types.h	\
X	misc.c
Xscreen.o:	\
X	./error.h	\
X	./ptyx.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/signal.h	\
X	/usr/include/standards.h	\
X	/usr/include/stdio.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/ioctl.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/ttychars.h	\
X	/usr/include/sys/ttydev.h	\
X	/usr/include/sys/types.h	\
X	screen.c
Xscrollbar.o:	\
X	./data.h	\
X	./error.h	\
X	./ptyx.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/Shell.h	\
X	/usr/include/X11/StringDefs.h	\
X	/usr/include/X11/Vendor.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xatom.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xmu.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/setjmp.h	\
X	/usr/include/standards.h	\
X	/usr/include/stdio.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/types.h	\
X	/usr/lpp/X11/Xamples/lib/Xaw/X11/Scroll.h	\
X	scrollbar.c
Xtabs.o:	\
X	./ptyx.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/standards.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/types.h	\
X	tabs.c
Xutil.o:	\
X	./data.h	\
X	./error.h	\
X	./ptyx.h	\
X	/usr/include/X11/CompObj.h	\
X	/usr/include/X11/CompObjP.h	\
X	/usr/include/X11/Composite.h	\
X	/usr/include/X11/CompositeP.h	\
X	/usr/include/X11/ConstrainP.h	\
X	/usr/include/X11/Constraint.h	\
X	/usr/include/X11/Core.h	\
X	/usr/include/X11/CoreP.h	\
X	/usr/include/X11/Intrinsic.h	\
X	/usr/include/X11/IntrinsicP.h	\
X	/usr/include/X11/Object.h	\
X	/usr/include/X11/ObjectP.h	\
X	/usr/include/X11/RectObj.h	\
X	/usr/include/X11/RectObjP.h	\
X	/usr/include/X11/WindowObj.h	\
X	/usr/include/X11/WindowObjP.h	\
X	/usr/include/X11/X.h	\
X	/usr/include/X11/Xlib.h	\
X	/usr/include/X11/Xos.h	\
X	/usr/include/X11/Xresource.h	\
X	/usr/include/X11/Xutil.h	\
X	/usr/include/X11/copyright.h	\
X	/usr/include/fcntl.h	\
X	/usr/include/float.h	\
X	/usr/include/jfs/fsparam.h	\
X	/usr/include/setjmp.h	\
X	/usr/include/signal.h	\
X	/usr/include/standards.h	\
X	/usr/include/stdio.h	\
X	/usr/include/string.h	\
X	/usr/include/strings.h	\
X	/usr/include/sys/access.h	\
X	/usr/include/sys/context.h	\
X	/usr/include/sys/file.h	\
X	/usr/include/sys/flock.h	\
X	/usr/include/sys/limits.h	\
X	/usr/include/sys/m_param.h	\
X	/usr/include/sys/m_types.h	\
X	/usr/include/sys/mstsave.h	\
X	/usr/include/sys/param.h	\
X	/usr/include/sys/select.h	\
X	/usr/include/sys/signal.h	\
X	/usr/include/sys/sysmacros.h	\
X	/usr/include/sys/time.h	\
X	/usr/include/sys/types.h	\
X	util.c
X## DON'T DELETE THIS LINE 'make depend' depends on it
X## DO NOT add stuff here -- it will go away
SHAR_EOF
chmod 0644 Makefile || echo "restore of Makefile fails"
if [ $TOUCH = can ]
then
    touch -am 1109131490 Makefile
fi
fi
# ============= Tekproc.c ==============
if test -f Tekproc.c; then echo "File Tekproc.c exists"; else
sed 's/^X//' << 'SHAR_EOF' > Tekproc.c &&
X/*
X * $XConsortium: Tekproc.c,v 1.43 88/10/07 13:28:23 jim Exp $
X *
X * Warning, there be crufty dragons here.
X */
X
X
X#include <X11/copyright.h>
X
X#ifdef AIXV3
X#include <time.h>
X#endif /* AIXV3 */
X
X/*
X * Copyright 1988 Massachusetts Institute of Technology
X * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
X *
X *                         All Rights Reserved
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted,
X * provided that the above copyright notice appear in all copies and that
X * both that copyright notice and this permission notice appear in
X * supporting documentation, and that the name of Digital Equipment
X * Corporation not be used in advertising or publicity pertaining to
X * distribution of the software without specific, written prior permission.
X *
X *
X * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
X * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
X * SOFTWARE.
X */
X
X/* Tekproc.c */
X
X#include <X11/Xos.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X#include <X11/Xutil.h>
X#include <X11/StringDefs.h>
X#include <X11/Shell.h>
X#include "ptyx.h"
X#include "Tekparse.h"
X#include <stdio.h>
X#ifdef mips			/* !defined(mips) || !defined(SYSTYPE_SYSV) */
X# ifndef SYSTYPE_SYSV
X# include <sgtty.h>
X# endif /* not SYSTYPE_SYSV */
X#else
X# include <sgtty.h>
X#endif /* mips */
X#include <ctype.h>
X#include <errno.h>
X#include <setjmp.h>
X#include <pwd.h>
X#include "data.h"
X#include "error.h"
X
X#ifdef macII
X#undef FIOCLEX					/* redefined from sgtty.h */
X#undef FIONCLEX					/* redefined from sgtty.h */
X#include <sys/ioctl.h>				/* to get FIONREAD */
X#endif /* macII */
X
X#ifdef MODEMENU
X#include "menu.h"
X#endif	/* MODEMENU */
X
Xextern void exit();
Xextern long time();
X
X#define TekColormap DefaultColormap( screen->display, \
X				    DefaultScreen(screen->display) )
X#define DefaultGCID DefaultGC(screen->display, DefaultScreen(screen->display))->gid
X
X/* Tek defines */
X
X#define	BEL		07
X#define	CANCEL		030
X#define	DOTDASHEDLINE	2
X#define	DOTTEDLINE	1
X#define	EAST		01
X#define	ETX		03
X#define	LARGEFONT	0
X#define	LARGEFONTNAME	"9x15"
X#define	LINEMASK	07
X#define	LONGDASHEDLINE	4
X#define	MARGIN1		0
X#define	MARGIN2		1
X#define MAX_PTS		150
X#define MAX_VTX		300
X#define	NAK		025
X#define	NORTH		04
X#define	PENDOWN		1
X#define	PENUP		0
X#define	SHORTDASHEDLINE	3
X#define	SMALLFONT	3
X#define	SMALLFONTNAME	"6x10"
X#define	SOLIDLINE	0
X#define	SOUTH		010
X#define	TEKBOTTOMPAD	23
X#define	TEKDEFHEIGHT	565
X#define	TEKDEFWIDTH	750
X#define	TEKHEIGHT	3072
X#define	TEKHOME		((TekChar[screen->page.fontsize].nlines - 1)\
X			 * TekChar[screen->page.fontsize].vsize)
X#define	TEKMINHEIGHT	452
X#define	TEKMINWIDTH	600
X#define	TEKTOPPAD	34
X#define	TEKWIDTH	4096
X#define	TEXT_BUF_SIZE	256
X#define	THREEFONT	2
X#define	THREEFONTNAME	"6x13"
X#define	TWOFONT		1
X#define	TWOFONTNAME	"8x13"
X#define	WEST		02
X
X#define	TekMove(x,y)	screen->cur_X = x; screen->cur_Y = y
X#define	input()		Tinput()
X#define	unput(c)	*Tpushback++ = c
X
X#ifndef lint
Xstatic char rcs_id[] = "$XConsortium: Tekproc.c,v 1.43 88/10/07 13:28:23 jim Exp $";
X#endif	/* lint */
X
Xstatic XPoint *T_box[TEKNUMFONTS] = {
X	T_boxlarge,
X	T_box2,
X	T_box3,
X	T_boxsmall,
X};
Xstatic struct Tek_Char {
X	int hsize;	/* in Tek units */
X	int vsize;	/* in Tek units */
X	int charsperline;
X	int nlines;
X} TekChar[TEKNUMFONTS] = {
X	{56, 88, 74, 35},	/* large */
X	{51, 82, 81, 38},	/* #2 */
X	{34, 53, 121, 58},	/* #3 */
X	{31, 48, 133, 64},	/* small */
X};
X
Xstatic Cursor GINcursor;
Xstatic XSegment *line_pt;
Xstatic int nplot;
Xstatic TekLink Tek0;
Xstatic jmp_buf Tekjump;
Xstatic TekLink *TekRecord;
Xstatic XSegment *Tline;
X
Xextern int Talptable[];
Xextern int Tbestable[];
Xextern int Tbyptable[];
Xextern int Tesctable[];
Xextern int Tipltable[];
Xextern int Tplttable[];
Xextern int Tpttable[];
Xextern int Tspttable[];
X
Xstatic int *curstate = Talptable;
Xstatic int *Tparsestate = Talptable;
X
X/* event handlers */
Xextern void HandleKeyPressed();
Xextern void HandleStringEvent();
Xextern void HandleEnterWindow();
Xextern void HandleLeaveWindow();
Xextern void HandleFocusChange();
Xextern void TekButtonPressed();
X
Xstatic char defaultTranslations[] = 
X    "<KeyPress>: insert()";
X
Xstatic XtActionsRec actionsList[] = { 
X    { "string",	HandleStringEvent },
X    { "insert",	HandleKeyPressed },
X};
X
Xstatic Dimension defOne = 1;
X
Xstatic XtResource resources[] = {
X    {XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension),
X	 XtOffset(Widget, core.width), XtRDimension, (caddr_t)&defOne},
X    {XtNheight, XtCHeight, XtRDimension, sizeof(Dimension),
X	 XtOffset(Widget, core.height), XtRDimension, (caddr_t)&defOne},
X};
X
Xstatic void TekInitialize(), TekRealize(), TekConfigure();
Xvoid TekExpose();
X
XWidgetClassRec tekClassRec = {
X  {
X/* core_class fields */	
X    /* superclass	  */	(WidgetClass) &widgetClassRec,
X    /* class_name	  */	"Tek4014",
X    /* widget_size	  */	sizeof(TekWidgetRec),
X    /* class_initialize   */    NULL,
X    /* class_part_initialize */ NULL,
X    /* class_inited       */	FALSE,
X    /* initialize	  */	TekInitialize,
X    /* initialize_hook    */    NULL,				
X    /* realize		  */	TekRealize,
X    /* actions		  */	actionsList,
X    /* num_actions	  */	XtNumber(actionsList),
X    /* resources	  */	resources,
X    /* num_resources	  */	XtNumber(resources),
X    /* xrm_class	  */	NULLQUARK,
X    /* compress_motion	  */	TRUE,
X    /* compress_exposure  */	TRUE,
X    /* compress_enterleave */   TRUE,
X    /* visible_interest	  */	FALSE,
X    /* destroy		  */	NULL,
X    /* resize		  */	TekConfigure,
X    /* expose		  */	TekExpose,
X    /* set_values	  */	NULL,
X    /* set_values_hook    */    NULL,
X    /* set_values_almost  */    NULL,
X    /* get_values_hook    */    NULL,
X    /* accept_focus	  */	NULL,
X    /* version            */    XtVersion,
X    /* callback_offsets   */    NULL,
X    /* tm_table           */    defaultTranslations,
X    /* query_geometry     */    XtInheritQueryGeometry,
X    /* display_accelerator*/    XtInheritDisplayAccelerator,
X    /* extension          */    NULL
X  }
X};
X#define tekWidgetClass ((WidgetClass)&tekClassRec)
X
Xstatic Boolean Tfailed = FALSE;
X
XTekWidget CreateTekWidget ()
X{
X    Widget tekshellwidget;
X    extern Arg ourTopLevelShellArgs[];
X    extern int number_ourTopLevelShellArgs;
X
X    /* this causes the Initialize method to be called */
X    tekshellwidget = XtCreateApplicationShell ("tektronix",
X					       topLevelShellWidgetClass,
X					       ourTopLevelShellArgs, 
X					       number_ourTopLevelShellArgs);
X    /* this causes the Realize method to be called */
X    tekWidget = (TekWidget) XtCreateManagedWidget ("tek4014", tekWidgetClass,
X						   tekshellwidget, NULL, 0);
X    return (tekWidget);
X}
X
X
Xint TekInit ()
X{
X    if (Tfailed) return (0);
X    if (tekWidget) return (1);
X    if (CreateTekWidget()) {
X	return (1);
X    }
X    return (0);
X}
X
XTekparse()
X{
X	register TScreen *screen = &term->screen;
X	register int c, x, y;
X	char ch;
X	int arg;
X	int Tinput();
X
X	for( ; ; )
X		switch(Tparsestate[c = input()]) {
X		 case CASE_REPORT:
X			/* report address */
X			if(screen->TekGIN) {
X				TekGINoff();
X				TekEnqMouse(0);
X			} else {
X				c = 064;	/* has hard copy unit */
X				if(screen->margin == MARGIN2)
X					c |= 02;
X				TekEnq(c, screen->cur_X, screen->cur_Y);
X			}
X			TekRecord->ptr[-1] = NAK; /* remove from recording */
X			Tparsestate = curstate;
X			break;
X
X		 case CASE_VT_MODE:
X			/* special return to vt102 mode */
X			Tparsestate = curstate;
X			TekRecord->ptr[-1] = NAK; /* remove from recording */
X			if(screen->logging) {
X				FlushLog(screen);
X				screen->logstart = buffer;
X			}
X			return;
X
X		 case CASE_SPT_STATE:
X			/* Enter Special Point Plot mode */
X			if(screen->TekGIN)
X				TekGINoff();
X			Tparsestate = curstate = Tspttable;
X			break;
X
X		 case CASE_GIN:
X			/* Do Tek GIN mode */
X			screen->TekGIN = &TekRecord->ptr[-1];
X				/* Set cross-hair cursor raster array */
X			if(GINcursor = make_tcross(
X			    screen->mousecolor,
X			    term->core.background_pixel))
X				XDefineCursor(
X				    screen->display,
X				    TShellWindow,
X				    GINcursor);
X			Tparsestate = Tbyptable;	/* Bypass mode */
X			break;
X
X		 case CASE_BEL:
X			/* BEL */
X			if(screen->TekGIN)
X				TekGINoff();
X			if(!TekRefresh)
X				Bell();
X			Tparsestate = curstate;	/* clear bypass condition */
X			break;
X
X		 case CASE_BS:
X			/* BS */
X			if(screen->TekGIN)
X				TekGINoff();
X			Tparsestate = curstate;	/* clear bypass condition */
X			TCursorBack();
X			break;
X
X		 case CASE_PT_STATE:
X			/* Enter Tek Point Plot mode */
X			if(screen->TekGIN)
X				TekGINoff();
X			Tparsestate = curstate = Tpttable;
X			break;
X
X		 case CASE_PLT_STATE:
X			/* Enter Tek Plot mode */
X			if(screen->TekGIN)
X				TekGINoff();
X			Tparsestate = curstate = Tplttable;
X			if((c = input()) == BEL)
X				screen->pen = PENDOWN;
X			else {
X				unput(c);
X				screen->pen = PENUP;
X			}
X			break;
X
X		 case CASE_TAB:
X			/* HT */
X			if(screen->TekGIN)
X				TekGINoff();
X			Tparsestate = curstate;	/* clear bypass condition */
X			TCursorForward();
X			break;
X
X		 case CASE_IPL_STATE:
X			/* Enter Tek Incremental Plot mode */
X			if(screen->TekGIN)
X				TekGINoff();
X			Tparsestate = curstate = Tipltable;
X			break;
X
X		 case CASE_ALP_STATE:
X			/* Enter Tek Alpha mode from any other mode */
X			if(screen->TekGIN)
X				TekGINoff();
X			/* if in one of graphics states, move alpha cursor */
X			if(nplot > 0)	/* flush line Tbuffer */
X				TekFlush();
X			Tparsestate = curstate = Talptable;
X			break;
X
X		 case CASE_UP:
X			/* cursor up */
X			if(screen->TekGIN)
X				TekGINoff();
X			Tparsestate = curstate;	/* clear bypass condition */
X			TCursorUp();
X			break;
X
X		 case CASE_COPY:
X			/* make copy */
X			if(screen->TekGIN)
X				TekGINoff();
X			TekCopy();
X			TekRecord->ptr[-1] = NAK; /* remove from recording */
X			Tparsestate = curstate;	/* clear bypass condition */
X			break;
X
X		 case CASE_PAGE:
X			/* Page Function */
X			if(screen->TekGIN)
X				TekGINoff();
X			TekPage();	/* clear bypass condition */
X			break;
X
X		 case CASE_BES_STATE:
X			/* Byp: an escape char */
X			Tparsestate = Tbestable;
X			break;
X
X		 case CASE_BYP_STATE:
X			/* set bypass condition */
X			Tparsestate = Tbyptable;
X			break;
X
X		 case CASE_IGNORE:
X			/* Esc: totally ignore CR, ESC, LF, ~ */
X			break;
X
X		 case CASE_ASCII:
X			/* Select ASCII char set */
X			/* ignore for now */
X			Tparsestate = curstate;
X			break;
X
X		 case CASE_APL:
X			/* Select APL char set */
X			/* ignore for now */
X			Tparsestate = curstate;
X			break;
X
X		 case CASE_CHAR_SIZE: 
X			/* character size selector */
X		        TekSetGCFont (screen->cur.fontsize = (c & 03));
X			Tparsestate = curstate;
X			break;
X
X		 case CASE_BEAM_VEC:
X			/* beam and vector selector */
X			/* only line types */
X			if((c &= LINEMASK) != screen->cur.linetype) {
X				if(nplot > 0)
X					TekFlush();
X				screen->cur.linetype = c;
X			}
X			Tparsestate = curstate;
X			break;
X
X		 case CASE_CURSTATE:
X			Tparsestate = curstate;
X			break;
X
X		 case CASE_PENUP:
X			/* Ipl: penup */
X			screen->pen = PENUP;
X			break;
X
X		 case CASE_PENDOWN:
X			/* Ipl: pendown */
X			screen->pen = PENDOWN;
X			break;
X
X		 case CASE_IPL_POINT:
X			/* Ipl: point */
X			x = screen->cur_X;
X			y = screen->cur_Y;
X			if(c & NORTH)
X				y++;
X			else if(c & SOUTH)
X				y--;
X			if(c & EAST)
X				x++;
X			else if(c & WEST)
X				x--;
X			if(screen->pen == PENDOWN)
X				TekDraw(x, y);
X			else
X				TekMove(x, y);
X			break;
X
X		 case CASE_PLT_VEC:
X			/* Plt: vector */
X			unput(c);
X			if(getpoint()) {
X				if(screen->pen == PENDOWN)
X					TekDraw(screen->cur.x, screen->cur.y);
X				else
X					TekMove(screen->cur.x, screen->cur.y);
X				screen->pen = PENDOWN;
X			}
X			break;
X
X		 case CASE_PT_POINT:
X			/* Pt: point */
X			unput(c);
X			if(getpoint()) {
X				TekMove(screen->cur.x, screen->cur.y);
X				TekDraw(screen->cur.x, screen->cur.y);
X			}
X			break;
X
X		 case CASE_SPT_POINT:
X			/* Spt: point */
X			/* ignore intensity character in c */
X			if(getpoint()) {
X				TekMove(screen->cur.x, screen->cur.y);
X				TekDraw(screen->cur.x, screen->cur.y);
X			}
X			break;
X
X		 case CASE_CR:
X			/* CR */
X			if(screen->TekGIN)
X				TekGINoff();
X			if(nplot > 0)	/* flush line Tbuffer */
X				TekFlush();
X			screen->cur_X = screen->margin == MARGIN1 ? 0 :
X			 TEKWIDTH / 2;
X			Tparsestate = curstate = Talptable;
X			break;
X
X		 case CASE_ESC_STATE:
X			/* ESC */
X			Tparsestate = Tesctable;
X			break;
X
X		 case CASE_LF:
X			/* LF */
X			if(screen->TekGIN)
X				TekGINoff();
X			TCursorDown();
X			if(!TekRefresh && (screen->display->qlen > 0 ||
X			 (ioctl(screen->display->fd, FIONREAD, (char *)&arg), arg) > 0))
X				xevents();
X			break;
X
X		 case CASE_SP:
X			/* SP */
X			TCursorForward();
X			break;
X
X		 case CASE_PRINT:
X			/* printable character */
X			ch = c;
X			c = screen->cur.fontsize;
X
X			XDrawString(
X			    screen->display,
X			    TWindow(screen), 
X			    screen->TnormalGC,
X			    (int)(screen->cur_X * TekScale(screen)) + screen->border,
X			    (int)((TEKHEIGHT + TEKTOPPAD - screen->cur_Y) * TekScale(screen)) + screen->border,
X			    &ch,
X			    1);
X			TCursorForward();
X			break;
X		 case CASE_OSC:
X			/* do osc escape */
X			do_osc(Tinput);
X			Tparsestate = curstate;
X			break;
X		}
X}			
X
XTekSetGCFont (size)
X    int size;  /* one of SMALLFONT, TWOFONT, THREEFONT, or LARGEFONT */
X    {
X    register TScreen *screen = &term->screen;
X    Font fid = screen->Tfont[size]->fid;
X    if (fid == DefaultGCID) 
X       /* we didn't succeed in opening a real font
X	  for this size.  Instead, use server default. */
X       XCopyGC (screen->display,
X	  DefaultGC(screen->display, DefaultScreen(screen->display)),
X	  GCFont, screen->TnormalGC);
X   else
X       XSetFont (screen->display, screen->TnormalGC, fid);
X    }
X
Xstatic int rcnt;
Xstatic char *rptr;
Xstatic int Tselect_mask;
X
XTinput()
X{
X	register TScreen *screen = &term->screen;
X	register char *cp;
X	register int i;
X	register TekLink *tek;
X	extern char *malloc();
X
X	if(Tpushback > Tpushb)
X		return(*--Tpushback);
X	if(TekRefresh) {
X		if(rcnt-- > 0)
X			return(*rptr++);
X		if(tek = TekRefresh->next) {
X			TekRefresh = tek;
X			rcnt = tek->count - 1;
X			rptr = tek->data;
X			return(*rptr++);
X		}
X		TekRefresh = (TekLink *)0;
X		longjmp(Tekjump, 1);
X	}
Xagain:
X	if(Tbcnt-- <= 0) {
X		if(nplot > 0)	/* flush line Tbuffer */
X			TekFlush();
X		Tselect_mask = pty_mask;	/* force a read */
X		for( ; ; ) {
X			if(Tselect_mask & pty_mask) {
X				if(screen->logging)
X					FlushLog(screen);
X				if((Tbcnt = read(screen->respond,
X				 Tbptr = Tbuffer, BUF_SIZE)) < 0) {
X					if(errno == EIO)
X						Cleanup (0);
X					else if(errno != EWOULDBLOCK)
X						Panic(
X				 "Tinput:read returned unexpected error (%d)\n",
X						 errno);
X				} else if(Tbcnt == 0)
X					Panic("input: read returned zero\n", 0);
X				else {
X					/* strip parity bit */
X					for(i = Tbcnt, cp = Tbptr ; i > 0 ; i--)
X						*cp++ &= CHAR;
X					break;
X				}
X			}
X			if (Ttoggled && curstate == Talptable) {
X				TCursorToggle(TOGGLE);
X				Ttoggled = FALSE;
X			}
X			if(QLength(screen->display))
X				Tselect_mask = X_mask;
X			else {
X				XFlush(screen->display);
X				Tselect_mask = Select_mask;
X				if((i = select(max_plus1, &Tselect_mask,
X					(int *)NULL, (int *)NULL,
X					(struct timeval *)NULL)) < 0){
X					if (errno != EINTR)
X						SysError(ERROR_TSELECT);
X					continue;
X				}
X			}
X			if(Tselect_mask & X_mask) {
X				xevents();
X				if(Tbcnt > 0)
X					goto again;
X			}
X		}
X		Tbcnt--;
X		if (!Ttoggled && curstate == Talptable) {
X			TCursorToggle(TOGGLE);
X			Ttoggled = TRUE;
X		}
X	}
X	if((tek = TekRecord)->count >= TEK_LINK_BLOCK_SIZE) {
X		if((TekRecord = tek->next = (TekLink *)malloc(sizeof(TekLink)))
X		 == (TekLink *)0)
X			Panic("Tinput: malloc error (%d)\n", errno);
X		tek = tek->next;
X		tek->next = (TekLink *)0;
X		tek->count = 0;
X		tek->ptr = tek->data;
X	}
X	tek->count++;
X	return(*tek->ptr++ = *Tbptr++);
X}
X
X/* this should become the Tek Widget's Resize proc */
Xstatic void TekConfigure(w)
X    Widget w;
X{
X    register TScreen *screen = &term->screen;
X    register int border = 2 * screen->border;
X    register double d;
X
X    XClearWindow(screen->display, TWindow(screen));
X    TWidth(screen) = w->core.width - border;
X    THeight(screen) = w->core.height - border;
X    TekScale(screen) = (double)TWidth(screen) / TEKWIDTH;
X    if((d = (double)THeight(screen) / (TEKHEIGHT + TEKTOPPAD + TEKBOTTOMPAD))
X       < TekScale(screen))
X      TekScale(screen) = d;
X    TFullWidth(screen) = w->core.width;
X    TFullHeight(screen) = w->core.height;
X}
X
X/* this should become the Tek Widget's Expose proc */
X/* need to use compress_events = TRUE so you don't need to 
X   look at the "count" in the exposure event ! */
X/*ARGSUSED*/
Xvoid TekExpose(w, event, region)
XWidget w;
XXExposeEvent *event;
XRegion region;
X{
X	register TScreen *screen = &term->screen;
X
X#ifdef lint
X	region = region;
X#endif
X	if(!Ttoggled)
X	    TCursorToggle(CLEAR);
X	Ttoggled = TRUE;
X	Tpushback = Tpushb;
X	screen->cur_X = 0;
X	screen->cur_Y = TEKHOME;
X	screen->cur = screen->page;
X        TekSetGCFont (screen->cur.fontsize);
X	screen->margin = MARGIN1;
X	if(screen->TekGIN) {
X		screen->TekGIN = NULL;
X		TekGINoff();
X	}
X	TekRefresh = &Tek0;
X	rptr = TekRefresh->data;
X	rcnt = TekRefresh->count;
X	Tparsestate = curstate = Talptable;
X	if(!screen->waitrefresh)
X		dorefresh();
X}
X
Xdorefresh()
X{
X	register TScreen *screen = &term->screen;
X	static Cursor wait_cursor = None;
X
X	if (wait_cursor == None)
X            wait_cursor = make_wait(screen->mousecolor, term->core.background_pixel);
X        XDefineCursor(screen->display, TShellWindow, wait_cursor);
X	XFlush(screen->display);
X	if(!setjmp(Tekjump))
X		Tekparse();
X	XDefineCursor(screen->display, TShellWindow,
X	 (screen->TekGIN && GINcursor) ? GINcursor : screen->arrow);
X}
X
XTekPage()
X{
X	register TScreen *screen = &term->screen;
X	register TekLink *tek, *tek2;
X
X	XClearWindow(screen->display, TWindow(screen));
X	screen->cur_X = 0;
X	screen->cur_Y = TEKHOME;
X	screen->margin = MARGIN1;
X	screen->page = screen->cur;
X	if(screen->TekGIN)
X		TekGINoff();
X	tek = TekRecord = &Tek0;
X	tek->count = 0;
X	tek->ptr = tek->data;
X	if(tek = tek->next)
X		do {
X			tek2 = tek->next;
X			free((char *)tek);
X		} while(tek = tek2);
X	TekRecord->next = (TekLink *)0;
X	TekRefresh = (TekLink *)0;
X	Ttoggled = TRUE;
X	Tparsestate = curstate = Talptable;	/* Tek Alpha mode */
X}
X
X#define	EXTRABITS	017
X#define	FIVEBITS	037
X#define	HIBITS		(FIVEBITS << SHIFTHI)
X#define	LOBITS		(FIVEBITS << SHIFTLO)
X#define	SHIFTHI		7
X#define	SHIFTLO		2
X#define	TWOBITS		03
X
Xgetpoint()
X{
X	register int c, x, y, e, lo_y = 0;
X	register TScreen *screen = &term->screen;
X
X	x = screen->cur.x;
X	y = screen->cur.y;
X	for( ; ; ) {
X		if((c = input()) < ' ') {	/* control character */
X			unput(c);
X			return(0);
X		}
X		if(c < '@') {	/* Hi X or Hi Y */
X			if(lo_y) {	/* seen a Lo Y, so this must be Hi X */
X				x &= ~HIBITS;
X				x |= (c & FIVEBITS) << SHIFTHI;
X				continue;
X			}
X			/* else Hi Y */
X			y &= ~HIBITS;
X			y |= (c & FIVEBITS) << SHIFTHI;
X			continue;
X		}
X		if(c < '`') {	/* Lo X */
X			x &= ~LOBITS;
X			x |= (c & FIVEBITS) << SHIFTLO;
X			screen->cur.x = x;
X			screen->cur.y = y;
X			return(1);	/* OK */
X		}
X		/* else Lo Y */
X		if(lo_y) {	/* seen a Lo Y, so other must be extra bits */
X			e = (y >> SHIFTLO) & EXTRABITS;
X			x &= ~TWOBITS;
X			x |= e & TWOBITS;
X			y &= ~TWOBITS;
X			y |= (e >> SHIFTLO) & TWOBITS;
X		}
X		y &= ~LOBITS;
X		y |= (c & FIVEBITS) << SHIFTLO;
X		lo_y++;
X	}
X}
X
XTCursorBack()
X{
X	register TScreen *screen = &term->screen;
X	register struct Tek_Char *t;
X	register int x, l;
X
X	x = ( screen->cur_X -=
X		(t = &TekChar[screen->cur.fontsize])->hsize
X	    );
X
X	if(screen->margin == MARGIN1 && x < 0 || screen->margin == MARGIN2
X	 && x < TEKWIDTH / 2) {
X		if((l = (screen->cur_Y + (t->vsize - 1)) / t->vsize + 1) >=
X		 t->nlines) {
X			screen->margin = !screen->margin;
X			l = 0;
X		}
X		screen->cur_Y = l * t->vsize;
X		screen->cur_X = (t->charsperline - 1) * t->hsize;
X	}
X}
X
XTCursorForward()
X{
X	register TScreen *screen = &term->screen;
X	register struct Tek_Char *t;
X	register int l;
X
X	if( ( screen->cur_X +=
X		( t = &TekChar[screen->cur.fontsize])->hsize
X	    ) > TEKWIDTH
X	  ) {
X		if((l = screen->cur_Y / t->vsize - 1) < 0) {
X			screen->margin = !screen->margin;
X			l = t->nlines - 1;
X		}
X		screen->cur_Y = l * t->vsize;
X		screen->cur_X = screen->margin == MARGIN1 ? 0 : TEKWIDTH / 2;
X	}
X}
X
XTCursorUp()
X{
X	register TScreen *screen = &term->screen;
X	register struct Tek_Char *t;
X	register int l;
X
X	t = &TekChar[screen->cur.fontsize];
X
X	if((l = (screen->cur_Y + (t->vsize - 1)) / t->vsize + 1) >= t->nlines) {
X		l = 0;
X		if((screen->margin = !screen->margin) != MARGIN1) {
X			if(screen->cur_X < TEKWIDTH / 2)
X				screen->cur_X += TEKWIDTH / 2;
X		} else if(screen->cur_X >= TEKWIDTH / 2)
X			screen->cur_X -= TEKWIDTH / 2;
X	}
X	screen->cur_Y = l * t->vsize;
X}
X
XTCursorDown()
X{
X	register TScreen *screen = &term->screen;
X	register struct Tek_Char *t;
X	register int l;
X
X	t = &TekChar[screen->cur.fontsize];
X
X	if((l = screen->cur_Y / t->vsize - 1) < 0) {
X		l = t->nlines - 1;
X		if((screen->margin = !screen->margin) != MARGIN1) {
X			if(screen->cur_X < TEKWIDTH / 2)
X				screen->cur_X += TEKWIDTH / 2;
X		} else if(screen->cur_X >= TEKWIDTH / 2)
X			screen->cur_X -= TEKWIDTH / 2;
X	}
X	screen->cur_Y = l * t->vsize;
X}
X
XTekDraw (x, y)
Xint x, y;
X{
X	register TScreen *screen = &term->screen;
X
X	if(nplot == 0 || T_lastx != screen->cur_X || T_lasty != screen->cur_Y) {
X		/*
X		 * We flush on each unconnected line segment if the line
X		 * type is not solid.  This solves a bug in X when drawing
X		 * points while the line type is not solid.
X		 */
X		if(nplot > 0 && screen->cur.linetype != SOLIDLINE)
X			TekFlush();
X	}
X	AddToDraw(screen->cur_X, screen->cur_Y, x, y);
X	T_lastx = screen->cur_X = x;
X	T_lasty = screen->cur_Y = y;
X}
X
XAddToDraw(x1, y1, x2, y2)
Xint x1, y1, x2, y2;
X{
X	register TScreen *screen = &term->screen;
X	register XSegment *lp;
X
X	if(nplot >= MAX_PTS) {
X		TekFlush();
X	}
X	lp = line_pt++;
X	lp->x1 = x1 = x1 * TekScale(screen) + screen->border;
X	lp->y1 = y1 = (TEKHEIGHT + TEKTOPPAD - y1) * TekScale(screen) +
X	 screen->border;
X	lp->x2 = x2 = x2 * TekScale(screen) + screen->border;
X	lp->y2 = y2 = (TEKHEIGHT + TEKTOPPAD - y2) * TekScale(screen) +
X	 screen->border;
X	nplot++;
X}
X
XTekFlush ()
X{
X	register TScreen *screen = &term->screen;
X
X	XDrawSegments(screen->display, TWindow(screen), 
X		((screen->cur.linetype == SOLIDLINE)?  screen->TnormalGC :
X		 screen->linepat[screen->cur.linetype - 1]),
X		 Tline, nplot);
X	nplot = 0;
X	line_pt = Tline;
X}
X
XTekGINoff()
X{
X	register TScreen *screen = &term->screen;
X	
X	XDefineCursor(screen->display, TShellWindow, screen->arrow);
X	if(GINcursor)
X		XFreeCursor(screen->display, GINcursor);
X	if(screen->TekGIN) {
X		*screen->TekGIN = CANCEL;	/* modify recording */
X		screen->TekGIN = NULL;
X	}
X}
X
XTekEnqMouse(c)
Xint c;
X{
X	register TScreen *screen = &term->screen;
X	int mousex, mousey, rootx, rooty;
X	unsigned int mask; /* XQueryPointer */
X	Window root, subw;
X
X	XQueryPointer(
X	    screen->display, TWindow(screen), 
X	    &root, &subw,
X	    &rootx, &rooty,
X	    &mousex, &mousey,
X	    &mask);
X	if((mousex = (mousex - screen->border) / TekScale(screen)) < 0)
X		mousex = 0;
X	else if(mousex >= TEKWIDTH)
X		mousex = TEKWIDTH - 1;
X	if((mousey = TEKHEIGHT + TEKTOPPAD - (mousey - screen->border) /
X	     TekScale(screen)) < 0)
X		mousey = 0;
X	else if(mousey >= TEKHEIGHT)
X		mousey = TEKHEIGHT - 1;
X	TekEnq(c, mousex, mousey);
X}
X
XTekEnq (status, x, y)
Xint status;
Xregister int x, y;
X{
X	register TScreen *screen = &term->screen;
X	int pty = screen->respond;
X	char cplot [5];
X
X	/* Translate x and y to Tektronix code */
X	cplot[1] = 040 | ((x >> SHIFTHI) & FIVEBITS);
X	cplot[2] = 040 | ((x >> SHIFTLO) & FIVEBITS);
X	cplot[3] = 040 | ((y >> SHIFTHI) & FIVEBITS);
X	cplot[4] = 040 | ((y >> SHIFTLO) & FIVEBITS);
X	if(cplot[0] = status)
X		write (pty, cplot, 5);
X	else
X		write (pty, &cplot[1], 4);
X}
X
XTekRun()
X{
X	register TScreen *screen = &term->screen;
X	register int i;
X	
X	if(!TWindow(screen) && !TekInit()) {
X		if(VWindow(screen)) {
X			screen->TekEmu = FALSE;
X			return;
X		}
X		Exit(ERROR_TINIT);
X	}
X	if(!screen->Tshow) {
X	    XtRealizeWidget (tekWidget->core.parent);
X	    set_tek_visibility (TRUE);
X	} 
X
X	if(screen->select || screen->always_highlight)
X		TekSelect();
X	if (L_flag > 0) {
X		XWarpPointer (screen->display, None, TWindow(screen),
X			    0, 0, 0, 0,
X			    TFullWidth(screen) >> 1, TFullHeight(screen) >> 1);
X		L_flag = -1;
X	}
X	Tpushback = Tpushb;
X	Tbptr = Tbuffer;
X	for(i = Tbcnt = bcnt ; i > 0 ; i--)
X		*Tbptr++ = *bptr++;
X	Tbptr = Tbuffer;
X	Ttoggled = TRUE;
X	if(!setjmp(Tekend))
X		Tekparse();
X	if(!Ttoggled) {
X		TCursorToggle(TOGGLE);
X		Ttoggled = TRUE;
X	}
X	screen->TekEmu = FALSE;
X	if (!screen->always_highlight)
X	    TekUnselect ();
X	reselectwindow (screen);
X}
X
X#define DOTTED_LENGTH 2
X#define DOT_DASHED_LENGTH 4
X#define SHORT_DASHED_LENGTH 2
X#define LONG_DASHED_LENGTH 2
X
Xstatic int dash_length[TEKNUMLINES] = {
X	DOTTED_LENGTH,
X	DOT_DASHED_LENGTH,
X	SHORT_DASHED_LENGTH,
X	LONG_DASHED_LENGTH,
X};
X
Xstatic unsigned char dotted[DOTTED_LENGTH] = {3, 1};
Xstatic unsigned char dot_dashed[DOT_DASHED_LENGTH] = {3, 4, 3, 1};
Xstatic unsigned char short_dashed[SHORT_DASHED_LENGTH] = {4, 4};
Xstatic unsigned char long_dashed[LONG_DASHED_LENGTH] = {4, 7};
X
Xstatic unsigned char *dashes[TEKNUMLINES] = {
X	dotted,
X	dot_dashed,
X	short_dashed,
X	long_dashed,
X};
X
X
X
X/*
X * The following is called the create the tekWidget
X */
X
Xstatic void TekInitialize(request, new)
X    Widget request, new;
X{
X   /* look for focus related events on the shell, because we need
X    * to care about the shell's border being part of our focus.
X    */
X    XtAddEventHandler(XtParent(new), EnterWindowMask, FALSE,
X		      HandleEnterWindow, (caddr_t)NULL);
X    XtAddEventHandler(XtParent(new), LeaveWindowMask, FALSE,
X		      HandleLeaveWindow, (caddr_t)NULL);
X    XtAddEventHandler(XtParent(new), FocusChangeMask, FALSE,
X		      HandleFocusChange, (caddr_t)NULL);
X    XtAddEventHandler(new, ButtonPressMask, FALSE,
X		      TekButtonPressed, (caddr_t)NULL);
X}
X
X
Xstatic void TekRealize (gw, valuemaskp, values)
X    Widget gw;
X    XtValueMask *valuemaskp;
X    XSetWindowAttributes *values;
X{
X    TekWidget tw = (TekWidget) gw;
X    register TScreen *screen = &term->screen;
X    register int i;
X    register TekLink *tek;
X    register double d;
X    register int border = 2 * screen->border;
X    XColor cdef;
X    Pixel pixels[2];
X    int pr;
X    XGCValues gcv;
X    int winX, winY, width, height;
X    XSizeHints sizehints;
X    char Tdefault[32];
X    extern char *malloc();
X
X    tw->core.border_pixel = term->core.border_pixel;
X
X    if (!(screen->Tfont[SMALLFONT] = XLoadQueryFont (screen->display,
X						     SMALLFONTNAME))) {
X	fprintf(stderr, "%s: Could not get font %s; using server default\n",
X		xterm_name, SMALLFONTNAME);
X	screen->Tfont[SMALLFONT] = XQueryFont (screen->display, DefaultGCID);
X    }
X    if((Tbuffer = (char *)malloc(BUF_SIZE)) == NULL ||
X       (Tpushb = (char *)malloc(10)) == NULL ||
X       (Tline = (XSegment *)malloc(MAX_VTX * sizeof(XSegment))) == NULL) {
X	fprintf (stderr, "%s: Not enough core for Tek mode\n", xterm_name);
X	goto mallocfailed;
X    }
X
X    screen->xorplane = 1;
X
X    screen->Tbackground = term->core.background_pixel;
X    screen->Tforeground = screen->foreground;
X    screen->Tcursorcolor = screen->foreground;
X
X    if (term->misc.T_geometry == NULL) {
X	sprintf (Tdefault, "=%dx%d",
X		TEKDEFWIDTH + border, TEKDEFHEIGHT + border);
X	term->misc.T_geometry = Tdefault;
X    }
X
X    winX = 1;
X    winY = 1;
X    width = TEKDEFWIDTH + border;
X    height = TEKDEFHEIGHT + border;
X
X    pr = XParseGeometry(term->misc.T_geometry, &winX, &winY, &width, &height);
X    if ((pr & XValue) && (pr & XNegative))
X      winX += DisplayWidth(screen->display, DefaultScreen(screen->display))
X                        - width - (term->core.parent->core.border_width * 2);
X    if ((pr & YValue) && (pr & YNegative))
X      winY += DisplayHeight(screen->display, DefaultScreen(screen->display))
X	- height - (term->core.parent->core.border_width * 2);
X  
X    /* set up size hints */
X    sizehints.min_width = TEKMINWIDTH + border;
X    sizehints.min_height = TEKMINHEIGHT + border;
X    sizehints.width_inc = 1;
X    sizehints.height_inc = 1;
X    sizehints.flags = PMinSize|PResizeInc;
X    sizehints.x = winX;
X    sizehints.y = winY;
X    if ((XValue&pr) || (YValue&pr))
X      sizehints.flags |= USSize|USPosition;
X    else sizehints.flags |= PSize|PPosition;
X    tw->core.width = sizehints.width = width;
X    tw->core.height = sizehints.height = height;
X    if ((WidthValue&pr) || (HeightValue&pr))
X      sizehints.flags |= USSize;
X    else sizehints.flags |= PSize;
X
X    (void) XtMakeResizeRequest ((Widget) tw, width, height,
X				&tw->core.width, &tw->core.height);
X
X    /* XXX This is bogus.  We are parsing geometries too late.  This
X     * is information that the shell widget ought to have before we get
X     * realized, so that it can do the right thing.
X     */
X    if (sizehints.flags & USPosition)
X      XMoveWindow (XtDisplay(tw), tw->core.parent->core.window,
X		   sizehints.x, sizehints.y);
X    XSetNormalHints (XtDisplay(tw), tw->core.parent->core.window,
X		     &sizehints);
X
X    values->win_gravity = NorthWestGravity;
X    values->background_pixel = screen->Tbackground;
X
X    if((tw->core.window = TWindow(screen) = 
X	XCreateWindow (screen->display,
X		       tw->core.parent->core.window,
X		       tw->core.x, tw->core.y,
X		       tw->core.width, tw->core.height, tw->core.border_width,
X		       (int) tw->core.depth,
X		       InputOutput, CopyFromParent,
X		       ((*valuemaskp)|CWBackPixel|CWWinGravity),
X		       values)) == NULL) {
X	fprintf(stderr, "%s: Can't create Tek window\n", xterm_name);
X	free((char *)Tline);
X      mallocfailed:
X	if(Tpushb) free((char *)Tpushb);
X	if(Tbuffer) free((char *)Tbuffer);
X	XFreeFont(screen->display, screen->Tfont[SMALLFONT]);
X	Tfailed = TRUE;
X	return;
X    }
X
X    screen->Tbox = T_box;
X
X    TFullWidth(screen) = width;
X    TFullHeight(screen) = height;
X    TWidth(screen) = width - border;
X    THeight(screen) = height - border;
X    TekScale(screen) = (double)TWidth(screen) / TEKWIDTH;
X    if((d = (double)THeight(screen) / (TEKHEIGHT + TEKTOPPAD +
X				       TEKBOTTOMPAD)) < TekScale(screen))
X      TekScale(screen) = d;
X    
X    screen->tobaseline[SMALLFONT] = screen->Tfont[SMALLFONT]->ascent;
X
X    if (!(screen->Tfont[THREEFONT] = XLoadQueryFont(screen->display,
X						    THREEFONTNAME)))
X      screen->Tfont[THREEFONT] = screen->Tfont[SMALLFONT];
X    screen->tobaseline[THREEFONT] = screen->Tfont[THREEFONT]->ascent;
X
X    if (!(screen->Tfont[TWOFONT] = XLoadQueryFont(screen->display,
X						  TWOFONTNAME)))
X      screen->Tfont[TWOFONT] = screen->Tfont[THREEFONT];
X    screen->tobaseline[TWOFONT] = screen->Tfont[TWOFONT]->ascent;
X
X    if (!(screen->Tfont[LARGEFONT] = XLoadQueryFont(screen->display,
X						    LARGEFONTNAME)))
X      screen->Tfont[LARGEFONT] = screen->Tfont[TWOFONT];
X    screen->tobaseline[LARGEFONT] = screen->Tfont[LARGEFONT]->ascent;
X
X    screen->cur.fontsize = LARGEFONT;	/* set large font	*/
X
X    gcv.graphics_exposures = TRUE;	/* default */
X    gcv.font = screen->Tfont[screen->cur.fontsize]->fid;
X    gcv.foreground = screen->Tforeground;
X    gcv.background = screen->Tbackground;
X    
X    /* if font wasn't successfully opened, then gcv.font will contain
X       the Default GC's ID, meaning that we must use the server default font. 
X     */
X    TEKgcFontMask = (gcv.font == DefaultGCID) ? 0 : GCFont;
X    screen->TnormalGC = XCreateGC (screen->display, TWindow(screen), 
X				   (TEKgcFontMask|GCGraphicsExposures|
X				    GCForeground|GCBackground), &gcv);
X
X    gcv.function = GXinvert;
X    gcv.plane_mask = screen->xorplane = (screen->Tbackground ^
X					 screen->Tcursorcolor);
X    screen->TcursorGC = XCreateGC (screen->display, TWindow(screen), 
X				   (GCFunction|GCPlaneMask), &gcv);
X
X    gcv.foreground = screen->Tforeground;
X    gcv.line_style = LineOnOffDash;
X    for(i = 0 ; i < TEKNUMLINES ; i++) {
X	screen->linepat[i] = XCreateGC (screen->display, TWindow(screen),
X					(GCForeground|GCLineStyle), &gcv); 
X	XSetDashes (screen->display, screen->linepat[i], 0,
X		    dashes[i], dash_length[i]);
X    }
X
X    if (term->flags & REVERSE_VIDEO)
X      TekReverseVideo(screen);
X    else
X      TekBackground(screen);
X
X    screen->margin = MARGIN1;		/* Margin 1		*/
X    screen->TekGIN = FALSE;			/* GIN off		*/
X
X
X    XDefineCursor(screen->display, TShellWindow, screen->pointer_cursor);
X    TekUnselect ();
X
X    {	/* there's gotta be a better way... */
X	static Arg args[] = {
X	    {XtNtitle, NULL},
X	    {XtNiconName, NULL},
X	};
X	char *icon_name, *title, *tek_icon_name, *tek_title;
X
X	args[0].value = (XtArgVal)&icon_name;
X	args[1].value = (XtArgVal)&title;
X	XtGetValues (tw->core.parent, args, 2);
X	tek_icon_name = XtMalloc(strlen(icon_name)+7);
X	strcpy(tek_icon_name, icon_name);
X	strcat(tek_icon_name, "(Tek)");
X	tek_title = XtMalloc(strlen(title)+7);
X	strcpy(tek_title, title);
X	strcat(tek_title, "(Tek)");
X	args[0].value = (XtArgVal)tek_icon_name;
X	args[1].value = (XtArgVal)tek_title;
X	XtSetValues (tw->core.parent, args, 2);
X	XtFree( tek_icon_name );
X	XtFree( tek_title );
X    }
X
X    tek = TekRecord = &Tek0;
X    tek->next = (TekLink *)0;
X    tek->count = 0;
X    tek->ptr = tek->data;
X    Tpushback = Tpushb;
X    screen->cur_X = 0;
X    screen->cur_Y = TEKHOME;
X    line_pt = Tline;
X    Ttoggled = TRUE;
X    return;
X}
X
XTekReverseVideo(screen)
Xregister TScreen *screen;
X{
X	register int flag, i;
X	XGCValues gcv;
X	 
X
X	i = screen->Tbackground;
X	screen->Tbackground = screen->Tforeground;
X	screen->Tforeground = i;
X	
X	XSetForeground(screen->display, screen->TnormalGC, 
X	 screen->Tforeground);
X	XSetBackground(screen->display, screen->TnormalGC, 
X	 screen->Tbackground);
X
X	if (tekWidget) {
X	    if (tekWidget->core.border_pixel == screen->Tbackground) {
X		tekWidget->core.border_pixel = screen->Tforeground;
X		tekWidget->core.parent->core.border_pixel =
X		  screen->Tforeground;
X		if (tekWidget->core.parent->core.window)
X		  XSetWindowBorder (screen->display,
X				    tekWidget->core.parent->core.window,
X				    tekWidget->core.border_pixel);
X	    }
X	}
X
X	for(i = 0 ; i < TEKNUMLINES ; i++) {
X		XSetForeground(screen->display, screen->linepat[i], 
X		 screen->Tforeground);
X	}
X
X	if(screen->cellsused) {
X		flag = (term->flags & REVERSE_VIDEO) != 0;
X		screen->Tcursorcolor = screen->Tbackground | screen->xorplane;
X		i = screen->select ? 2 : !flag;
X		screen->colorcells[i].pixel = screen->Tcursorcolor;
X		XStoreColor(screen->display, TekColormap, &screen->colorcells[i]);
X		screen->colorcells[flag].pixel = screen->Tforeground |
X		 screen->xorplane;
X		XStoreColor(screen->display, TekColormap, &screen->colorcells[flag]);
X	} else
X		screen->Tcursorcolor = screen->Tforeground;
X
X	gcv.plane_mask = screen->xorplane = (screen->Tbackground ^
X					     screen->Tcursorcolor);
X	XChangeGC (screen->display, screen->TcursorGC, GCPlaneMask, &gcv);
X	TekBackground(screen);
X}
X
XTekBackground(screen)
Xregister TScreen *screen;
X{
X	if(TWindow(screen))
X		XSetWindowBackground(screen->display, TWindow(screen), 
X		 screen->Tbackground);
X}
X
X/*
X * Toggles cursor on or off at cursor position in screen.
X */
XTCursorToggle(toggle)
Xint toggle;
X{
X	register TScreen *screen = &term->screen;
X	register int c, x, y;
X	register T_fontsize *Tf;
X
X	if (!screen->Tshow) return;
X
X	c = screen->cur.fontsize;
X	Tf = &Tfontsize[c];
X
X	x = (screen->cur_X * TekScale(screen)) + screen->border;
X	y = ((TEKHEIGHT + TEKTOPPAD - screen->cur_Y) * TekScale(screen)) +
X	 screen->border - screen->tobaseline[c];
X	if (toggle) {
X	   if (screen->select || screen->always_highlight) 
X		XFillRectangle(
X		    screen->display, TWindow(screen), screen->TcursorGC,
X		    x, y,
X		    (unsigned) Tf->Twidth, (unsigned) Tf->Theight);
X	  else { /* fix to use different GC! */
X		  screen->Tbox[c]->x = x;
X		  screen->Tbox[c]->y = y ;
X		  XDrawLines(screen->display, TWindow(screen), 
X		    screen->TcursorGC,
X		    screen->Tbox[c], NBOX, CoordModePrevious);
X	   }
X	} else {
X	   if (screen->select || screen->always_highlight) 
X		XClearArea(screen->display, TWindow(screen), x, y,
X		    (unsigned) Tf->Twidth, (unsigned) Tf->Theight, FALSE);
X	   else { 
X		  screen->Tbox[c]->x = x;
X		  screen->Tbox[c]->y = y ;
X		  XDrawLines(screen->display, TWindow(screen), 
X		    screen->TcursorGC,
X		    screen->Tbox[c], NBOX, CoordModePrevious);
X	   }
X	}
X}
X
XTekSelect()
X{
X	register TScreen *screen = &term->screen;
X
X	if (tekWidget && TShellWindow)
X	  XSetWindowBorder (screen->display, TShellWindow,
X			    tekWidget->core.border_pixel);
X}
X
XTekUnselect()
X{
X	register TScreen *screen = &term->screen;
X
X	if (tekWidget && TShellWindow && !screen->always_highlight)
X	  XSetWindowBorderPixmap (screen->display, TShellWindow,
X				  screen->graybordertile);
X}
X
XTekCopy()
X{
X	register TekLink *Tp;
X	register int fd;
X	register TScreen *screen = &term->screen;
X	register struct tm *tp;
X	long l;
X	char buf[32];
X
X	/* for login windows, check that a user has logged in */
X	if(L_flag && !checklogin()) {
X		Bell();
X		return;
X	}
X	time(&l);
X	tp = localtime(&l);
X	sprintf(buf, "COPY%02d-%02d-%02d.%02d:%02d:%02d", tp->tm_year,
X	 tp->tm_mon, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec);
X	if(access(buf, F_OK) >= 0) {	/* file exists */
X		if(access(buf, W_OK) < 0) {
X			Bell();
X			return;
X		}
X	} else if(access(".", W_OK) < 0) {	/* can't write in directory */
X		Bell();
X		return;
X	}
X	if((fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) {
X		Bell();
X		return;
X	}
X	chown(buf, screen->uid, screen->gid);
X	sprintf(buf, "\033%c\033%c", screen->page.fontsize + '8',
X	 screen->page.linetype + '`');
X	write(fd, buf, 4);
X	Tp = &Tek0; 
X	do
X		write(fd, (char *)Tp->data, Tp->count);
X	while(Tp = Tp->next);
X	close(fd);
X}
X
X#ifdef MODEMENU
X/*
X * TMENU_LARGE through TMENU_SMALL must be first, as they must be the same
X * as the font size values LARGEFONT through SMALLFONT
X */
X#define	TMENU_LARGE	0
X#define	TMENU_NUM2	(TMENU_LARGE+1)
X#define	TMENU_NUM3	(TMENU_NUM2+1)
X#define	TMENU_SMALL	(TMENU_NUM3+1)
X#define	TMENU_VTWIN	(TMENU_SMALL+1)
X#define	TMENU_LINE	(TMENU_VTWIN+1)
X#define	TMENU_PAGE	(TMENU_LINE+1)
X#define	TMENU_RESET	(TMENU_PAGE+1)
X#define	TMENU_COPY	(TMENU_RESET+1)
X#define	TMENU_VTMODE	(TMENU_COPY+1)
X#define	TMENU_HIDETEK	(TMENU_VTMODE+1)
X
Xstatic char *Ttext[] = {
X	"Large Characters",
X	"#2 Size Characters",
X	"#3 Size Characters",
X	"Small Characters",
X	"VT Window Showing",
X	"-",
X	"PAGE",
X	"RESET",
X	"COPY",
X	"Select VT Mode",
X	"Hide Tek Window",
X	0,
X};
X
Xstatic Tmodes curmodes;
Xstatic int Tsize;
Xstatic Boolean vshow;
X
XMenu *Tsetupmenu(menu)
Xregister Menu **menu;
X{
X	register TScreen *screen = &term->screen;
X	register char **cp;
X	register int size = screen->cur.fontsize;
X
X	curmodes = screen->cur;
X	if (*menu == NULL) {
X		if ((*menu = NewMenu("Tektronix")) == NULL)
X			return(NULL);
X		for(cp = Ttext ; *cp ; cp++)
X			AddMenuItem(*menu, *cp);
X		CheckItem(*menu, size);
X		if(vshow = screen->Vshow)
X			CheckItem(*menu, TMENU_VTWIN);
X		else
X			DisableItem(*menu, TMENU_HIDETEK);
X
X		DisableItem(*menu, TMENU_LINE);
X		Tsize = size;
X		return(*menu);
X	}
X	if (Tsize != size) {
X		UncheckItem(*menu, Tsize);
X		CheckItem(*menu, Tsize = size);
X	}
X	if(vshow != screen->Vshow) {
X		SetItemCheck(*menu, TMENU_VTWIN, (vshow = screen->Vshow));
X		SetItemDisable(*menu, TMENU_HIDETEK, !vshow);
X	}
X
X	return(*menu);
X}
X
Xstatic char *changesize[] = {
X	"\0338",
X	"\0339",
X	"\033:",
X	"\033;",
X};
X
XTdomenufunc(item)
Xint item;
X{
X	register TScreen *screen = &term->screen;
X	register char *tp;
X	register char *fp;
X
X	switch (item) {
X	case TMENU_LARGE:
X	case TMENU_NUM2:
X	case TMENU_NUM3:
X	case TMENU_SMALL:
X		if(!Ttoggled) {
X			TCursorToggle(TOGGLE);
X			Ttoggled = TRUE;
X		}
X		if(Tbcnt < 0)
X			Tbcnt = 0;
X		for(fp = changesize[item], tp = &Tbptr[Tbcnt] ; *fp ; ) {
X			*tp++ = *fp++;
X			Tbcnt++;
X		}
X		break;
X
X	case TMENU_RESET:
X		bzero((char *)&curmodes, sizeof(Tmodes));
X			/* drop through */
X	case TMENU_PAGE:
X		TekRefresh = (TekLink *)0;
X		screen->cur = curmodes;
X		TekPage();
X		screen->cur_X = 0;
X		screen->cur_Y = TEKHOME;
X		break;
X
X	case TMENU_COPY:
X		TekCopy();
X		break;
X
X	case TMENU_HIDETEK:
X		set_tek_visibility (FALSE);
X		reselectwindow(screen);
X		TekRefresh = (TekLink *)0;
X			/* drop through */
X	case TMENU_VTMODE:
X		if(TekRefresh)
X			dorefresh();
X		end_tek_mode ();
X		break;
X
X	case TMENU_VTWIN:
X		if (!screen->Vshow) {
X		    set_vt_visibility (TRUE);
X		} else {
X		    set_vt_visibility (FALSE);
X		    if (!screen->TekEmu && TekRefresh) dorefresh ();
X		    end_vt_mode ();
X		}
X
X		reselectwindow(screen);
X		break;
X	}
X	if(TekRefresh)
X		dorefresh();
X}
X#endif	/* MODEMENU */
X
X
SHAR_EOF
chmod 0644 Tekproc.c || echo "restore of Tekproc.c fails"
if [ $TOUCH = can ]
then
    touch -am 1109131490 Tekproc.c
fi
fi
# ============= input.c ==============
if test -f input.c; then echo "File input.c exists"; else
sed 's/^X//' << 'SHAR_EOF' > input.c &&
X/*
X *	$XConsortium: input.c,v 1.5 88/09/06 17:08:05 jim Exp $
X */
X
X#ifndef lint
Xstatic char *rcsid_input_c = "$XConsortium: input.c,v 1.5 88/09/06 17:08:05 jim Exp $";
X#endif	/* lint */
X
X#include <X11/copyright.h>
X
X/*
X * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
X *
X *                         All Rights Reserved
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted,
X * provided that the above copyright notice appear in all copies and that
X * both that copyright notice and this permission notice appear in
X * supporting documentation, and that the name of Digital Equipment
X * Corporation not be used in advertising or publicity pertaining to
X * distribution of the software without specific, written prior permission.
X *
X *
X * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
X * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
X * SOFTWARE.
X */
X
X/* input.c */
X
X#ifndef lint
Xstatic char rcs_id[] = "$XConsortium: input.c,v 1.5 88/09/06 17:08:05 jim Exp $";
X#endif	/* lint */
X
X#include <X11/Xlib.h>
X#include <X11/keysym.h>
X#ifdef AIXV3
X#include "DECkeysym.h"
X#else /* AIXV3 */
X#include <X11/DECkeysym.h>
X#endif /* AIXV3 */
X#include <X11/Intrinsic.h>
X#include <X11/Xutil.h>
X#include <stdio.h>
X#include "ptyx.h"
X
Xint MetaMode = 1;	/* prefix with ESC when Meta Key is down */
X
Xstatic XComposeStatus compose_status = {NULL, 0};
Xstatic char *kypd_num = " XXXXXXXX\tXXX\rXXXxxxxXXXXXXXXXXXXXXXXXXXXX*+,-.\\0123456789XXX=";
Xstatic char *kypd_apl = " ABCDEFGHIJKLMNOPQRSTUVWXYZ??????abcdefghijklmnopqrstuvwxyzXXX";
Xstatic char *cur = "DACB";
X
Xstatic int funcvalue(), sunfuncvalue();
Xextern Boolean sunFunctionKeys;
X
Xvoid
XAdjustAfterInput (screen)
Xregister TScreen *screen;
X{
X	if(screen->scrollkey && screen->topline != 0)
X		WindowScroll(screen, 0);
X	if(screen->marginbell) {
X		int col = screen->max_col - screen->nmarginbell;
X		if(screen->bellarmed >= 0) {
X			if(screen->bellarmed == screen->cur_row) {
X				if(screen->cur_col >= col) {
X					if(screen->cur_col == col)
X						Bell();
X					screen->bellarmed = -1;
X				}
X			} else
X				screen->bellarmed = screen->cur_col <
X				 col ? screen->cur_row : -1;
X		} else if(screen->cur_col < col)
X			screen->bellarmed = screen->cur_row;
X	}
X}
X
XInput (keyboard, screen, event)
Xregister TKeyboard	*keyboard;
Xregister TScreen		*screen;
Xregister XKeyPressedEvent *event;
X{
X
X#define STRBUFSIZE 100
X
X	 char strbuf[STRBUFSIZE];
X	register char *string;
X	register int key = FALSE;
X	int	pty	= screen->respond;
X	int	nbytes;
X	int 	keycode;
X	ANSI	reply;
X
X	nbytes = XLookupString (event, strbuf, STRBUFSIZE, 
X		&keycode, &compose_status);
X
X	string = &strbuf[0];
X	reply.a_pintro = 0;
X	reply.a_final = 0;
X	reply.a_nparam = 0;
X	reply.a_inters = 0;
X
X	if (IsPFKey(keycode)) {
X		reply.a_type = SS3;
X		unparseseq(&reply, pty);
X		unparseputc((char)(keycode-XK_KP_F1+'P'), pty);
X		key = TRUE;
X	} else if (IsKeypadKey(keycode)) {
X	  	if (keyboard->flags & KYPD_APL)	{
X			reply.a_type   = SS3;
X			unparseseq(&reply, pty);
X			unparseputc(kypd_apl[keycode-XK_KP_Space], pty);
X		} else
X			unparseputc(kypd_num[keycode-XK_KP_Space], pty);
X		key = TRUE;
X        } else if (IsCursorKey(keycode) &&
X        	keycode != XK_Prior && keycode != XK_Next) {
X       		if (keyboard->flags & CURSOR_APL) {
X			reply.a_type = SS3;
X			unparseseq(&reply, pty);
X			unparseputc(cur[keycode-XK_Left], pty);
X		} else {
X			reply.a_type = CSI;
X			reply.a_final = cur[keycode-XK_Left];
X			unparseseq(&reply, pty);
X		}
X		key = TRUE;
X	 } else if (IsFunctionKey(keycode) || IsMiscFunctionKey(keycode) ||
X	 	keycode == XK_Prior || keycode == XK_Next ||
X	 	keycode == DXK_Remove) {
X		reply.a_type = CSI;
X		reply.a_nparam = 1;
X		if (sunFunctionKeys) {
X		    reply.a_param[0] = sunfuncvalue (keycode);
X		    reply.a_final = 'z';
X		} else {
X		    reply.a_param[0] = funcvalue (keycode);
X		    reply.a_final = '~';
X		}
X		if (reply.a_param[0] > 0)
X			unparseseq(&reply, pty);
X		key = TRUE;
X	} else if (nbytes > 0) {
X		if(screen->TekGIN) {
X			TekEnqMouse(*string++);
X			TekGINoff();
X			nbytes--;
X		}
X		if ((nbytes == 1) && MetaMode && (event->state & Mod1Mask))
X			unparseputc(033, pty);
X		while (nbytes-- > 0)
X			unparseputc(*string++, pty);
X		key = TRUE;
X	}
X	if(key && !screen->TekEmu)
X	        AdjustAfterInput(screen);
X#ifdef ENABLE_PRINT
X	if (keycode == XK_F2) TekPrint();
X#endif
X	return;
X}
X
XStringInput (screen, string)
Xregister TScreen	*screen;
Xregister char *string;
X{
X	int	pty	= screen->respond;
X	int	nbytes;
X
X	nbytes = strlen(string);
X	if(nbytes && screen->TekGIN) {
X		TekEnqMouse(*string++);
X		TekGINoff();
X		nbytes--;
X	}
X	while (nbytes-- > 0)
X		unparseputc(*string++, pty);
X	if(!screen->TekEmu)
X	        AdjustAfterInput(screen);
X}
X
Xstatic int funcvalue (keycode)
X	int keycode;
X{
X	switch (keycode) {
X		case XK_F1:	return(11);
X		case XK_F2:	return(12);
X		case XK_F3:	return(13);
X		case XK_F4:	return(14);
X		case XK_F5:	return(15);
X		case XK_F6:	return(17);
X		case XK_F7:	return(18);
X		case XK_F8:	return(19);
X		case XK_F9:	return(20);
X		case XK_F10:	return(21);
X		case XK_F11:	return(23);
X		case XK_F12:	return(24);
X		case XK_F13:	return(25);
X		case XK_F14:	return(26);
X		case XK_F15:	return(28);
X		case XK_Help:	return(28);
X		case XK_F16:	return(29);
X		case XK_Menu:	return(29);
X		case XK_F17:	return(31);
X		case XK_F18:	return(32);
X		case XK_F19:	return(33);
X		case XK_F20:	return(34);
X
X		case XK_Find :	return(1);
X		case XK_Insert:	return(2);
X		case XK_Delete:	return(3);
X		case DXK_Remove: return(3);
X		case XK_Select:	return(4);
X		case XK_Prior:	return(5);
X		case XK_Next:	return(6);
X		default:	return(-1);
X	}
X}
X
X
Xstatic int sunfuncvalue (keycode)
X	int keycode;
X  {
X  	switch (keycode) {
X		case XK_F1:	return(224);
X		case XK_F2:	return(225);
X		case XK_F3:	return(226);
X		case XK_F4:	return(227);
X		case XK_F5:	return(228);
X		case XK_F6:	return(229);
X		case XK_F7:	return(230);
X		case XK_F8:	return(231);
X		case XK_F9:	return(232);
X		case XK_F10:	return(233);
X		case XK_F11:	return(192);
X		case XK_F12:	return(193);
X		case XK_F13:	return(194);
X		case XK_F14:	return(195);
X		case XK_F15:	return(196);
X		case XK_Help:	return(196);
X		case XK_F16:	return(197);
X		case XK_Menu:	return(197);
X		case XK_F17:	return(198);
X		case XK_F18:	return(199);
X		case XK_F19:	return(200);
X		case XK_F20:	return(201);
X
X		case XK_R1:	return(208);
X		case XK_R2:	return(209);
X		case XK_R3:	return(210);
X		case XK_R4:	return(211);
X		case XK_R5:	return(212);
X		case XK_R6:	return(213);
X		case XK_R7:	return(214);
X		case XK_R8:	return(215);
X		case XK_R9:	return(216);
X		case XK_R10:	return(217);
X		case XK_R11:	return(218);
X		case XK_R12:	return(219);
X		case XK_R13:	return(220);
X		case XK_R14:	return(221);
X		case XK_R15:	return(222);
X  
X		case XK_Find :	return(1);
X		case XK_Insert:	return(2);
X		case XK_Delete:	return(3);
X		case DXK_Remove: return(3);
X		case XK_Select:	return(4);
X		case XK_Prior:	return(5);
X		case XK_Next:	return(6);
X		default:	return(-1);
X	}
X}
X
SHAR_EOF
chmod 0644 input.c || echo "restore of input.c fails"
if [ $TOUCH = can ]
then
    touch -am 1109131490 input.c
fi
fi
# ============= main.c ==============
if test -f main.c; then echo "File main.c exists"; else
sed 's/^X//' << 'SHAR_EOF' > main.c &&
X#ifndef lint
Xstatic char rcs_id[] = "$XConsortium: main.c,v 1.96 88/10/18 14:43:19 swick Exp $";
X#endif	/* lint */
X
X/*
X * The tty setup code was completely rewritten by Dave Serisky at 
X * Hewlett-Packard and should now work properly under both System V and
X * 4BSD.  However, the toolkit stuff is still pretty crufty.  In general,
X * beware, for there be dragons here.
X */
X
X#include <X11/copyright.h>
X
X/***********************************************************
XCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
Xand the Massachusetts Institute of Technology, Cambridge, Massachusetts.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its 
Xdocumentation for any purpose and without fee is hereby granted, 
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in 
Xsupporting documentation, and that the names of Digital or MIT not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.  
X
XDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X
X/* main.c */
X
X#include <X11/Xos.h>
X#include <X11/Xlib.h>
X#include <pwd.h>
X#include <ctype.h>
X
X#ifdef AIXV3
X#include <sys/termio.h>
X#endif /* AIXV3 */
X
X/*
X * The macII claims not to be SYSV, but it uses System V terminal control,
X * process groups, and signals.  If it walks like a duck and talks like duck,
X * ....  But, we still want to keep things separate for when other hybrids
X * become supported.
X */
X#ifdef macII
X#include <sys/ioctl.h>
X#include <sys/termio.h>
X#include <sys/stat.h>
X#include <sys/ttychars.h>
X#define vhangup() ;
X#define setpgrp2 setpgrp
X#define USE_SYSV_TERMIO
X#define USE_SYSV_UTMP
X#define USE_SYSV_PGRP
X#define USE_SYSV_SIGNALS
X#endif /* macII */
X
X#ifdef SYSV				/* note that macII is *not* SYSV */
X#include <sys/ioctl.h>
X#include <sys/termio.h>
X#ifndef mips
X#include <sys/ptyio.h>
X#endif /* not mips */
X#include <sys/stat.h>
X#ifdef JOBCONTROL
X#include <sys/bsdtty.h>
X#endif	/* JOBCONTROL */
X#define USE_SYSV_TERMIO
X#define USE_SYSV_UTMP
X#define USE_SYSV_SIGNALS
X#define	USE_SYSV_PGRP
X#else	/* else not SYSV */		/* BSD and macII */
X#ifdef macII
X#undef FIOCLEX
X#undef FIONCLEX
X#endif
X#include <sgtty.h>
X#include <sys/wait.h>
X#include <sys/resource.h>
X#endif	/* !SYSV */
X
X
X#include <stdio.h>
X#include <errno.h>
X#include <signal.h>
X#include <setjmp.h>
X
X#ifdef hpux
X#include <sys/utsname.h>
X#endif /* hpux */
X
X#ifdef apollo
X#define ttyslot() 1
X#define vhangup() ;
X#endif /* apollo */
X
X#include <utmp.h>
X#include <sys/param.h>	/* for NOFILE */
X
X#include "ptyx.h"
X#include "data.h"
X#include "error.h"
X#include "main.h"
X#include <X11/StringDefs.h>
X#include <X11/Shell.h>
X
Xextern Pixmap make_gray();
Xextern char *malloc();
Xextern char *calloc();
Xextern char *realloc();
Xextern char *ttyname();
Xextern void exit();
Xextern void sleep();
Xextern void Bcopy();
Xextern void vhangup();
Xextern long lseek();
X
Xint switchfb[] = {0, 2, 1, 3};
X
Xstatic int reapchild ();
X
Xstatic Bool added_utmp_entry = False;
X
Xstatic char **command_to_exec;
X
X#ifdef USE_SYSV_TERMIO
X/* The following structures are initialized in main() in order
X** to eliminate any assumptions about the internal order of their
X** contents.
X*/
Xstatic struct termio d_tio;
X#ifdef TIOCSLTC
Xstatic struct ltchars d_ltc;
X#endif	/* TIOCSLTC */
X#ifdef TIOCLSET
Xstatic unsigned int d_lmode;
X#endif	/* TIOCLSET */
X#else /* not USE_SYSV_TERMIO */
X
X#ifdef AIXV3
X
Xstatic struct termios   terminal_modes;
X
X#else /* not AIXV3 */
X
Xstatic struct  sgttyb d_sg = {
X        0, 0, 0177, CKILL, EVENP|ODDP|ECHO|XTABS|CRMOD
X
Xstatic struct  sgttyb d_sg = {
X        0, 0, 0177, CKILL, EVENP|ODDP|ECHO|XTABS|CRMOD
X};
Xstatic struct  tchars d_tc = {
X        CINTR, CQUIT, CSTART,
X        CSTOP, CEOF, CBRK,
X};
Xstatic struct  ltchars d_ltc = {
X        CSUSP, CDSUSP, CRPRNT,
X        CFLUSH, CWERASE, CLNEXT
X};
Xstatic int d_disipline = NTTYDISC;
Xstatic long int d_lmode = LCRTBS|LCRTERA|LCRTKIL|LCTLECH;
X
X#endif /* AIXV3 */
X
X#endif /* USE_SYSV_TERMIO */
X
Xstatic int parse_tty_modes ();
X/*
X * SYSV has the termio.c_cc[V] and ltchars; BSD has tchars and ltchars
X */
Xstatic int override_tty_modes = 0;
Xstruct _xttymodes {
X    char *name;
X    int len;
X    int set;
X    char value;
X} ttymodelist[] = {
X{ "intr", 4, 0, '\0' },			/* tchars.t_intrc ; VINTR */
X#define XTTYMODE_intr 0
X{ "quit", 4, 0, '\0' },			/* tchars.t_quitc ; VQUIT */
X#define XTTYMODE_quit 1
X{ "erase", 5, 0, '\0' },		/* sgttyb.sg_erase ; VERASE */
X#define XTTYMODE_erase 2
X{ "kill", 4, 0, '\0' },			/* sgttyb.sg_kill ; VKILL */
X#define XTTYMODE_kill 3
X{ "eof", 3, 0, '\0' },			/* tchars.t_eofc ; VEOF */
X#define XTTYMODE_eof 4
X{ "eol", 3, 0, '\0' },			/* VEOL */
X#define XTTYMODE_eol 5
X{ "swtch", 5, 0, '\0' },		/* VSWTCH */
X#define XTTYMODE_swtch 6
X{ "start", 5, 0, '\0' },		/* tchars.t_startc */
X#define XTTYMODE_start 7
X{ "stop", 4, 0, '\0' },			/* tchars.t_stopc */
X#define XTTYMODE_stop 8
X{ "brk", 3, 0, '\0' },			/* tchars.t_brkc */
X#define XTTYMODE_brk 9
X{ "susp", 4, 0, '\0' },			/* ltchars.t_suspc */
X#define XTTYMODE_susp 10
X{ "dsusp", 5, 0, '\0' },		/* ltchars.t_dsuspc */
X#define XTTYMODE_dsusp 11
X{ "rprnt", 5, 0, '\0' },		/* ltchars.t_rprntc */
X#define XTTYMODE_rprnt 12
X{ "flush", 5, 0, '\0' },		/* ltchars.t_flushc */
X#define XTTYMODE_flush 13
X{ "weras", 5, 0, '\0' },		/* ltchars.t_werasc */
X#define XTTYMODE_weras 14
X{ "lnext", 5, 0, '\0' },		/* ltchars.t_lnextc */
X#define XTTYMODE_lnext 15
X#define NXTTYMODES 16
X};
X
X#ifdef USE_SYSV_UTMP
Xextern struct utmp *getutent();
Xextern struct utmp *getutid();
Xextern struct utmp *getutline();
Xextern void pututline();
Xextern void setutent();
Xextern void endutent();
Xextern void utmpname();
X
Xextern struct passwd *getpwent();
Xextern struct passwd *getpwuid();
Xextern struct passwd *getpwnam();
Xextern void setpwent();
Xextern void endpwent();
Xextern struct passwd *fgetpwent();
X#else	/* not USE_SYSV_UTMP */
Xstatic char etc_utmp[] = "/etc/utmp";
X#endif	/* USE_SYSV_UTMP */
X
Xstatic char *get_ty;
Xstatic int inhibit;
Xstatic char passedPty[2];	/* name if pty if slave */
Xstatic int loginpty;
X
X#ifdef TIOCCONS
Xstatic int Console;
X#endif	/* TIOCCONS */
X#ifndef USE_SYSV_UTMP
Xstatic int tslot;
X#endif	/* USE_SYSV_UTMP */
Xstatic jmp_buf env;
X
Xchar *ProgramName;
XBoolean sunFunctionKeys;
X
X#ifdef AIXV3
X
X#ifndef CTRL
X#define CTRL(c)		('c'&0x1f)
X#endif
X
Xstatic void
Xset_default_terminal_modes()
X{
X	int  i;
X
X	terminal_modes.c_iflag = (BRKINT|ICRNL|IXON|IXOFF|IMAXBEL);
X	terminal_modes.c_oflag = (OPOST|ONLCR|TAB3);
X	terminal_modes.c_cflag = (CS8|CREAD|HUPCL|B9600);
X	terminal_modes.c_lflag = (ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOKE|ECHOCTL);
X	for(i=0; i< NCCS; i++){
X	    terminal_modes.c_cc[i] = 0;
X	}
X	terminal_modes.c_cc[VINTR] = CTRL(c);
X	terminal_modes.c_cc[VQUIT] = CTRL(\\);
X	terminal_modes.c_cc[VERASE] = CTRL(h);
X	terminal_modes.c_cc[VKILL] = CTRL(u);
X	terminal_modes.c_cc[VEOF] = CTRL(d);
X	terminal_modes.c_cc[VEOL] = CTRL(@);
X	terminal_modes.c_cc[VEOL2] = CTRL(@);
X	terminal_modes.c_cc[VSTRT] = CTRL(q);
X	terminal_modes.c_cc[VSTOP] = CTRL(s);
X	terminal_modes.c_cc[VSUSP] = CTRL(z);
X	terminal_modes.c_cc[VDSUSP] = CTRL(y);
X	terminal_modes.c_cc[VREPRINT] = CTRL(r);
X	terminal_modes.c_cc[VDISCRD] = CTRL(o);
X	terminal_modes.c_cc[VWERSE] = CTRL(w);
X	terminal_modes.c_cc[VLNEXT] = CTRL(v);
X}
X
Xstatic void
Xget_tty_info(ttyfd)
X    int  ttyfd;
X{
X    if( tcgetattr(ttyfd, &terminal_modes) < 0 ){
X	/* it failed, punt */
X	set_default_terminal_modes();
X    }
X}
X
Xstatic void
Xset_tty_info(ttyfd)
X    int  ttyfd;
X{
X    ioctl(ttyfd,TXADDCD,"posix");
X    if( tcsetattr(ttyfd, TCSANOW, &terminal_modes) < 0 ){
X	/* failed, punt */
X	exit(0);
X    }
X}
X#endif /* AIXV3 */
X
Xstatic struct _resource {
X    char *xterm_name;
X    char *icon_geometry;
X    char *title;
X    char *icon_name;
X    char *term_name;
X    char *tty_modes;
X    Boolean utmpInhibit;
X    Boolean sunFunctionKeys;	/* %%% should be widget resource? */
X} resource;
X
X#ifndef GETTY_EXE
X#define GETTY_EXE "/etc/getty"
X#endif /* GETTY_EXE */
X
Xstatic char *getty_program = GETTY_EXE;
X
X/* used by VT (charproc.c) */
X
X#define offset(field)	XtOffset(struct _resource *, field)
X
Xstatic XtResource application_resources[] = {
X    {"name", "Name", XtRString, sizeof(char *),
X	offset(xterm_name), XtRString, "xterm"},
X    {"iconGeometry", "IconGeometry", XtRString, sizeof(char *),
X	offset(icon_geometry), XtRString, (caddr_t) NULL},
X    {XtNtitle, XtCTitle, XtRString, sizeof(char *),
X	offset(title), XtRString, (caddr_t) NULL},
X    {XtNiconName, XtCIconName, XtRString, sizeof(char *),
X	offset(icon_name), XtRString, (caddr_t) NULL},
X    {"termName", "TermName", XtRString, sizeof(char *),
X	offset(term_name), XtRString, (caddr_t) NULL},
X    {"ttyModes", "TtyModes", XtRString, sizeof(char *),
X	offset(tty_modes), XtRString, (caddr_t) NULL},
X    {"utmpInhibit", "UtmpInhibit", XtRBoolean, sizeof (Boolean),
X	offset(utmpInhibit), XtRString, "false"},
X    {"sunFunctionKeys", "SunFunctionKeys", XtRBoolean, sizeof (Boolean),
X	offset(sunFunctionKeys), XtRString, "false"},
X};
X#undef offset
X
X/* Command line options table.  Only resources are entered here...there is a
X   pass over the remaining options after XtParseCommand is let loose. */
X
Xstatic XrmOptionDescRec optionDescList[] = {
X{"-geometry",	"*vt100.geometry",XrmoptionSepArg,	(caddr_t) NULL},
X{"-132",	"*c132",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+132",	"*c132",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-ah",		"*alwaysHighlight", XrmoptionNoArg,	(caddr_t) "on"},
X{"+ah",		"*alwaysHighlight", XrmoptionNoArg,	(caddr_t) "off"},
X{"-b",		"*internalBorder",XrmoptionSepArg,	(caddr_t) NULL},
X{"-cb",		"*cutToBeginningOfLine", XrmoptionNoArg, (caddr_t) "off"},
X{"+cb",		"*cutToBeginningOfLine", XrmoptionNoArg, (caddr_t) "on"},
X{"-cc",		"*charClass",	XrmoptionSepArg,	(caddr_t) NULL},
X{"-cn",		"*cutNewline",	XrmoptionNoArg,		(caddr_t) "off"},
X{"+cn",		"*cutNewline",	XrmoptionNoArg,		(caddr_t) "on"},
X{"-cr",		"*cursorColor",	XrmoptionSepArg,	(caddr_t) NULL},
X{"-cu",		"*curses",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+cu",		"*curses",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-e",		NULL,		XrmoptionSkipLine,	(caddr_t) NULL},
X{"-fb",		"*boldFont",	XrmoptionSepArg,	(caddr_t) NULL},
X{"-j",		"*jumpScroll",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+j",		"*jumpScroll",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-l",		"*logging",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+l",		"*logging",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-lf",		"*logFile",	XrmoptionSepArg,	(caddr_t) NULL},
X{"-ls",		"*loginShell",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+ls",		"*loginShell",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-mb",		"*marginBell",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+mb",		"*marginBell",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-mc",		"*multiClickTime", XrmoptionSepArg,	(caddr_t) NULL},
X{"-ms",		"*pointerColor",XrmoptionSepArg,	(caddr_t) NULL},
X{"-nb",		"*nMarginBell",	XrmoptionSepArg,	(caddr_t) NULL},
X{"-rw",		"*reverseWrap",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+rw",		"*reverseWrap",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-s",		"*multiScroll",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+s",		"*multiScroll",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-sb",		"*scrollBar",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+sb",		"*scrollBar",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-sf",		"*sunFunctionKeys", XrmoptionNoArg,	(caddr_t) "on"},
X{"+sf",		"*sunFunctionKeys", XrmoptionNoArg,	(caddr_t) "off"},
X{"-si",		"*scrollInput",	XrmoptionNoArg,		(caddr_t) "off"},
X{"+si",		"*scrollInput",	XrmoptionNoArg,		(caddr_t) "on"},
X{"-sk",		"*scrollKey",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+sk",		"*scrollKey",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-sl",		"*saveLines",	XrmoptionSepArg,	(caddr_t) NULL},
X{"-t",		"*tekStartup",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+t",		"*tekStartup",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-tm",		"*ttyModes",	XrmoptionSepArg,	(caddr_t) NULL},
X{"-tn",		"*termName",	XrmoptionSepArg,	(caddr_t) NULL},
X{"-ut",		"*utmpInhibit",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+ut",		"*utmpInhibit",	XrmoptionNoArg,		(caddr_t) "off"},
X{"-vb",		"*visualBell",	XrmoptionNoArg,		(caddr_t) "on"},
X{"+vb",		"*visualBell",	XrmoptionNoArg,		(caddr_t) "off"},
X/* bogus old compatibility stuff for which there are
X   standard XtInitialize options now */
X{"%",		"*tekGeometry",	XrmoptionStickyArg,	(caddr_t) NULL},
X{"#",		".iconGeometry",XrmoptionStickyArg,	(caddr_t) NULL},
X{"-T",		"*title",	XrmoptionSepArg,	(caddr_t) NULL},
X{"-n",		"*iconName",	XrmoptionSepArg,	(caddr_t) NULL},
X{"-r",		"*reverseVideo",XrmoptionNoArg,		(caddr_t) "on"},
X{"+r",		"*reverseVideo",XrmoptionNoArg,		(caddr_t) "off"},
X{"-rv",		"*reverseVideo",XrmoptionNoArg,		(caddr_t) "on"},
X{"+rv",		"*reverseVideo",XrmoptionNoArg,		(caddr_t) "off"},
X{"-w",		".borderWidth", XrmoptionSepArg,	(caddr_t) NULL},
X};
X
Xstatic struct _options {
X  char *opt;
X  char *desc;
X} options[] = {
X{ "-help",                 "print out this message" },
X{ "-display displayname",  "X server to contact" },
X{ "-geometry geom",        "size (in characters) and position" },
X{ "-/+rv",                 "turn on/off reverse video" },
X{ "-bg color",             "background color" },
X{ "-fg color",             "foreground color" },
X{ "-bd color",             "border color" },
X{ "-bw number",            "border width in pixels" },
X{ "-fn fontname",          "normal text font" },
X{ "-iconic",               "start iconic" },
X{ "-name string",          "client instance, icon, and title strings" },
X{ "-title string",         "title string" },
X{ "-xrm resourcestring",   "additional resource specifications" },
X{ "-/+132",                "turn on/off column switch inhibiting" },
X{ "-/+ah",                 "turn on/off always highlight" },
X{ "-b number",             "internal border in pixels" },
X{ "-/+cb",                 "turn on/off cut-to-beginning-of-line inhibit" },
X{ "-cc classrange",        "specify additional character classes" },
X{ "-/+cn",                 "turn on/off cut newline inhibit" },
X{ "-cr color",             "text cursor color" },
X{ "-/+cu",                 "turn on/off curses emulation" },
X{ "-fb fontname",          "bold text font" },
X{ "-/+j",                  "turn on/off jump scroll" },
X{ "-/+l",                  "turn on/off logging" },
X{ "-lf filename",          "logging filename" },
X{ "-/+ls",                 "turn on/off login shell" },
X{ "-/+mb",                 "turn on/off margin bell" },
X{ "-mc milliseconds",      "multiclick time in milliseconds" },
X{ "-ms color",             "pointer color" },
X{ "-nb number",            "margin bell in characters from right end" },
X{ "-/+rw",                 "turn on/off reverse wraparound" },
X{ "-/+s",                  "turn on/off multiscroll" },
X{ "-/+sb",                 "turn on/off scrollbar" },
X{ "-/+sf",                 "turn on/off Sun Function Key escape codes" },
X{ "-/+si",                 "turn on/off scroll-on-input inhibit" },
X{ "-/+sk",                 "turn on/off scroll-on-keypress" },
X{ "-sl number",            "number of scrolled lines to save" },
X{ "-/+t",                  "turn on/off Tek emulation window" },
X{ "-tm string",            "terminal mode keywords and characters" },
X{ "-tn name",              "TERM environment variable name" },
X{ "-/+ut",                 "turn on/off utmp inhibit" },
X{ "-/+vb",                 "turn on/off visual bell" },
X{ "-e command args",       "command to execute" },
X{ "%geom",                 "Tek window geometry" },
X{ "#geom",                 "icon window geometry" },
X{ "-T string",             "title name for window" },
X{ "-n string",             "icon name for window" },
X{ "-C",                    "console mode" },
X{ "-L",                    "getty mode started from init" },
X{ "-Sxxd",                 "slave mode on \"ttyxx\", file descriptor \"d\"" },
X{ NULL, NULL }};
X
Xstatic char *message[] = {
X"Fonts must be fixed width and, if both normal and bold are specified, must",
X"have the same size.  If only a normal font is specified, it will be used for",
X"both normal and bold text (by doing overstriking).  The -e option, if given,",
X"must be appear at the end of the command line, otherwise the user's default",
X"shell will be started.  Options that start with a plus sign (+) restore the",
X"default.",
XNULL};
X
Xstatic void Syntax (badOption)
X    char *badOption;
X{
X    struct _options *opt;
X    int col;
X    char **cpp;
X
X    fprintf (stderr, "%s:  bad command line option \"%s\"\r\n\n",
X	     ProgramName, badOption);
X
X    fprintf (stderr, "usage:  %s", ProgramName);
X    col = 8 + strlen(ProgramName);
X    for (opt = options; opt->opt; opt++) {
X	int len = 3 + strlen(opt->opt);	 /* space [ string ] */
X	if (col + len > 79) {
X	    fprintf (stderr, "\r\n   ");  /* 3 spaces */
X	    col = 3;
X	}
X	fprintf (stderr, " [%s]", opt->opt);
X	col += len;
X    }
X
X    fprintf (stderr, "\r\n\nType %s -help for a full description.\r\n\n",
X	     ProgramName);
X    exit (1);
X}
X
Xstatic void Help ()
X{
X    struct _options *opt;
X    char **cpp;
X
X    fprintf (stderr, "usage:\n        %s [-options ...] [-e command args]\n\n",
X	     ProgramName);
X    fprintf (stderr, "where options include:\n");
X    for (opt = options; opt->opt; opt++) {
X	fprintf (stderr, "    %-28s %s\n", opt->opt, opt->desc);
X    }
X
X    putc ('\n', stderr);
X    for (cpp = message; *cpp; cpp++) {
X	fputs (*cpp, stderr);
X	putc ('\n', stderr);
X    }
X    putc ('\n', stderr);
X
X    exit (0);
X}
X
X#ifndef lint
X/* this silliness causes the linker to include the VendorShell
X * module from Xaw, rather than the one from Xt.
X */
Xstatic Junk()
X{
X#include <X11/Vendor.h>
XWidgetClass junk = vendorShellWidgetClass;
X}
X#endif
X
X
Xextern WidgetClass xtermWidgetClass;
X
XArg ourTopLevelShellArgs[] = {
X	{ XtNallowShellResize, (XtArgVal) TRUE },	
X	{ XtNinput, (XtArgVal) TRUE },
X};
Xint number_ourTopLevelShellArgs = 2;
X	
XWidget toplevel;
X
Xmain (argc, argv)
Xint argc;
Xchar **argv;
X{
X	register TScreen *screen;
X	register int i, pty;
X	int Xsocket, mode;
X	char *basename();
X	int xerror(), xioerror();
X	int fd1 = -1;
X	int fd2 = -1;
X	int fd3 = -1;
X
X	ProgramName = argv[0];
X
X	ttydev = (char *) malloc (strlen (TTYDEV) + 1);
X	ptydev = (char *) malloc (strlen (PTYDEV) + 1);
X	if (!ttydev || !ptydev) {
X	    fprintf (stderr, 
X	    	     "%s:  unable to allocate memory for ttydev or ptydev\n",
X		     ProgramName);
X	    exit (1);
X	}
X	strcpy (ttydev, TTYDEV);
X	strcpy (ptydev, PTYDEV);
X
X#ifdef USE_SYSV_TERMIO
X	/* Initialization is done here rather than above in order
X	** to prevent any assumptions about the order of the contents
X	** of the various terminal structures (which may change from
X	** implementation to implementation).
X	*/
X#ifdef macII
X	d_tio.c_iflag = ICRNL|IXON;
X	d_tio.c_oflag = OPOST|ONLCR|TAB3;
X    	d_tio.c_cflag = B9600|CS8|CREAD|PARENB|HUPCL;
X    	d_tio.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK;
X
X	d_tio.c_line = 0;
X
X	d_tio.c_cc[VINTR] = CINTR;
X	d_tio.c_cc[VQUIT] = CQUIT;
X	d_tio.c_cc[VERASE] = CERASE;
X	d_tio.c_cc[VKILL] = CKILL;
X    	d_tio.c_cc[VEOF] = CEOF;
X	d_tio.c_cc[VEOL] = CNUL;
X	d_tio.c_cc[VEOL2] = CNUL;
X	d_tio.c_cc[VSWTCH] = CNUL;
X
X        d_ltc.t_suspc = CSUSP;		/* t_suspc */
X        d_ltc.t_dsuspc = CDSUSP;	/* t_dsuspc */
X        d_ltc.t_rprntc = 0;		/* reserved...*/
X        d_ltc.t_flushc = 0;
X        d_ltc.t_werasc = 0;
X        d_ltc.t_lnextc = 0;
X#else  /* macII */
X	d_tio.c_iflag = ICRNL|IXON;
X	d_tio.c_oflag = OPOST|ONLCR|TAB3;
X#ifdef BAUD_0
X    	d_tio.c_cflag = CS8|CREAD|PARENB|HUPCL;
X#else	/* !BAUD_0 */
X    	d_tio.c_cflag = B9600|CS8|CREAD|PARENB|HUPCL;
X#endif	/* !BAUD_0 */
X    	d_tio.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK;
X	d_tio.c_line = 0;
X	d_tio.c_cc[VINTR] = 0x7f;		/* DEL  */
X	d_tio.c_cc[VQUIT] = '\\' & 0x3f;	/* '^\'	*/
X	d_tio.c_cc[VERASE] = '#';		/* '#'	*/
X	d_tio.c_cc[VKILL] = '@';		/* '@'	*/
X    	d_tio.c_cc[VEOF] = 'D' & 0x3f;		/* '^D'	*/
X	d_tio.c_cc[VEOL] = '@' & 0x3f;		/* '^@'	*/
X#ifdef VSWTCH
X	d_tio.c_cc[VSWTCH] = '@' & 0x3f;	/* '^@'	*/
X#endif	/* VSWTCH */
X	/* now, try to inherit tty settings */
X	{
X	    int i;
X
X	    for (i = 0; i <= 2; i++) {
X		struct termio deftio;
X		if (ioctl (i, TCGETA, &deftio) == 0) {
X		    d_tio.c_cc[VINTR] = deftio.c_cc[VINTR];
X		    d_tio.c_cc[VQUIT] = deftio.c_cc[VQUIT];
X		    d_tio.c_cc[VERASE] = deftio.c_cc[VERASE];
X		    d_tio.c_cc[VKILL] = deftio.c_cc[VKILL];
X		    d_tio.c_cc[VEOF] = deftio.c_cc[VEOF];
X		    d_tio.c_cc[VEOL] = deftio.c_cc[VEOL];
X#ifdef VSWTCH
X		    d_tio.c_cc[VSWTCH] = deftio.c_cc[VSWTCH];
X#endif /* VSWTCH */
X		    break;
X		}
X	    }
X	}
X#ifdef TIOCSLTC
X        d_ltc.t_suspc = '\000';		/* t_suspc */
X        d_ltc.t_dsuspc = '\000';	/* t_dsuspc */
X        d_ltc.t_rprntc = '\377';	/* reserved...*/
X        d_ltc.t_flushc = '\377';
X        d_ltc.t_werasc = '\377';
X        d_ltc.t_lnextc = '\377';
X#endif	/* TIOCSLTC */
X#ifdef TIOCLSET
X	d_lmode = 0;
X#endif	/* TIOCLSET */
X#endif  /* macII */
X#endif	/* USE_SYSV_TERMIO */
X
X	/* This is ugly.  When running under init, we need to make sure
X	 * Xlib/Xt won't use file descriptors 0/1/2, because we need to
X	 * stomp on them.  This check doesn't guarantee a -L found is
X	 * really an option, but the opens don't hurt anyway.
X	 */
X	for (i = 1; i < argc; i++) {
X	    if ((argv[i][0] == '-') && (argv[i][1] == 'L')) {
X		fd1 = open ("/dev/null", O_RDONLY, 0);
X		fd2 = open ("/dev/null", O_RDONLY, 0);
X		fd3 = open ("/dev/null", O_RDONLY, 0);
X		break;
X	    }
X	}
X	/* Init the Toolkit. */
X	toplevel = XtInitialize("xterm", "XTerm",
X		optionDescList, XtNumber(optionDescList), &argc, argv);
X
X	XtGetApplicationResources( toplevel, &resource, application_resources,
X				   XtNumber(application_resources), NULL, 0 );
X
X	/*
X	 * fill in terminal modes
X	 */
X	if (resource.tty_modes) {
X	    int n = parse_tty_modes (resource.tty_modes,
X				     ttymodelist, NXTTYMODES);
X	    if (n < 0) {
X		fprintf (stderr, "%s:  bad tty modes \"%s\"\n",
X			 ProgramName, resource.tty_modes);
X	    } else if (n > 0) {
X		override_tty_modes = 1;
X	    }
X	}
X
X	xterm_name = resource.xterm_name;
X	sunFunctionKeys = resource.sunFunctionKeys;
X	if (strcmp(xterm_name, "-") == 0) xterm_name = "xterm";
X	if (resource.icon_geometry != NULL) {
X	    int scr, junk;
X	    Arg args[2];
X
X	    for(scr = 0;	/* yyuucchh */
X		XtScreen(toplevel) != ScreenOfDisplay(XtDisplay(toplevel),scr);
X		scr++);
X
X	    args[0].name = XtNiconX;
X	    args[1].name = XtNiconY;
X	    XGeometry(XtDisplay(toplevel), scr, resource.icon_geometry, "",
X		      0, 0, 0, 0, 0, &args[0].value, &args[1].value,
X		      &junk, &junk);
X	    XtSetValues( toplevel, args, 2);
X	}
X
X	XtSetValues (toplevel, ourTopLevelShellArgs, 
X		     number_ourTopLevelShellArgs);
X
X	/* Now that we are in control again, close any uglies. */
X	if (fd1 >= 0)
X	    (void)close(fd1);
X	if (fd2 >= 0)
X	    (void)close(fd2);
X	if (fd3 >= 0)
X	    (void)close(fd3);
X
X
X	/* Parse the rest of the command line */
X	for (argc--, argv++ ; argc > 0 ; argc--, argv++) {
X	    if(**argv != '-') Syntax (*argv);
X
X	    switch(argv[0][1]) {
X	     case 'h':
X		Help ();
X		/* NOTREACHED */
X#ifdef TIOCCONS
X	     case 'C':
X		Console = TRUE;
X		continue;
X#endif	/* TIOCCONS */
X	     case 'L':
X		L_flag = 1;
X		get_ty = argv[--argc];
X		ptydev[strlen(ptydev) - 2] = ttydev[strlen(ttydev) - 2] =
X			get_ty[strlen(get_ty) - 2];
X		ptydev[strlen(ptydev) - 1] = ttydev[strlen(ttydev) - 1] =
X			get_ty[strlen(get_ty) - 1];
X		if ((loginpty = open(ptydev, O_RDWR, 0)) < 0) {
X			consolepr("pty open of \"%s\" failed, ttydev \"%s\", get_ty \"%s\"\n",
X				  ptydev, ttydev, get_ty);
X			exit(ERROR_PTYS);
X		}
X		chown(ttydev, 0, 0);
X		chmod(ttydev, 0622);
X		continue;
X
X	     case 'S':
X		sscanf(*argv + 2, "%c%c%d", passedPty, passedPty+1,
X		 &am_slave);
X		if (am_slave <= 0) Syntax(*argv);
X		continue;
X#ifdef DEBUG
X	     case 'D':
X		debug = TRUE;
X		continue;
X#endif	/* DEBUG */
X	     case 'e':
X		if (argc <= 1) Syntax (*argv);
X		command_to_exec = ++argv;
X		break;
X	     default:
X		Syntax (*argv);
X	    }
X	    break;
X	}
X
X        term = (XtermWidget) XtCreateManagedWidget(
X	    "vt100", xtermWidgetClass, toplevel, NULL, 0);
X            /* this causes the initialize method to be called */
X
X        screen = &term->screen;
X
X	term->flags = WRAPAROUND;
X#ifdef DO_AUTOREPEAT
X	/*
X	 * This whole autorepeat crud is bogus as it is really global state,
X	 * not per window state.  Use "xset r" instead.
X	 */
X	term->flags |= AUTOREPEAT;
X#endif /* DO_AUTOREPEAT */
X	if (!screen->jumpscroll)	term->flags |= SMOOTHSCROLL;
X	if (term->misc.reverseWrap)		term->flags |= REVERSEWRAP;
X
X	inhibit = 0;
X	if (term->misc.logInhibit)			inhibit |= I_LOG;
X	if (term->misc.signalInhibit)		inhibit |= I_SIGNAL;
X	if (term->misc.tekInhibit)			inhibit |= I_TEK;
X
X	term->initflags = term->flags;
X
X/*
X * Set title and icon name if not specified
X */
X
X	if (get_ty || command_to_exec) {
X	    char window_title[1024];
X	    Arg args[2];
X
X	    if (!resource.title) {
X		if (get_ty) {
X#ifdef hpux
X		    struct utsname name;    /* crock for hpux 8 char names */
X		    uname(&name);
X		    strcpy (window_title, "login(");
X		    strcpy (window_title+6, name.nodename);
X		    strcat (window_title, ")");
X#else 
X		    strcpy (window_title, "login(");
X		    (void) gethostname(window_title+6, sizeof(window_title)-6);
X		    strcat (window_title, ")");
X#endif
X		    resource.title = window_title;
X		} else if (command_to_exec) {
X		    resource.title = basename (command_to_exec[0]);
X		} /* else not reached */
X	    }
X
X	    if (!resource.icon_name) 
X	      resource.icon_name = resource.title;
X	    XtSetArg (args[0], XtNtitle, resource.title);
X	    XtSetArg (args[1], XtNiconName, resource.icon_name);		
X
X	    XtSetValues (toplevel, args, 2);
X	}
X
X
X	if(inhibit & I_TEK)
X		screen->TekEmu = FALSE;
X
X	if(screen->TekEmu && !TekInit())
X		exit(ERROR_INIT);
X
X	/* set up stderr properly */
X	i = -1;
X#ifdef DEBUG
X	if(debug)
X		i = open ("xterm.debug.log", O_WRONLY | O_CREAT | O_TRUNC,
X		 0666);
X	else
X#endif	/* DEBUG */
X	if(get_ty) {
X#ifdef USE_SYSV_PGRP
X		/* This is kind of vile and discusting.  While it is fine
X		 * to just go and open up /dev/console on a BSD system, we
X		 * can't do that on a SYSV system because if we do we might
X		 * become the controlling terminal for it and break login
X		 * attempts to it.
X		 *
X		 * The solution is to fork off a child, let it open up
X		 * /dev/console and when it has done that we can open it up
X		 * without fear of taking control of it.  After opening up
X		 * the console, we can go and kill the child process.
X		 *
X		 * Told you it was ugly.  But its a BSD world....
X		 */
X		int pid;
X		int status;
X		int pf[2];
X
X		pipe(pf);
X		pid = fork();
X		if (pid == 0) {
X			/* child:
X			 *  - close off the read side of the pipe,
X			 *  - do a setpgrp() so that we can gain control
X			 *    of /dev/console,
X			 *  - close the write side fo the pipe (so that our
X			 *    parent will know what we have done),
X			 *  - wait around till we are killed.
X			 */
X			(void) close(pf[0]);
X			(void) setpgrp();
X			(void) open("/dev/console", O_WRONLY, 0);
X			(void) close(pf[1]);
X			(void) pause();
X		} else if (pid > 0) {
X			/* parent:
X			 *  - read from pipe -- read will terminate when
X			 *    child closes the pipe or exit's,
X			 *  - open /dev/console,
X			 *  - kill off child,
X			 *  - wait on child.
X			 */
X			(void) close(pf[1]);
X			(void) read(pf[0], (char *) &status, sizeof(status));
X			i = open("/dev/console", O_WRONLY, 0);
X			(void) kill(pid, 9);
X			while (pid != wait(&status)) {
X				if (errno == EINTR)
X					continue;
X				else
X					break;
X			}
X			(void) close(pf[0]);
X		}
X#else	/* USE_SYSV_PGRP */
X		i = open("/dev/console", O_WRONLY, 0);
X#endif	/* !USE_SYSV_PGRP */
X	}
X	if(i >= 0) {
X#ifdef USE_SYSV_TERMIO
X		/* SYSV has another pointer which should be part of the
X		** FILE structure but is actually a seperate array.
X		*/
X		unsigned char *old_bufend;
X
X		old_bufend = (unsigned char *) _bufend(stderr);
X		fileno(stderr) = i;
X		(unsigned char *) _bufend(stderr) = old_bufend;
X#else	/* USE_SYSV_TERMIO */
X		fileno(stderr) = i;
X#endif	/* USE_SYSV_TERMIO */
X
X		/* mark this file as close on exec */
X		(void) fcntl(i, F_SETFD, 1);
X	}
X
X	/* open a terminal for client */
X	get_terminal ();
X	spawn ();
X	/* Child process is out there, let's catch it's termination */
X	signal (SIGCHLD, reapchild);
X
X	/* Realize procs have now been executed */
X
X	Xsocket = screen->display->fd;
X	pty = screen->respond;
X
X	if (am_slave) { /* Write window id so master end can read and use */
X	    char buf[80];
X
X	    buf[0] = '\0';
X	    sprintf (buf, "%lx\n", 
X	    	     screen->TekEmu ? XtWindow (XtParent (tekWidget)) :
X				      XtWindow (XtParent (term)));
X	    write (pty, buf, strlen (buf));
X	}
X
X	if (term->misc.log_on) {
X		StartLog(screen);
X	}
X	screen->inhibit = inhibit;
X
X#ifdef USE_SYSV_TERMIO
X	if (0 > (mode = fcntl(pty, F_GETFL, 0)))
X		Error();
X	mode |= O_NDELAY;
X	if (fcntl(pty, F_SETFL, mode))
X		Error();
X#else	/* USE_SYSV_TERMIO */
X
X#ifdef AIXV3
X        /* place controller side of pty in NO DELAY MODE     */
X        /* otherwise it hangs,                               */
X    fcntl(pty, F_SETFL, O_NDELAY );
X        /* place controller side of pty in NO DELAY MODE     */
X        /* otherwise it hangs,                               */
X
X#else /* AIXV3 */
X	mode = 1;
X	if (ioctl (pty, FIONBIO, (char *)&mode) == -1) SysError (ERROR_FIONBIO);
X#endif /* AIXV3 */
X
X#endif	/* USE_SYSV_TERMIO */
X	
X	pty_mask = 1 << pty;
X	X_mask = 1 << Xsocket;
X	Select_mask = pty_mask | X_mask;
X	max_plus1 = (pty < Xsocket) ? (1 + Xsocket) : (1 + pty);
X
X#ifdef DEBUG
X	if (debug) printf ("debugging on\n");
X#endif	/* DEBUG */
X	XSetErrorHandler(xerror);
X	XSetIOErrorHandler(xioerror);
X	for( ; ; )
X		if(screen->TekEmu) {
X			TekRun();
X		} else
X			VTRun();
X}
X
Xchar *basename(name)
Xchar *name;
X{
X	register char *cp;
X	char *rindex();
X
X	return((cp = rindex(name, '/')) ? cp + 1 : name);
X}
X
X/* This function opens up a pty master and stuffs it's value into pty.
X * If it finds one, it returns a value of 0.  If it does not find one,
X * it returns a value of !0.  This routine is designed to be re-entrant,
X * so that if a pty master is found and later, we find that the slave
X * has problems, we can re-enter this function and get another one.
X */
X
Xget_pty (pty)
Xint *pty;
X{
X	static int devindex, letter = 0;
X
X#if defined (mips) && defined (SYSTYPE_SYSV)
X	struct stat fstat_buf;
X
X	*pty = open ("/dev/ptc", O_RDWR);
X	if (*pty < 0 || (fstat (*pty, &fstat_buf)) < 0) {
X	  return(1);
X	}
X	sprintf (ttydev, "/dev/ttyq%d", minor(fstat_buf.st_rdev));
X	sprintf (ptydev, "/dev/ptyq%d", minor(fstat_buf.st_rdev));
X	if ((*tty = open (ttydev, O_RDWR)) < 0) {
X	  close (*pty);
X	  return(1);
X	}
X	/* got one! */
X	return(0);
X#else /* not (mips && SYSTYPE_SYSV) */
X	while (PTYCHAR1[letter]) {
X	    ttydev [strlen(ttydev) - 2]  = ptydev [strlen(ptydev) - 2] =
X		    PTYCHAR1 [letter];
X
X	    while (PTYCHAR2[devindex]) {
X		ttydev [strlen(ttydev) - 1] = ptydev [strlen(ptydev) - 1] =
X			PTYCHAR2 [devindex];
X		if ((*pty = open (ptydev, O_RDWR)) >= 0) {
X			/* We need to set things up for our next entry
X			 * into this function!
X			 */
X			(void) devindex++;
X			return(0);
X		}
X		devindex++;
X	    }
X	    devindex = 0;
X	    (void) letter++;
X	}
X	/* We were unable to allocate a pty master!  Return an error
X	 * condition and let our caller terminate cleanly.
X	 */
X	return(1);
X#endif /* mips && SYSTYPE_SYSV */
X}
X
Xget_terminal ()
X/* 
X * sets up X and initializes the terminal structure except for term.buf.fildes.
X */
X{
X	register TScreen *screen = &term->screen;
X	
X	screen->graybordertile = make_gray(term->core.border_pixel,
X		term->core.background_pixel,
X		DefaultDepth(screen->display, DefaultScreen(screen->display)));
X
X
X	{
X	    unsigned long fg, bg;
X
X	    fg = screen->mousecolor;
X	    bg = (screen->mousecolor == term->core.background_pixel) ?
X		screen->foreground : term->core.background_pixel;
X
X	    screen->arrow = make_arrow (fg, bg);
X	}
X}
X
X/*
X * The only difference in /etc/termcap between 4014 and 4015 is that 
X * the latter has support for switching character sets.  We support the
X * 4015 protocol, but ignore the character switches.  Therefore, we should
X * probably choose 4014 over 4015.
X */
X
Xstatic char *tekterm[] = {
X	"tek4014",
X	"tek4015",		/* has alternate character set switching */
X	"tek4013",
X	"tek4010",
X	"dumb",
X	0
X};
X
Xstatic char *vtterm[] = {
X#ifdef USE_X11TERM
X	"x11term",		/* for people who want special term name */
X#endif
X	"xterm",		/* the prefered name, should be fastest */
X	"vt102",
X	"vt100",
X	"ansi",
X	"dumb",
X	0
X};
X
Xhungtty()
X{
X	longjmp(env, 1);
X}
X
Xtypedef enum {		/* c == child, p == parent                        */
X	PTY_BAD,	/* c->p: can't open pty slave for some reason     */
X	PTY_FATALERROR,	/* c->p: we had a fatal error with the pty        */
X	PTY_GOOD,	/* c->p: we have a good pty, let's go on          */
X	PTY_NEW,	/* p->c: here is a new pty slave, try this        */
X	PTY_NOMORE,	/* p->c; no more pty's, terminate                 */
X	UTMP_ADDED,	/* c->p: utmp entry has been added                */
X	UTMP_TTYSLOT,	/* c->p: here is my ttyslot                       */
X} status_t;
X
Xtypedef struct {
X	status_t status;
X	int error;
X	int fatal_error;
X	int tty_slot;
X	char buffer[1024];
X} handshake_t;
X
X/* HsSysError()
X *
X * This routine does the equivalent of a SysError but it handshakes
X * over the errno and error exit to the master process so that it can
X * display our error message and exit with our exit code so that the
X * user can see it.
X */
X
Xvoid
XHsSysError(pf, error)
Xint pf;
Xint error;
X{
X	handshake_t handshake;
X
X	handshake.status = PTY_FATALERROR;
X	handshake.error = errno;
X	handshake.fatal_error = error;
X	strcpy(handshake.buffer, ttydev);
X	write(pf, &handshake, sizeof(handshake));
X	exit(error);
X}
X
Xspawn ()
X/* 
X *  Inits pty and tty and forks a login process.
X *  Does not close fd Xsocket.
X *  If getty,  execs getty rather than csh and uses std fd's rather
X *  than opening a pty/tty pair.
X *  If slave, the pty named in passedPty is already open for use
X */
X{
X	extern char *SysErrorMsg();
X	register TScreen *screen = &term->screen;
X	int Xsocket = screen->display->fd;
X	handshake_t handshake;
X	int index1, tty = -1;
X	int pc_pipe[2];	/* this pipe is used for parent to child transfer */
X	int cp_pipe[2];	/* this pipe is used for child to parent transfer */
X	int discipline;
X	int done;
X#ifdef USE_SYSV_TERMIO
X	struct termio tio;
X	struct termio dummy_tio;
X#ifdef TIOCLSET
X	unsigned lmode;
X#endif	/* TIOCLSET */
X#ifdef TIOCSLTC
X	struct ltchars ltc;
X#endif	/* TIOCSLTC */
X	int one = 1;
X	int zero = 0;
X	int status;
X#else	/* else not USE_SYSV_TERMIO */
X
X#ifdef AIXV3
X#else /* not AIXV3 */
X	unsigned lmode;
X	struct tchars tc;
X	struct ltchars ltc;
X	struct sgttyb sg;
X#endif /* AIXV3 */
X
X#endif	/* USE_SYSV_TERMIO */
X
X	char termcap [1024];
X	char newtc [1024];
X	char *ptr, *shname, *shname_minus;
X	int i, no_dev_tty = FALSE;
X#ifdef USE_SYSV_TERMIO
X	char *dev_tty_name = (char *) 0;
X	int fd;			/* for /etc/wtmp */
X#endif	/* USE_SYSV_TERMIO */
X	char **envnew;		/* new environment */
X	char buf[32];
X	char *TermName = NULL;
X	int ldisc = 0;
X#ifdef sun
X#ifdef TIOCSSIZE
X	struct ttysize ts;
X#endif	/* TIOCSSIZE */
X#else	/* not sun */
X#ifdef TIOCSWINSZ
X	struct winsize ws;
X#endif	/* TIOCSWINSZ */
X#endif	/* sun */
X	struct passwd *pw = NULL;
X#ifdef UTMP
X	struct utmp utmp;
X#endif	/* UTMP */
X	extern int Exit();
X	char *getenv();
X	char *strindex ();
X
X	screen->uid = getuid();
X	screen->gid = getgid();
X
X#if !defined(SYSV) || defined(JOBCONTROL)  /* a reason why macII isn't SYSV */
X	/* so that TIOCSWINSZ || TIOCSIZE doesn't block */
X	signal(SIGTTOU,SIG_IGN);
X#endif	/* !defined(SYSV) || defined(JOBCONTROL) */
X
X	if (get_ty) {
X		screen->respond = loginpty;
X	} else if (am_slave) {
X		screen->respond = am_slave;
X		ptydev[strlen(ptydev) - 2] = ttydev[strlen(ttydev) - 2] =
X			passedPty[0];
X		ptydev[strlen(ptydev) - 1] = ttydev[strlen(ttydev) - 1] =
X			passedPty[1];
X
X		setgid (screen->gid);
X		setuid (screen->uid);
X	} else {
X 		/*
X 		 * Sometimes /dev/tty hangs on open (as in the case of a pty
X 		 * that has gone away).  Simply make up some reasonable
X 		 * defaults.
X 		 */
X 		signal(SIGALRM, hungtty);
X 		alarm(2);		/* alarm(1) might return too soon */
X 		if (! setjmp(env)) {
X 			tty = open ("/dev/tty", O_RDWR, 0);
X 			alarm(0);
X 		} else {
X 			tty = -1;
X 			errno = ENXIO;
X 		}
X 		signal(SIGALRM, SIG_DFL);
X 
X 		if (tty < 0) {
X			if (errno != ENXIO) SysError(ERROR_OPDEVTTY);
X			else {
X				no_dev_tty = TRUE;
X#ifdef USE_SYSV_TERMIO
X				tio = d_tio;
X#ifdef TIOCSLTC
X				ltc = d_ltc;
X#endif	/* TIOCSLTC */
X#ifdef TIOCLSET
X				lmode = d_lmode;
X#endif	/* TIOCLSET */
X#else	/* not USE_SYSV_TERMIO */
X
X#ifdef AIXV3
X				set_default_terminal_modes();
X#else /* not AIXV3 */
X				sg = d_sg;
X				tc = d_tc;
X				discipline = d_disipline;
X				ltc = d_ltc;
X				lmode = d_lmode;
X#endif /* AIXV3 */
X
X#endif	/* USE_SYSV_TERMIO */
X			}
X		} else {
X			/* get a copy of the current terminal's state */
X
X#ifdef USE_SYSV_TERMIO
X			if(ioctl(tty, TCGETA, &tio) == -1)
X				SysError(ERROR_TIOCGETP);
X#ifdef TIOCSLTC
X			if(ioctl(tty, TIOCGLTC, &ltc) == -1)
X				SysError(ERROR_TIOCGLTC);
X#endif	/* TIOCSLTC */
X#ifdef TIOCLSET
X			if(ioctl(tty, TIOCLGET, &lmode) == -1)
X				SysError(ERROR_TIOCLGET);
X#endif	/* TIOCLSET */
X#else	/* not USE_SYSV_TERMIO */
X
X#ifdef AIXV3
X			get_tty_info(tty);
X#else /* not AIXV3 */
X			if(ioctl(tty, TIOCGETP, (char *)&sg) == -1)
X				SysError (ERROR_TIOCGETP);
X			if(ioctl(tty, TIOCGETC, (char *)&tc) == -1)
X				SysError (ERROR_TIOCGETC);
X			if(ioctl(tty, TIOCGETD, (char *)&discipline) == -1)
X				SysError (ERROR_TIOCGETD);
X			if(ioctl(tty, TIOCGLTC, (char *)&ltc) == -1)
X				SysError (ERROR_TIOCGLTC);
X			if(ioctl(tty, TIOCLGET, (char *)&lmode) == -1)
X				SysError (ERROR_TIOCLGET);
X#endif	/* AIXV3 */
X#endif	/* USE_SYSV_TERMIO */
X			close (tty);
X			/* tty is no longer an open fd! */
X			tty = -1;
X		}
X
X		if (get_pty (&screen->respond)) {
X			/*  no ptys! */
X			(void) fprintf(stderr, "%s: no available ptys\n",
X				       xterm_name);
X			exit (ERROR_PTYS);
X		}
X	}
X
X	/* avoid double MapWindow requests, for wm's that care... */
X	XtSetMappedWhenManaged( screen->TekEmu ? XtParent(tekWidget) :
X			        XtParent(term), False );
X        /* Realize the Tek or VT widget, depending on which mode we're in.
X           If VT mode, this calls VTRealize (the widget's Realize proc) */
X        XtRealizeWidget (screen->TekEmu ? XtParent(tekWidget) :
X			 XtParent(term));
X
X	if(screen->TekEmu) {
X		envnew = tekterm;
X		ptr = newtc;
X	} else {
X		envnew = vtterm;
X		ptr = termcap;
X	}
X	TermName = NULL;
X	if (resource.term_name) {
X	    if (tgetent (ptr, resource.term_name) == 1) {
X		TermName = resource.term_name;
X		if (!screen->TekEmu)
X		    resize (screen, TermName, termcap, newtc);
X	    } else {
X		fprintf (stderr, "%s:  invalid termcap entry \"%s\".\n",
X			 ProgramName, resource.term_name);
X	    }
X	}
X	if (!TermName) {
X	    while (*envnew != NULL) {
X		if(tgetent(ptr, *envnew) == 1) {
X			TermName = *envnew;
X			if(!screen->TekEmu)
X			    resize(screen, TermName, termcap, newtc);
X			break;
X		}
X		envnew++;
X	    }
X	    if (TermName == NULL) {
X		fprintf (stderr, "%s:  unable to find usable termcap entry.\n",
X			 ProgramName);
X		Exit (1);
X	    }
X	}
X
X#ifdef sun
X#ifdef TIOCSSIZE
X	/* tell tty how big window is */
X	if(screen->TekEmu) {
X		ts.ts_lines = 38;
X		ts.ts_cols = 81;
X	} else {
X		ts.ts_lines = screen->max_row + 1;
X		ts.ts_cols = screen->max_col + 1;
X	}
X#endif	/* TIOCSSIZE */
X#else	/* not sun */
X#ifdef TIOCSWINSZ
X	/* tell tty how big window is */
X	if(screen->TekEmu) {
X		ws.ws_row = 38;
X		ws.ws_col = 81;
X		ws.ws_xpixel = TFullWidth(screen);
X		ws.ws_ypixel = TFullHeight(screen);
X	} else {
X		ws.ws_row = screen->max_row + 1;
X		ws.ws_col = screen->max_col + 1;
X		ws.ws_xpixel = FullWidth(screen);
X		ws.ws_ypixel = FullHeight(screen);
X	}
X#endif	/* TIOCSWINSZ */
X#endif	/* sun */
X
X	if (!am_slave) {
X	    if (pipe(pc_pipe) || pipe(cp_pipe))
X		SysError (ERROR_FORK);
X	    if ((screen->pid = fork ()) == -1)
X		SysError (ERROR_FORK);
X		
X	    if (screen->pid == 0) {
X		/*
X		 * now in child process
X		 */
X		extern char **environ;
X		int pgrp = getpid();
X#ifdef USE_SYSV_TERMIO
X		char numbuf[12];
X#endif	/* USE_SYSV_TERMIO */
X
X		/* close parent's sides of the pipes */
X		close (cp_pipe[0]);
X		close (pc_pipe[1]);
X
X		/* Make sure that our sides of the pipes are not in the
X		 * 0, 1, 2 range so that we don't fight with stdin, out
X		 * or err.
X		 */
X		if (cp_pipe[1] <= 2) {
X			if ((i = fcntl(cp_pipe[1], F_DUPFD, 3)) >= 0) {
X				(void) close(cp_pipe[1]);
X				cp_pipe[1] = i;
X			}
X		}
X		if (pc_pipe[0] <= 2) {
X			if ((i = fcntl(pc_pipe[0], F_DUPFD, 3)) >= 0) {
X				(void) close(pc_pipe[0]);
X				pc_pipe[0] = i;
X			}
X		}
X
X		/* we don't need the socket, or the pty master anymore */
X		close (Xsocket);
X		close (screen->respond);
X
X		/* Now is the time to set up our process group and
X		 * open up the pty slave.
X		 */
X#ifdef	USE_SYSV_PGRP
X		(void) setpgrp();
X#endif	/* USE_SYSV_PGRP */
X		while (1) {
X#ifdef	USE_SYSV_PGRP
X			if (get_ty) {
X				/* It is not our job to open up the
X				 * tty.  We will let getty do it -- that
X				 * is what it expects.  We need to do this
X				 * because of the way that SYSV tty process
X				 * groups work.  Getty closes fd's 0, 1, 2
X				 * and re-opens them to the line passed to
X				 * it.  When the last close is done to the
X				 * line, it seems to break the tty's connection
X				 * to the current process group, and ^C's no
X				 * longer work.  However, our process group
X				 * is still associated with the line to the
X				 * extent that we can use /dev/tty.
X				 */
X				break;
X			}
X#endif	/* USE_SYSV_PGRP */
X			if ((tty = open(ttydev, O_RDWR, 0)) >= 0) {
X#ifdef	USE_SYSV_PGRP
X				/* We need to make sure that we are acutally
X				 * the process group leader for the pty.  If
X				 * we are, then we should now be able to open
X				 * /dev/tty.
X				 */
X				if ((i = open("/dev/tty", O_RDWR, 0)) >= 0) {
X					/* success! */
X					close(i);
X					break;
X				}
X#else	/* USE_SYSV_PGRP */
X				break;
X#endif	/* USE_SYSV_PGRP */
X			}
X
X			/* let our master know that the open failed */
X			handshake.status = PTY_BAD;
X			handshake.error = errno;
X			strcpy(handshake.buffer, ttydev);
X			write(cp_pipe[1], (char *) &handshake,
X			    sizeof(handshake));
X
X			/* get reply from parent */
X			i = read(pc_pipe[0], (char *) &handshake,
X			    sizeof(handshake));
X			if (i <= 0) {
X				/* parent terminated */
X				exit(1);
X			}
X
X			if (handshake.status == PTY_NOMORE) {
X				/* No more ptys, let's shutdown. */
X				exit(1);
X			}
X
X			/* We have a new pty to try */
X			free(ttydev);
X			ttydev = malloc((unsigned)
X			    (strlen(handshake.buffer) + 1));
X			strcpy(ttydev, handshake.buffer);
X		}
X
X		/* use the same tty name that everyone else will use
X		** (from ttyname)
X		*/
X#ifdef	USE_SYSV_PGRP
X		if (!get_ty && (ptr = ttyname(tty)))
X#else	/* USE_SYSV_PGRP */
X		if (ptr = ttyname(tty))
X#endif	/* USE_SYSV_PGRP */
X		{
X			/* it may be bigger */
X			ttydev = realloc (ttydev, (unsigned) (strlen(ptr) + 1));
X			(void) strcpy(ttydev, ptr);
X		}
X
X		/* change ownership of tty to real group and user id */
X		chown (ttydev, screen->uid, screen->gid);
X
X		/* change protection of tty */
X		chmod (ttydev, 0622);
X
X		if (!get_ty) {
X#ifdef USE_SYSV_TERMIO
X#ifdef mips
X		    /* If the control tty had its modes screwed around with,
X		       eg. by lineedit in the shell, or emacs, etc. then tio
X		       will have bad values.  Let's just get termio from the
X		       new tty and tailor it.  */
X		    if (ioctl (tty, TCGETA, &tio) == -1)
X		      SysError (ERROR_TIOCGETP);
X		    tio.c_lflag |= ECHOE;
X#endif /* mips */
X		    /* Now is also the time to change the modes of the
X		     * child pty.
X		     */
X		    /* input: nl->nl, don't ignore cr, cr->nl */
X		    tio.c_iflag &= ~(INLCR|IGNCR);
X		    tio.c_iflag |= ICRNL;
X		    /* ouput: cr->cr, nl is not return, no delays, ln->cr/nl */
X		    tio.c_oflag &=
X		     ~(OCRNL|ONLRET|NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
X		    tio.c_oflag |= ONLCR;
X#ifdef BAUD_0
X		    /* baud rate is 0 (don't care) */
X		    tio.c_cflag &= ~(CBAUD);
X#else	/* !BAUD_0 */
X		    /* baud rate is 9600 (nice default) */
X		    tio.c_cflag &= ~(CBAUD);
X		    tio.c_cflag |= B9600;
X#endif	/* !BAUD_0 */
X		    /* enable signals, canonical processing (erase, kill, etc),
X		    ** echo
X		    */
X		    tio.c_lflag |= ISIG|ICANON|ECHO;
X		    /* reset EOL to defalult value */
X		    tio.c_cc[VEOL] = '@' & 0x3f;		/* '^@'	*/
X		    /* certain shells (ksh & csh) change EOF as well */
X		    tio.c_cc[VEOF] = 'D' & 0x3f;		/* '^D'	*/
X
X#define TMODE(ind,var) if (ttymodelist[ind].set) var = ttymodelist[ind].value;
X		    if (override_tty_modes) {
X			/* sysv-specific */
X			TMODE (XTTYMODE_intr, tio.c_cc[VINTR]);
X			TMODE (XTTYMODE_quit, tio.c_cc[VQUIT]);
X			TMODE (XTTYMODE_erase, tio.c_cc[VERASE]);
X			TMODE (XTTYMODE_kill, tio.c_cc[VKILL]);
X			TMODE (XTTYMODE_eof, tio.c_cc[VEOF]);
X			TMODE (XTTYMODE_eol, tio.c_cc[VEOL]);
X#ifdef VSWTCH
X			TMODE (XTTYMODE_swtch, d_tio.c_cc[VSWTCH]);
X#endif
X#ifdef TIOCSLTC
X			/* both SYSV and BSD have ltchars */
X			TMODE (XTTYMODE_susp, ltc.t_suspc);
X			TMODE (XTTYMODE_dsusp, ltc.t_dsuspc);
X			TMODE (XTTYMODE_rprnt, ltc.t_rprntc);
X			TMODE (XTTYMODE_flush, ltc.t_flushc);
X			TMODE (XTTYMODE_weras, ltc.t_werasc);
X			TMODE (XTTYMODE_lnext, ltc.t_lnextc);
X#endif
X		    }
X#undef TMODE
X
X		    if (ioctl (tty, TCSETA, &tio) == -1)
X			    HsSysError(cp_pipe[1], ERROR_TIOCSETP);
X#ifdef TIOCSLTC
X		    if (ioctl (tty, TIOCSLTC, &ltc) == -1)
X			    HsSysError(cp_pipe[1], ERROR_TIOCSETC);
X#endif	/* TIOCSLTC */
X#ifdef TIOCLSET
X		    if (ioctl (tty, TIOCLSET, (char *)&lmode) == -1)
X			    HsSysError(cp_pipe[1], ERROR_TIOCLSET);
X#endif	/* TIOCLSET */
X#ifdef TIOCCONS
X		    if (Console) {
X			    int on = 1;
X			    if (ioctl (tty, TIOCCONS, (char *)&on) == -1)
X				    HsSysError(cp_pipe[1], ERROR_TIOCCONS);
X		    }
X#endif	/* TIOCCONS */
X#else	/* USE_SYSV_TERMIO */
X
X#ifdef AIXV3
X/*
X	c_iflag = (BRKINT|ICRNL|IXON|IXOFF|IMAXBEL);
X	c_oflag = (OPOST|ONLCR|TAB3);
X	c_cflag = (CS8|CREAD|HUPCL|B9600);
X	c_lflag = (ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOKE|ECHOCTL);
X*/
X	/* set some flags that should be on */
X	terminal_modes.c_oflag |= OPOST;
X	/* set some flags that should be on */
X
X	/* set some flags that should be off */
X	terminal_modes.c_cflag &= ~( CLOCAL );
X	/* set some flags that should be off */
X
X#define TMODE(ind,var) if (ttymodelist[ind].set) var = ttymodelist[ind].value;
X    if( override_tty_modes ){
X	TMODE( XTTYMODE_intr, terminal_modes.c_cc[VINTR] );
X	TMODE( XTTYMODE_quit, terminal_modes.c_cc[VQUIT] );
X	TMODE( XTTYMODE_erase, terminal_modes.c_cc[VERASE] );
X	TMODE( XTTYMODE_kill, terminal_modes.c_cc[VKILL] );
X	TMODE( XTTYMODE_eof, terminal_modes.c_cc[VEOF] );
X	TMODE( XTTYMODE_eol, terminal_modes.c_cc[VEOL] );
X/*
X	TMODE( XTTYMODE_, terminal_modes.c_cc[VEOL2] );
X*/
X	TMODE( XTTYMODE_start, terminal_modes.c_cc[VSTRT] );
X	TMODE( XTTYMODE_stop, terminal_modes.c_cc[VSTOP] );
X	TMODE( XTTYMODE_susp, terminal_modes.c_cc[VSUSP] );
X	TMODE( XTTYMODE_dsusp, terminal_modes.c_cc[VDSUSP] );
X	TMODE( XTTYMODE_rprnt, terminal_modes.c_cc[VREPRINT] );
X	TMODE( XTTYMODE_flush, terminal_modes.c_cc[VDISCRD] );
X	TMODE( XTTYMODE_weras, terminal_modes.c_cc[VWERSE] );
X	TMODE( XTTYMODE_lnext, terminal_modes.c_cc[VLNEXT] );
X    }
X
X
X	set_tty_info(tty);
X
X#else /* not AIXV3 */
X		    sg.sg_flags &= ~(ALLDELAY | XTABS | CBREAK | RAW);
X		    sg.sg_flags |= ECHO | CRMOD;
X		    /* make sure speed is set on pty so that editors work right*/
X		    sg.sg_ispeed = B9600;
X		    sg.sg_ospeed = B9600;
X		    /* reset t_brkc to default value */
X		    tc.t_brkc = -1;
X
X#define TMODE(ind,var) if (ttymodelist[ind].set) var = ttymodelist[ind].value;
X		    if (override_tty_modes) {
X			TMODE (XTTYMODE_intr, tc.t_quitc);
X			TMODE (XTTYMODE_quit, tc.t_quitc);
X			TMODE (XTTYMODE_erase, sg.sg_erase);
X			TMODE (XTTYMODE_kill, sg.sg_kill);
X			TMODE (XTTYMODE_eof, tc.t_eofc);
X			TMODE (XTTYMODE_start, tc.t_startc);
X			TMODE (XTTYMODE_stop, tc.t_stopc);
X			TMODE (XTTYMODE_brk, tc.t_brkc);
X			/* both SYSV and BSD have ltchars */
X			TMODE (XTTYMODE_susp, ltc.t_suspc);
X			TMODE (XTTYMODE_dsusp, ltc.t_dsuspc);
X			TMODE (XTTYMODE_rprnt, ltc.t_rprntc);
X			TMODE (XTTYMODE_flush, ltc.t_flushc);
X			TMODE (XTTYMODE_weras, ltc.t_werasc);
X			TMODE (XTTYMODE_lnext, ltc.t_lnextc);
X		    }
X#undef TMODE
X
X		    if (ioctl (tty, TIOCSETP, (char *)&sg) == -1)
X			    HsSysError (cp_pipe[1], ERROR_TIOCSETP);
X		    if (ioctl (tty, TIOCSETC, (char *)&tc) == -1)
X			    HsSysError (cp_pipe[1], ERROR_TIOCSETC);
X		    if (ioctl (tty, TIOCSETD, (char *)&discipline) == -1)
X			    HsSysError (cp_pipe[1], ERROR_TIOCSETD);
X		    if (ioctl (tty, TIOCSLTC, (char *)&ltc) == -1)
X			    HsSysError (cp_pipe[1], ERROR_TIOCSLTC);
X		    if (ioctl (tty, TIOCLSET, (char *)&lmode) == -1)
X			    HsSysError (cp_pipe[1], ERROR_TIOCLSET);
X#ifdef TIOCCONS
X		    if (Console) {
X			    int on = 1;
X			    if (ioctl (tty, TIOCCONS, (char *)&on) == -1)
X				    HsSysError(cp_pipe[1], ERROR_TIOCCONS);
X		    }
X#endif	/* TIOCCONS */
X
X#endif /* AIXV3 */
X
X#endif	/* !USE_SYSV_TERMIO */
X		}
X
X		signal (SIGCHLD, SIG_DFL);
X		signal (SIGHUP, SIG_IGN);
X		/* restore various signals to their defaults */
X		signal (SIGINT, SIG_DFL);
X		signal (SIGQUIT, SIG_DFL);
X		signal (SIGTERM, SIG_DFL);
X
X		/* copy the environment before Setenving */
X		for (i = 0 ; environ [i] != NULL ; i++) ;
X		/*
X		 * The `4' (`5' for SYSV) is the number of Setenv()
X		 * calls which may add a new entry to the environment.
X		 * The `1' is for the NULL terminating entry.
X		 */
X#ifdef SYSV				/* macII doesn't do COLUMNS/LINES */
X		envnew = (char **) calloc ((unsigned) i + (5 + 1), sizeof(char *));
X#else /* not SYSV */
X		envnew = (char **) calloc ((unsigned) i + (4 + 1), sizeof(char *));
X#endif /* SYSV */
X		Bcopy((char *)environ, (char *)envnew, i * sizeof(char *));
X		environ = envnew;
X		Setenv ("TERM=", TermName);
X		if(!TermName)
X			*newtc = 0;
X#ifdef SYSV				/* macII does not want this */
X		sprintf (numbuf, "%d", screen->max_col + 1);
X		Setenv("COLUMNS=", numbuf);
X		sprintf (numbuf, "%d", screen->max_row + 1);
X		Setenv("LINES=", numbuf);
X#else /* not SYSV (including macII) */
X		if (term->misc.titeInhibit) {
X		    remove_termcap_entry (newtc, ":ti=");
X		    remove_termcap_entry (newtc, ":te=");
X		}
X		Setenv ("TERMCAP=", newtc);
X#endif	/* SYSV */
X
X		sprintf (buf, "%lu", screen->TekEmu ? 
X			 ((unsigned long) XtWindow (XtParent(tekWidget))) :
X			 ((unsigned long) XtWindow (XtParent(term))));
X		Setenv ("WINDOWID=", buf);
X		/* put the display into the environment of the shell*/
X		Setenv ("DISPLAY=", XDisplayString (screen->display));
X
X		signal(SIGTERM, SIG_DFL);
X
X		/* this is the time to go and set up stdin, out, and err
X		 */
X
X#ifdef	USE_SYSV_PGRP
X		if (!get_ty)
X#endif	/* USE_SYSV_PGRP */
X		{
X		    /* dup the tty */
X		    for (i = 0; i <= 2; i++)
X			if (i != tty) {
X			    (void) close(i);
X			    (void) dup(tty);
X			}
X
X		    /* and close the tty */
X		    if (tty > 2)
X			(void) close(tty);
X		}
X
X#ifndef	USE_SYSV_PGRP
X		ioctl(0, TIOCSPGRP, (char *)&pgrp);
X		if (get_ty) {
X			signal(SIGHUP, SIG_IGN);
X#ifndef AIXV3
X			vhangup();
X#endif /* AIXV3 */
X		}
X		setpgrp(0,0);
X		if (get_ty)
X			signal(SIGHUP, SIG_DFL);
X		close(open(ttydev, O_WRONLY, 0));
X		setpgrp (0, pgrp);
X#endif /* USE_SYSV_PGRP */
X
X#ifdef UTMP
X#ifdef USE_SYSV_UTMP
X		/* Set up our utmp entry now.  We need to do it here
X		** for the following reasons:
X		**   - It needs to have our correct process id (for
X		**     login).
X		**   - If our parent was to set it after the fork(),
X		**     it might make it out before we need it.
X		**   - We need to do it before we go and change our
X		**     user and group id's.
X		*/
X
X		(void) setutent ();
X		/* set up entry to search for */
X		(void) strncpy(utmp.ut_id,ttydev + strlen(ttydev) - 2,
X		 sizeof (utmp.ut_id));
X		utmp.ut_type = DEAD_PROCESS;
X
X		/* position to entry in utmp file */
X		(void) getutid(&utmp);
X
X		/* set up the new entry */
X		if (get_ty) {
X		    utmp.ut_type = LOGIN_PROCESS;
X		    utmp.ut_exit.e_exit = 0;
X		    (void) strncpy(utmp.ut_user, "GETTY",
X		    	    sizeof(utmp.ut_user));
X		} else {
X		    pw = getpwuid(screen->uid);
X		    utmp.ut_type = USER_PROCESS;
X		    utmp.ut_exit.e_exit = 2;
X		    (void) strncpy(utmp.ut_user,
X			    (pw && pw->pw_name) ? pw->pw_name : "????",
X			    sizeof(utmp.ut_user));
X		}
X		    
X		(void) strncmp(utmp.ut_id, ttydev + strlen(ttydev) - 2,
X			sizeof(utmp.ut_id));
X		(void) strncpy (utmp.ut_line,
X			ttydev + strlen("/dev/"), sizeof (utmp.ut_line));
X		utmp.ut_pid = getpid();
X		utmp.ut_time = time ((long *) 0);
X
X		/* write out the entry */
X		if (!resource.utmpInhibit) (void) pututline(&utmp);
X
X		/* close the file */
X		(void) endutent();
X
X		if (get_ty && !resource.utmpInhibit) {
X		    /* set wtmp entry if wtmp file exists */
X		    if ((fd = open("/etc/wtmp", O_WRONLY | O_APPEND)) >= 0) {
X			(void) write(fd, &utmp, sizeof(utmp));
X			(void) close(fd);
X		    }
X		}
X#else	/* USE_SYSV_UTMP */
X		/* We can now get our ttyslot!  We can also set the initial
X		 * UTMP entry.
X		 */
X		tslot = ttyslot();
X		added_utmp_entry = False;
X		if (!get_ty) {
X			if (!resource.utmpInhibit &&
X			    (pw = getpwuid(screen->uid)) &&
X			    (i = open(etc_utmp, O_WRONLY)) >= 0) {
X				bzero((char *)&utmp, sizeof(struct utmp));
X				(void) strcpy(utmp.ut_line, ttydev + strlen("/dev/"));
X				(void) strcpy(utmp.ut_name, pw->pw_name);
X				(void) strcpy(utmp.ut_host, 
X					      XDisplayString (screen->display));
X				time(&utmp.ut_time);
X				lseek(i, (long)(tslot * sizeof(struct utmp)), 0);
X				write(i, (char *)&utmp, sizeof(struct utmp));
X				added_utmp_entry = True;
X				close(i);
X			} else
X				tslot = -tslot;
X		}
X
X		/* Let's pass our ttyslot to our parent so that it can
X		 * clean up after us.
X		 */
X		handshake.tty_slot = tslot;
X#endif	/* USE_SYSV_UTMP */
X
X		/* Let our parent know that we set up our utmp entry
X		 * so that it can clean up after us.
X		 */
X		handshake.status = UTMP_ADDED;
X		handshake.error = 0;
X		strcpy(handshake.buffer, ttydev);
X		(void) write(cp_pipe[1], &handshake, sizeof(handshake));
X#endif	/* UTMP */
X
X#ifdef TIOCCONS
X		if (get_ty && Console) {
X		    int on = 1;
X		    if (ioctl (1, TIOCCONS, (char *)&on) == -1)
X			HsSysError(cp_pipe[0], ERROR_TIOCCONS);
X		}
X#endif /* TIOCCONS */
X
X#ifdef	SYSV
X		/* Getty is runnable only by root, so we can't set our [ug]ids
X		 * before we try to exec it.
X		 */
X		if (!get_ty) {
X		    setgid (screen->gid);
X		    setuid (screen->uid);
X		}
X#else	/* SYSV */
X		setgid (screen->gid);
X		setuid (screen->uid);
X#endif	/* SYSV */
X
X		/* mark the pipes as close on exec */
X		fcntl(cp_pipe[1], F_SETFD, 1);
X		fcntl(pc_pipe[0], F_SETFD, 1);
X#ifdef	NOTDEF
X		/* mark all other fd's close on exec */
X		for (i = 3; i < NOFILE; i++)
X		    (void) fcntl(i, F_SETFD, 1);
X#endif	/* NOTDEF */
X
X		/* We are at the point where we are going to
X		 * exec our shell (or whatever).  Let our parent
X		 * know we arrived safely.
X		 */
X		handshake.status = PTY_GOOD;
X		handshake.error = 0;
X		(void) strcpy(handshake.buffer, ttydev);
X#ifdef	USE_SYSV_PGRP
X		/* If this is going to be a getty, let's leave the pipe
X		 * open so that we can pass through a bad exec of getty.
X		 * If the exec succeedes, the pipe will close and our
X		 * parent will assume success.
X		 */
X		if (!get_ty)
X			(void) write(cp_pipe[1], &handshake, sizeof(handshake));
X#else	/* USE_SYSV_PGRP */
X		(void) write(cp_pipe[1], &handshake, sizeof(handshake));
X#endif	/* !USE_SYSV_PGRP */
X
X		/* need to reset after all the ioctl bashing we did above */
X#ifdef sun
X#ifdef TIOCSSIZE
X		ioctl  (0, TIOCSSIZE, &ts);
X#endif	/* TIOCSSIZE */
X#else	/* not sun */
X#ifdef TIOCSWINSZ
X		ioctl (0, TIOCSWINSZ, (char *)&ws);
X#endif	/* TIOCSWINSZ */
X#endif	/* sun */
X
X		if (command_to_exec) {
X			execvp(*command_to_exec, command_to_exec);
X			/* print error message on screen */
X			fprintf(stderr, "%s: Can't execvp %s\n", xterm_name,
X			 *command_to_exec);
X		} else if (get_ty) {
X			signal(SIGHUP, SIG_IGN);
X#ifdef SYSV				/* macII does NOT want this */
X#ifndef mips
X			ioctl (0, TIOCTTY, &zero);
X#endif /* not mips */
X			execlp (getty_program, "getty", get_ty, "Xwindow", 0);
X#ifdef	USE_SYSV_PGRP
X			/* The exec of getty failed.  We can't just go on and
X			 * exec a shell (just pop up a root shell -- never!)
X			 * because we never opened up the tty (pty slave).
X			 * For that reason, we also can't dump something to
X			 * the window.
X			 */
X			handshake.status = PTY_FATALERROR;
X			handshake.error = errno;
X			handshake.fatal_error = ERROR_EXEC;
X			strcpy(handshake.buffer, getty_program);
X			(void) write(cp_pipe[1], &handshake, sizeof(handshake));
X			exit(ERROR_EXEC);
X#else	/* USE_SYSV_PGRP */
X			/* now is the time to set our [ug]id's */
X			setgid (screen->gid);
X			setuid (screen->uid);
X#endif	/* USE_SYSV_PGRP */
X#else	/* !SYSV */
X			ioctl (0, TIOCNOTTY, (char *) NULL);
X			execlp (getty_program, "+", "Xwindow", get_ty, 0);
X#endif	/* !SYSV */
X		}
X		signal(SIGHUP, SIG_DFL);
X
X#ifdef UTMP
X		if(((ptr = getenv("SHELL")) == NULL || *ptr == 0) &&
X		 ((pw == NULL && (pw = getpwuid(screen->uid)) == NULL) ||
X		 *(ptr = pw->pw_shell) == 0))
X#else	/* UTMP */
X		if(((ptr = getenv("SHELL")) == NULL || *ptr == 0) &&
X		 ((pw = getpwuid(screen->uid)) == NULL ||
X		 *(ptr = pw->pw_shell) == 0))
X#endif	/* UTMP */
X			ptr = "/bin/sh";
X		if(shname = rindex(ptr, '/'))
X			shname++;
X		else
X			shname = ptr;
X		shname_minus = malloc(strlen(shname) + 2);
X		(void) strcpy(shname_minus, "-");
X		(void) strcat(shname_minus, shname);
X#ifndef AIXV3
X#ifndef USE_SYSV_TERMIO
X		ldisc = XStrCmp("csh", shname + strlen(shname) - 3) == 0 ?
X		 NTTYDISC : 0;
X		ioctl(0, TIOCSETD, (char *)&ldisc);
X#endif	/* !USE_SYSV_TERMIO */
X#endif /* not AIXV3 */
X		execlp (ptr, term->misc.login_shell ? shname_minus : shname, 0);
X
X		/* Exec failed. */
X		fprintf (stderr, "%s: Could not exec %s!\n", xterm_name, ptr);
X		sleep(5);
X		exit(ERROR_EXEC);
X	    }
X
X	    /* Parent process.  Let's handle handshaked requests to our
X	     * child process.
X	     */
X
X	    /* close childs's sides of the pipes */
X	    close (cp_pipe[1]);
X	    close (pc_pipe[0]);
X
X	    for (done = 0; !done; ) {
X		if (read(cp_pipe[0], &handshake, sizeof(handshake)) <= 0) {
X			/* Our child is done talking to us.  If it terminated
X			 * due to an error, we will catch the death of child
X			 * and clean up.
X			 */
X			close(cp_pipe[0]);
X			close(pc_pipe[1]);
X			break;
X		}
X
X		switch(handshake.status) {
X		case PTY_GOOD:
X			/* Success!  Let's free up resources and
X			 * continue.
X			 */
X			close(cp_pipe[0]);
X			close(pc_pipe[1]);
X			done = 1;
X			break;
X
X		case PTY_BAD:
X			if (get_ty) {
X				/* This is a getty.  We were given a specific
X				 * pty to use, so we won't try to get another
X				 * one.
X				 */
X				errno = handshake.error;
X				(void) perror(handshake.buffer);
X				handshake.status = PTY_NOMORE;
X				write(pc_pipe[1], &handshake, sizeof(handshake));
X				exit(1);
X			} else {
X				/* The open of the pty failed!  Let's get
X				 * another one.
X				 */
X				(void) close(screen->respond);
X				if (get_pty(&screen->respond)) {
X				    /* no more ptys! */
X				    (void) fprintf(stderr,
X					"%s: no available ptys\n", xterm_name);
X				    handshake.status = PTY_NOMORE;
X				    write(pc_pipe[1], &handshake, sizeof(handshake));
X				    exit (ERROR_PTYS);
X				}
X			}
X			handshake.status = PTY_NEW;
X			(void) strcpy(handshake.buffer, ttydev);
X			write(pc_pipe[1], &handshake, sizeof(handshake));
X			break;
X
X		case PTY_FATALERROR:
X			errno = handshake.error;
X			SysError(handshake.fatal_error);
X
X		case UTMP_ADDED:
X			/* The utmp entry was set by our slave.  Remember
X			 * this so that we can reset it later.
X			 */
X			added_utmp_entry = True;
X#ifndef	USE_SYSV_UTMP
X			tslot = handshake.tty_slot;
X#endif	/* USE_SYSV_UTMP */
X			free(ttydev);
X			ttydev = malloc((unsigned) strlen(handshake.buffer) + 1);
X			strcpy(ttydev, handshake.buffer);
X			break;
X		}
X	    }
X	    /* close our sides of the pipes */
X	    close (cp_pipe[0]);
X	    close (pc_pipe[1]);
X	}
X
X	/*
X	 * still in parent (xterm process)
X	 */
X
X	signal(SIGHUP,SIG_IGN);
X
X/*
X * Unfortunately, System V seems to have trouble divorcing the child process
X * from the process group of xterm.  This is a problem because hitting the 
X * INTR or QUIT characters on the keyboard will cause xterm to go away if we
X * don't ignore the signals.  This is annoying.
X */
X
X#if defined(USE_SYSV_SIGNALS) && !defined(JOBCONTROL)
X	signal (SIGINT, SIG_IGN);
X	signal (SIGQUIT, SIG_IGN);
X	signal (SIGTERM, SIG_IGN);
X#else /* else is bsd or has job control */
X#ifdef SYSV
X	/* if we were spawned by a jobcontrol smart shell (like ksh or csh),
X	 * then our pgrp and pid will be the same.  If we were spawned by
X	 * a jobcontrol dump shell (like /bin/sh), then we will be in out
X	 * parents pgrp, and we must ignore keyboard signals, or will will
X	 * tank on everything.
X	 */
X	if (getpid() == getpgrp()) {
X	    (void) signal(SIGINT, Exit);
X	    (void) signal(SIGQUIT, Exit);
X	    (void) signal(SIGTERM, Exit);
X	} else {
X	    (void) signal(SIGINT, SIG_IGN);
X	    (void) signal(SIGQUIT, SIG_IGN);
X	    (void) signal(SIGTERM, SIG_IGN);
X	}
X#else	/* SYSV */
X	signal (SIGINT, Exit);
X	signal (SIGQUIT, Exit);
X	signal (SIGTERM, Exit);
X#endif	/* SYSV */
X#endif /* USE_SYSV_SIGNALS and not JOBCONTROL */
X
X	return;
X}							/* end spawn */
X
XExit(n)
Xint n;
X{
X	register TScreen *screen = &term->screen;
X        int pty = term->screen.respond;  /* file descriptor of pty */
X#ifdef UTMP
X#ifdef USE_SYSV_UTMP
X	struct utmp utmp;
X	struct utmp *utptr;
X
X	/* cleanup the utmp entry we forged earlier */
X	if (!resource.utmpInhibit && added_utmp_entry) {
X	    utmp.ut_type = USER_PROCESS;
X	    (void) strncpy(utmp.ut_id, ttydev + strlen(ttydev) - 2,
X		    sizeof(utmp.ut_id));
X	    (void) setutent();
X	    utptr = getutid(&utmp);
X	    /* write it out only if it exists, and the pid's match */
X	    if (utptr && (utptr->ut_pid = screen->pid)) {
X		    utptr->ut_type = DEAD_PROCESS;
X		    utptr->ut_time = time((long *) 0);
X		    (void) pututline(utptr);
X	    }
X	    (void) endutent();
X	}
X#else	/* not USE_SYSV_UTMP */
X	register int i;
X	struct utmp utmp;
X
X	if (!resource.utmpInhibit && added_utmp_entry &&
X	    (!am_slave && tslot > 0 && (i = open(etc_utmp, O_WRONLY)) >= 0)) {
X		bzero((char *)&utmp, sizeof(struct utmp));
X		lseek(i, (long)(tslot * sizeof(struct utmp)), 0);
X		write(i, (char *)&utmp, sizeof(struct utmp));
X		close(i);
X	}
X#endif	/* USE_SYSV_UTMP */
X#endif	/* UTMP */
X        close(pty); /* close explicitly to avoid race with slave side */
X	if(screen->logging)
X		CloseLog(screen);
X
X	if(!get_ty && !am_slave) {
X		/* restore ownership of tty */
X		chown (ttydev, 0, 0);
X
X		/* restore modes of tty */
X		chmod (ttydev, 0666);
X	}
X	exit(n);
X}
X
Xresize(screen, TermName, oldtc, newtc)
XTScreen *screen;
Xchar *TermName;
Xregister char *oldtc, *newtc;
X{
X	register char *ptr1, *ptr2;
X	register int i;
X	register int li_first = 0;
X	register char *temp;
X	char *index(), *strindex();
X
X#ifndef SYSV				/* macII *does* want this */
X	if ((ptr1 = strindex (oldtc, "co#")) == NULL){
X		strcat (oldtc, "co#80:");
X		ptr1 = strindex (oldtc, "co#");
X	}
X	if ((ptr2 = strindex (oldtc, "li#")) == NULL){
X		strcat (oldtc, "li#24:");
X		ptr2 = strindex (oldtc, "li#");
X	}
X	if(ptr1 > ptr2) {
X		li_first++;
X		temp = ptr1;
X		ptr1 = ptr2;
X		ptr2 = temp;
X	}
X	ptr1 += 3;
X	ptr2 += 3;
X	strncpy (newtc, oldtc, i = ptr1 - oldtc);
X	newtc += i;
X	sprintf (newtc, "%d", li_first ? screen->max_row + 1 :
X	 screen->max_col + 1);
X	newtc += strlen(newtc);
X	ptr1 = index (ptr1, ':');
X	strncpy (newtc, ptr1, i = ptr2 - ptr1);
X	newtc += i;
X	sprintf (newtc, "%d", li_first ? screen->max_col + 1 :
X	 screen->max_row + 1);
X	ptr2 = index (ptr2, ':');
X	strcat (newtc, ptr2);
X#endif	/* !SYSV */
X}
X
Xstatic reapchild ()
X{
X#if defined(USE_SYSV_SIGNALS) && !defined(JOBCONTROL)
X	int status, pid;
X
X	pid = wait(&status);
X	if (pid == -1) {
X		(void) signal(SIGCHLD, reapchild);
X		return;
X	}
X#else	/* defined(USE_SYSV_SIGNALS) && !defined(JOBCONTROL) */
X	union wait status;
X	register int pid;
X	
X#ifdef DEBUG
X	if (debug) fputs ("Exiting\n", stderr);
X#endif	/* DEBUG */
X	pid  = wait3 (&status, WNOHANG, (struct rusage *)NULL);
X	if (!pid) {
X#ifdef USE_SYSV_SIGNALS
X		(void) signal(SIGCHLD, reapchild);
X#endif /* USE_SYSV_SIGNALS */
X		return;
X	}
X#endif	/* defined(USE_SYSV_SIGNALS) && !defined(JOBCONTROL) */
X
X
X	if (pid != term->screen.pid) {
X#ifdef USE_SYSV_SIGNALS
X		(void) signal(SIGCHLD, reapchild);
X#endif	/* USE_SYSV_SIGNALS */
X		return;
X	}
X	
X	Cleanup(0);
X}
X
X/* VARARGS1 */
Xconsolepr(fmt,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9)
Xchar *fmt;
X{
X	extern int errno;
X	extern char *SysErrorMsg();
X	int oerrno;
X	int f;
X 	char buf[ BUFSIZ ];
X
X	oerrno = errno;
X 	strcpy(buf, "xterm: ");
X 	sprintf(buf+strlen(buf), fmt, x0,x1,x2,x3,x4,x5,x6,x7,x8,x9);
X 	strcat(buf, ": ");
X 	strcat(buf, SysErrorMsg (oerrno));
X 	strcat(buf, "\n");	
X	f = open("/dev/console",O_WRONLY);
X	write(f, buf, strlen(buf));
X	close(f);
X#ifdef TIOCNOTTY
X	if ((f = open("/dev/tty", 2)) >= 0) {
X		ioctl(f, TIOCNOTTY, (char *)NULL);
X		close(f);
X	}
X#endif	/* TIOCNOTTY */
X}
X
Xchecklogin() 
X{
X	register int ts, i;
X	register struct passwd *pw;
X#ifdef USE_SYSV_UTMP
X	char *name;
X	struct utmp utmp;
X	struct utmp *utptr;
X#else /* not USE_SYSV_UTMP */
X	struct utmp utmp;
X#endif /* USE_SYSV_UTMP */
X
X#ifdef USE_SYSV_UTMP
X	(void) setutent ();
X	/* set up entry to search for */
X	(void) strncpy(utmp.ut_id,ttydev + strlen(ttydev) - 2,
X	 sizeof (utmp.ut_id));
X	utmp.ut_type = DEAD_PROCESS;
X
X	/* position to entry in utmp file */
X	utptr = getutid(&utmp);
X
X	/* entry must:
X	 *  - exist,
X	 *  - have a name in ut_user,
X	 *  - that is not GETTY (seems to null it out in this case, but
X	 *    better to be safe),
X	 *  - have an entry in /etc/utmp for that user.
X	 *
X	 * BTW, endutent() seems to zero out utptr.
X	 */
X	if (!utptr || !*utptr->ut_user || !XStrCmp(utptr->ut_user, "GETTY") ||
X	 (pw = getpwnam(utptr->ut_name)) == NULL) {
X		endutent();
X		return(FALSE);
X	}
X	endutent();
X#else	/* not USE_SYSV_UTMP */
X	ts = tslot > 0 ? tslot : -tslot;
X	if((i = open(etc_utmp, O_RDONLY)) < 0)
X		return(FALSE);
X	lseek(i, (long)(ts * sizeof(struct utmp)), 0);
X	ts = read(i, (char *)&utmp, sizeof(utmp));
X	close(i);
X	if(ts != sizeof(utmp) || XStrCmp(get_ty, utmp.ut_line) != 0 ||
X	 !*utmp.ut_name || (pw = getpwnam(utmp.ut_name)) == NULL)
X		return(FALSE);
X#endif	/* USE_SYSV_UTMP */
X	chdir(pw->pw_dir);
X	/* This is kind of ugly since we won't be able to clean up /etc/utmp
X	 * ourselves, but it shouldn't be too bad, since we will be kicked
X	 * off right away again by init and  will clean things up at that time.
X	 */
X	setgid(pw->pw_gid);
X	setuid(pw->pw_uid);
X	L_flag = 0;
X	return(TRUE);
X}
X
Xremove_termcap_entry (buf, str)
X    char *buf;
X    char *str;
X{
X    register char *strinbuf;
X
X    strinbuf = strindex (buf, str);
X    if (strinbuf) {
X        register char *colonPtr = index (strinbuf+1, ':');
X        if (colonPtr) {
X            register char *cp;
X
X            while (*colonPtr) {
X                *strinbuf++ = *colonPtr++;      /* copy down */
X            }
X            *strinbuf = '\0';
X        } else {
X            strinbuf[1] = '\0';
X        }
X    }
X    return;
X}
X
X/*
X * parse_tty_modes accepts lines of the following form:
X *
X *         [SETTING] ...
X *
X * where setting consists of the words in the modelist followed by a character
X * or ^char.
X */
Xstatic int parse_tty_modes (s, modelist, nmodes)
X    char *s;
X    struct _xttymodes *modelist;
X    int nmodes;
X{
X    struct _xttymodes *mp;
X    int c, i;
X    int count = 0;
X
X    while (1) {
X	while (*s && isascii(*s) && isspace(*s)) s++;
X	if (!*s) return count;
X
X	for (mp = modelist, i = 0; mp->name; mp++, i++) {
X	    if (strncmp (s, mp->name, mp->len) == 0) break;
X	}
X	if (!mp->name) return -1;
X
X	s += mp->len;
X	while (*s && isascii(*s) && isspace(*s)) s++;
X	if (!*s) return -1;
X
X	if (*s == '^') {
X	    s++;
X	    c = ((*s == '?') ? 0177 : *s & 31);	 /* keep control bits */
X	} else {
X	    c = *s;
X	}
X	mp->value = c;
X	mp->set = 1;
X	count++;
X	s++;
X    }
X}
SHAR_EOF
chmod 0644 main.c || echo "restore of main.c fails"
if [ $TOUCH = can ]
then
    touch -am 1109131490 main.c
fi
fi
exit 0
John Harvey	Austin, Texas
AT HOME  ...!sequoia!johnbob!jph  OR
..!uunet!cs.utexas.edu!execu!sequoia!johnbob!jph
AT WORK  johnbob at ausvmq  OR  john at johnbob  OR  johnbob at austin
         @cs.utexas.edu:ibmchs!auschs!johnbob.austin.ibm.com!john  OR
..!uunet!cs.utexas.edu!ibmaus!auschs!johnbob.austin.ibm.com!john
I don't speak for anybody.  Not even myself.



More information about the Comp.unix.aix mailing list