2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * Copyright (c) 1983 Regents of the University of California.
8 * All rights reserved. The Berkeley software License Agreement
9 * specifies the terms and conditions for redistribution.
12 #pragma ident "%Z%%M% %I% %E% SMI"
15 * Stolen from ucb/lpr/printjob.c
21 static struct termios termios_set
;
22 static struct termios termios_clear
;
24 static int parse_modes(char *modes
);
25 static void setty(int);
32 if (parse_modes(modes
))
43 static struct mds cmodes
[] = {
44 "-parity", CS8
, PARENB
|CSIZE
,
45 "-evenp", CS8
, PARENB
|CSIZE
,
46 "-oddp", CS8
, PARENB
|PARODD
|CSIZE
,
47 "parity", PARENB
|CS7
, PARODD
|CSIZE
,
48 "evenp", PARENB
|CS7
, PARODD
|CSIZE
,
49 "oddp", PARENB
|PARODD
|CS7
, CSIZE
,
70 #if 0 /* this bit isn't supported */
77 #define CRTSCTS 0x80000000
79 "crtscts", CRTSCTS
, 0,
80 "-crtscts", 0, CRTSCTS
,
82 #define CRTSXOFF 0x40000000
84 "crtsxoff", CRTSXOFF
, 0,
85 "-crtsxoff", 0, CRTSXOFF
,
86 "litout", CS8
, (CSIZE
|PARENB
),
87 "-litout", (CS7
|PARENB
), CSIZE
,
88 "pass8", CS8
, (CSIZE
|PARENB
),
89 "-pass8", (CS7
|PARENB
), CSIZE
,
90 "raw", CS8
, (CSIZE
|PARENB
),
91 "-raw", (CS7
|PARENB
), CSIZE
,
92 "cooked", (CS7
|PARENB
), CSIZE
,
93 "sane", (CS7
|PARENB
|CREAD
), (CSIZE
|PARODD
|CLOCAL
),
97 static struct mds imodes
[] = {
101 "-brkint", 0, BRKINT
,
103 "-ignpar", 0, IGNPAR
,
105 "-parmrk", 0, PARMRK
,
109 "-istrip", 0, ISTRIP
,
116 "-nl", ICRNL
, (INLCR
|IGNCR
),
129 "-decctlq", IXANY
, 0,
134 "imaxbel", IMAXBEL
, 0,
135 "-imaxbel", 0, IMAXBEL
,
138 "raw", 0, (unsigned long)-1,
139 "-raw", (BRKINT
|IGNPAR
|ISTRIP
|ICRNL
|IXON
|IMAXBEL
), 0,
140 "cooked", (BRKINT
|IGNPAR
|ISTRIP
|ICRNL
|IXON
), 0,
141 "sane", (BRKINT
|IGNPAR
|ISTRIP
|ICRNL
|IXON
|IMAXBEL
),
142 (IGNBRK
|PARMRK
|INPCK
|INLCR
|IGNCR
|IUCLC
|IXOFF
),
146 static struct mds lmodes
[] = {
152 "-iexten", 0, IEXTEN
,
154 "-icanon", 0, ICANON
,
156 "-cbreak", ICANON
, 0,
167 "crterase", ECHOE
, 0,
168 "-crterase", 0, ECHOE
,
174 "-echonl", 0, ECHONL
,
176 "-noflsh", 0, NOFLSH
,
178 "-tostop", 0, TOSTOP
,
179 "echoctl", ECHOCTL
, 0,
180 "-echoctl", 0, ECHOCTL
,
181 "ctlecho", ECHOCTL
, 0,
182 "-ctlecho", 0, ECHOCTL
,
183 "echoprt", ECHOPRT
, 0,
184 "-echoprt", 0, ECHOPRT
,
185 "prterase", ECHOPRT
, 0,
186 "-prterase", 0, ECHOPRT
,
188 "-echoke", 0, ECHOKE
,
189 "crtkill", ECHOKE
, 0,
190 "-crtkill", 0, ECHOKE
,
191 #if 0 /* this bit isn't supported yet */
192 "defecho", DEFECHO
, 0,
193 "-defecho", 0, DEFECHO
,
195 "raw", 0, (ISIG
|ICANON
|XCASE
|IEXTEN
),
196 "-raw", (ISIG
|ICANON
|IEXTEN
), 0,
197 "cooked", (ISIG
|ICANON
), 0,
198 "sane", (ISIG
|ICANON
|ECHO
|ECHOE
|ECHOK
|ECHOCTL
|ECHOKE
),
199 (XCASE
|ECHOPRT
|ECHONL
|NOFLSH
),
203 static struct mds omodes
[] = {
216 "-nl", ONLCR
, (OCRNL
|ONLRET
),
223 "-onlret", 0, ONLRET
,
224 "fill", OFILL
, OFDEL
,
225 "-fill", 0, OFILL
|OFDEL
,
226 "nul-fill", OFILL
, OFDEL
,
227 "del-fill", OFILL
|OFDEL
, 0,
236 "tab0", TAB0
, TABDLY
,
237 "tabs", TAB0
, TABDLY
,
238 "tab1", TAB1
, TABDLY
,
239 "tab2", TAB2
, TABDLY
,
240 "-tabs", XTABS
, TABDLY
,
241 "tab3", XTABS
, TABDLY
,
250 #if 0 /* these bits aren't supported yet */
251 "pageout", PAGEOUT
, 0,
252 "-pageout", 0, PAGEOUT
,
261 "33", CR1
, (CRDLY
|TABDLY
|NLDLY
|FFDLY
|VTDLY
|BSDLY
),
262 "tty33", CR1
, (CRDLY
|TABDLY
|NLDLY
|FFDLY
|VTDLY
|BSDLY
),
263 "tn", CR1
, (CRDLY
|TABDLY
|NLDLY
|FFDLY
|VTDLY
|BSDLY
),
264 "tn300", CR1
, (CRDLY
|TABDLY
|NLDLY
|FFDLY
|VTDLY
|BSDLY
),
265 "ti", CR2
, (CRDLY
|TABDLY
|NLDLY
|FFDLY
|VTDLY
|BSDLY
),
266 "ti700", CR2
, (CRDLY
|TABDLY
|NLDLY
|FFDLY
|VTDLY
|BSDLY
),
267 "05", NL1
, (CRDLY
|TABDLY
|NLDLY
|FFDLY
|VTDLY
|BSDLY
),
268 "vt05", NL1
, (CRDLY
|TABDLY
|NLDLY
|FFDLY
|VTDLY
|BSDLY
),
269 "tek", FF1
, (CRDLY
|TABDLY
|NLDLY
|FFDLY
|VTDLY
|BSDLY
),
270 "37", (FF1
|VT1
|CR2
|TAB1
|NL1
), (NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
),
271 "tty37", (FF1
|VT1
|CR2
|TAB1
|NL1
), (NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
),
272 "sane", (OPOST
|ONLCR
), (OLCUC
|OCRNL
|ONOCR
|ONLRET
|OFILL
|OFDEL
|
273 NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
),
278 * Parse a set of modes.
288 termios_clear
.c_iflag
= 0;
289 termios_clear
.c_oflag
= 0;
290 termios_clear
.c_cflag
= 0;
291 termios_clear
.c_lflag
= 0;
292 termios_set
.c_iflag
= 0;
293 termios_set
.c_oflag
= 0;
294 termios_set
.c_cflag
= 0;
295 termios_set
.c_lflag
= 0;
297 curtoken
= strtok(modes
, ",");
298 while (curtoken
!= NULL
) {
300 for (i
= 0; imodes
[i
].string
!= NULL
; i
++) {
301 if (strcmp(curtoken
, imodes
[i
].string
) == 0) {
303 termios_clear
.c_iflag
|= imodes
[i
].reset
;
304 termios_set
.c_iflag
|= imodes
[i
].set
;
307 for (i
= 0; omodes
[i
].string
!= NULL
; i
++) {
308 if (strcmp(curtoken
, omodes
[i
].string
) == 0) {
310 termios_clear
.c_oflag
|= omodes
[i
].reset
;
311 termios_set
.c_oflag
|= omodes
[i
].set
;
314 for (i
= 0; cmodes
[i
].string
!= NULL
; i
++) {
315 if (strcmp(curtoken
, cmodes
[i
].string
) == 0) {
317 termios_clear
.c_cflag
|= cmodes
[i
].reset
;
318 termios_set
.c_cflag
|= cmodes
[i
].set
;
321 for (i
= 0; lmodes
[i
].string
!= NULL
; i
++) {
322 if (strcmp(curtoken
, lmodes
[i
].string
) == 0) {
324 termios_clear
.c_lflag
|= lmodes
[i
].reset
;
325 termios_set
.c_lflag
|= lmodes
[i
].set
;
329 CDEBUG(5, "unknown mode %s in STTY= string", curtoken
);
332 curtoken
= strtok((char *)NULL
, ",");
343 struct termios termios
;
345 if ((*Ioctl
)(fd
, TCGETS
, &termios
) < 0) {
346 CDEBUG(5, "ioctl(TCGETS): %d", errno
);
350 termios
.c_iflag
&= ~termios_clear
.c_iflag
;
351 termios
.c_iflag
|= termios_set
.c_iflag
;
352 termios
.c_oflag
&= ~termios_clear
.c_oflag
;
353 termios
.c_oflag
|= termios_set
.c_oflag
;
354 termios
.c_cflag
&= ~termios_clear
.c_cflag
;
355 termios
.c_cflag
|= termios_set
.c_cflag
;
356 termios
.c_lflag
&= ~termios_clear
.c_lflag
;
357 termios
.c_lflag
|= termios_set
.c_lflag
;
359 if ((*Ioctl
)(fd
, TCSETSF
, &termios
) < 0) {
360 CDEBUG(5, "ioctl(TCSETSF): %d", errno
);