?? ckutio.c
字號:
} else { ch = n; n = 1; }#else n = read(ttyfd,&ch,1); /* Otherwise call the system. */#endif } alarm(0); /* Turn off timer, */ signal(SIGALRM,SIG_DFL); /* and interrupt. */ return( (n > 0) ? (ch & 0377) : n ); /* Return char or -1. */}/* T T S N D B -- Send a BREAK signal */ttsndb() { int x; long n; char spd; if (ttyfd < 0) return(-1); /* Not open. */#ifdef PROVX1 gtty(ttyfd,&ttbuf); /* Get current tty flags */ spd = ttbuf.sg_ospeed; /* Save speed */ ttbuf.sg_ospeed = B50; /* Change to 50 baud */ stty(ttyfd,&ttbuf); /* ... */ write(ttyfd,brnuls,3); /* Send 3 nulls */ ttbuf.sg_ospeed = spd; /* Restore speed */ stty(ttyfd,&ttbuf); /* ... */ return(0);#else#ifdef UXIII if (ioctl(ttyfd,TCSBRK,(char *)0) < 0) { /* Send a BREAK */ perror("Can't send BREAK"); return(-1); } return(0);#else#ifdef ANYBSD n = FWRITE; /* Flush output queue. */ ioctl(ttyfd,TIOCFLUSH,&n); /* Ignore any errors.. */ if (ioctl(ttyfd,TIOCSBRK,(char *)0) < 0) { /* Turn on BREAK */ perror("Can't send BREAK"); return(-1); } x = msleep(275); /* Sleep for so many milliseconds */ if (ioctl(ttyfd,TIOCCBRK,(char *)0) < 0) { /* Turn off BREAK */ perror("BREAK stuck!!!"); doexit(1); /* Get out, closing the line. */ /* with exit status = 1 */ } return(x);#else#ifdef V7 genbrk(ttyfd); /* Simulate a BREAK */ return(x);#endif#endif#endif#endif}/* M S L E E P -- Millisecond version of sleep(). *//* Intended only for small intervals. For big ones, just use sleep().*/msleep(m) int m; {#ifdef PROVX1 if (m <= 0) return(0); sleep(-((m * 60 + 500) / 1000)); return(0);#endif#ifdef ANYBSD int t1, t3, t4; if (m <= 0) return(0);#ifndef BSD42/* 2.9 and 4.1 BSD do it this way */ if (ftime(&ftp) < 0) return(-1); /* Get current time. */ t1 = ((ftp.time & 0xff) * 1000) + ftp.millitm; while (1) { ftime(&ftp); /* new time */ t3 = (((ftp.time & 0xff) * 1000) + ftp.millitm) - t1; if (t3 > m) return (t3); }#else/* 4.2 & above can do it with select()... */ if (gettimeofday(&tv, &tz) < 0) return(-1); /* Get current time. */ t1 = tv.tv_sec; /* Seconds */ tv.tv_sec = 0; /* Use select() */ tv.tv_usec = m * 1000; return(select( 0, (int *)0, (int *)0, (int *)0, &tv) );#endif#endif#ifdef UXIII#ifdef XENIX#define CLOCK_TICK 50 /* millisecs per clock tick */#else#define CLOCK_TICK 17 /* 1/60 sec */#endif extern long times(); long t1, t2, tarray[4]; int t3; if (m <= 0) return(0); if ((t1 = times(tarray)) < 0) return(-1); while (1) { if ((t2 = times(tarray)) < 0) return(-1); t3 = ((int)(t2 - t1)) * CLOCK_TICK; if (t3 > m) return(t3); }#endif#ifdef TOWER1 int t1, t3; if (m <= 0) return(0); if (ftime(&ftp) < 0) return(-1); /* Get current time. */ t1 = ((ftp.time & 0xff) * 1000) + ftp.millitm; while (1) { ftime(&ftp); /* new time */ t3 = (((ftp.time & 0xff) * 1000) + ftp.millitm) - t1; if (t3 > m) return (t3); }#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 char *asctime(); /* V7 way */ struct tm *localtime(); struct tm *tp; time(&clock); tp = localtime(&clock); *s = asctime(tp);#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 */#ifndef UXIII gtty(0,&ccold); /* Structure for restoring */ gtty(0,&cccbrk); /* For setting CBREAK mode */ gtty(0,&ccraw); /* For setting RAW mode */#else ioctl(0,TCGETA,&ccold); ioctl(0,TCGETA,&cccbrk); ioctl(0,TCGETA,&ccraw);#endif cgmf = 1; /* Flag that we got them. */}/* 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 */#ifndef UXIII cccbrk.sg_flags |= CBREAK; /* Set to character wakeup, */ cccbrk.sg_flags &= ~ECHO; /* no echo. */ x = stty(0,&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; cccbrk.c_cc[5] = 1; x = ioctl(0,TCSETAW,&cccbrk); /* set new modes . */#endif if (x > -1) setbuf(stdout,NULL); /* Make console unbuffered. */#ifdef V7 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 V7 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 */#ifndef UXIII ccraw.sg_flags |= (RAW|TANDEM); /* Set rawmode, XON/XOFF */ ccraw.sg_flags &= ~(ECHO|CRMOD); /* Set char wakeup, no echo */ return(stty(0,&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 */#ifndef UXIII return(stty(0,&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 V7 lseek(kmem[CON], (long) qaddr[CON], 0); x = read(kmem[CON], &n, sizeof(int)); return((x == sizeof(int))? n: 0);#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}/* C O N I N C -- Get a character from the console */coninc(timo) int timo; { int n = 0; char ch; 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 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 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 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 return(-1);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -