xref: /titanic_52/usr/src/cmd/bnu/setmode.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1988,1989,1999 by Sun Microsystems, Inc.
3*7c478bd9Sstevel@tonic-gate  * All rights reserved.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate 
6*7c478bd9Sstevel@tonic-gate /*
7*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1983 Regents of the University of California.
8*7c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
9*7c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
10*7c478bd9Sstevel@tonic-gate  */
11*7c478bd9Sstevel@tonic-gate 
12*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
13*7c478bd9Sstevel@tonic-gate 
14*7c478bd9Sstevel@tonic-gate /*
15*7c478bd9Sstevel@tonic-gate  * Stolen from ucb/lpr/printjob.c
16*7c478bd9Sstevel@tonic-gate  */
17*7c478bd9Sstevel@tonic-gate 
18*7c478bd9Sstevel@tonic-gate #include <string.h>
19*7c478bd9Sstevel@tonic-gate #include "uucp.h"
20*7c478bd9Sstevel@tonic-gate 
21*7c478bd9Sstevel@tonic-gate static struct termios termios_set;
22*7c478bd9Sstevel@tonic-gate static struct termios termios_clear;
23*7c478bd9Sstevel@tonic-gate 
24*7c478bd9Sstevel@tonic-gate setmode(modes, fd)
25*7c478bd9Sstevel@tonic-gate 	char *modes;
26*7c478bd9Sstevel@tonic-gate 	int fd;
27*7c478bd9Sstevel@tonic-gate {
28*7c478bd9Sstevel@tonic-gate 	if (parse_modes(modes))
29*7c478bd9Sstevel@tonic-gate 		setty(fd);
30*7c478bd9Sstevel@tonic-gate }
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate struct mds {
33*7c478bd9Sstevel@tonic-gate 	char	*string;
34*7c478bd9Sstevel@tonic-gate 	unsigned long	set;
35*7c478bd9Sstevel@tonic-gate 	unsigned long	reset;
36*7c478bd9Sstevel@tonic-gate };
37*7c478bd9Sstevel@tonic-gate 						/* Control Modes */
38*7c478bd9Sstevel@tonic-gate static struct mds cmodes[] = {
39*7c478bd9Sstevel@tonic-gate 	"-parity", CS8, PARENB|CSIZE,
40*7c478bd9Sstevel@tonic-gate 	"-evenp", CS8, PARENB|CSIZE,
41*7c478bd9Sstevel@tonic-gate 	"-oddp", CS8, PARENB|PARODD|CSIZE,
42*7c478bd9Sstevel@tonic-gate 	"parity", PARENB|CS7, PARODD|CSIZE,
43*7c478bd9Sstevel@tonic-gate 	"evenp", PARENB|CS7, PARODD|CSIZE,
44*7c478bd9Sstevel@tonic-gate 	"oddp", PARENB|PARODD|CS7, CSIZE,
45*7c478bd9Sstevel@tonic-gate 	"parenb", PARENB, 0,
46*7c478bd9Sstevel@tonic-gate 	"-parenb", 0, PARENB,
47*7c478bd9Sstevel@tonic-gate 	"parodd", PARODD, 0,
48*7c478bd9Sstevel@tonic-gate 	"-parodd", 0, PARODD,
49*7c478bd9Sstevel@tonic-gate 	"cs8", CS8, CSIZE,
50*7c478bd9Sstevel@tonic-gate 	"cs7", CS7, CSIZE,
51*7c478bd9Sstevel@tonic-gate 	"cs6", CS6, CSIZE,
52*7c478bd9Sstevel@tonic-gate 	"cs5", CS5, CSIZE,
53*7c478bd9Sstevel@tonic-gate 	"cstopb", CSTOPB, 0,
54*7c478bd9Sstevel@tonic-gate 	"-cstopb", 0, CSTOPB,
55*7c478bd9Sstevel@tonic-gate 	"stopb", CSTOPB, 0,
56*7c478bd9Sstevel@tonic-gate 	"-stopb", 0, CSTOPB,
57*7c478bd9Sstevel@tonic-gate 	"hupcl", HUPCL, 0,
58*7c478bd9Sstevel@tonic-gate 	"hup", HUPCL, 0,
59*7c478bd9Sstevel@tonic-gate 	"-hupcl", 0, HUPCL,
60*7c478bd9Sstevel@tonic-gate 	"-hup", 0, HUPCL,
61*7c478bd9Sstevel@tonic-gate 	"clocal", CLOCAL, 0,
62*7c478bd9Sstevel@tonic-gate 	"-clocal", 0, CLOCAL,
63*7c478bd9Sstevel@tonic-gate 	"nohang", CLOCAL, 0,
64*7c478bd9Sstevel@tonic-gate 	"-nohang", 0, CLOCAL,
65*7c478bd9Sstevel@tonic-gate #if 0		/* this bit isn't supported */
66*7c478bd9Sstevel@tonic-gate 	"loblk", LOBLK, 0,
67*7c478bd9Sstevel@tonic-gate 	"-loblk", 0, LOBLK,
68*7c478bd9Sstevel@tonic-gate #endif
69*7c478bd9Sstevel@tonic-gate 	"cread", CREAD, 0,
70*7c478bd9Sstevel@tonic-gate 	"-cread", 0, CREAD,
71*7c478bd9Sstevel@tonic-gate #ifndef CRTSCTS
72*7c478bd9Sstevel@tonic-gate #define	CRTSCTS	0x80000000
73*7c478bd9Sstevel@tonic-gate #endif
74*7c478bd9Sstevel@tonic-gate 	"crtscts", CRTSCTS, 0,
75*7c478bd9Sstevel@tonic-gate 	"-crtscts", 0, CRTSCTS,
76*7c478bd9Sstevel@tonic-gate #ifndef CRTSXOFF
77*7c478bd9Sstevel@tonic-gate #define	CRTSXOFF 0x40000000
78*7c478bd9Sstevel@tonic-gate #endif
79*7c478bd9Sstevel@tonic-gate 	"crtsxoff", CRTSXOFF, 0,
80*7c478bd9Sstevel@tonic-gate 	"-crtsxoff", 0, CRTSXOFF,
81*7c478bd9Sstevel@tonic-gate 	"litout", CS8, (CSIZE|PARENB),
82*7c478bd9Sstevel@tonic-gate 	"-litout", (CS7|PARENB), CSIZE,
83*7c478bd9Sstevel@tonic-gate 	"pass8", CS8, (CSIZE|PARENB),
84*7c478bd9Sstevel@tonic-gate 	"-pass8", (CS7|PARENB), CSIZE,
85*7c478bd9Sstevel@tonic-gate 	"raw", CS8, (CSIZE|PARENB),
86*7c478bd9Sstevel@tonic-gate 	"-raw", (CS7|PARENB), CSIZE,
87*7c478bd9Sstevel@tonic-gate 	"cooked", (CS7|PARENB), CSIZE,
88*7c478bd9Sstevel@tonic-gate 	"sane", (CS7|PARENB|CREAD), (CSIZE|PARODD|CLOCAL),
89*7c478bd9Sstevel@tonic-gate 	0
90*7c478bd9Sstevel@tonic-gate };
91*7c478bd9Sstevel@tonic-gate 						/* Input Modes */
92*7c478bd9Sstevel@tonic-gate static struct mds imodes[] = {
93*7c478bd9Sstevel@tonic-gate 	"ignbrk", IGNBRK, 0,
94*7c478bd9Sstevel@tonic-gate 	"-ignbrk", 0, IGNBRK,
95*7c478bd9Sstevel@tonic-gate 	"brkint", BRKINT, 0,
96*7c478bd9Sstevel@tonic-gate 	"-brkint", 0, BRKINT,
97*7c478bd9Sstevel@tonic-gate 	"ignpar", IGNPAR, 0,
98*7c478bd9Sstevel@tonic-gate 	"-ignpar", 0, IGNPAR,
99*7c478bd9Sstevel@tonic-gate 	"parmrk", PARMRK, 0,
100*7c478bd9Sstevel@tonic-gate 	"-parmrk", 0, PARMRK,
101*7c478bd9Sstevel@tonic-gate 	"inpck", INPCK, 0,
102*7c478bd9Sstevel@tonic-gate 	"-inpck", 0, INPCK,
103*7c478bd9Sstevel@tonic-gate 	"istrip", ISTRIP, 0,
104*7c478bd9Sstevel@tonic-gate 	"-istrip", 0, ISTRIP,
105*7c478bd9Sstevel@tonic-gate 	"inlcr", INLCR, 0,
106*7c478bd9Sstevel@tonic-gate 	"-inlcr", 0, INLCR,
107*7c478bd9Sstevel@tonic-gate 	"igncr", IGNCR, 0,
108*7c478bd9Sstevel@tonic-gate 	"-igncr", 0, IGNCR,
109*7c478bd9Sstevel@tonic-gate 	"icrnl", ICRNL, 0,
110*7c478bd9Sstevel@tonic-gate 	"-icrnl", 0, ICRNL,
111*7c478bd9Sstevel@tonic-gate 	"-nl", ICRNL, (INLCR|IGNCR),
112*7c478bd9Sstevel@tonic-gate 	"nl", 0, ICRNL,
113*7c478bd9Sstevel@tonic-gate 	"iuclc", IUCLC, 0,
114*7c478bd9Sstevel@tonic-gate 	"-iuclc", 0, IUCLC,
115*7c478bd9Sstevel@tonic-gate 	"lcase", IUCLC, 0,
116*7c478bd9Sstevel@tonic-gate 	"-lcase", 0, IUCLC,
117*7c478bd9Sstevel@tonic-gate 	"LCASE", IUCLC, 0,
118*7c478bd9Sstevel@tonic-gate 	"-LCASE", 0, IUCLC,
119*7c478bd9Sstevel@tonic-gate 	"ixon", IXON, 0,
120*7c478bd9Sstevel@tonic-gate 	"-ixon", 0, IXON,
121*7c478bd9Sstevel@tonic-gate 	"ixany", IXANY, 0,
122*7c478bd9Sstevel@tonic-gate 	"-ixany", 0, IXANY,
123*7c478bd9Sstevel@tonic-gate 	"decctlq", 0, IXANY,
124*7c478bd9Sstevel@tonic-gate 	"-decctlq", IXANY, 0,
125*7c478bd9Sstevel@tonic-gate 	"ixoff", IXOFF, 0,
126*7c478bd9Sstevel@tonic-gate 	"-ixoff", 0, IXOFF,
127*7c478bd9Sstevel@tonic-gate 	"tandem", IXOFF, 0,
128*7c478bd9Sstevel@tonic-gate 	"-tandem", 0, IXOFF,
129*7c478bd9Sstevel@tonic-gate 	"imaxbel", IMAXBEL, 0,
130*7c478bd9Sstevel@tonic-gate 	"-imaxbel", 0, IMAXBEL,
131*7c478bd9Sstevel@tonic-gate 	"pass8", 0, ISTRIP,
132*7c478bd9Sstevel@tonic-gate 	"-pass8", ISTRIP, 0,
133*7c478bd9Sstevel@tonic-gate 	"raw", 0, (unsigned long)-1,
134*7c478bd9Sstevel@tonic-gate 	"-raw", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON|IMAXBEL), 0,
135*7c478bd9Sstevel@tonic-gate 	"cooked", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON), 0,
136*7c478bd9Sstevel@tonic-gate 	"sane", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON|IMAXBEL),
137*7c478bd9Sstevel@tonic-gate 		(IGNBRK|PARMRK|INPCK|INLCR|IGNCR|IUCLC|IXOFF),
138*7c478bd9Sstevel@tonic-gate 	0
139*7c478bd9Sstevel@tonic-gate };
140*7c478bd9Sstevel@tonic-gate 						/* Local Modes */
141*7c478bd9Sstevel@tonic-gate static struct mds lmodes[] = {
142*7c478bd9Sstevel@tonic-gate 	"isig", ISIG, 0,
143*7c478bd9Sstevel@tonic-gate 	"-isig", 0, ISIG,
144*7c478bd9Sstevel@tonic-gate 	"noisig", 0, ISIG,
145*7c478bd9Sstevel@tonic-gate 	"-noisig", ISIG, 0,
146*7c478bd9Sstevel@tonic-gate 	"iexten", IEXTEN, 0,
147*7c478bd9Sstevel@tonic-gate 	"-iexten", 0, IEXTEN,
148*7c478bd9Sstevel@tonic-gate 	"icanon", ICANON, 0,
149*7c478bd9Sstevel@tonic-gate 	"-icanon", 0, ICANON,
150*7c478bd9Sstevel@tonic-gate 	"cbreak", 0, ICANON,
151*7c478bd9Sstevel@tonic-gate 	"-cbreak", ICANON, 0,
152*7c478bd9Sstevel@tonic-gate 	"xcase", XCASE, 0,
153*7c478bd9Sstevel@tonic-gate 	"-xcase", 0, XCASE,
154*7c478bd9Sstevel@tonic-gate 	"lcase", XCASE, 0,
155*7c478bd9Sstevel@tonic-gate 	"-lcase", 0, XCASE,
156*7c478bd9Sstevel@tonic-gate 	"LCASE", XCASE, 0,
157*7c478bd9Sstevel@tonic-gate 	"-LCASE", 0, XCASE,
158*7c478bd9Sstevel@tonic-gate 	"echo", ECHO, 0,
159*7c478bd9Sstevel@tonic-gate 	"-echo", 0, ECHO,
160*7c478bd9Sstevel@tonic-gate 	"echoe", ECHOE, 0,
161*7c478bd9Sstevel@tonic-gate 	"-echoe", 0, ECHOE,
162*7c478bd9Sstevel@tonic-gate 	"crterase", ECHOE, 0,
163*7c478bd9Sstevel@tonic-gate 	"-crterase", 0, ECHOE,
164*7c478bd9Sstevel@tonic-gate 	"echok", ECHOK, 0,
165*7c478bd9Sstevel@tonic-gate 	"-echok", 0, ECHOK,
166*7c478bd9Sstevel@tonic-gate 	"lfkc", ECHOK, 0,
167*7c478bd9Sstevel@tonic-gate 	"-lfkc", 0, ECHOK,
168*7c478bd9Sstevel@tonic-gate 	"echonl", ECHONL, 0,
169*7c478bd9Sstevel@tonic-gate 	"-echonl", 0, ECHONL,
170*7c478bd9Sstevel@tonic-gate 	"noflsh", NOFLSH, 0,
171*7c478bd9Sstevel@tonic-gate 	"-noflsh", 0, NOFLSH,
172*7c478bd9Sstevel@tonic-gate 	"tostop", TOSTOP, 0,
173*7c478bd9Sstevel@tonic-gate 	"-tostop", 0, TOSTOP,
174*7c478bd9Sstevel@tonic-gate 	"echoctl", ECHOCTL, 0,
175*7c478bd9Sstevel@tonic-gate 	"-echoctl", 0, ECHOCTL,
176*7c478bd9Sstevel@tonic-gate 	"ctlecho", ECHOCTL, 0,
177*7c478bd9Sstevel@tonic-gate 	"-ctlecho", 0, ECHOCTL,
178*7c478bd9Sstevel@tonic-gate 	"echoprt", ECHOPRT, 0,
179*7c478bd9Sstevel@tonic-gate 	"-echoprt", 0, ECHOPRT,
180*7c478bd9Sstevel@tonic-gate 	"prterase", ECHOPRT, 0,
181*7c478bd9Sstevel@tonic-gate 	"-prterase", 0, ECHOPRT,
182*7c478bd9Sstevel@tonic-gate 	"echoke", ECHOKE, 0,
183*7c478bd9Sstevel@tonic-gate 	"-echoke", 0, ECHOKE,
184*7c478bd9Sstevel@tonic-gate 	"crtkill", ECHOKE, 0,
185*7c478bd9Sstevel@tonic-gate 	"-crtkill", 0, ECHOKE,
186*7c478bd9Sstevel@tonic-gate #if 0		/* this bit isn't supported yet */
187*7c478bd9Sstevel@tonic-gate 	"defecho", DEFECHO, 0,
188*7c478bd9Sstevel@tonic-gate 	"-defecho", 0, DEFECHO,
189*7c478bd9Sstevel@tonic-gate #endif
190*7c478bd9Sstevel@tonic-gate 	"raw", 0, (ISIG|ICANON|XCASE|IEXTEN),
191*7c478bd9Sstevel@tonic-gate 	"-raw", (ISIG|ICANON|IEXTEN), 0,
192*7c478bd9Sstevel@tonic-gate 	"cooked", (ISIG|ICANON), 0,
193*7c478bd9Sstevel@tonic-gate 	"sane", (ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE),
194*7c478bd9Sstevel@tonic-gate 		(XCASE|ECHOPRT|ECHONL|NOFLSH),
195*7c478bd9Sstevel@tonic-gate 	0,
196*7c478bd9Sstevel@tonic-gate };
197*7c478bd9Sstevel@tonic-gate 						/* Output Modes */
198*7c478bd9Sstevel@tonic-gate static struct mds omodes[] = {
199*7c478bd9Sstevel@tonic-gate 	"opost", OPOST, 0,
200*7c478bd9Sstevel@tonic-gate 	"-opost", 0, OPOST,
201*7c478bd9Sstevel@tonic-gate 	"nopost", 0, OPOST,
202*7c478bd9Sstevel@tonic-gate 	"-nopost", OPOST, 0,
203*7c478bd9Sstevel@tonic-gate 	"olcuc", OLCUC, 0,
204*7c478bd9Sstevel@tonic-gate 	"-olcuc", 0, OLCUC,
205*7c478bd9Sstevel@tonic-gate 	"lcase", OLCUC, 0,
206*7c478bd9Sstevel@tonic-gate 	"-lcase", 0, OLCUC,
207*7c478bd9Sstevel@tonic-gate 	"LCASE", OLCUC, 0,
208*7c478bd9Sstevel@tonic-gate 	"-LCASE", 0, OLCUC,
209*7c478bd9Sstevel@tonic-gate 	"onlcr", ONLCR, 0,
210*7c478bd9Sstevel@tonic-gate 	"-onlcr", 0, ONLCR,
211*7c478bd9Sstevel@tonic-gate 	"-nl", ONLCR, (OCRNL|ONLRET),
212*7c478bd9Sstevel@tonic-gate 	"nl", 0, ONLCR,
213*7c478bd9Sstevel@tonic-gate 	"ocrnl", OCRNL, 0,
214*7c478bd9Sstevel@tonic-gate 	"-ocrnl", 0, OCRNL,
215*7c478bd9Sstevel@tonic-gate 	"onocr", ONOCR, 0,
216*7c478bd9Sstevel@tonic-gate 	"-onocr", 0, ONOCR,
217*7c478bd9Sstevel@tonic-gate 	"onlret", ONLRET, 0,
218*7c478bd9Sstevel@tonic-gate 	"-onlret", 0, ONLRET,
219*7c478bd9Sstevel@tonic-gate 	"fill", OFILL, OFDEL,
220*7c478bd9Sstevel@tonic-gate 	"-fill", 0, OFILL|OFDEL,
221*7c478bd9Sstevel@tonic-gate 	"nul-fill", OFILL, OFDEL,
222*7c478bd9Sstevel@tonic-gate 	"del-fill", OFILL|OFDEL, 0,
223*7c478bd9Sstevel@tonic-gate 	"ofill", OFILL, 0,
224*7c478bd9Sstevel@tonic-gate 	"-ofill", 0, OFILL,
225*7c478bd9Sstevel@tonic-gate 	"ofdel", OFDEL, 0,
226*7c478bd9Sstevel@tonic-gate 	"-ofdel", 0, OFDEL,
227*7c478bd9Sstevel@tonic-gate 	"cr0", CR0, CRDLY,
228*7c478bd9Sstevel@tonic-gate 	"cr1", CR1, CRDLY,
229*7c478bd9Sstevel@tonic-gate 	"cr2", CR2, CRDLY,
230*7c478bd9Sstevel@tonic-gate 	"cr3", CR3, CRDLY,
231*7c478bd9Sstevel@tonic-gate 	"tab0", TAB0, TABDLY,
232*7c478bd9Sstevel@tonic-gate 	"tabs", TAB0, TABDLY,
233*7c478bd9Sstevel@tonic-gate 	"tab1", TAB1, TABDLY,
234*7c478bd9Sstevel@tonic-gate 	"tab2", TAB2, TABDLY,
235*7c478bd9Sstevel@tonic-gate 	"-tabs", XTABS, TABDLY,
236*7c478bd9Sstevel@tonic-gate 	"tab3", XTABS, TABDLY,
237*7c478bd9Sstevel@tonic-gate 	"nl0", NL0, NLDLY,
238*7c478bd9Sstevel@tonic-gate 	"nl1", NL1, NLDLY,
239*7c478bd9Sstevel@tonic-gate 	"ff0", FF0, FFDLY,
240*7c478bd9Sstevel@tonic-gate 	"ff1", FF1, FFDLY,
241*7c478bd9Sstevel@tonic-gate 	"vt0", VT0, VTDLY,
242*7c478bd9Sstevel@tonic-gate 	"vt1", VT1, VTDLY,
243*7c478bd9Sstevel@tonic-gate 	"bs0", BS0, BSDLY,
244*7c478bd9Sstevel@tonic-gate 	"bs1", BS1, BSDLY,
245*7c478bd9Sstevel@tonic-gate #if 0		/* these bits aren't supported yet */
246*7c478bd9Sstevel@tonic-gate 	"pageout", PAGEOUT, 0,
247*7c478bd9Sstevel@tonic-gate 	"-pageout", 0, PAGEOUT,
248*7c478bd9Sstevel@tonic-gate 	"wrap", WRAP, 0,
249*7c478bd9Sstevel@tonic-gate 	"-wrap", 0, WRAP,
250*7c478bd9Sstevel@tonic-gate #endif
251*7c478bd9Sstevel@tonic-gate 	"litout", 0, OPOST,
252*7c478bd9Sstevel@tonic-gate 	"-litout", OPOST, 0,
253*7c478bd9Sstevel@tonic-gate 	"raw", 0, OPOST,
254*7c478bd9Sstevel@tonic-gate 	"-raw", OPOST, 0,
255*7c478bd9Sstevel@tonic-gate 	"cooked", OPOST, 0,
256*7c478bd9Sstevel@tonic-gate 	"33", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
257*7c478bd9Sstevel@tonic-gate 	"tty33", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
258*7c478bd9Sstevel@tonic-gate 	"tn", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
259*7c478bd9Sstevel@tonic-gate 	"tn300", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
260*7c478bd9Sstevel@tonic-gate 	"ti", CR2, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
261*7c478bd9Sstevel@tonic-gate 	"ti700", CR2, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
262*7c478bd9Sstevel@tonic-gate 	"05", NL1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
263*7c478bd9Sstevel@tonic-gate 	"vt05", NL1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
264*7c478bd9Sstevel@tonic-gate 	"tek", FF1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
265*7c478bd9Sstevel@tonic-gate 	"37", (FF1|VT1|CR2|TAB1|NL1), (NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY),
266*7c478bd9Sstevel@tonic-gate 	"tty37", (FF1|VT1|CR2|TAB1|NL1), (NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY),
267*7c478bd9Sstevel@tonic-gate 	"sane", (OPOST|ONLCR), (OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL|
268*7c478bd9Sstevel@tonic-gate 			NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY),
269*7c478bd9Sstevel@tonic-gate 	0,
270*7c478bd9Sstevel@tonic-gate };
271*7c478bd9Sstevel@tonic-gate 
272*7c478bd9Sstevel@tonic-gate /*
273*7c478bd9Sstevel@tonic-gate  * Parse a set of modes.
274*7c478bd9Sstevel@tonic-gate  */
275*7c478bd9Sstevel@tonic-gate static int
276*7c478bd9Sstevel@tonic-gate parse_modes(modes)
277*7c478bd9Sstevel@tonic-gate 	char *modes;
278*7c478bd9Sstevel@tonic-gate {
279*7c478bd9Sstevel@tonic-gate 	register char *curtoken;
280*7c478bd9Sstevel@tonic-gate 	register int match;
281*7c478bd9Sstevel@tonic-gate 	register int i;
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate 	termios_clear.c_iflag = 0;
284*7c478bd9Sstevel@tonic-gate 	termios_clear.c_oflag = 0;
285*7c478bd9Sstevel@tonic-gate 	termios_clear.c_cflag = 0;
286*7c478bd9Sstevel@tonic-gate 	termios_clear.c_lflag = 0;
287*7c478bd9Sstevel@tonic-gate 	termios_set.c_iflag = 0;
288*7c478bd9Sstevel@tonic-gate 	termios_set.c_oflag = 0;
289*7c478bd9Sstevel@tonic-gate 	termios_set.c_cflag = 0;
290*7c478bd9Sstevel@tonic-gate 	termios_set.c_lflag = 0;
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate 	curtoken = strtok(modes, ",");
293*7c478bd9Sstevel@tonic-gate 	while (curtoken != NULL) {
294*7c478bd9Sstevel@tonic-gate 		match = 0;
295*7c478bd9Sstevel@tonic-gate 		for (i = 0; imodes[i].string != NULL; i++) {
296*7c478bd9Sstevel@tonic-gate 			if (strcmp(curtoken, imodes[i].string) == 0) {
297*7c478bd9Sstevel@tonic-gate 				match++;
298*7c478bd9Sstevel@tonic-gate 				termios_clear.c_iflag |= imodes[i].reset;
299*7c478bd9Sstevel@tonic-gate 				termios_set.c_iflag |= imodes[i].set;
300*7c478bd9Sstevel@tonic-gate 			}
301*7c478bd9Sstevel@tonic-gate 		}
302*7c478bd9Sstevel@tonic-gate 		for (i = 0; omodes[i].string != NULL; i++) {
303*7c478bd9Sstevel@tonic-gate 			if (strcmp(curtoken, omodes[i].string) == 0) {
304*7c478bd9Sstevel@tonic-gate 				match++;
305*7c478bd9Sstevel@tonic-gate 				termios_clear.c_oflag |= omodes[i].reset;
306*7c478bd9Sstevel@tonic-gate 				termios_set.c_oflag |= omodes[i].set;
307*7c478bd9Sstevel@tonic-gate 			}
308*7c478bd9Sstevel@tonic-gate 		}
309*7c478bd9Sstevel@tonic-gate 		for (i = 0; cmodes[i].string != NULL; i++) {
310*7c478bd9Sstevel@tonic-gate 			if (strcmp(curtoken, cmodes[i].string) == 0) {
311*7c478bd9Sstevel@tonic-gate 				match++;
312*7c478bd9Sstevel@tonic-gate 				termios_clear.c_cflag |= cmodes[i].reset;
313*7c478bd9Sstevel@tonic-gate 				termios_set.c_cflag |= cmodes[i].set;
314*7c478bd9Sstevel@tonic-gate 			}
315*7c478bd9Sstevel@tonic-gate 		}
316*7c478bd9Sstevel@tonic-gate 		for (i = 0; lmodes[i].string != NULL; i++) {
317*7c478bd9Sstevel@tonic-gate 			if (strcmp(curtoken, lmodes[i].string) == 0) {
318*7c478bd9Sstevel@tonic-gate 				match++;
319*7c478bd9Sstevel@tonic-gate 				termios_clear.c_lflag |= lmodes[i].reset;
320*7c478bd9Sstevel@tonic-gate 				termios_set.c_lflag |= lmodes[i].set;
321*7c478bd9Sstevel@tonic-gate 			}
322*7c478bd9Sstevel@tonic-gate 		}
323*7c478bd9Sstevel@tonic-gate 		if (!match) {
324*7c478bd9Sstevel@tonic-gate 			CDEBUG(5, "unknown mode %s in STTY= string", curtoken);
325*7c478bd9Sstevel@tonic-gate 			return (0);
326*7c478bd9Sstevel@tonic-gate 		}
327*7c478bd9Sstevel@tonic-gate 		curtoken = strtok((char *)NULL, ",");
328*7c478bd9Sstevel@tonic-gate 	}
329*7c478bd9Sstevel@tonic-gate 	return (1);
330*7c478bd9Sstevel@tonic-gate }
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate /*
333*7c478bd9Sstevel@tonic-gate  * setup tty lines.
334*7c478bd9Sstevel@tonic-gate  */
335*7c478bd9Sstevel@tonic-gate static
336*7c478bd9Sstevel@tonic-gate setty(fd)
337*7c478bd9Sstevel@tonic-gate {
338*7c478bd9Sstevel@tonic-gate 	struct termios termios;
339*7c478bd9Sstevel@tonic-gate 
340*7c478bd9Sstevel@tonic-gate 	if ((*Ioctl)(fd, TCGETS, &termios) < 0) {
341*7c478bd9Sstevel@tonic-gate 		CDEBUG(5, "ioctl(TCGETS): %d", errno);
342*7c478bd9Sstevel@tonic-gate 		return;
343*7c478bd9Sstevel@tonic-gate 	}
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate 	termios.c_iflag &= ~termios_clear.c_iflag;
346*7c478bd9Sstevel@tonic-gate 	termios.c_iflag |= termios_set.c_iflag;
347*7c478bd9Sstevel@tonic-gate 	termios.c_oflag &= ~termios_clear.c_oflag;
348*7c478bd9Sstevel@tonic-gate 	termios.c_oflag |= termios_set.c_oflag;
349*7c478bd9Sstevel@tonic-gate 	termios.c_cflag &= ~termios_clear.c_cflag;
350*7c478bd9Sstevel@tonic-gate 	termios.c_cflag |= termios_set.c_cflag;
351*7c478bd9Sstevel@tonic-gate 	termios.c_lflag &= ~termios_clear.c_lflag;
352*7c478bd9Sstevel@tonic-gate 	termios.c_lflag |= termios_set.c_lflag;
353*7c478bd9Sstevel@tonic-gate 
354*7c478bd9Sstevel@tonic-gate 	if ((*Ioctl)(fd, TCSETSF, &termios) < 0) {
355*7c478bd9Sstevel@tonic-gate 		CDEBUG(5, "ioctl(TCSETSF): %d", errno);
356*7c478bd9Sstevel@tonic-gate 		return;
357*7c478bd9Sstevel@tonic-gate 	}
358*7c478bd9Sstevel@tonic-gate }
359