/* RBSB.C by Chuck Forsberg * mode function and most of the rest of the system dependent * stuff for rb.c and sb.c This file is #included so the includer * can set parameters such as HOWMANY. */ #ifdef USG #include #include #include #include #define OS "USG" #endif #ifdef V7 #include #include #include #define OS "V7" #endif #ifndef OS #include #include #include #define REGULUS #define OS "REGULUS" #define void int #define time_t long #endif #ifdef ICANON struct termio oldtty, tty; #else struct sgttyb oldtty, tty; #endif /* * mode(n) * 1: save old tty stat, set raw mode * 0: restore original tty mode */ mode(n) { static did0 = FALSE; switch(n) { case 1: #ifdef USG if(!did0) (void) ioctl(0, TCGETA, &oldtty); tty = oldtty; /* No echo, crlf mapping, INTR, QUIT, delays, no erase/kill */ tty.c_lflag &= ~(ECHO | ICANON | ISIG); tty.c_iflag = IGNBRK; tty.c_oflag = 0; /* Transparent output */ tty.c_cflag &= ~PARENB; /* Leave baud rate alone, disable parity */ tty.c_cflag |= CS8; /* Set character size = 8 */ tty.c_cc[VMIN] = HOWMANY; /* Satisfy reads when this many chars in */ tty.c_cc[VTIME] = 1; /* ... or in this many tenths of seconds */ (void) ioctl(0, TCSETA, &tty); #endif #ifdef V7 if(!did0) { ioctl(0, TIOCEXCL, 0); ioctl(0, TIOCGETP, &oldtty); } tty = oldtty; tty.sg_flags |= RAW; tty.sg_flags &= ~ECHO; ioctl(0, TIOCSETP, &tty); #endif #ifdef REGULUS if(!did0) { ioctl(0, TCGETA, &oldtty); } tty = oldtty; tty.c_lflag = 0; tty.c_iflag = IGNBRK; tty.c_oflag = 0; /* Transparent output */ tty.c_cflag &= ~PARENB; /* Leave baud rate alone, disable parity */ tty.c_cflag |= CS8; /* Set character size = 8 */ tty.c_cc[VMIN] = HOWMANY; /* Satisfy reads when this many chars in */ tty.c_cc[VTIME] = 1; /* ... or in this many tenths of seconds */ ioctl(0, TCSETA, &tty); #endif #ifdef REGULUS10 if(!did0) { ioctl(0, TIOCGETP, &oldtty); } /* Sorry, No structure assignment in Regulus C */ movmem( (char *)&oldtty, (char *)&tty, sizeof(tty)); tty.sg_flags |= (EIGHTBIT|RAW); tty.sg_flags &= ~ECHO; tty.sg_ledit &= ~LEDIT; ioctl(0, TIOCSETP, &tty); #endif did0 = TRUE; return OK; case 0: if(!did0) return ERROR; #ifdef USG (void) ioctl(0, TCSBRK, 1); /* Wait for output to drain */ (void) ioctl(0, TCFLSH, 1); /* Flush input queue */ (void) ioctl(0, TCSETAW, &oldtty); /* Restore original modes */ (void) ioctl(0, TCXONC,1); /* Restart output */ #endif #ifdef V7 ioctl(0, TIOCSETP, &oldtty); ioctl(0, TIOCNXCL, 0); #endif #ifdef REGULUS ioctl(0, TCSETAW, &oldtty); /* Restore original modes */ #endif #ifdef REGULUS10 ioctl(0, TIOCSETP, &oldtty); #endif return OK; default: return ERROR; } }