[alt.sources] ecu - SCO XENIX V/{2,3}86 Extended CU part 34/47

wht@tridom.uucp (Warren Tucker) (10/12/89)

---- Cut Here and unpack ----
#!/bin/sh
# this is part 34 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file xsel386/select.txt continued
#
CurArch=34
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file xsel386/select.txt"
sed 's/^X//' << 'SHAR_EOF' >> xsel386/select.txt
X    09     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys   
X    0a     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys   
X    0b     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys   
X    
X_s3sysent:
X    01     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 |
X    02     | 00 | 06 | 04 | 03 | 0 0 0 0 3 3 1 1 | _statfs   
X    03     | 00 | 05 | 04 | 03 | 0 0 0 0 3 3 1 3 | _fstatfs  
X    04     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 3 | _setpgrp  
X    05     | 00 | 00 | 00 | 08 | 0 0 0 0 0 0 0 0 | _cxenix   
X    06     | 00 | 04 | 03 | 03 | 0 0 0 0 0 1 3 3 | _uadmin   
X    07     | 00 | 00 | 00 | 09 | 0 0 0 0 0 0 0 0 | _utssys   
X    08     | 00 | 03 | 03 | 03 | 0 0 0 0 0 3 3 3 | _fcntl    
X    09     | 00 | 03 | 02 | 05 | 0 0 0 0 0 0 5 3 | _ulimit   
X    0a     | 00 | 00 | 01 | 03 | 0 0 0 0 0 0 0 1 | _rmdir    
X    0b     | 00 | 00 | 02 | 03 | 0 0 0 0 0 0 3 1 | _mkdir    
X    0c     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys    
X    
X_svidsysent:
X
X    01     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 |
X    02     | 00 | 06 | 04 | 03 | 0 0 0 0 3 3 1 1 | _statfs  
X    03     | 00 | 05 | 04 | 03 | 0 0 0 0 3 3 1 3 | _fstatfs 
X    04     | 00 | 00 | 01 | 03 | 0 0 0 0 0 0 0 3 | _setpgrp 
X    05     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys   
X    06     | 00 | 00 | 03 | 03 | 0 0 0 0 0 1 3 3 | _uadmin  
X    07     | 00 | 00 | 00 | 09 | 0 0 0 0 0 0 0 0 | _utssys  
X    08     | 00 | 00 | 03 | 03 | 0 0 0 0 0 3 3 3 | _fcntl   
X    09     | 00 | 00 | 02 | 05 | 0 0 0 0 0 0 5 3 | _ulimit  
X    0a     | 00 | 00 | 01 | 03 | 0 0 0 0 0 0 0 1 | _rmdir   
X    0b     | 00 | 00 | 02 | 03 | 0 0 0 0 0 0 3 1 | _mkdir   
X    0c     | 00 | 00 | 03 | 03 | 0 0 0 0 0 0 0 0 | _nosys   
X
X_clentry: used for oem CLOCAL routines.  Empty on my system.
X
X_cxentry: used for SCO added stuff.
X
X    00     | 00 | 05 | 03 | 03 | 0 0 0 0 0 4 7 1 | _shutdown
X    01     | 00 | 04 | 03 | 03 | 0 0 0 0 0 7 3 3 | _locking
X    02     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 3 1 | _creatsem
X    03     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 1 | _opensem
X    04     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 3 | _sigsem
X    05     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 3 | _waitsem
X    06     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 3 | _nbwaitsem
X    07     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 3 | _rdchk
X    08     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 4 | _stkgrow
X    09     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys
X    0a     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 5 3 | _chsize
X    0b     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 1 | _ftime
X    0c     | 00 | 02 | 01 | 05 | 0 0 0 0 0 0 0 5 | _nap
X    0d     | 00 | 05 | 04 | 01 | 0 0 0 0 3 4 3 1 | _sdget
X    0e     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 7 | _sdfree
X    0f     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 3 7 | _sdenter
X    10     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 7 | _sdleave
X    11     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 7 | _sdgetv
X    12     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 3 7 | _sdwaitv
X    13     | 00 | 05 | 03 | 01 | 0 0 0 0 0 7 5 3 | _brkctl
X    14     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys
X    15     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 1 3 | _nfs_sys
X    16     | 00 | 04 | 03 | 03 | 0 0 0 0 0 1 3 3 | _msgctl
X    17     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 3 5 | _msgget
X    18     | 00 | 05 | 04 | 03 | 0 0 0 0 3 3 1 3 | _msgsnd
X    19     | 06 | 07 | 05 | 03 | 0 0 0 3 5 3 1 3 | _msgrcv
X    1a     | 00 | 05 | 04 | 03 | 0 0 0 0 7 3 4 3 | _semctl
X    1b     | 00 | 04 | 03 | 03 | 0 0 0 0 0 3 3 5 | _semget
X    1c     | 00 | 04 | 03 | 03 | 0 0 0 0 0 4 1 3 | _semop
X    1d     | 00 | 04 | 03 | 03 | 0 0 0 0 0 1 3 3 | _shmctl
X    1e     | 00 | 04 | 03 | 03 | 0 0 0 0 0 3 4 5 | _shmget
X    1f     | 00 | 04 | 03 | 06 | 0 0 0 0 0 3 7 3 | _shmat
X    20     | 00 | 04 | 03 | 03 | 0 0 0 0 0 1 3 3 | _proctl
X    21     | 00 | 03 | 00 | 06 | 0 0 0 0 0 0 3 7 | _execseg
X    22     | 00 | 02 | 00 | 03 | 0 0 0 0 0 0 0 7 | _unexecseg
X    23     | 00 | 00 | 03 | 03 | 0 0 0 0 0 5 5 1 | _swapon
X    24     | 00 | 09 | 05 | 03 | 0 0 0 1 1 1 1 3 | _select
X
XI couldn't really figure out how uadmin() was accessed.  libc's
Xuadmin.o links in a routine that calls system call 0x37.  Hmmm...
X
XThe _cxentry is accessed by (documented in the programmer's reference
Xunder System Calls) setting a bit in the system call number.  It seems
Xas though it actually shifts the system call number up half a word and
Xputs 0x28 in the low order halfword.
X
XNow we see that select() exists as a cxenix function (number 0x24),
X
XThere is also poll(), putmsg(), and getmsg() -- streams stuff.
XSince the tty device is not a streams device (actually it looks as if
Xthe streams stuff has been nulled out -- look at the master file for
Xmore information) it is highly unlikely that these routines will do
Xanything useful.  Infact, they don't.  Change the SYSNUM (and symbols)
Xin the example open.s above to their appropriate values to try out the
Xstreams routines.
X
Xselect.s looks something like:
X
X; select
X;
X;
X;
X
X	title	select
X
X	.386
X
XSYSNUM	equ 	2428h
X
Xextrn	_errno:dword
X
Xpublic  _select
X
X_TEXT	segment  dword use32 public 'CODE'
X	assume   cs: _TEXT
X_select	proc near
X	mov	eax, SYSNUM		; Get system call number.
X
X	;
X	; I don't even pretend to understand masm syntax.  I tried
X	; the following line (and variations) without any success.
X	;
X
X;	call    far 7:0			; Switch to kernel and call SYSNUM.
X
X	;
X	; Don't laugh, it works.
X	;
X
X	db 9ah
X	dw 0,0
X	dw 7
X
X	jb	short _cerror		; below == error.
X
X	xor	eax, eax		; zero return value (no error).
X	ret				; done.
X
X_cerror:
X	mov	_errno, eax		; Save error code in _errno.
X	mov	eax, -1			; Return -1 (as error).
X	ret				; done.
X
X_select	endp
X
X_TEXT	ends
X
X	end
X
XThere is a header file you'll need in <sys/select.h> which has some
Xinformation in it.
X
XA Synopsis of the SCO XENIX implementation:
X
X	#include <sys/select.h>
X
X	nfds = select(width readfds, writefds, exceptfds, timeout)
X	int width, *readfds, *writefds, *exceptfds;
X	struct timeval *timeout;  /* timeval is a pointer to a structure */
X
XI tested select() and found it to be half way implemented.  It seems
Xas if there must be some extra field in struct cdevsw <sys/conf.h>.
X
XSo, I guess I wait 'til 3.2.
X
XPax, Keith
X
XPs, FYI.
X
XPps, if I made a mistake in my description of system call handling on
XSCO XENIX or what not, please correct me.
X
XPpps, `call far 7:0' seems really reasonable to me.
X-- 
Xag@elgar.CTS.COM         Keith Gabryelski          ...!{ucsd, crash}!elgar!ag
X
X
SHAR_EOF
echo "File xsel386/select.txt is complete"
chmod 0644 xsel386/select.txt || echo "restore of xsel386/select.txt fails"
echo "x - extracting xsel386/ttiocom.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > xsel386/ttiocom.c &&
X/* CHK=0x162D */
X
X#include <sys/types.h>
X#include <sys/tty.h>
X#include <sys/select.h>
X
Xttiocom(ttyp, com, arg, flag)
Xstruct tty *ttyp;
Xint com, arg, flag;     /* there should be better types for this :-) */
X{
X        if (com == IOC_SELECT)
X        {
X                ttselect(ttyp, flag);
X                return(0);      /*** THIS IS IMPORTANT ***/
X        }
X        return(Ttiocom(ttyp, com ,arg, flag));
X}
X
SHAR_EOF
chmod 0644 xsel386/ttiocom.c || echo "restore of xsel386/ttiocom.c fails"
echo "x - extracting ckermit/ckutio-orig.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ckermit/ckutio-orig.c &&
X/* CHK=0x2848 */
Xchar *ckxv = "Unix tty I/O, 4E(047), 27 Jan 88";
X
X/*  C K U T I O  */
X
X/* C-Kermit interrupt, terminal control & i/o functions for Unix systems */
X
X/*
X Author: Frank da Cruz (SY.FDC@CU20B),
X Columbia University Center for Computing Activities, January 1985.
X Copyright (C) 1985, 1988, Trustees of Columbia University in the City of New 
X York.  Permission is granted to any individual or institution to use, copy, or
X redistribute this software so long as it is not sold for profit, provided this
X copyright notice is retained. 
X*/
X/* Includes for all Unixes (conditional includes come later) */
X
X#include <sys/types.h>			/* Types */
X
X#include <sys/dir.h>			/* Directory */
X#include <ctype.h>			/* Character types */
X#ifdef NULL
X#undef NULL
X#endif /* NULL */
X#include <stdio.h>			/* Unix Standard i/o */
X#include <signal.h>			/* Interrupts */
X
X#ifndef ZILOG
X#include <setjmp.h>			/* Longjumps */
X#else
X#include <setret.h>
X#endif
X
X#include "ckcdeb.h"			/* Typedefs, formats for debug() */
X
X/* Maximum length for the name of a tty device */
X
X#ifndef DEVNAMLEN
X#define DEVNAMLEN 25
X#endif
X
X/* 4.1 BSD support added by Charles E. Brooks, EDN-VAX */
X/* Fortune 32:16 Pro:For 1.8 support mostly like 4.1, added by J-P Dumas */
X
X#ifdef BSD4
X#define ANYBSD
X#ifdef MAXNAMLEN
X#define BSD42
X#ifdef aegis
Xchar *ckxsys = " Apollo DOMAIN/IX 4.2 BSD";
X#else
Xchar *ckxsys = " 4.2 BSD";
X#endif /* aegis */
X#else
X#ifdef FT18
X#define BSD41
Xchar *ckxsys = " Fortune For:Pro 1.8";
X#else
X#define BSD41
X#ifndef C70
Xchar *ckxsys = " 4.1 BSD";
X#endif /* not c70 */
X#endif /* ft18 */
X#endif /* maxnamlen */
X#endif /* bsd4 */
X
X/* 2.9bsd support contributed by Bradley Smith, UCLA */
X#ifdef BSD29
X#define ANYBSD
Xchar *ckxsys = " 2.9 BSD";
X#endif /* bsd29 */
X
X/*
X Version 7 UNIX support contributed by Gregg Wonderly,
X Oklahoma State University:  gregg@okstate.csnet
X*/
X#ifdef	V7
Xchar *ckxsys = " Version 7 UNIX (tm)";
X#endif /* v7 */
X
X/* BBN C70 support from Frank Wancho, WANCHO@SIMTEL20 */
X#ifdef C70
Xchar *ckxsys = " BBN C/70";
X#endif /* c70 */
X
X/* IBM 370 IX/370 support from Wayne Van Pelt, GE/CRD, Schenectedy, NY */
X#ifdef IX370
Xchar *ckxsys = " IBM IX/370";
X#endif /* ix370 */
X
X/* Amdahl UTS 2.4 (v7 derivative) for IBM 370 series compatible mainframes */
X/* Contributed by Garard Gaye, Jean-Pierre Dumas, DUMAS@SUMEX-AIM. */
X#ifdef UTS24
Xchar *ckxsys = " Amdahl UTS 2.4";
X#endif /* uts24 */
X
X/* Pro/Venix Version 1.x support from Columbia U. */
X#ifdef PROVX1
Xchar *ckxsys = " Pro-3xx Venix v1";
X#endif /* provx1 */
X
X/* Tower support contributed by John Bray, Auburn, Alabama */
X#ifdef TOWER1
Xchar *ckxsys = " NCR Tower 1632, OS 1.02";
X#endif /* tower1 */
X
X/* Sys III/V, Xenix, PC/IX support by Herm Fischer, Encino, CA */
X#ifdef UXIII
X#ifdef XENIX
Xchar *ckxsys = " Xenix/286";
X#else
X#ifdef PCIX
Xchar *ckxsys = " PC/IX";
X#else
X#ifdef ISIII
Xchar *ckxsys = " Interactive Systems Corp System III";
X#else
X#ifdef hpux
X/* HP 9000 Series changes contributed by Bill Coalson */
Xchar *ckxsys = " HP 9000 Series HP-UX";
X#else
X#ifdef aegis
X/* Apollo Aegis support from SAS Institute, Cary, NC */
Xchar *ckxsys = " Apollo DOMAIN/IX System V";
X#else
X#ifdef ZILOG
Xchar *ckxsys = " Zilog S8000 Zeus 3.21+";
X#else
X#ifdef VXVE
X/* Control Data Corp VX/VE 5.2.1 System V support by */
X/* S.O. Lidie, Lehigh University, LUSOL@LEHICDC1.BITNET */
Xchar *ckxsys = " CDC VX/VE 5.2.1 System V";
X#else
Xchar *ckxsys = " AT&T System III/System V";
X#endif /* vxve  */
X#endif /* zilog */
X#endif /* aegis */
X#endif /* hpux  */
X#endif /* isiii */
X#endif /* pcix  */
X#endif /* xenix */
X#endif /* uxiii */
X
X/* Features... */
X
X/* Do own buffering, using unbuffered read() calls... */
X#ifdef UXIII
X#define MYREAD
X#endif /* uxiii */
X
X#ifdef BSD42
X#undef MYREAD
X#include <errno.h>
X#endif /* bsd42 */
X
X
X/*
X Variables available to outside world:
X
X   dftty  -- Pointer to default tty name string, like "/dev/tty".
X   dfloc  -- 0 if dftty is console, 1 if external line.
X   dfprty -- Default parity
X   dfflow -- Default flow control
X   ckxech -- Flag for who echoes console typein:
X     1 - The program (system echo is turned off)
X     0 - The system (or front end, or terminal).
X   functions that want to do their own echoing should check this flag
X   before doing so.
X
X   flfnam -- Name of lock file, including its path, e.g.,
X		"/usr/spool/uucp/LCK..cul0" or "/etc/locks/tty77"
X   hasLock -- Flag set if this kermit established a uucp lock.
X   inbufc -- number of tty line rawmode unread characters
X		(system III/V unixes)
X   backgrd -- Flag indicating program executing in background ( & on
X		end of shell command). Used to ignore INT and QUIT signals.
X
X Functions for assigned communication line (either external or console tty):
X
X   sysinit()               -- System dependent program initialization
X   syscleanup()            -- System dependent program shutdown
X   ttopen(ttname,local,mdmtyp) -- Open the named tty for exclusive access.
X   ttclos()                -- Close & reset the tty, releasing any access lock.
X   ttpkt(speed,flow)       -- Put the tty in packet mode and set the speed.
X   ttvt(speed,flow)        -- Put the tty in virtual terminal mode.
X				or in DIALING or CONNECTED modem control state.
X   ttinl(dest,max,timo)    -- Timed read line from the tty.
X   ttinc(timo)             -- Timed read character from tty.
X   myread()		   -- System 3 raw mode bulk buffer read, gives
X			   --   subsequent chars one at a time and simulates
X			   --   FIONREAD!
X   myunrd(c)		   -- Places c back in buffer to be read (one only)
X   ttchk()                 -- See how many characters in tty input buffer.
X   ttxin(n,buf)            -- Read n characters from tty (untimed).
X   ttol(string,length)     -- Write a string to the tty.
X   ttoc(c)                 -- Write a character to the tty.
X   ttflui()                -- Flush tty input buffer.
X
X   ttlock(ttname)	   -- Lock against uucp collisions (Sys III)
X   ttunlck()		   -- Unlock "       "     "
X   look4lk(ttname)	   -- Check if a lock file exists
X*/
X
X
X/*
XFunctions for console terminal:
X
X   congm()   -- Get console terminal modes.
X   concb(esc) -- Put the console in single-character wakeup mode with no echo.
X   conbin(esc) -- Put the console in binary (raw) mode.
X   conres()  -- Restore the console to mode obtained by congm().
X   conoc(c)  -- Unbuffered output, one character to console.
X   conol(s)  -- Unbuffered output, null-terminated string to the console.
X   conola(s) -- Unbuffered output, array of strings to the console.
X   conxo(n,s) -- Unbuffered output, n characters to the console.
X   conchk()  -- Check if characters available at console (bsd 4.2).
X		Check if escape char (^\) typed at console (System III/V).
X   coninc(timo)  -- Timed get a character from the console.
X   conint()  -- Enable terminal interrupts on the console if not background.
X   connoi()  -- Disable terminal interrupts on the console if not background.
X
XTime functions
X
X   msleep(m) -- Millisecond sleep
X   ztime(&s) -- Return pointer to date/time string
X   rtimer() --  Reset timer
X   gtimer()  -- Get elapsed time since last call to rtimer()
X*/
X
X
X/* Conditional Includes */
X
X#ifdef FT18
X#include <sys/file.h>	  		/* File information */
X#endif /* ft18 */
X
X/* Whether to #include <sys/file.h>... */
X#ifndef PROVX1
X#ifndef aegis
X#ifndef XENIX
X#include <sys/file.h>	  		/* File information */
X#endif /* xenix */
X#endif /* aegis */
X#endif /* provx1 */
X
X#ifdef aegis
X#ifdef BSD4
X#include <sys/file.h>
X#include <fcntl.h>
X#endif /* bsd4 */
X#endif /* aegis */
X
X/* System III, System V */
X
X#ifdef UXIII
X#include <termio.h>
X#include <sys/ioctl.h>
X#include <fcntl.h>			/* directory reading for locking */
X#include <errno.h>			/* error numbers for system returns */
X#endif /* uxiii */
X
X#ifdef HPUX
X#include <sys/modem.h>
X#endif
X
X/* Not Sys III/V */
X
X#ifndef UXIII
X#include <sgtty.h>			/* Set/Get tty modes */
X#ifndef PROVX1
X#ifndef V7
X#ifndef BSD41
X#include <sys/time.h>			/* Clock info (for break generation) */
X#endif /* not bsd41 */
X#endif /* not v7 */
X#endif /* not provx1 */
X#endif /* not uxiii */
X
X#ifdef BSD41
X#include <sys/timeb.h>			/* BSD 4.1 ... ceb */
X#endif /* bsd41 */
X
X#ifdef BSD29
X#include <sys/timeb.h>			/* BSD 2.9 (Vic Abell, Purdue) */
X#endif /* bsd29 */
X
X#ifdef TOWER1
X#include <sys/timeb.h>			/* Clock info for NCR Tower */
X#endif /* tower1 */
X
X#ifdef aegis
X#include "/sys/ins/base.ins.c"
X#include "/sys/ins/error.ins.c"
X#include "/sys/ins/ios.ins.c"
X#include "/sys/ins/sio.ins.c"
X#include "/sys/ins/pad.ins.c"
X#include "/sys/ins/time.ins.c"
X#include "/sys/ins/pfm.ins.c"
X#include "/sys/ins/pgm.ins.c"
X#include "/sys/ins/ec2.ins.c"
X#include "/sys/ins/type_uids.ins.c"
X#include <default_acl.h>
X#undef TIOCEXCL
X#undef FIONREAD
X#endif
X
X/* The following two conditional #defines are catch-alls for those systems */
X/* that didn't have or couldn't find <file.h>... */
X
X#ifndef FREAD
X#define FREAD 0x01
X#endif
X
X#ifndef FWRITE
X#define FWRITE 0x10
X#endif
X
X
X/* Declarations */
X
Xlong time();				/* All Unixes should have this... */
Xextern int errno;			/* System call error code. */
X
X/* Special stuff for V7 input buffer peeking */
X
X#ifdef	V7
Xint kmem[2] = { -1, -1};
Xchar *initrawq(), *qaddr[2]={0,0};
X#define CON 0
X#define TTY 1
X#endif /* v7 */
X
X/* dftty is the device name of the default device for file transfer */
X/* dfloc is 0 if dftty is the user's console terminal, 1 if an external line */
X
X#ifdef PROVX1
X    char *dftty = "/dev/com1.dout"; /* Only example so far of a system */
X    int dfloc = 1;		    /* that goes in local mode by default */
X#else
X    char *dftty = CTTNAM;		/* Remote by default, use normal */
X    int dfloc = 0;			/* controlling terminal name. */
X#endif /* provx1 */
X
X    int dfprty = 0;			/* Default parity (0 = none) */
X    int ttprty = 0;			/* Parity in use. */
X    int ttmdm = 0;			/* Modem in use. */
X    int dfflow = 1;			/* Xon/Xoff flow control */
X    int backgrd = 0;			/* Assume in foreground (no '&' ) */
X
Xint ckxech = 0; /* 0 if system normally echoes console characters, else 1 */
X
X/* Declarations of variables global within this module */
X
Xstatic long tcount;			/* Elapsed time counter */
X
Xstatic char *brnuls = "\0\0\0\0\0\0\0"; /* A string of nulls */
X
Xstatic jmp_buf sjbuf, jjbuf;		/* Longjump buffer */
Xstatic int lkf = 0,			/* Line lock flag */
X    conif = 0,				/* Console interrupts on/off flag */
X    cgmf = 0,				/* Flag that console modes saved */
X    xlocal = 0,				/* Flag for tty local or remote */
X	ttyfd = -1;				/* TTY file descriptor */
Xstatic char escchr;			/* Escape or attn character */
X
X#ifdef BSD42
X    static struct timeval tv;		/* For getting time, from sys/time.h */
X    static struct timezone tz;
X#endif /* bsd42 */
X
X#ifdef BSD29
X    static long clock;			/* For getting time from sys/time.h */
X    static struct timeb ftp;		/* And from sys/timeb.h */
X#endif /* bsd29 */
X
X#ifdef BSD41
X    static long clock;			/* For getting time from sys/time.h */
X    static struct timeb ftp;		/* And from sys/timeb.h */
X#endif /* bsd41 */
X
X#ifdef TOWER1
Xstatic long clock;			/* For getting time from sys/time.h */
Xstatic struct timeb ftp;		/* And from sys/timeb.h */
X#endif /* tower1 */
X
X#ifdef V7
Xstatic long clock;
X#endif /* v7 */
X
X/* sgtty/termio information... */
X
X#ifdef UXIII
X  static struct termio ttold = {0};	/* Init'd for word alignment, */
X  static struct termio ttraw = {0};	/* which is important for some */
X  static struct termio tttvt = {0};	/* systems, like Zilog... */
X  static struct termio ccold = {0};
X  static struct termio ccraw = {0};
X  static struct termio cccbrk = {0};
X#else
X  static struct sgttyb 			/* sgtty info... */
X    ttold, ttraw, tttvt, ttbuf,		/* for communication line */
X    ccold, ccraw, cccbrk;		/* and for console */
X#endif /* uxiii */
X
Xstatic char flfnam[80];			/* uucp lock file path name */
Xstatic int hasLock = 0;			/* =1 if this kermit locked uucp */
Xstatic int inbufc = 0;			/* stuff for efficient SIII raw line */
Xstatic int ungotn = -1;			/* pushback to unread character */
Xstatic int conesc = 0;			/* set to 1 if esc char (^\) typed */
X
Xstatic int ttlock();			/* definition of ttlock subprocedure */
Xstatic int ttunlck();			/* and unlock subprocedure */
Xstatic char ttnmsv[DEVNAMLEN];		/* copy of open path for tthang */
X
X
X#ifdef aegis
Xstatic status_$t st;			/* error status return value */
Xstatic short concrp = 0; 		/* true if console is CRP pad */
X#define CONBUFSIZ 10
Xstatic char conbuf[CONBUFSIZ];		/* console readahead buffer */
Xstatic int  conbufn = 0;		/* # chars in readahead buffer */
Xstatic char *conbufp;			/* next char in readahead buffer */
Xstatic uid_$t ttyuid;			/* tty type uid */
Xstatic uid_$t conuid;			/* stdout type uid */
X
X/* APOLLO Aegis main()
X * establish acl usage and cleanup handling
X *    this makes sure that CRP pads
X *    get restored to a usable mode
X */
Xmain(argc,argv) int argc; char **argv; {
X	status_$t status;
X	pfm_$cleanup_rec dirty;
X
X	int pid = getpid();
X
X	/* acl usage according to invoking environment */
X	default_acl(USE_DEFENV);
X
X	/* establish a cleanup continuation */
X	status = pfm_$cleanup(dirty);
X	if (status.all != pfm_$cleanup_set)
X	{
X		/* only handle faults for the original process */
X		if (pid == getpid() && status.all > pgm_$max_severity)
X		{	/* blew up in main process */
X			status_$t quo;
X			pfm_$cleanup_rec clean;
X
X			/* restore the console in any case */
X			conres();
X
X			/* attempt a clean exit */
X			debug(F101, "cleanup fault status", "", status.all);
X
X			/* doexit(), then send status to continuation */
X			quo = pfm_$cleanup(clean);
X			if (quo.all == pfm_$cleanup_set)
X				doexit(pgm_$program_faulted);
X			else if (quo.all > pgm_$max_severity)
X				pfm_$signal(quo); /* blew up in doexit() */
X		}
X		/* send to the original continuation */
X		pfm_$signal(status);
X		/*NOTREACHED*/
X	}
X	return(ckcmai(argc, argv));
X}
X#endif /* aegis */
X
X
X/*  S Y S I N I T  --  System-dependent program initialization.  */
X
Xsysinit() {
X
X/* for now, nothing... */
X    return(0);
X}
X
X/*  S Y S C L E A N U P  --  System-dependent program cleanup.  */
X
Xsyscleanup() {
X
X/* for now, nothing... */
X    return(0);
X}
X
X
X/*  T T O P E N  --  Open a tty for exclusive access.  */
X
X/*  Returns 0 on success, -1 on failure.  */
X/*
X  If called with lcl < 0, sets value of lcl as follows:
X  0: the terminal named by ttname is the job's controlling terminal.
X  1: the terminal named by ttname is not the job's controlling terminal.
X  But watch out: if a line is already open, or if requested line can't
X  be opened, then lcl remains (and is returned as) -1.
X*/
Xttopen(ttname,lcl,modem) char *ttname; int *lcl, modem; {
X
X#ifdef UXIII
X#ifndef CIE
X    char *ctermid();			/* Wish they all had this! */
X#endif /* not cie */
X#endif /* uxiii */
X
X#ifdef CIE				/* CIE Regulus doesn't... */
X#define ctermid(x) strcpy(x,"")
X#endif
X
X    char *x; extern char* ttyname();
X    char cname[DEVNAMLEN+4];
X
X    if (ttyfd > -1) return(0);		/* If already open, ignore this call */
X    ttmdm = modem;			/* Make this available to other fns */
X    xlocal = *lcl;			/* Make this available to other fns */
X#ifdef NEWUUCP
X    acucntrl("disable",ttname);		/* Open getty on line (4.3BSD) */
X#endif /* newuucp */
X
X
X#ifdef UXIII
X    /* if modem connection, don't wait for carrier */
X    ttyfd = open(ttname,O_RDWR | (modem ? O_NDELAY : 0) );
X#else
X    ttyfd = open(ttname,2);		/* Try to open for read/write */
X#endif /* uxiii */
X
X    if (ttyfd < 0) {			/* If couldn't open, fail. */
X	perror(ttname);
X	return(-1);
X    }
X#ifdef aegis
X    /* Apollo C runtime claims that console pads are tty devices, which
X     * is reasonable, but they aren't any good for packet transfer. */
X    ios_$inq_type_uid((short)ttyfd, ttyuid, st);
X    if (st.all != status_$ok) {
X	fprintf(stderr, "problem getting tty object type: ");
X	error_$print(st);
X    } else if (ttyuid != sio_$uid) { /* reject non-SIO lines */
X	close(ttyfd); ttyfd = -1;
X	errno = ENOTTY; perror(ttname);
X	return(-1);
X    }
X#endif /* aegis */
X    strncpy(ttnmsv,ttname,DEVNAMLEN);	/* Open, keep copy of name locally. */
X
X/* Caller wants us to figure out if line is controlling tty */
X
X    debug(F111,"ttopen ok",ttname,*lcl);
X    if (*lcl == -1) {
X	if (strcmp(ttname,CTTNAM) == 0) {   /* "/dev/tty" always remote */
X	    debug(F110," Same as CTTNAM",ttname,0);
X	    xlocal = 0;
X	} else if (isatty(0)) {		/* Else, if stdin not redirected */
X	    x = ttyname(0);		/* then compare its device name */
X	    strncpy(cname,x,DEVNAMLEN);	/* (copy from internal static buf) */
X	    debug(F110," ttyname(0)",x,0);
X	    x = ttyname(ttyfd); 	/* ...with real name of ttname. */
X	    xlocal = (strncmp(x,cname,DEVNAMLEN) == 0) ? 0 : 1;
X	    debug(F111," ttyname",x,xlocal);
X	} else {			/* Else, if stdin redirected... */
X#ifdef UXIII
X/* Sys III/V provides nice ctermid() function to get name of controlling tty */
X    	    ctermid(cname);		/* Get name of controlling terminal */
X	    debug(F110," ctermid",cname,0);
X	    x = ttyname(ttyfd); 	/* Compare with name of comm line. */
X	    xlocal = (strncmp(x,cname,DEVNAMLEN) == 0) ? 0 : 1;
X	    debug(F111," ttyname",x,xlocal);
X#else
X/* Just assume local, so "set speed" and similar commands will work */
X/* If not really local, how could it work anyway?... */
X	    xlocal = 1;
X	    debug(F101," redirected stdin","",xlocal);
X#endif /* uxiii */
X        }
X    }    
X
X/* Now check if line is locked -- if so fail, else lock for ourselves */
X
X    lkf = 0;				/* Check lock */
X    if (xlocal > 0) {
X	if (ttlock(ttname) < 0) {
X	    fprintf(stderr,"Exclusive access to %s denied\n",ttname);
X	    close(ttyfd); ttyfd = -1;
X	    debug(F110," Access denied by lock",ttname,0);
X	    return(-1);			/* Not if already locked */
X    	} else lkf = 1;
X    }
X
X/* Got the line, now set the desired value for local. */
X
X    if (*lcl < 0) *lcl = xlocal;
X
X/* Some special stuff for v7... */
X
X#ifdef	V7
X	if (kmem[TTY] < 0) {	/*  If open, then skip this.  */
X		qaddr[TTY] = initrawq(ttyfd);	/* Init the queue. */
X		if ((kmem[TTY] = open("/dev/kmem", 0)) < 0) {
X			fprintf(stderr, "Can't read /dev/kmem in ttopen.\n");
X			perror("/dev/kmem");
X			exit(1);
X		}
X	}
X#endif /* v7 */
X
X/* Request exclusive access on systems that allow it. */
X
X#ifndef XENIX
X/* Xenix exclusive access prevents open(close(...)) from working... */
X#ifdef TIOCEXCL
X    	if (ioctl(ttyfd,TIOCEXCL, NULL) < 0)
X	    fprintf(stderr,"Warning, problem getting exclusive access\n");
X#endif /* tiocexcl */
X#endif /* xenix */
X
X/* Get tty device settings */
X
X#ifndef UXIII
X    gtty(ttyfd,&ttold);			/* Get sgtty info */
X#ifdef aegis
X    sio_$control((short)ttyfd, sio_$raw_nl, false, st);
X    if (xlocal) {	/* ignore breaks from local line */
X	sio_$control((short)ttyfd, sio_$int_enable, false, st);
X	sio_$control((short)ttyfd, sio_$quit_enable, false, st);
X    }
X#endif /* aegis */
X    gtty(ttyfd,&ttraw);			/* And a copy of it for packets*/
X    gtty(ttyfd,&tttvt);			/* And one for virtual tty service */
X#else
X    ioctl(ttyfd,TCGETA,&ttold);		/* Same deal for Sys III, Sys V */
X#ifdef aegis
X    sio_$control((short)ttyfd, sio_$raw_nl, false, st);
X    if (xlocal) {	/* ignore breaks from local line */
X	sio_$control((short)ttyfd, sio_$int_enable, false, st);
X	sio_$control((short)ttyfd, sio_$quit_enable, false, st);
X    }
X#endif /* aegis */
X    ioctl(ttyfd,TCGETA,&ttraw);
X    ioctl(ttyfd,TCGETA,&tttvt);
X#endif /* not uxiii */
X
X#ifdef VXVE
X    ttraw.c_line = 0;			/* STTY line 0 for VX/VE */
X    ioctl(ttyfd,TCSETA,&ttraw);
X    tttvt.c_line = 0;			/* STTY line 0 for VX/VE */
X    ioctl(ttyfd,TCSETA,&tttvt);
X#endif /* vxve */
X
X    debug(F101,"ttopen, ttyfd","",ttyfd);
X    debug(F101," lcl","",*lcl);
X    debug(F111," lock file",flfnam,lkf);
X    return(0);
X}
X
X
X/*  T T C L O S  --  Close the TTY, releasing any lock.  */
X
Xttclos() {
X    if (ttyfd < 0) return(0);		/* Wasn't open. */
X    if (xlocal) {
X	if (tthang())			/* Hang up phone line */
X	    fprintf(stderr,"Warning, problem hanging up the phone\n");
X    	if (ttunlck())			/* Release uucp-style lock */
X	    fprintf(stderr,"Warning, problem releasing lock\n");
X    }
X    ttres();				/* Reset modes. */
X/* Relinquish exclusive access if we might have had it... */
X#ifndef XENIX
X#ifdef TIOCEXCL
X#ifdef TIOCNXCL
X    if (ioctl(ttyfd, TIOCNXCL, NULL) < 0)
X    	fprintf(stderr,"Warning, problem relinquishing exclusive access\n");
X#endif /* tiocnxcl */
X#endif /* tiocexcl */
X#endif /* not xenix */
X    close(ttyfd);			/* Close it. */
X#ifdef NEWUUCP
X    acucntrl("enable",flfnam);		/* Close getty on line. */
X#endif /* newuucp */
X    ttyfd = -1;				/* Mark it as closed. */
X    return(0);
X}
X
X/*  T T H A N G -- Hangup phone line */
X
Xtthang() {
X#ifdef UXIII
X#ifdef HPUX
X    unsigned long dtr_down = 00000000000,
X                  modem_rtn;
SHAR_EOF
echo "End of part 34"
echo "File ckermit/ckutio-orig.c is continued in part 35"
echo "35" > s2_seq_.tmp
exit 0
-- 
-------------------------------------------------------------------
Warren Tucker, Tridom Corporation       ...!gatech!emory!tridom!wht 
Ker-au'-lo-phon.  An 8-foot partial flue-stop, having metal pipes
surmounted by adjustable rings, and with a hole bored near the top
of each pipe, producing a soft and "reedy" tone.