ttcompat.c revision 1.1 1 /*
2 * Copyright (c) 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. 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.
21 *
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
32 * SUCH DAMAGE.
33 */
34
35 /*
36 * ttcompat.c -- convert sgtty flags to termios
37 * originally from /sys/kern/tty_compat.c
38 */
39
40 #include <sys/param.h>
41 #include <sys/types.h>
42
43 #include <unistd.h>
44 #include <sys/ioctl_compat.h>
45 #include <termios.h>
46 #include <syslog.h>
47 #include <fcntl.h>
48 #include <dirent.h>
49 #include <errno.h>
50 #include <stdio.h>
51 #include <string.h>
52 #include <stdlib.h>
53 #include "extern.h"
54
55 void
56 sttyclearflags(tp, flags)
57 struct termios *tp;
58 long flags;
59 {
60 register long iflag = tp->c_iflag;
61 register long oflag = tp->c_oflag;
62 register long lflag = tp->c_lflag;
63 register long cflag = tp->c_cflag;
64
65 if (flags & TANDEM)
66 iflag &= ~IXOFF;
67 if (flags & ECHO)
68 lflag &= ~ECHO;
69 if (flags & CRMOD) {
70 iflag &= ~ICRNL;
71 oflag &= ~ONLCR;
72 }
73 if (flags & XTABS)
74 oflag &= ~OXTABS;
75
76
77 if (flags & RAW) {
78 iflag |= BRKINT|IXON|IMAXBEL;
79 lflag |= ISIG|IEXTEN;
80 if (flags & CBREAK)
81 lflag &= ~ICANON;
82 else
83 lflag |= ICANON;
84 }
85
86 switch (flags & ANYP) {
87 case EVENP:
88 iflag |= INPCK;
89 cflag |= PARODD;
90 break;
91 case ODDP:
92 iflag |= INPCK;
93 cflag &= ~PARODD;
94 break;
95 }
96
97 if (flags & (RAW|LITOUT|PASS8)) {
98 cflag &= ~CSIZE;
99 cflag |= CS7|PARENB;
100 iflag |= ISTRIP;
101 oflag |= OPOST;
102 }
103
104 tp->c_iflag = iflag;
105 tp->c_oflag = oflag;
106 tp->c_lflag = lflag;
107 tp->c_cflag = cflag;
108 }
109
110 void
111 sttysetflags(tp, flags)
112 struct termios *tp;
113 long flags;
114 {
115 register long iflag = tp->c_iflag;
116 register long oflag = tp->c_oflag;
117 register long lflag = tp->c_lflag;
118 register long cflag = tp->c_cflag;
119
120 if (flags & TANDEM)
121 iflag |= IXOFF;
122 if (flags & ECHO)
123 lflag |= ECHO;
124 if (flags & CRMOD) {
125 iflag |= ICRNL;
126 oflag |= ONLCR;
127 }
128 if (flags & XTABS)
129 oflag |= OXTABS;
130
131 if (flags & RAW) {
132 iflag &= IXOFF;
133 lflag &= ~(ISIG|ICANON|IEXTEN);
134 }
135
136 switch (flags & ANYP) {
137 case EVENP:
138 iflag |= INPCK;
139 cflag &= ~PARODD;
140 break;
141 case ODDP:
142 iflag |= INPCK;
143 cflag |= PARODD;
144 break;
145 }
146
147 if (flags & (RAW|LITOUT|PASS8)) {
148 cflag &= ~(CSIZE|PARENB);
149 cflag |= CS8;
150 if ((flags & (RAW|PASS8)) == 0)
151 iflag |= ISTRIP;
152 else
153 iflag &= ~ISTRIP;
154 if ((flags & (RAW|LITOUT)) == 0)
155 oflag |= OPOST;
156 else
157 oflag &= ~OPOST;
158 }
159
160 tp->c_iflag = iflag;
161 tp->c_oflag = oflag;
162 tp->c_lflag = lflag;
163 tp->c_cflag = cflag;
164 }
165
166 void
167 sttyclearlflags(tp, flags)
168 struct termios *tp;
169 long flags;
170 {
171 register long iflag = tp->c_iflag;
172 register long oflag = tp->c_oflag;
173 register long lflag = tp->c_lflag;
174 register long cflag = tp->c_cflag;
175
176 /* Nothing we can do with CRTBS. */
177 if (flags & PRTERA)
178 lflag &= ~ECHOPRT;
179 if (flags & CRTERA)
180 lflag &= ~ECHOE;
181 /* Nothing we can do with TILDE. */
182 if (flags & MDMBUF)
183 cflag &= ~MDMBUF;
184 if (flags & NOHANG)
185 cflag |= HUPCL;
186 if (flags & CRTKIL)
187 lflag &= ~ECHOKE;
188 if (flags & CTLECH)
189 lflag &= ~ECHOCTL;
190 if ((flags & DECCTQ) == 0)
191 iflag &= ~IXANY;
192 lflag &= ~(flags&(TOSTOP|FLUSHO|PENDIN|NOFLSH));
193
194 if (flags & (RAW|LITOUT|PASS8)) {
195 cflag &= ~CSIZE;
196 cflag |= CS7|PARENB;
197 iflag |= ISTRIP;
198 oflag |= OPOST;
199 }
200
201 tp->c_iflag = iflag;
202 tp->c_oflag = oflag;
203 tp->c_lflag = lflag;
204 tp->c_cflag = cflag;
205 }
206
207 void
208 sttysetlflags(tp, flags)
209 struct termios *tp;
210 long flags;
211 {
212 register long iflag = tp->c_iflag;
213 register long oflag = tp->c_oflag;
214 register long lflag = tp->c_lflag;
215 register long cflag = tp->c_cflag;
216
217 /* Nothing we can do with CRTBS. */
218 if (flags & PRTERA)
219 lflag |= ECHOPRT;
220 if (flags & CRTERA)
221 lflag |= ECHOE;
222 /* Nothing we can do with TILDE. */
223 if (flags & MDMBUF)
224 cflag |= MDMBUF;
225 if (flags & NOHANG)
226 cflag &= ~HUPCL;
227 if (flags & CRTKIL)
228 lflag |= ECHOKE;
229 if (flags & CTLECH)
230 lflag |= ECHOCTL;
231 if ((flags & DECCTQ) == 0)
232 iflag |= IXANY;
233 lflag &= ~(TOSTOP|FLUSHO|PENDIN|NOFLSH);
234 lflag |= flags&(TOSTOP|FLUSHO|PENDIN|NOFLSH);
235
236 if (flags & (RAW|LITOUT|PASS8)) {
237 cflag &= ~(CSIZE|PARENB);
238 cflag |= CS8;
239 if ((flags & (RAW|PASS8)) == 0)
240 iflag |= ISTRIP;
241 else
242 iflag &= ~ISTRIP;
243 if ((flags & (RAW|LITOUT)) == 0)
244 oflag |= OPOST;
245 else
246 oflag &= ~OPOST;
247 }
248
249 tp->c_iflag = iflag;
250 tp->c_oflag = oflag;
251 tp->c_lflag = lflag;
252 tp->c_cflag = cflag;
253 }
254