|
|
1.1 ! root 1: /* ! 2: * fixtty.c ! 3: * ! 4: * Set the tty properly on entry in dial() and exit in hangup(). ! 5: */ ! 6: ! 7: #include "dcp.h" ! 8: #include "dial.h" ! 9: ! 10: #if SGTTY ! 11: #include <sgtty.h> ! 12: ! 13: static struct sgttyb save; ! 14: ! 15: ttyinit(fd, baud) ! 16: int fd, baud; ! 17: { ! 18: struct sgttyb ttyb; ! 19: ! 20: gtty(fd, &ttyb); ! 21: save = ttyb; ! 22: if ( (ttyb.sg_ispeed=findspeed(baud)) == 0 ) ! 23: return( M_ILL_BD ); ! 24: ttyb.sg_ospeed = ttyb.sg_ispeed; ! 25: ttyb.sg_flags = CBREAK; ! 26: stripflg = 1; ! 27: ttyb.sg_erase = -1; ! 28: ttyb.sg_kill = -1; ! 29: if ( stty(fd, &ttyb) == -1 ) ! 30: return( M_L_PROB ); ! 31: ioctl(fd, TIOCHPCL); ! 32: } ! 33: ! 34: ! 35: ttyexit(fd) ! 36: int fd; ! 37: { ! 38: stty(fd, &save); ! 39: sleep(2); ! 40: stty(fd, &save); ! 41: stripflg = 0; ! 42: } ! 43: ! 44: ! 45: #elif TERMIO ! 46: ! 47: #include <termio.h> ! 48: ! 49: static struct termio save; ! 50: ! 51: ttyinit(fd, baud) ! 52: int fd, baud; ! 53: { ! 54: struct termio tio; ! 55: unsigned short tmp; ! 56: ! 57: ioctl(fd, TCGETA, &tio); ! 58: save = tio; ! 59: tio.c_iflag = ISTRIP; ! 60: stripflg = 1; ! 61: tio.c_oflag = 0; ! 62: tio.c_cflag &= ~(CBAUD|CSIZE|PARENB); ! 63: if ( (tmp=findspeed(baud)) == 0 ) ! 64: return( M_ILL_BD ); ! 65: tio.c_cflag |= tmp; ! 66: tio.c_cflag |= (HUPCL|CS8); ! 67: tio.c_lflag = 0; ! 68: if ( ioctl(fd, TCSETA, &tio) == -1 ) ! 69: return(M_L_PROB); ! 70: return(0); ! 71: } ! 72: ! 73: ttyexit(fd) ! 74: int fd; ! 75: { ! 76: ioctl(fd, TCSETA, &save); ! 77: sleep (2); ! 78: ioctl(fd, TCSETA, &save); ! 79: stripflg = 0; ! 80: } ! 81: ! 82: #endif ! 83: ! 84: static struct speedlist { ! 85: int value; ! 86: int name; ! 87: } ! 88: speeds[] = { ! 89: {0, 0}, ! 90: {110, B110}, ! 91: {300, B300}, ! 92: {600, B600}, ! 93: {1200, B1200}, ! 94: {2400, B2400}, ! 95: {4800, B4800}, ! 96: {9600, B9600}, ! 97: {19200, B19200}, ! 98: {-1, -1 } ! 99: }; ! 100: ! 101: static ! 102: findspeed(speed) ! 103: int speed; ! 104: { ! 105: register struct speedlist *ps; ! 106: ! 107: for (ps=speeds; ps->value>=0; ps++) ! 108: if (ps->value == speed) ! 109: return (ps->name); ! 110: ! 111: return (0); ! 112: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.