📄 ckutio.c
字号:
if (flow == DIALING) ttraw.c_cflag |= CLOCAL|HUPCL; if (flow == CONNECT) ttraw.c_cflag &= ~CLOCAL; ttraw.c_lflag &= ~(ICANON|ECHO); ttraw.c_lflag |= ISIG; /* do check for interrupt */ ttraw.c_iflag |= (BRKINT|IGNPAR); ttraw.c_iflag &= ~(IGNBRK|INLCR|IGNCR|ICRNL|INPCK|ISTRIP); ttraw.c_oflag &= ~OPOST; ttraw.c_cflag &= ~(CSIZE|PARENB); ttraw.c_cflag |= (CS8|CREAD); ttraw.c_cc[VMIN] = 1; ttraw.c_cc[VTIME] = 0; if (s > -1) { /* Do the speed */ cfsetispeed(&ttraw, s); cfsetospeed(&ttraw, s); } if (tcsetattr(ttyfd,TCSANOW,&ttraw) < 0) return(-1);/* Set the new modes. */#ifdef MYREAD#ifdef BSD4/* Try to make reads nonblocking */#ifdef aegis return(0);#endif /* aegis */#ifdef FIONBIO x = 1; if (ioctl(ttyfd,FIONBIO,&x) < 0) { perror("ttpkt ioctl"); return(-1); }#else /* fionbio */#ifdef FNDELAY if (fcntl(ttyfd,F_SETFL,fcntl(ttyfd,F_GETFL,0) | FNDELAY) == -1) { return(-1); }#endif /* fndelay */#endif /* fionbio */ ttflui(); /* Flush any pending input */ return(0);#endif /* bsd4 */#ifdef MINIX ttflui(); /* Flush any pending input */ return(0);#endif#else /* myread */ ttflui(); /* Flush any pending input */ return(0);#endif /* myread */#endif /* not uxiii */#ifdef UXIII if (flow == 1) ttraw.c_iflag |= (IXON|IXOFF); if (flow == 0) ttraw.c_iflag &= ~(IXON|IXOFF); if (flow == DIALING) ttraw.c_cflag |= CLOCAL|HUPCL; if (flow == CONNECT) ttraw.c_cflag &= ~CLOCAL; ttraw.c_lflag &= ~(ICANON|ECHO); ttraw.c_lflag |= ISIG; /* do check for interrupt */ ttraw.c_iflag |= (BRKINT|IGNPAR); ttraw.c_iflag &= ~(IGNBRK|INLCR|IGNCR|ICRNL|IUCLC|INPCK|ISTRIP|IXANY); ttraw.c_oflag &= ~OPOST; ttraw.c_cflag &= ~(CSIZE|PARENB); ttraw.c_cflag |= (CS8|CREAD);#ifdef IX370 ttraw.c_cc[4] = 48; /* So Series/1 doesn't interrupt on every char */ ttraw.c_cc[5] = 1;#else#ifdef VXVE ttraw.c_cc[4] = 1; /* [VMIN] for CDC VX/VE */ ttraw.c_cc[5] = 0; /* [VTIME] for CDC VX/VE */#else#ifdef MYREAD ttraw.c_cc[4] = 200; /* return max of this many characters */ ttraw.c_cc[5] = 1; /* or when this many secs/10 expire w/no input */#else ttraw.c_cc[4] = 1; /* [VMIN] Maybe should be bigger for all Sys V? */ ttraw.c_cc[5] = 0; /* [VTIME] Should be set high enough to ignore */ /* intercharacter spacing? */ /* But then we have to distinguish between Sys III and Sys V.. */#endif#endif#endif if (s > -1) { /* set speed */ ttraw.c_cflag &= ~CBAUD; ttraw.c_cflag |= s; } if (ioctl(ttyfd,TCSETAW,&ttraw) < 0) return(-1); /* set new modes . */ if (flow == DIALING) {#ifndef aegis if (fcntl(ttyfd,F_SETFL, fcntl(ttyfd, F_GETFL, 0) & ~O_NDELAY) < 0 ) return(-1);#endif /* not aegis */ close( open(ttnmsv,2) ); /* magic to force mode change!!! */ } ttflui(); return(0);#endif /* uxiii */}/* T T V T -- Condition communication line for use as virtual terminal */ttvt(speed,flow) int speed, flow; { int s; if (ttyfd < 0) return(-1); /* Not open. */ s = ttsspd(speed); /* Check the speed */#ifndef UXIII if (flow == 1) tttvt.c_iflag |= (IXON|IXOFF); if (flow == 0) tttvt.c_iflag &= ~(IXON|IXOFF); if (flow == DIALING) tttvt.c_cflag |= CLOCAL|HUPCL; if (flow == CONNECT) tttvt.c_cflag &= ~CLOCAL; tttvt.c_lflag &= ~(ISIG|ICANON|ECHO); tttvt.c_iflag |= (IGNBRK|IGNPAR); tttvt.c_iflag &= ~(INLCR|IGNCR|ICRNL|BRKINT|INPCK|ISTRIP); tttvt.c_oflag &= ~OPOST; tttvt.c_cflag &= ~(CSIZE|PARENB); tttvt.c_cflag |= (CS8|CREAD); tttvt.c_cc[VMIN] = 1; tttvt.c_cc[VTIME] = 0; if (s > -1) { /* set speed */ cfsetispeed(&tttvt, s); cfsetospeed(&tttvt, s); } if (tcsetattr(ttyfd,TCSANOW,&tttvt) < 0) return(-1);#ifdef MYREAD#ifdef BSD4/* Make reads nonblocking */#ifdef aegis return(0);#endif if (fcntl(ttyfd,F_SETFL,fcntl(ttyfd,F_GETFL,0) | FNDELAY) == -1) return(-1); else return(0);#endif /* bsd4 */#endif /* myread */#else /* uxiii */ if (flow == 1) tttvt.c_iflag |= (IXON|IXOFF); if (flow == 0) tttvt.c_iflag &= ~(IXON|IXOFF); if (flow == DIALING) tttvt.c_cflag |= CLOCAL|HUPCL; if (flow == CONNECT) tttvt.c_cflag &= ~CLOCAL; tttvt.c_lflag &= ~(ISIG|ICANON|ECHO); tttvt.c_iflag |= (IGNBRK|IGNPAR); tttvt.c_iflag &= ~(INLCR|IGNCR|ICRNL|IUCLC|BRKINT|INPCK|ISTRIP|IXANY); tttvt.c_oflag &= ~OPOST; tttvt.c_cflag &= ~(CSIZE|PARENB); tttvt.c_cflag |= (CS8|CREAD); tttvt.c_cc[4] = 1; tttvt.c_cc[5] = 0; if (s > -1) { /* set speed */ tttvt.c_cflag &= ~CBAUD; tttvt.c_cflag |= s; } if (ioctl(ttyfd,TCSETAW,&tttvt) < 0) return(-1); /* set new modes . */ if (flow == DIALING) {#ifndef aegis if (fcntl(ttyfd,F_SETFL, fcntl(ttyfd, F_GETFL, 0) & ~O_NDELAY) < 0 ) return(-1);#endif close( open(ttnmsv,2) ); /* magic to force mode change!!! */ }#endif return(0);}/* T T S S P D -- Return the internal baud rate code for 'speed'. */ttsspd(speed) { int s, spdok; if (speed < 0) return(-1); spdok = 1; /* Assume arg ok */ switch (speed) {#ifndef MINIX case 0: s = B0; break; /* Just the common ones. */#endif case 110: s = B110; break; /* The others from ttydev.h */#ifndef MINIX case 150: s = B150; break; /* could also be included if */#endif case 300: s = B300; break; /* necessary... */#ifndef MINIX case 600: s = B600; break;#endif case 1200: s = B1200; break;#ifndef MINIX case 1800: s = B1800; break;#endif case 2400: s = B2400; break; case 4800: s = B4800; break; case 9600: s = B9600; break;#ifdef MINIX case 19200: s = B19200; break; case 38400: s = B38400; break; case 57600: s = B57600; break; case 115200: s = B115200; break;#endif#ifdef PLEXUS case 19200: s = EXTA; break;#endif#ifdef aegis case 19200: s = EXTA; break;#endif default: spdok = 0; fprintf(stderr,"Unsupported line speed - %d\n",speed); fprintf(stderr,"Current speed not changed\n"); break; } if (spdok) return(s); else return(-1); }/* T T F L U I -- Flush tty input buffer */ttflui() {#ifndef UXIII long n;#endif if (ttyfd < 0) return(-1); /* Not open. */ ungotn = -1; /* Initialize myread() stuff */ inbufc = 0;#ifdef aegis sio_$control((short)ttyfd, sio_$flush_in, true, st); if (st.all != status_$ok) { fprintf(stderr, "flush failed: "); error_$print(st); } else { /* sometimes the flush doesn't work */ for (;;) { char buf[256]; /* eat all the characters that shouldn't be available */ (void)ios_$get((short)ttyfd, ios_$cond_opt, buf, 256L, st); if (st.all == ios_$get_conditional_failed) break; fprintf(stderr, "flush failed(2): "); error_$print(st); } }#else#ifdef UXIII#ifndef VXVE if (ioctl(ttyfd,TCFLSH,0) < 0) perror("flush failed");#endif /* vxve */#else#ifdef TIOCFLUSH#ifdef ANYBSD n = FREAD; /* Specify read queue */ if (ioctl(ttyfd,TIOCFLUSH,&n) < 0) perror("flush failed");#else if (ioctl(ttyfd,TIOCFLUSH, (char *)NULL) < 0) perror("flush failed");#endif#endif#endif#endif return(0);}/* Interrupt Functions *//* Timeout handler for communication line input functions */timerh() { longjmp(sjbuf,1);} /* Set up terminal interrupts on console terminal */#ifdef UXIIIesctrp() { /* trap console escapes (^\) */ conesc = 1; signal(SIGQUIT,SIG_IGN); /* ignore until trapped */}#endif#ifdef V7esctrp() { /* trap console escapes (^\) */ conesc = 1; signal(SIGQUIT,SIG_IGN); /* ignore until trapped */}#endif#ifdef C70esctrp() { /* trap console escapes (^\) */ conesc = 1; signal(SIGQUIT,SIG_IGN); /* ignore until trapped */}#endif/* C O N I N T -- Console Interrupt setter */conint(f) int (*f)(); { /* Set an interrupt trap. */ int x, y;#ifdef SIGTSTP int stptrap(); /* Suspend trap */#endif/* Check for background operation, even if not running on real tty, so that *//* background flag can be set correctly. */#ifdef BSD4 int mypgrp; /* In BSD, we can check whether */ int ctpgrp; /* this process's group is the */ /* same as the controlling */ mypgrp = getpgrp(0); /* terminal's process group. */ ioctl (1, TIOCGPGRP, &ctpgrp); x = (mypgrp != ctpgrp); /* If they differ, then background. */ debug(F101,"conint process group test","",x);#else x = (signal(SIGINT,SIG_IGN) == SIG_IGN); debug(F101,"conint signal test","",x);#endif y = isatty(0); debug(F101,"conint isatty test","",y);#ifdef BSD29/* For some reason the signal() test doesn't work under 2.9 BSD... */ backgrd = !y;#else#ifdef MINIX/* Signal test definitely doesn't work on Minix */ backgrd = !y;#else backgrd = (x || !y);#endif#endif debug(F101,"conint backgrd","",backgrd); signal(SIGHUP,f); /* Ensure lockfile cleared on hangup */ signal(SIGTERM,f); /* or soft kill. *//* check if invoked in background -- if so signals set to be ignored */ if (backgrd) { /* In background, ignore signals */#ifdef SIGTSTP signal(SIGTSTP,SIG_IGN); /* Keyboard stop */#endif signal(SIGQUIT,SIG_IGN); /* Keyboard quit */ signal(SIGINT,SIG_IGN); /* Keyboard interrupt */ } else { signal(SIGINT,f); /* Catch terminal interrupt */#ifdef SIGTSTP signal(SIGTSTP,stptrap); /* Keyboard stop */#endif#ifdef UXIII signal(SIGQUIT,esctrp); /* Quit signal, Sys III/V. */ if (conesc) conesc = 0; /* Clear out pending escapes */#else#ifdef V7 signal(SIGQUIT,esctrp); /* V7 like Sys III/V */ if (conesc) conesc = 0;#else#ifdef aegis signal(SIGQUIT,f); /* Apollo, catch it like others. */#else signal(SIGQUIT,SIG_IGN); /* Others, ignore like 4D & earlier. */#endif#endif#endif conif = 1; /* Flag console interrupts on. */ } return;}/* C O N N O I -- Reset console terminal interrupts */connoi() { /* Console-no-interrupts */#ifdef SIGTSTP signal(SIGTSTP,SIG_DFL);#endif signal(SIGINT,SIG_DFL); signal(SIGHUP,SIG_DFL); signal(SIGQUIT,SIG_DFL); signal(SIGTERM,SIG_DFL); conif = 0; /* Flag interrupt trapping off */}/* myread() -- For use by systems that can do nonblocking read() calls *//* Returns: -1 if no characters available, timer expired -2 upon error (such as disconnect), otherwise value of character (0 or greater)*/myread() { static int inbuf_item; static CHAR inbuf[257]; CHAR readit; if (ungotn >= 0) { readit = ungotn; ungotn = -1; } else { if (inbufc > 0) { readit = inbuf[++inbuf_item]; } else {#ifdef aegis /* myread() returns -1 when no input is available. All the users of */ /* myread() explicitly loop until it returns a character or error. */ /* The Apollo code waits for input to be available. */ /* read in characters */ inbufc = ios_$get((short)ttyfd, ios_$cond_opt, inbuf, 256L, st); errno = EIO; if (st.all == ios_$get_conditional_failed) /* get at least one */ inbufc = ios_$get((short)ttyfd, 0, inbuf, 1L, st); if (st.all == ios_$end_of_file) inbufc = 0; else if (st.all != status_$ok) { inbufc = -1; errno = EIO; }#else inbufc = read(ttyfd,inbuf,256); if (inbufc > 0) { inbuf[inbufc] = '\0'; debug(F101,"myread read","",inbufc); }#endif /* aegis */ if (inbufc == 0) { if (ttmdm) { debug(F101,"myread read=0, ttmdm","",ttmdm); errno = 9999; /* magic number for no carrier */ return(-2); /* end of file has no errno */ } else return(-1); /* in sys 5 means no data available */ } if (inbufc < 0) { /* Real error */#ifdef EWOULDBLOCK if (errno == EWOULDBLOCK) return(-1); else return(-2);#else return(-2);#endif /* ewouldblock */ } readit = inbuf[inbuf_item = 0]; } inbufc--; } return(((int) readit) & 255);}myunrd(ch) CHAR ch; { /* push back up to one character */ ungotn = ch;}/* I N I T R A W Q -- Set up to read /DEV/KMEM for character count. */#ifdef V7/* Used in Version 7 to simulate Berkeley's FIONREAD ioctl call. This eliminates blocking on a read, because we can read /dev/kmem to get the number of characters available for raw input. If your system can't or you won't let it read /dev/kmem (the world that is) then you must figure out a different way to do the counting of characters available, or else replace this by a dummy function that always returns 0.*//* * Call this routine as: initrawq(tty) * where tty is the file descriptor of a terminal. It will return * (as a char *) the kernel-mode memory address of the rawq character
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -