1: /* $Header: /home/hyperion/mu/christos/src/sys/tcsh-6.00/RCS/tc.disc.c,v 3.0 1991/07/04 21:49:28 christos Exp $ */ 2: /* 3: * tc.disc.c: Functions to set/clear line disciplines 4: * 5: */ 6: /*- 7: * Copyright (c) 1980, 1991 The Regents of the University of California. 8: * All rights reserved. 9: * 10: * Redistribution and use in source and binary forms, with or without 11: * modification, are permitted provided that the following conditions 12: * are met: 13: * 1. Redistributions of source code must retain the above copyright 14: * notice, this list of conditions and the following disclaimer. 15: * 2. Redistributions in binary form must reproduce the above copyright 16: * notice, this list of conditions and the following disclaimer in the 17: * documentation and/or other materials provided with the distribution. 18: * 3. All advertising materials mentioning features or use of this software 19: * must display the following acknowledgement: 20: * This product includes software developed by the University of 21: * California, Berkeley and its contributors. 22: * 4. Neither the name of the University nor the names of its contributors 23: * may be used to endorse or promote products derived from this software 24: * without specific prior written permission. 25: * 26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36: * SUCH DAMAGE. 37: */ 38: #include "config.h" 39: #if !defined(lint) && !defined(pdp11) 40: static char *rcsid() 41: { return "$Id: tc.disc.c,v 3.0 1991/07/04 21:49:28 christos Exp $"; } 42: #endif 43: 44: #include "sh.h" 45: 46: #ifdef OREO 47: #include <compat.h> 48: #endif /* OREO */ 49: 50: static bool add_discipline = 0; /* Did we add a line discipline */ 51: 52: #if defined(IRIS4D) || defined(OREO) 53: # define HAVE_DISC 54: # ifndef POSIX 55: static struct termio otermiob; 56: # else 57: static struct termios otermiob; 58: # endif /* POSIX */ 59: #endif /* IRIS4D || OREO */ 60: 61: #ifdef _IBMR2 62: # define HAVE_DISC 63: char strPOSIX[] = "posix"; 64: #endif /* _IBMR2 */ 65: 66: #if !defined(HAVE_DISC) && defined(TIOCGETD) && defined(NTTYDISC) 67: static int oldisc; 68: #endif /* !HAVE_DISC && TIOCGETD && NTTYDISC */ 69: 70: int 71: /*ARGSUSED*/ 72: setdisc(f) 73: int f; 74: { 75: #ifdef IRIS4D 76: # ifndef POSIX 77: struct termio termiob; 78: # else 79: struct termios termiob; 80: # endif 81: 82: if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) { 83: otermiob = termiob; 84: if (termiob.c_line != NTTYDISC || termiob.c_cc[VSWTCH] == 0) { 85: termiob.c_line = NTTYDISC; 86: termiob.c_cc[VSWTCH] = CSWTCH; 87: if (ioctl(f, TCSETA, (ioctl_t) & termiob) != 0) 88: return (-1); 89: } 90: } 91: else 92: return (-1); 93: add_discipline = 1; 94: return (0); 95: #endif /* IRIS4D */ 96: 97: 98: #ifdef OREO 99: # ifndef POSIX 100: struct termio termiob; 101: # else 102: struct termios termiob; 103: # endif 104: 105: struct ltchars ltcbuf; 106: 107: if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) { 108: otermiob = termiob; 109: if ((getcompat(COMPAT_BSDTTY) & COMPAT_BSDTTY) != COMPAT_BSDTTY) { 110: setcompat(COMPAT_BSDTTY); 111: if (ioctl(f, TIOCGLTC, (ioctl_t) & ltcbuf) != 0) 112: xprintf("Couldn't get local chars.\n"); 113: else { 114: ltcbuf.t_suspc = '\032'; /* ^Z */ 115: ltcbuf.t_dsuspc = '\031'; /* ^Y */ 116: ltcbuf.t_rprntc = '\022'; /* ^R */ 117: ltcbuf.t_flushc = '\017'; /* ^O */ 118: ltcbuf.t_werasc = '\027'; /* ^W */ 119: ltcbuf.t_lnextc = '\026'; /* ^V */ 120: if (ioctl(f, TIOCSLTC, (ioctl_t) & ltcbuf) != 0) 121: xprintf("Couldn't set local chars.\n"); 122: } 123: termiob.c_cc[VSWTCH] = '\0'; 124: if (ioctl(f, TCSETAF, (ioctl_t) & termiob) != 0) 125: return (-1); 126: } 127: } 128: else 129: return (-1); 130: add_discipline = 1; 131: return (0); 132: #endif /* OREO */ 133: 134: 135: #ifdef _IBMR2 136: union txname tx; 137: 138: tx.tx_which = 0; 139: 140: if (ioctl(f, TXGETLD, (ioctl_t) & tx) == 0) { 141: if (strcmp(tx.tx_name, strPOSIX) != 0) 142: if (ioctl(f, TXADDCD, (ioctl_t) strPOSIX) == 0) { 143: add_discipline = 1; 144: return (0); 145: } 146: return (0); 147: } 148: else 149: return (-1); 150: #endif /* _IBMR2 */ 151: 152: #ifndef HAVE_DISC 153: # if defined(TIOCGETD) && defined(NTTYDISC) 154: if (ioctl(f, TIOCGETD, (ioctl_t) & oldisc) == 0) { 155: if (oldisc != NTTYDISC) { 156: int ldisc = NTTYDISC; 157: 158: if (ioctl(f, TIOCSETD, (ioctl_t) & ldisc) != 0) 159: return (-1); 160: add_discipline = 1; 161: } 162: else 163: oldisc = -1; 164: return (0); 165: } 166: else 167: return (-1); 168: # else 169: return (0); 170: # endif /* TIOCGETD && NTTYDISC */ 171: #endif /* !HAVE_DISC */ 172: } /* end setdisc */ 173: 174: 175: int 176: /*ARGSUSED*/ 177: resetdisc(f) 178: int f; 179: { 180: if (add_discipline) { 181: add_discipline = 0; 182: #if defined(OREO) || defined(IRIS4D) 183: return (ioctl(f, TCSETAF, &otermiob)); 184: #endif /* OREO || IRIS4D */ 185: 186: #ifdef _IBMR2 187: return (ioctl(f, TXDELCD, (ioctl_t) strPOSIX)); 188: #endif /* _IBMR2 */ 189: 190: #ifndef HAVE_DISC 191: # if defined(TIOCSETD) && defined(NTTYDISC) 192: return (ioctl(f, TIOCSETD, (ioctl_t) & oldisc)); 193: # endif /* TIOCSETD && NTTYDISC */ 194: #endif /* !HAVE_DISC */ 195: } 196: return (0); 197: } /* end resetdisc */