1 /* $Header: /p/tcsh/cvsroot/tcsh/tc.disc.c,v 3.17 2006/03/02 18:46:45 christos Exp $ */
3 * tc.disc.c: Functions to set/clear line disciplines
7 * Copyright (c) 1980, 1991 The Regents of the University of California.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 RCSID("$tcsh: tc.disc.c,v 3.17 2006/03/02 18:46:45 christos Exp $")
44 static int add_discipline = 0; /* Did we add a line discipline */
46 #if defined(IRIS4D) || defined(OREO) || defined(sonyrisc)
49 static struct termio otermiob;
51 static struct termios otermiob;
53 #endif /* IRIS4D || OREO */
57 char strPOSIX[] = "posix";
60 #if !defined(HAVE_DISC) && defined(TIOCGETD) && defined(NTTYDISC)
62 #endif /* !HAVE_DISC && TIOCGETD && NTTYDISC */
70 struct termio termiob;
72 struct termios termiob;
75 if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) {
77 #if (SYSVREL < 4) || !defined(IRIS4D)
78 if (termiob.c_line != NTTYDISC || termiob.c_cc[VSWTCH] == 0) { /*}*/
79 termiob.c_line = NTTYDISC;
81 if (termiob.c_cc[VSWTCH] == 0) {
83 termiob.c_cc[VSWTCH] = CSWTCH;
84 if (ioctl(f, TCSETA, (ioctl_t) & termiob) != 0)
97 struct termio termiob;
99 struct termios termiob;
102 struct ltchars ltcbuf;
104 if (ioctl(f, TCGETA, (ioctl_t) & termiob) == 0) {
105 int comp = getcompat(COMPAT_BSDTTY);
107 if ((comp & COMPAT_BSDTTY) != COMPAT_BSDTTY) {
108 (void) setcompat(comp | COMPAT_BSDTTY);
109 if (ioctl(f, TIOCGLTC, (ioctl_t) & ltcbuf) != 0)
110 xprintf(CGETS(21, 1, "Couldn't get local chars.\n"));
112 ltcbuf.t_suspc = CTL_ESC('\032'); /* ^Z */
113 ltcbuf.t_dsuspc = CTL_ESC('\031'); /* ^Y */
114 ltcbuf.t_rprntc = CTL_ESC('\022'); /* ^R */
115 ltcbuf.t_flushc = CTL_ESC('\017'); /* ^O */
116 ltcbuf.t_werasc = CTL_ESC('\027'); /* ^W */
117 ltcbuf.t_lnextc = CTL_ESC('\026'); /* ^V */
118 if (ioctl(f, TIOCSLTC, (ioctl_t) & ltcbuf) != 0)
119 xprintf(CGETS(21, 2, "Couldn't set local chars.\n"));
121 termiob.c_cc[VSWTCH] = '\0';
122 if (ioctl(f, TCSETAF, (ioctl_t) & termiob) != 0)
138 if (ioctl(f, TXGETLD, (ioctl_t) & tx) == 0) {
139 if (strcmp(tx.tx_name, strPOSIX) != 0)
140 if (ioctl(f, TXADDCD, (ioctl_t) strPOSIX) == 0) {
151 # if defined(TIOCGETD) && defined(NTTYDISC)
152 if (ioctl(f, TIOCGETD, (ioctl_t) & oldisc) == 0) {
153 if (oldisc != NTTYDISC) {
154 int ldisc = NTTYDISC;
156 if (ioctl(f, TIOCSETD, (ioctl_t) & ldisc) != 0)
169 # endif /* TIOCGETD && NTTYDISC */
170 #endif /* !HAVE_DISC */
178 if (add_discipline) {
180 #if defined(OREO) || defined(IRIS4D)
181 return (ioctl(f, TCSETAF, (ioctl_t) & otermiob));
182 #endif /* OREO || IRIS4D */
185 return (ioctl(f, TXDELCD, (ioctl_t) strPOSIX));
189 # if defined(TIOCSETD) && defined(NTTYDISC)
190 return (ioctl(f, TIOCSETD, (ioctl_t) & oldisc));
191 # endif /* TIOCSETD && NTTYDISC */
192 #endif /* !HAVE_DISC */
196 } /* end resetdisc */