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