No empty .Rs/.Re
[netbsd-mini2440.git] / bin / stty / modes.c
blobf646efe9dc415d028e59838e3192a7edec78da69
1 /* $NetBSD: modes.c,v 1.16 2003/08/07 09:05:41 agc Exp $ */
3 /*-
4 * Copyright (c) 1991, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 #ifndef lint
34 #if 0
35 static char sccsid[] = "@(#)modes.c 8.3 (Berkeley) 4/2/94";
36 #else
37 __RCSID("$NetBSD: modes.c,v 1.16 2003/08/07 09:05:41 agc Exp $");
38 #endif
39 #endif /* not lint */
41 #include <sys/types.h>
43 #include <stddef.h>
44 #include <string.h>
46 #include "stty.h"
47 #include "extern.h"
49 struct modes {
50 const char *name;
51 tcflag_t set;
52 tcflag_t unset;
56 * The code in optlist() depends on minus options following regular
57 * options, i.e. "foo" must immediately precede "-foo".
59 const struct modes cmodes[] = {
60 { "cs5", CS5, CSIZE },
61 { "cs6", CS6, CSIZE },
62 { "cs7", CS7, CSIZE },
63 { "cs8", CS8, CSIZE },
64 { "cstopb", CSTOPB, 0 },
65 { "-cstopb", 0, CSTOPB },
66 { "cread", CREAD, 0 },
67 { "-cread", 0, CREAD },
68 { "parenb", PARENB, 0 },
69 { "-parenb", 0, PARENB },
70 { "parodd", PARODD, 0 },
71 { "-parodd", 0, PARODD },
72 { "parity", PARENB | CS7, PARODD | CSIZE },
73 { "-parity", CS8, PARODD | PARENB | CSIZE },
74 { "evenp", PARENB | CS7, PARODD | CSIZE },
75 { "-evenp", CS8, PARODD | PARENB | CSIZE },
76 { "oddp", PARENB | CS7 | PARODD, CSIZE },
77 { "-oddp", CS8, PARODD | PARENB | CSIZE },
78 { "pass8", CS8, PARODD | PARENB | CSIZE },
79 { "-pass8", PARENB | CS7, PARODD | CSIZE },
80 { "hupcl", HUPCL, 0 },
81 { "-hupcl", 0, HUPCL },
82 { "hup", HUPCL, 0 },
83 { "-hup", 0, HUPCL },
84 { "clocal", CLOCAL, 0 },
85 { "-clocal", 0, CLOCAL },
86 { "crtscts", CRTSCTS, 0 },
87 { "-crtscts", 0, CRTSCTS },
88 { "mdmbuf", MDMBUF, 0 },
89 { "-mdmbuf", 0, MDMBUF },
90 { "cdtrcts", CDTRCTS, 0 },
91 { "-cdtrcts", 0, CDTRCTS },
92 { .name = NULL },
95 const 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 { .name = NULL },
131 const 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 { .name = NULL },
183 const 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 { "ocrnl", OCRNL, 0 },
191 { "-ocrnl", 0, OCRNL },
192 { "tabs", 0, OXTABS }, /* "preserve" tabs */
193 { "-tabs", OXTABS, 0 },
194 { "oxtabs", OXTABS, 0 },
195 { "-oxtabs", 0, OXTABS },
196 { "onocr", ONOCR, 0 },
197 { "-onocr", 0, ONOCR },
198 { "onlret", ONLRET, 0 },
199 { "-onlret", 0, ONLRET },
200 { .name = NULL },
203 #define CHK(s) (!strcmp(name, s))
206 msearch(char ***argvp, struct info *ip)
208 const struct modes *mp;
209 char *name;
211 name = **argvp;
213 for (mp = cmodes; mp->name; ++mp)
214 if (CHK(mp->name)) {
215 ip->t.c_cflag &= ~mp->unset;
216 ip->t.c_cflag |= mp->set;
217 ip->set = 1;
218 return (1);
220 for (mp = imodes; mp->name; ++mp)
221 if (CHK(mp->name)) {
222 ip->t.c_iflag &= ~mp->unset;
223 ip->t.c_iflag |= mp->set;
224 ip->set = 1;
225 return (1);
227 for (mp = lmodes; mp->name; ++mp)
228 if (CHK(mp->name)) {
229 ip->t.c_lflag &= ~mp->unset;
230 ip->t.c_lflag |= mp->set;
231 ip->set = 1;
232 return (1);
234 for (mp = omodes; mp->name; ++mp)
235 if (CHK(mp->name)) {
236 ip->t.c_oflag &= ~mp->unset;
237 ip->t.c_oflag |= mp->set;
238 ip->set = 1;
239 return (1);
241 return (0);