xref: /original-bsd/bin/stty/modes.c (revision 13deef58)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)modes.c	5.5 (Berkeley) 07/10/92";
10 #endif /* not lint */
11 
12 #include <sys/types.h>
13 #include <stddef.h>
14 #include <string.h>
15 #include "stty.h"
16 
17 struct modes {
18 	char *name;
19 	long set;
20 	long unset;
21 };
22 
23 /*
24  * The code in optlist() depends on minus options following regular
25  * options, i.e. "foo" must immediately precede "-foo".
26  */
27 struct modes cmodes[] = {
28 	"cs5",		CS5, CSIZE,
29 	"cs6",		CS6, CSIZE,
30 	"cs7",		CS7, CSIZE,
31 	"cs8",		CS8, CSIZE,
32 	"cstopb",	CSTOPB, 0,
33 	"-cstopb",	0, CSTOPB,
34 	"cread",	CREAD, 0,
35 	"-cread",	0, CREAD,
36 	"parenb",	PARENB, 0,
37 	"-parenb",	0, PARENB,
38 	"parodd",	PARODD, 0,
39 	"-parodd",	0, PARODD,
40 	"parity",	PARENB | CS7, PARODD | CSIZE,
41 	"-parity",	CS8, PARODD | PARENB | CSIZE,
42 	"evenp",	PARENB | CS7, PARODD | CSIZE,
43 	"-evenp",	CS8, PARODD | PARENB | CSIZE,
44 	"oddp",		PARENB | CS7 | PARODD, CSIZE,
45 	"-oddp",	CS8, PARODD | PARENB | CSIZE,
46 	"pass8",	CS8, PARODD | PARENB | CSIZE,
47 	"-pass8",	PARENB | CS7, PARODD | CSIZE,
48 	"hupcl",	HUPCL, 0,
49 	"-hupcl",	0, HUPCL,
50 	"hup",		HUPCL, 0,
51 	"-hup",		0, HUPCL,
52 	"clocal",	CLOCAL, 0,
53 	"-clocal",	0, CLOCAL,
54 	"crtscts",	CRTSCTS, 0,
55 	"-crtscts",	0, CRTSCTS,
56 	NULL
57 };
58 
59 struct modes imodes[] = {
60 	"ignbrk",	IGNBRK, 0,
61 	"-ignbrk",	0, IGNBRK,
62 	"brkint",	BRKINT, 0,
63 	"-brkint",	0, BRKINT,
64 	"ignpar",	IGNPAR, 0,
65 	"-ignpar",	0, IGNPAR,
66 	"parmrk",	PARMRK, 0,
67 	"-parmrk",	0, PARMRK,
68 	"inpck",	INPCK, 0,
69 	"-inpck",	0, INPCK,
70 	"istrip",	ISTRIP, 0,
71 	"-istrip",	0, ISTRIP,
72 	"inlcr",	INLCR, 0,
73 	"-inlcr",	0, INLCR,
74 	"igncr",	IGNCR, 0,
75 	"-igncr",	0, IGNCR,
76 	"icrnl",	ICRNL, 0,
77 	"-icrnl",	0, ICRNL,
78 	"ixon",		IXON, 0,
79 	"-ixon",	0, IXON,
80 	"flow",		IXON, 0,
81 	"-flow",	0, IXON,
82 	"ixoff",	IXOFF, 0,
83 	"-ixoff",	0, IXOFF,
84 	"tandem",	IXOFF, 0,
85 	"-tandem",	0, IXOFF,
86 	"ixany",	IXANY, 0,
87 	"-ixany",	0, IXANY,
88 	"decctlq",	0, IXANY,
89 	"-decctlq",	IXANY, 0,
90 	"imaxbel",	IMAXBEL, 0,
91 	"-imaxbel",	0, IMAXBEL,
92 	NULL
93 };
94 
95 struct modes lmodes[] = {
96 	"echo",		ECHO, 0,
97 	"-echo",	0, ECHO,
98 	"echoe",	ECHOE, 0,
99 	"-echoe",	0, ECHOE,
100 	"crterase",	ECHOE, 0,
101 	"-crterase",	0, ECHOE,
102 	"crtbs",	ECHOE, 0,   /* crtbs not supported, close enough */
103 	"-crtbs",	0, ECHOE,
104 	"echok",	ECHOK, 0,
105 	"-echok",	0, ECHOK,
106 	"echoke",	ECHOKE, 0,
107 	"-echoke",	0, ECHOKE,
108 	"crtkill",	ECHOKE, 0,
109 	"-crtkill",	0, ECHOKE,
110 	"altwerase",	ALTWERASE, 0,
111 	"-altwerase",	0, ALTWERASE,
112 	"iexten",	IEXTEN, 0,
113 	"-iexten",	0, IEXTEN,
114 	"echonl",	ECHONL, 0,
115 	"-echonl",	0, ECHONL,
116 	"echoctl",	ECHOCTL, 0,
117 	"-echoctl",	0, ECHOCTL,
118 	"ctlecho",	ECHOCTL, 0,
119 	"-ctlecho",	0, ECHOCTL,
120 	"echoprt",	ECHOPRT, 0,
121 	"-echoprt",	0, ECHOPRT,
122 	"prterase",	ECHOPRT, 0,
123 	"-prterase",	0, ECHOPRT,
124 	"isig",		ISIG, 0,
125 	"-isig",	0, ISIG,
126 	"icanon",	ICANON, 0,
127 	"-icanon",	0, ICANON,
128 	"noflsh",	NOFLSH, 0,
129 	"-noflsh",	0, NOFLSH,
130 	"tostop",	TOSTOP, 0,
131 	"-tostop",	0, TOSTOP,
132 	"mdmbuf",	MDMBUF, 0,
133 	"-mdmbuf",	0, MDMBUF,
134 	"flusho",	FLUSHO, 0,
135 	"-flusho",	0, FLUSHO,
136 	"pendin",	PENDIN, 0,
137 	"-pendin",	0, PENDIN,
138 	"crt",		ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT,
139 	"-crt",		ECHOK, ECHOE|ECHOKE|ECHOCTL,
140 	"newcrt",	ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT,
141 	"-newcrt",	ECHOK, ECHOE|ECHOKE|ECHOCTL,
142 	"nokerninfo",	NOKERNINFO, 0,
143 	"-nokerninfo",	0, NOKERNINFO,
144 	"kerninfo",	0, NOKERNINFO,
145 	"-kerninfo",	NOKERNINFO, 0,
146 	NULL
147 };
148 
149 struct modes omodes[] = {
150 	"opost",	OPOST, 0,
151 	"-opost",	0, OPOST,
152 	"litout",	0, OPOST,
153 	"-litout",	OPOST, 0,
154 	"onlcr",	ONLCR, 0,
155 	"-onlcr",	0, ONLCR,
156 	"tabs",		0, OXTABS,	/* "preserve" tabs */
157 	"-tabs",	OXTABS, 0,
158 	"oxtabs",	OXTABS, 0,
159 	"-oxtabs",	0, OXTABS,
160 	NULL
161 };
162 
163 #define	CHK(s)	(*name == s[0] && !strcmp(name, s))
164 
165 msearch(argvp, ip)
166 	char ***argvp;
167 	struct info *ip;
168 {
169 	register struct modes *mp;
170 	register char *name;
171 
172 	name = **argvp;
173 
174 	for (mp = cmodes; mp->name; ++mp)
175 		if (CHK(mp->name)) {
176 			ip->t.c_cflag &= ~mp->unset;
177 			ip->t.c_cflag |= mp->set;
178 			ip->set = 1;
179 			return(1);
180 		}
181 	for (mp = imodes; mp->name; ++mp)
182 		if (CHK(mp->name)) {
183 			ip->t.c_iflag &= ~mp->unset;
184 			ip->t.c_iflag |= mp->set;
185 			ip->set = 1;
186 			return(1);
187 		}
188 	for (mp = lmodes; mp->name; ++mp)
189 		if (CHK(mp->name)) {
190 			ip->t.c_lflag &= ~mp->unset;
191 			ip->t.c_lflag |= mp->set;
192 			ip->set = 1;
193 			return(1);
194 		}
195 	for (mp = omodes; mp->name; ++mp)
196 		if (CHK(mp->name)) {
197 			ip->t.c_oflag &= ~mp->unset;
198 			ip->t.c_oflag |= mp->set;
199 			ip->set = 1;
200 			return(1);
201 		}
202 	return(0);
203 }
204