⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckutio.c

📁 操作系统源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
char *ckxv = "Unix tty I/O, 4E(047), 27 Jan 88";/*  C K U T I O  *//* C-Kermit interrupt, terminal control & i/o functions for Unix systems *//* Author: Frank da Cruz (SY.FDC@CU20B), Columbia University Center for Computing Activities, January 1985. Copyright (C) 1985, 1988, Trustees of Columbia University in the City of New  York.  Permission is granted to any individual or institution to use, copy, or redistribute this software so long as it is not sold for profit, provided this copyright notice is retained. *//* Includes for all Unixes (conditional includes come later) */#include <sys/types.h>			/* Types */#include <sys/dir.h>			/* Directory */#include <ctype.h>			/* Character types */#ifdef NULL#undef NULL#endif /* NULL */#include <stdio.h>			/* Unix Standard i/o */#include <signal.h>			/* Interrupts */#ifndef ZILOG#include <setjmp.h>			/* Longjumps */#else#include <setret.h>#endif#include "ckcdeb.h"			/* Typedefs, formats for debug() *//* Maximum length for the name of a tty device */#ifndef DEVNAMLEN#define DEVNAMLEN 25#endif/* 4.1 BSD support added by Charles E. Brooks, EDN-VAX *//* Fortune 32:16 Pro:For 1.8 support mostly like 4.1, added by J-P Dumas */#ifdef BSD4#define ANYBSD#ifdef MAXNAMLEN#define BSD42#ifdef aegischar *ckxsys = " Apollo DOMAIN/IX 4.2 BSD";#elsechar *ckxsys = " 4.2 BSD";#endif /* aegis */#else#ifdef FT18#define BSD41char *ckxsys = " Fortune For:Pro 1.8";#else#define BSD41#ifndef C70char *ckxsys = " 4.1 BSD";#endif /* not c70 */#endif /* ft18 */#endif /* maxnamlen */#endif /* bsd4 *//* 2.9bsd support contributed by Bradley Smith, UCLA */#ifdef BSD29#define ANYBSDchar *ckxsys = " 2.9 BSD";#endif /* bsd29 *//* Version 7 UNIX support contributed by Gregg Wonderly, Oklahoma State University:  gregg@okstate.csnet*/#ifdef	V7#ifndef MINIXchar *ckxsys = " Version 7 UNIX (tm)";#endif#endif /* v7 *//* Minix support added by Charles Hedrick, Rutgers University:  hedrick@aramis.rutgers.edu Minix also has V7 enabled.*/#ifdef MINIXchar *ckxsys = " Minix";#define TANDEM 0#define MYREAD#include <limits.h>#endif/* BBN C70 support from Frank Wancho, WANCHO@SIMTEL20 */#ifdef C70char *ckxsys = " BBN C/70";#endif /* c70 *//* IBM 370 IX/370 support from Wayne Van Pelt, GE/CRD, Schenectedy, NY */#ifdef IX370char *ckxsys = " IBM IX/370";#endif /* ix370 *//* Amdahl UTS 2.4 (v7 derivative) for IBM 370 series compatible mainframes *//* Contributed by Garard Gaye, Jean-Pierre Dumas, DUMAS@SUMEX-AIM. */#ifdef UTS24char *ckxsys = " Amdahl UTS 2.4";#endif /* uts24 *//* Pro/Venix Version 1.x support from Columbia U. */#ifdef PROVX1char *ckxsys = " Pro-3xx Venix v1";#endif /* provx1 *//* Tower support contributed by John Bray, Auburn, Alabama */#ifdef TOWER1char *ckxsys = " NCR Tower 1632, OS 1.02";#endif /* tower1 *//* Sys III/V, Xenix, PC/IX support by Herm Fischer, Encino, CA */#ifdef UXIII#ifdef XENIXchar *ckxsys = " Xenix/286";#else#ifdef PCIXchar *ckxsys = " PC/IX";#else#ifdef ISIIIchar *ckxsys = " Interactive Systems Corp System III";#else#ifdef hpux/* HP 9000 Series changes contributed by Bill Coalson */char *ckxsys = " HP 9000 Series HP-UX";#else#ifdef aegis/* Apollo Aegis support from SAS Institute, Cary, NC */char *ckxsys = " Apollo DOMAIN/IX System V";#else#ifdef ZILOGchar *ckxsys = " Zilog S8000 Zeus 3.21+";#else#ifdef VXVE/* Control Data Corp VX/VE 5.2.1 System V support by *//* S.O. Lidie, Lehigh University, LUSOL@LEHICDC1.BITNET */char *ckxsys = " CDC VX/VE 5.2.1 System V";#elsechar *ckxsys = " AT&T System III/System V";#endif /* vxve  */#endif /* zilog */#endif /* aegis */#endif /* hpux  */#endif /* isiii */#endif /* pcix  */#endif /* xenix */#endif /* uxiii *//* Features... *//* Do own buffering, using unbuffered read() calls... */#ifdef UXIII#define MYREAD#endif /* uxiii */#ifdef BSD42#undef MYREAD#include <errno.h>#endif /* bsd42 *//* Variables available to outside world:   dftty  -- Pointer to default tty name string, like "/dev/tty".   dfloc  -- 0 if dftty is console, 1 if external line.   dfprty -- Default parity   dfflow -- Default flow control   ckxech -- Flag for who echoes console typein:     1 - The program (system echo is turned off)     0 - The system (or front end, or terminal).   functions that want to do their own echoing should check this flag   before doing so.   flfnam -- Name of lock file, including its path, e.g.,		"/usr/spool/uucp/LCK..cul0" or "/etc/locks/tty77"   hasLock -- Flag set if this kermit established a uucp lock.   inbufc -- number of tty line rawmode unread characters		(system III/V unixes)   backgrd -- Flag indicating program executing in background ( & on		end of shell command). Used to ignore INT and QUIT signals. Functions for assigned communication line (either external or console tty):   sysinit()               -- System dependent program initialization   syscleanup()            -- System dependent program shutdown   ttopen(ttname,local,mdmtyp) -- Open the named tty for exclusive access.   ttclos()                -- Close & reset the tty, releasing any access lock.   ttpkt(speed,flow)       -- Put the tty in packet mode and set the speed.   ttvt(speed,flow)        -- Put the tty in virtual terminal mode.				or in DIALING or CONNECTED modem control state.   ttinl(dest,max,timo)    -- Timed read line from the tty.   ttinc(timo)             -- Timed read character from tty.   myread()		   -- System 3 raw mode bulk buffer read, gives			   --   subsequent chars one at a time and simulates			   --   FIONREAD!   myunrd(c)		   -- Places c back in buffer to be read (one only)   ttchk()                 -- See how many characters in tty input buffer.   ttxin(n,buf)            -- Read n characters from tty (untimed).   ttol(string,length)     -- Write a string to the tty.   ttoc(c)                 -- Write a character to the tty.   ttflui()                -- Flush tty input buffer.   ttlock(ttname)	   -- Lock against uucp collisions (Sys III)   ttunlck()		   -- Unlock "       "     "   look4lk(ttname)	   -- Check if a lock file exists*//*Functions for console terminal:   congm()   -- Get console terminal modes.   concb(esc) -- Put the console in single-character wakeup mode with no echo.   conbin(esc) -- Put the console in binary (raw) mode.   conres()  -- Restore the console to mode obtained by congm().   conoc(c)  -- Unbuffered output, one character to console.   conol(s)  -- Unbuffered output, null-terminated string to the console.   conola(s) -- Unbuffered output, array of strings to the console.   conxo(n,s) -- Unbuffered output, n characters to the console.   conchk()  -- Check if characters available at console (bsd 4.2).		Check if escape char (^\) typed at console (System III/V).   coninc(timo)  -- Timed get a character from the console.   conint()  -- Enable terminal interrupts on the console if not background.   connoi()  -- Disable terminal interrupts on the console if not background.Time functions   msleep(m) -- Millisecond sleep   ztime(&s) -- Return pointer to date/time string   rtimer() --  Reset timer   gtimer()  -- Get elapsed time since last call to rtimer()*//* Conditional Includes */#ifdef FT18#include <sys/file.h>	  		/* File information */#endif /* ft18 *//* Whether to #include <sys/file.h>... */#ifndef PROVX1#ifndef aegis#ifndef MINIX#ifndef XENIX#include <sys/file.h>	  		/* File information */#endif /* xenix */#endif /* MINIX */#endif /* aegis */#endif /* provx1 */#ifdef aegis#ifdef BSD4#include <sys/file.h>#include <fcntl.h>#endif /* bsd4 */#endif /* aegis *//* System III, System V */#ifdef UXIII#include <termio.h>#include <sys/ioctl.h>#include <fcntl.h>			/* directory reading for locking */#include <errno.h>			/* error numbers for system returns */#endif /* uxiii */#ifdef HPUX#include <sys/modem.h>#endif/* Not Sys III/V */#ifndef UXIII#include <termios.h>			/* Set/Get tty modes */#ifndef PROVX1#ifndef V7#ifndef BSD41#include <sys/time.h>			/* Clock info (for break generation) */#endif /* not bsd41 */#endif /* not v7 */#endif /* not provx1 */#endif /* not uxiii */#ifdef BSD41#include <sys/timeb.h>			/* BSD 4.1 ... ceb */#endif /* bsd41 */#ifdef BSD29#include <sys/timeb.h>			/* BSD 2.9 (Vic Abell, Purdue) */#endif /* bsd29 */#ifdef TOWER1#include <sys/timeb.h>			/* Clock info for NCR Tower */#endif /* tower1 */#ifdef aegis#include "/sys/ins/base.ins.c"#include "/sys/ins/error.ins.c"#include "/sys/ins/ios.ins.c"#include "/sys/ins/sio.ins.c"#include "/sys/ins/pad.ins.c"#include "/sys/ins/time.ins.c"#include "/sys/ins/pfm.ins.c"#include "/sys/ins/pgm.ins.c"#include "/sys/ins/ec2.ins.c"#include "/sys/ins/type_uids.ins.c"#include <default_acl.h>#undef TIOCEXCL#undef FIONREAD#endif/* The following two conditional #defines are catch-alls for those systems *//* that didn't have or couldn't find <file.h>... */#ifndef FREAD#define FREAD 0x01#endif#ifndef FWRITE#define FWRITE 0x10#endif/* Declarations */long time();				/* All Unixes should have this... */extern int errno;			/* System call error code. *//* Special stuff for V7 input buffer peeking */#ifdef	V7int kmem[2] = { -1, -1};char *initrawq(), *qaddr[2]={0,0};#define CON 0#define TTY 1#endif /* v7 *//* dftty is the device name of the default device for file transfer *//* dfloc is 0 if dftty is the user's console terminal, 1 if an external line */#ifdef PROVX1    char *dftty = "/dev/com1.dout"; /* Only example so far of a system */    int dfloc = 1;		    /* that goes in local mode by default */#else    char *dftty = CTTNAM;		/* Remote by default, use normal */    int dfloc = 0;			/* controlling terminal name. */#endif /* provx1 */    int dfprty = 0;			/* Default parity (0 = none) */    int ttprty = 0;			/* Parity in use. */    int ttmdm = 0;			/* Modem in use. */    int dfflow = 1;			/* Xon/Xoff flow control */    int backgrd = 0;			/* Assume in foreground (no '&' ) */int ckxech = 0; /* 0 if system normally echoes console characters, else 1 *//* Declarations of variables global within this module */static long tcount;			/* Elapsed time counter */static char *brnuls = "\0\0\0\0\0\0\0"; /* A string of nulls */static jmp_buf sjbuf, jjbuf;		/* Longjump buffer */static int lkf = 0,			/* Line lock flag */    conif = 0,				/* Console interrupts on/off flag */    cgmf = 0,				/* Flag that console modes saved */    xlocal = 0,				/* Flag for tty local or remote */    ttyfd = -1;				/* TTY file descriptor */static char escchr;			/* Escape or attn character */#ifdef BSD42    static struct timeval tv;		/* For getting time, from sys/time.h */    static struct timezone tz;#endif /* bsd42 */#ifdef BSD29    static long clock;			/* For getting time from sys/time.h */    static struct timeb ftp;		/* And from sys/timeb.h */#endif /* bsd29 */#ifdef BSD41    static long clock;			/* For getting time from sys/time.h */    static struct timeb ftp;		/* And from sys/timeb.h */#endif /* bsd41 */#ifdef TOWER1static long clock;			/* For getting time from sys/time.h */static struct timeb ftp;		/* And from sys/timeb.h */#endif /* tower1 */#ifdef V7static long clock;#endif /* v7 *//* termio/termios information... */#ifdef UXIII  static struct termio ttold = {0};	/* Init'd for word alignment, */  static struct termio ttraw = {0};	/* which is important for some */  static struct termio tttvt = {0};	/* systems, like Zilog... */  static struct termio ccold = {0};  static struct termio ccraw = {0};  static struct termio cccbrk = {0};#else  static struct termios 		/* termios info... */    ttold, ttraw, tttvt, ttbuf,		/* for communication line */    ccold, ccraw, cccbrk;		/* and for console */#endif /* uxiii */static char flfnam[80];			/* uucp lock file path name */static int hasLock = 0;			/* =1 if this kermit locked uucp */static int inbufc = 0;			/* stuff for efficient SIII raw line */static int ungotn = -1;			/* pushback to unread character */static int conesc = 0;			/* set to 1 if esc char (^\) typed */static int ttlock();			/* definition of ttlock subprocedure */static int ttunlck();			/* and unlock subprocedure */static char ttnmsv[DEVNAMLEN];		/* copy of open path for tthang */#ifdef aegisstatic status_$t st;			/* error status return value */static short concrp = 0; 		/* true if console is CRP pad */#define CONBUFSIZ 10static char conbuf[CONBUFSIZ];		/* console readahead buffer */static int  conbufn = 0;		/* # chars in readahead buffer */static char *conbufp;			/* next char in readahead buffer */static uid_$t ttyuid;			/* tty type uid */static uid_$t conuid;			/* stdout type uid *//* APOLLO Aegis main() * establish acl usage and cleanup handling *    this makes sure that CRP pads *    get restored to a usable mode */main(argc,argv) int argc; char **argv; {	status_$t status;	pfm_$cleanup_rec dirty;	int pid = getpid();	/* acl usage according to invoking environment */	default_acl(USE_DEFENV);	/* establish a cleanup continuation */	status = pfm_$cleanup(dirty);	if (status.all != pfm_$cleanup_set)	{		/* only handle faults for the original process */		if (pid == getpid() && status.all > pgm_$max_severity)		{	/* blew up in main process */			status_$t quo;			pfm_$cleanup_rec clean;			/* restore the console in any case */			conres();			/* attempt a clean exit */			debug(F101, "cleanup fault status", "", status.all);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -