modes.c revision 1.6 1 /*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * 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[] = "from: @(#)modes.c 5.4 (Berkeley) 6/10/91";*/
36 static char rcsid[] = "$Id: modes.c,v 1.6 1994/04/12 06:08:48 cgd Exp $";
37 #endif /* not lint */
38
39 #include <sys/types.h>
40 #include <stddef.h>
41 #include <string.h>
42 #include "stty.h"
43
44 struct modes {
45 char *name;
46 long set;
47 long unset;
48 };
49
50 /*
51 * The code in optlist() depends on minus options following regular
52 * options, i.e. "foo" must immediately precede "-foo".
53 */
54 struct modes cmodes[] = {
55 "cs5", CS5, CSIZE,
56 "cs6", CS6, CSIZE,
57 "cs7", CS7, CSIZE,
58 "cs8", CS8, CSIZE,
59 "cstopb", CSTOPB, 0,
60 "-cstopb", 0, CSTOPB,
61 "cread", CREAD, 0,
62 "-cread", 0, CREAD,
63 "parenb", PARENB, 0,
64 "-parenb", 0, PARENB,
65 "parodd", PARODD, 0,
66 "-parodd", 0, PARODD,
67 "parity", PARENB | CS7, PARODD | CSIZE,
68 "-parity", CS8, PARODD | PARENB | CSIZE,
69 "evenp", PARENB | CS7, PARODD | CSIZE,
70 "-evenp", CS8, PARODD | PARENB | CSIZE,
71 "oddp", PARENB | CS7 | PARODD, CSIZE,
72 "-oddp", CS8, PARODD | PARENB | CSIZE,
73 "pass8", CS8, PARODD | PARENB | 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 "xtabs", OXTABS, 0,
185 "-xtabs", 0, OXTABS,
186 "oxtabs", OXTABS, 0,
187 "-oxtabs", 0, OXTABS,
188 NULL
189 };
190
191 #define CHK(s) (*name == s[0] && !strcmp(name, s))
192
193 msearch(argvp, ip)
194 char ***argvp;
195 struct info *ip;
196 {
197 register struct modes *mp;
198 register char *name;
199
200 name = **argvp;
201
202 for (mp = cmodes; mp->name; ++mp)
203 if (CHK(mp->name)) {
204 ip->t.c_cflag &= ~mp->unset;
205 ip->t.c_cflag |= mp->set;
206 ip->set = 1;
207 return(1);
208 }
209 for (mp = imodes; mp->name; ++mp)
210 if (CHK(mp->name)) {
211 ip->t.c_iflag &= ~mp->unset;
212 ip->t.c_iflag |= mp->set;
213 ip->set = 1;
214 return(1);
215 }
216 for (mp = lmodes; mp->name; ++mp)
217 if (CHK(mp->name)) {
218 ip->t.c_lflag &= ~mp->unset;
219 ip->t.c_lflag |= mp->set;
220 ip->set = 1;
221 return(1);
222 }
223 for (mp = omodes; mp->name; ++mp)
224 if (CHK(mp->name)) {
225 ip->t.c_oflag &= ~mp->unset;
226 ip->t.c_oflag |= mp->set;
227 ip->set = 1;
228 return(1);
229 }
230 return(0);
231 }
232