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