modes.c revision 1.1.1.2 1 /*-
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #ifndef lint
35 static char sccsid[] = "@(#)modes.c 8.3 (Berkeley) 4/2/94";
36 #endif /* not lint */
37
38 #include <sys/types.h>
39 #include <stddef.h>
40 #include <string.h>
41 #include "stty.h"
42
43 struct modes {
44 char *name;
45 long set;
46 long unset;
47 };
48
49 /*
50 * The code in optlist() depends on minus options following regular
51 * options, i.e. "foo" must immediately precede "-foo".
52 */
53 struct modes cmodes[] = {
54 { "cs5", CS5, CSIZE },
55 { "cs6", CS6, CSIZE },
56 { "cs7", CS7, CSIZE },
57 { "cs8", CS8, CSIZE },
58 { "cstopb", CSTOPB, 0 },
59 { "-cstopb", 0, CSTOPB },
60 { "cread", CREAD, 0 },
61 { "-cread", 0, CREAD },
62 { "parenb", PARENB, 0 },
63 { "-parenb", 0, PARENB },
64 { "parodd", PARODD, 0 },
65 { "-parodd", 0, PARODD },
66 { "parity", PARENB | CS7, PARODD | CSIZE },
67 { "-parity", CS8, PARODD | PARENB | CSIZE },
68 { "evenp", PARENB | CS7, PARODD | CSIZE },
69 { "-evenp", CS8, PARODD | PARENB | CSIZE },
70 { "oddp", PARENB | CS7 | PARODD, CSIZE },
71 { "-oddp", CS8, PARODD | PARENB | CSIZE },
72 { "pass8", CS8, PARODD | PARENB | CSIZE },
73 { "-pass8", PARENB | CS7, PARODD | CSIZE },
74 { "hupcl", HUPCL, 0 },
75 { "-hupcl", 0, HUPCL },
76 { "hup", HUPCL, 0 },
77 { "-hup", 0, HUPCL },
78 { "clocal", CLOCAL, 0 },
79 { "-clocal", 0, CLOCAL },
80 { "crtscts", CRTSCTS, 0 },
81 { "-crtscts", 0, CRTSCTS },
82 { "mdmbuf", MDMBUF, 0 },
83 { "-mdmbuf", 0, MDMBUF },
84 { NULL },
85 };
86
87 struct modes imodes[] = {
88 { "ignbrk", IGNBRK, 0 },
89 { "-ignbrk", 0, IGNBRK },
90 { "brkint", BRKINT, 0 },
91 { "-brkint", 0, BRKINT },
92 { "ignpar", IGNPAR, 0 },
93 { "-ignpar", 0, IGNPAR },
94 { "parmrk", PARMRK, 0 },
95 { "-parmrk", 0, PARMRK },
96 { "inpck", INPCK, 0 },
97 { "-inpck", 0, INPCK },
98 { "istrip", ISTRIP, 0 },
99 { "-istrip", 0, ISTRIP },
100 { "inlcr", INLCR, 0 },
101 { "-inlcr", 0, INLCR },
102 { "igncr", IGNCR, 0 },
103 { "-igncr", 0, IGNCR },
104 { "icrnl", ICRNL, 0 },
105 { "-icrnl", 0, ICRNL },
106 { "ixon", IXON, 0 },
107 { "-ixon", 0, IXON },
108 { "flow", IXON, 0 },
109 { "-flow", 0, IXON },
110 { "ixoff", IXOFF, 0 },
111 { "-ixoff", 0, IXOFF },
112 { "tandem", IXOFF, 0 },
113 { "-tandem", 0, IXOFF },
114 { "ixany", IXANY, 0 },
115 { "-ixany", 0, IXANY },
116 { "decctlq", 0, IXANY },
117 { "-decctlq", IXANY, 0 },
118 { "imaxbel", IMAXBEL, 0 },
119 { "-imaxbel", 0, IMAXBEL },
120 { NULL },
121 };
122
123 struct modes lmodes[] = {
124 { "echo", ECHO, 0 },
125 { "-echo", 0, ECHO },
126 { "echoe", ECHOE, 0 },
127 { "-echoe", 0, ECHOE },
128 { "crterase", ECHOE, 0 },
129 { "-crterase", 0, ECHOE },
130 { "crtbs", ECHOE, 0 }, /* crtbs not supported, close enough */
131 { "-crtbs", 0, ECHOE },
132 { "echok", ECHOK, 0 },
133 { "-echok", 0, ECHOK },
134 { "echoke", ECHOKE, 0 },
135 { "-echoke", 0, ECHOKE },
136 { "crtkill", ECHOKE, 0 },
137 { "-crtkill", 0, ECHOKE },
138 { "altwerase", ALTWERASE, 0 },
139 { "-altwerase", 0, ALTWERASE },
140 { "iexten", IEXTEN, 0 },
141 { "-iexten", 0, IEXTEN },
142 { "echonl", ECHONL, 0 },
143 { "-echonl", 0, ECHONL },
144 { "echoctl", ECHOCTL, 0 },
145 { "-echoctl", 0, ECHOCTL },
146 { "ctlecho", ECHOCTL, 0 },
147 { "-ctlecho", 0, ECHOCTL },
148 { "echoprt", ECHOPRT, 0 },
149 { "-echoprt", 0, ECHOPRT },
150 { "prterase", ECHOPRT, 0 },
151 { "-prterase", 0, ECHOPRT },
152 { "isig", ISIG, 0 },
153 { "-isig", 0, ISIG },
154 { "icanon", ICANON, 0 },
155 { "-icanon", 0, ICANON },
156 { "noflsh", NOFLSH, 0 },
157 { "-noflsh", 0, NOFLSH },
158 { "tostop", TOSTOP, 0 },
159 { "-tostop", 0, TOSTOP },
160 { "flusho", FLUSHO, 0 },
161 { "-flusho", 0, FLUSHO },
162 { "pendin", PENDIN, 0 },
163 { "-pendin", 0, PENDIN },
164 { "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
165 { "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL },
166 { "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
167 { "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL },
168 { "nokerninfo", NOKERNINFO, 0 },
169 { "-nokerninfo",0, NOKERNINFO },
170 { "kerninfo", 0, NOKERNINFO },
171 { "-kerninfo", NOKERNINFO, 0 },
172 { NULL },
173 };
174
175 struct modes omodes[] = {
176 { "opost", OPOST, 0 },
177 { "-opost", 0, OPOST },
178 { "litout", 0, OPOST },
179 { "-litout", OPOST, 0 },
180 { "onlcr", ONLCR, 0 },
181 { "-onlcr", 0, ONLCR },
182 { "tabs", 0, OXTABS }, /* "preserve" tabs */
183 { "-tabs", OXTABS, 0 },
184 { "oxtabs", OXTABS, 0 },
185 { "-oxtabs", 0, OXTABS },
186 { NULL },
187 };
188
189 #define CHK(s) (*name == s[0] && !strcmp(name, s))
190
191 int
192 msearch(argvp, ip)
193 char ***argvp;
194 struct info *ip;
195 {
196 struct modes *mp;
197 char *name;
198
199 name = **argvp;
200
201 for (mp = cmodes; mp->name; ++mp)
202 if (CHK(mp->name)) {
203 ip->t.c_cflag &= ~mp->unset;
204 ip->t.c_cflag |= mp->set;
205 ip->set = 1;
206 return (1);
207 }
208 for (mp = imodes; mp->name; ++mp)
209 if (CHK(mp->name)) {
210 ip->t.c_iflag &= ~mp->unset;
211 ip->t.c_iflag |= mp->set;
212 ip->set = 1;
213 return (1);
214 }
215 for (mp = lmodes; mp->name; ++mp)
216 if (CHK(mp->name)) {
217 ip->t.c_lflag &= ~mp->unset;
218 ip->t.c_lflag |= mp->set;
219 ip->set = 1;
220 return (1);
221 }
222 for (mp = omodes; mp->name; ++mp)
223 if (CHK(mp->name)) {
224 ip->t.c_oflag &= ~mp->unset;
225 ip->t.c_oflag |= mp->set;
226 ip->set = 1;
227 return (1);
228 }
229 return (0);
230 }
231