📄 ckutio.c
字号:
if (t3 > m) return (t3); }#endif#endif}/* R T I M E R -- Reset elapsed time counter */rtimer() { tcount = time( (long *) 0 );}/* G T I M E R -- Get current value of elapsed time counter in seconds */gtimer() { int x; x = (int) (time( (long *) 0 ) - tcount); rtimer(); return( (x < 0) ? 0 : x );}/* Z T I M E -- Return date/time string */ztime(s) char **s; {#ifdef UXIII extern long time(); /* Sys III/V way to do it */ char *ctime(); long clock_storage; clock_storage = time( (long *) 0 ); *s = ctime( &clock_storage );#endif#ifdef PROVX1 int utime[2]; /* Venix way */ time(utime); *s = ctime(utime);#endif#ifdef ANYBSD char *asctime(); /* Berkeley way */ struct tm *localtime(); struct tm *tp;#ifdef BSD42 gettimeofday(&tv, &tz); /* BSD 4.2 */ time(&tv.tv_sec); tp = localtime(&tv.tv_sec);#else time(&clock); /* BSD 4.1, 2.9 ... ceb */ tp = localtime(&clock);#endif *s = asctime(tp);#endif#ifdef TOWER1 char *asctime(); /* Tower way */ struct tm *localtime(); struct tm *tp; time(&clock); tp = localtime(&clock); *s = asctime(tp);#endif#ifdef V7#ifdef MINIX int utime[2]; /* Venix way */ time(utime); *s = ctime(utime);#else char *asctime(); /* V7 way */ struct tm *localtime(); struct tm *tp; time(&clock); tp = localtime(&clock); *s = asctime(tp);#endif#endif}/* C O N G M -- Get console terminal modes. *//* Saves current console mode, and establishes variables for switching between current (presumably normal) mode and other modes.*/congm() { if (!isatty(0)) return(0); /* only for real ttys */#ifdef aegis ios_$inq_type_uid(ios_$stdin, conuid, st); if (st.all != status_$ok) { fprintf(stderr, "problem getting stdin objtype: "); error_$print(st); } concrp = (conuid == mbx_$uid); conbufn = 0;#endif#ifndef UXIII tcgetattr(0,&ccold); /* Structure for restoring */ tcgetattr(0,&cccbrk); /* For setting CBREAK mode */ tcgetattr(0,&ccraw); /* For setting RAW mode */#else ioctl(0,TCGETA,&ccold); ioctl(0,TCGETA,&cccbrk); ioctl(0,TCGETA,&ccraw);#endif#ifdef VXVE cccbrk.c_line = 0; /* STTY line 0 for CDC VX/VE */ ioctl(0,TCSETA,&cccbrk); ccraw.c_line = 0; /* STTY line 0 for CDC VX/VE */ ioctl(0,TCSETA,&ccraw);#endif /* vxve */ cgmf = 1; /* Flag that we got them. */ return(0);}/* C O N C B -- Put console in cbreak mode. *//* Returns 0 if ok, -1 if not */concb(esc) char esc; { int x; if (!isatty(0)) return(0); /* only for real ttys */ if (cgmf == 0) congm(); /* Get modes if necessary. */ escchr = esc; /* Make this available to other fns */ ckxech = 1; /* Program can echo characters */#ifdef aegis conbufn = 0; if (concrp) return(write(1, "\035\002", 2)); if (conuid == input_pad_$uid) {pad_$raw(ios_$stdin, st); return(0);}#endif#ifndef UXIII cccbrk.c_lflag &= ~(ICANON|ECHO); cccbrk.c_cc[VINTR] = 003; /* interrupt char is control-c */ cccbrk.c_cc[VQUIT] = escchr; /* escape during packet modes */ cccbrk.c_cc[VMIN] = 1; cccbrk.c_cc[VTIME] = 1; x = tcsetattr(0,TCSANOW,&cccbrk);#else cccbrk.c_lflag &= ~(ICANON|ECHO); cccbrk.c_cc[0] = 003; /* interrupt char is control-c */ cccbrk.c_cc[1] = escchr; /* escape during packet modes */ cccbrk.c_cc[4] = 1;#ifdef ZILOG cccbrk.c_cc[5] = 0;#else cccbrk.c_cc[5] = 1;#endif /* zilog */ x = ioctl(0,TCSETAW,&cccbrk); /* set new modes . */#endif#ifndef aegis if (x > -1) setbuf(stdout,(char *) NULL); /* Make console unbuffered. */#endif#ifdef V7#ifndef MINIX if (kmem[CON] < 0) { qaddr[CON] = initrawq(0); if((kmem[CON] = open("/dev/kmem", 0)) < 0) { fprintf(stderr, "Can't read /dev/kmem in concb.\n"); perror("/dev/kmem"); exit(1); } }#endif#endif return(x);}/* C O N B I N -- Put console in binary mode *//* Returns 0 if ok, -1 if not */conbin(esc) char esc; { if (!isatty(0)) return(0); /* only for real ttys */ if (cgmf == 0) congm(); /* Get modes if necessary. */ escchr = esc; /* Make this available to other fns */ ckxech = 1; /* Program can echo characters */#ifdef aegis conbufn = 0; if (concrp) return(write(1, "\035\002", 2)); if (conuid == input_pad_$uid) {pad_$raw(ios_$stdin, st); return(0);}#endif#ifndef UXIII ccraw.c_lflag &= ~(ISIG|ICANON|ECHO); ccraw.c_iflag |= (BRKINT|IGNPAR); ccraw.c_iflag &= ~(IGNBRK|INLCR|IGNCR|ICRNL|IXON|IXOFF|INPCK|ISTRIP); ccraw.c_oflag &= ~OPOST; ccraw.c_cc[VMIN] = 1; ccraw.c_cc[VTIME] = 1; return(tcsetattr(0,TCSANOW,&ccraw));#else ccraw.c_lflag &= ~(ISIG|ICANON|ECHO); ccraw.c_iflag |= (BRKINT|IGNPAR); ccraw.c_iflag &= ~(IGNBRK|INLCR|IGNCR|ICRNL|IUCLC|IXON|IXANY|IXOFF |INPCK|ISTRIP); ccraw.c_oflag &= ~OPOST;/*** Kermit used to put the console in 8-bit raw mode, but some users have *** pointed out that this should not be done, since some sites actually *** use terminals with parity settings on their Unix systems, and if we *** override the current settings and stop doing parity, then their terminals *** will display blotches for characters whose parity is wrong. Therefore, *** the following two lines are commented out (Larry Afrin, Clemson U): *** *** ccraw.c_cflag &= ~(PARENB|CSIZE); *** ccraw.c_cflag |= (CS8|CREAD); *** *** Sys III/V sites that have trouble with this can restore these lines. ***/ ccraw.c_cc[4] = 1; ccraw.c_cc[5] = 1; return(ioctl(0,TCSETAW,&ccraw) ); /* set new modes . */#endif}/* C O N R E S -- Restore the console terminal */conres() { if (cgmf == 0) return(0); /* Don't do anything if modes */ if (!isatty(0)) return(0); /* only for real ttys */#ifndef UXIII /* except for sIII, */ sleep(1); /* not known! */#endif /* (sIII does wait in ioctls) */ ckxech = 0; /* System should echo chars */#ifdef aegis conbufn = 0; if (concrp) return(write(1, "\035\001", 2)); if (conuid == input_pad_$uid) {pad_$cooked(ios_$stdin, st); return(0);}#endif#ifndef UXIII return(tcsetattr(0,TCSANOW,&ccold)); /* Restore controlling tty */#else return(ioctl(0,TCSETAW,&ccold));#endif}/* C O N O C -- Output a character to the console terminal */conoc(c) char c; { write(1,&c,1);}/* C O N X O -- Write x characters to the console terminal */conxo(x,s) char *s; int x; { write(1,s,x);}/* C O N O L -- Write a line to the console terminal */conol(s) char *s; { int len; len = strlen(s); write(1,s,len);}/* C O N O L A -- Write an array of lines to the console terminal */conola(s) char *s[]; { int i; for (i=0 ; *s[i] ; i++) conol(s[i]);}/* C O N O L L -- Output a string followed by CRLF */conoll(s) char *s; { conol(s); write(1,"\r\n",2);}/* C O N C H K -- Return how many characters available at console */conchk() { int x; long n;#ifdef PROVX1 x = ioctl(0, TIOCQCNT, &ttbuf); n = ttbuf.sg_ispeed & 0377; return((x < 0) ? 0 : n);#else#ifdef aegis if (conbufn > 0) return(conbufn); /* use old count if nonzero */ /* read in more characters */ conbufn = ios_$get(ios_$stdin, ios_$cond_opt, conbuf, (long)sizeof(conbuf), st); if (st.all != status_$ok) conbufn = 0; conbufp = conbuf; return(conbufn);#else#ifdef V7#ifdef MINIX if (conesc) { /* Escape typed */ conesc = 0; signal(SIGQUIT,esctrp); /* Restore escape */ return(1); } return(0);#else lseek(kmem[CON], (long) qaddr[CON], 0); x = read(kmem[CON], &n, sizeof(int)); return((x == sizeof(int))? n: 0);#endif#else#ifdef UXIII if (conesc) { /* Escape typed */ conesc = 0; signal(SIGQUIT,esctrp); /* Restore escape */ return(1); } return(0);#else#ifdef C70 if (conesc) { /* Escape typed */ conesc = 0; signal(SIGQUIT,esctrp); /* Restore escape */ return(1); } return(0);#else#ifdef FIONREAD x = ioctl(0, FIONREAD, &n); /* BSD and maybe some others */ return((x < 0) ? 0 : n);#else return(0); /* Others can't do. */#endif#endif#endif#endif#endif#endif}/* C O N I N C -- Get a character from the console */coninc(timo) int timo; { int n = 0; char ch;#ifdef aegis fflush(stdout); if (conchk() > 0) { --conbufn; return(*conbufp++ & 0377); }#endif if (timo <= 0 ) { /* untimed */ n = read(0, &ch, 1); /* Read a character. */ ch &= 0377; if (n > 0) return(ch); /* Return the char if read */ else #ifdef UXIII#ifndef CIE /* CIE Regulus has no such symbol */ if (n < 0 && errno == EINTR) /* if read was interrupted by QUIT */ return(escchr); /* user entered escape character */ else /* couldnt be ^c, sigint never returns */#endif#endif return(-1); /* Return the char, or -1. */ } signal(SIGALRM,timerh); /* Timed read, so set up timer */ alarm(timo); if (setjmp(sjbuf)) n = -2; else { n = read(0, &ch, 1); ch &= 0377; } alarm(0); /* Stop timing, we got our character */ signal(SIGALRM,SIG_DFL); if (n > 0) return(ch); else#ifdef UXIII#ifndef CIE /* CIE Regulus has no such symbol */ if (n == -1 && errno == EINTR) /* If read interrupted by QUIT, */ return(escchr); /* user entered escape character, */ else /* can't be ^c, sigint never returns */#endif#endif return(-1);}#ifdef ATT7300#include <sys/phone.h>#include <dial.h>#define ATT7300 4 /* REH */CALL tcfig;struct termio ctermio = {0};struct updata ph;static int att7300 = 0; /* REH *//* A T T D I A L -- Dial up the remote system *//* Purpose: to open and dial a number on the internal modem available on the * ATT7300 UNIX PC. Richard E. Hill, Dickinson, TX. */attdial(ttname,speed,telnbr) char *ttname,*telnbr; int speed; { int err; if (ttyfd > 0) { ioctl(ttyfd,TCGETA,&ctermio); /* save current settings */ err=ttclos(); /* close port */ } else ioctl(0,TCGETA,&ctermio); /* get standard settings *//* Open line, check availability & data mode, turn on speaker, close port. */ ttyfd = open (ttname,O_RDWR | O_NDELAY); if (err=ioctl(ttyfd,PIOCOFFHOOK,&ph)) { printf("Phone line for %s not available:%d %d %d\n", ttname,ttyfd,err,errno); close(ttyfd); ttyfd = -1; return(-1); } ioctl(ttyfd,PIOCGETP,&ph); /* set phone parameters */ if (ph.c_lineparam & VOICE) { printf("Phone line %s not in data mode. Switch to data & redial\n", ttname); ioctl(ttyfd,PIOCDISC,&ph); close(ttyfd); ttyfd = -1; return(-1); } ph.c_feedback |= (SPEAKERON | RINGON | NORMSPK); ioctl(ttyfd,PIOCSETP,&ph); /* set phone parameters */ ioctl(ttyfd,PIOCDISC,&ph); /* release phone resources for dial */ close(ttyfd);/* fprintf(stderr,"Phone line status. line_par:%o dialtone_wait:%o \line_status:%o feedback:%o\n", ph.c_lineparam, ph.c_waitdialtone, ph.c_linestatus,ph.c_feedback);*//* Close line so that it can be reopened using system routine "dial". *//* Set terminal configuration parameters. */ ctermio.c_iflag |= (BRKINT|IGNPAR|IXON|IXOFF); ctermio.c_iflag &= ~(IGNBRK|INLCR|IGNCR|ICRNL|IUCLC|INPCK|ISTRIP| IXANY); ctermio.c_oflag &= ~OPOST; ctermio.c_cflag = (B1200 | CS8 | CREAD | CLOCAL | HUPCL); ctermio.c_lflag &= ~(ICANON|ECHO); ctermio.c_cc[4] = 1; ctermio.c_cc[5] = 0; tcfig.attr = &ctermio; tcfig.baud = speed <= 1200 ? speed : 1200; tcfig.speed = speed <= 300 ? 300 : 1200; tcfig.line = ttname; tcfig.telno = telnbr; tcfig.modem = 0; fprintf (stderr,"dialing:%s on line:%s at %d baud, speed:%d\n", tcfig.telno,tcfig.line,tcfig.baud,tcfig.speed); if ((ttyfd = dial(tcfig)) > 0) { att7300 = 1;/* ioctl(ttyfd,TCGETA,&ctermio); fprintf(stderr,"after dial:iflag:%o, oflag:%o, cflag:%o, lflag:%o,\ line:%o\n", ctermio.c_iflag,ctermio.c_oflag,ctermio.c_cflag, ctermio.c_lflag, ctermio.c_line);*/ return(0); } printf("Sorry, connection not made. Error status: %d\n",ttyfd); return(-2);}#endif /* ATT7300 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -