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