1 /* $NetBSD: ttcompat.c,v 1.11 2002/07/14 15:28:00 wiz Exp $ */
4 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * ttcompat.c -- convert sgtty flags to termios
34 * originally from /sys/kern/tty_compat.c
37 #include <sys/param.h>
38 #include <sys/types.h>
41 #include <sys/ioctl_compat.h>
52 /* Macros to clear/set/test flags. */
53 #define SET(t, f) (t) |= (f)
54 #define CLR(t, f) (t) &= ~(f)
55 #define ISSET(t, f) ((t) & (f))
57 static int sttygetoflags(struct termios
*);
58 static void sttysetoflags(struct termios
*, int);
61 sttygetoflags(struct termios
*tp
)
63 tcflag_t iflag
= tp
->c_iflag
;
64 tcflag_t lflag
= tp
->c_lflag
;
65 tcflag_t oflag
= tp
->c_oflag
;
66 tcflag_t cflag
= tp
->c_cflag
;
69 if (ISSET(cflag
, PARENB
)) {
70 if (ISSET(iflag
, INPCK
)) {
71 if (ISSET(cflag
, PARODD
))
76 SET(flags
, EVENP
|ODDP
);
78 if (ISSET(cflag
, CSIZE
) == CS8
) {
79 if (!ISSET(iflag
, ISTRIP
))
81 if (!ISSET(oflag
, OPOST
))
85 if (!ISSET(lflag
, ICANON
)) {
87 if (ISSET(iflag
, IXON
) || ISSET(lflag
, ISIG
|IEXTEN
) ||
98 sttysetoflags(struct termios
*tp
, int flags
)
100 tcflag_t iflag
= tp
->c_iflag
;
101 tcflag_t oflag
= tp
->c_oflag
;
102 tcflag_t lflag
= tp
->c_lflag
;
103 tcflag_t cflag
= tp
->c_cflag
;
105 if (ISSET(flags
, RAW
)) {
107 CLR(lflag
, ISIG
|ICANON
|IEXTEN
);
110 SET(iflag
, BRKINT
|IXON
|IMAXBEL
);
111 SET(lflag
, ISIG
|IEXTEN
);
112 if (ISSET(flags
, CBREAK
))
116 switch (ISSET(flags
, ANYP
)) {
137 if (ISSET(flags
, RAW
|LITOUT
|PASS8
)) {
140 if (!ISSET(flags
, RAW
|PASS8
))
144 if (!ISSET(flags
, RAW
|LITOUT
))
162 sttyclearflags(struct termios
*tp
, int flags
)
164 tcflag_t iflag
= tp
->c_iflag
;
165 tcflag_t oflag
= tp
->c_oflag
;
166 tcflag_t lflag
= tp
->c_lflag
;
167 tcflag_t cflag
= tp
->c_cflag
;
168 int oflags
= sttygetoflags(tp
) & ~flags
;
170 if (ISSET(flags
, TANDEM
))
172 if (ISSET(flags
, ECHO
))
174 if (ISSET(flags
, CRMOD
)) {
178 if (ISSET(flags
, XTABS
))
187 sttysetoflags(tp
, oflags
);
191 sttysetflags(struct termios
*tp
, int flags
)
193 tcflag_t iflag
= tp
->c_iflag
;
194 tcflag_t oflag
= tp
->c_oflag
;
195 tcflag_t lflag
= tp
->c_lflag
;
196 tcflag_t cflag
= tp
->c_cflag
;
197 int oflags
= sttygetoflags(tp
) | flags
;
199 if (ISSET(flags
, TANDEM
))
201 if (ISSET(flags
, ECHO
))
203 if (ISSET(flags
, CRMOD
)) {
207 if (ISSET(flags
, XTABS
))
215 sttysetoflags(tp
, oflags
);
219 sttyclearlflags(struct termios
*tp
, int flags
)
221 tcflag_t iflag
= tp
->c_iflag
;
222 tcflag_t oflag
= tp
->c_oflag
;
223 tcflag_t lflag
= tp
->c_lflag
;
224 tcflag_t cflag
= tp
->c_cflag
;
225 int oflags
= sttygetoflags(tp
) & ~flags
;
227 /* Nothing we can do with CRTBS. */
228 if (ISSET(flags
, PRTERA
))
230 if (ISSET(flags
, CRTERA
))
232 /* Nothing we can do with TILDE. */
233 if (ISSET(flags
, MDMBUF
))
235 if (ISSET(flags
, NOHANG
))
237 if (ISSET(flags
, CRTKIL
))
239 if (ISSET(flags
, CTLECH
))
241 if (ISSET(flags
, DECCTQ
))
243 CLR(lflag
, ISSET(flags
, TOSTOP
|FLUSHO
|PENDIN
|NOFLSH
));
250 sttysetoflags(tp
, oflags
);
254 sttysetlflags(struct termios
*tp
, int flags
)
256 tcflag_t iflag
= tp
->c_iflag
;
257 tcflag_t oflag
= tp
->c_oflag
;
258 tcflag_t lflag
= tp
->c_lflag
;
259 tcflag_t cflag
= tp
->c_cflag
;
260 int oflags
= sttygetoflags(tp
) | flags
;
262 /* Nothing we can do with CRTBS. */
263 if (ISSET(flags
, PRTERA
))
265 if (ISSET(flags
, CRTERA
))
267 /* Nothing we can do with TILDE. */
268 if (ISSET(flags
, MDMBUF
))
270 if (ISSET(flags
, NOHANG
))
272 if (ISSET(flags
, CRTKIL
))
274 if (ISSET(flags
, CTLECH
))
276 if (ISSET(flags
, DECCTQ
))
278 SET(lflag
, ISSET(flags
, TOSTOP
|FLUSHO
|PENDIN
|NOFLSH
));
285 sttysetoflags(tp
, oflags
);