2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
36 static char sccsid[] = "@(#)modes.c 8.3 (Berkeley) 4/2/94";
38 static const char rcsid[] =
39 "$FreeBSD: src/bin/stty/modes.c,v 1.8.2.2 2001/07/04 22:40:00 kris Exp $";
42 #include <sys/types.h>
47 int msearch __P((char ***, struct info *));
56 * The code in optlist() depends on minus options following regular
57 * options, i.e. "foo" must immediately precede "-foo".
59 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 },
84 { "clocal", CLOCAL, 0 },
85 { "-clocal", 0, CLOCAL },
86 { "crtscts", CRTSCTS, 0 },
87 { "-crtscts", 0, CRTSCTS },
88 { "ctsflow", CCTS_OFLOW, 0 },
89 { "-ctsflow", 0, CCTS_OFLOW },
90 { "dsrflow", CDSR_OFLOW, 0 },
91 { "-dsrflow", 0, CDSR_OFLOW },
92 { "dtrflow", CDTR_IFLOW, 0 },
93 { "-dtrflow", 0, CDTR_IFLOW },
94 { "rtsflow", CRTS_IFLOW, 0 },
95 { "-rtsflow", 0, CRTS_IFLOW },
96 { "mdmbuf", MDMBUF, 0 },
97 { "-mdmbuf", 0, MDMBUF },
101 struct modes imodes[] = {
102 { "ignbrk", IGNBRK, 0 },
103 { "-ignbrk", 0, IGNBRK },
104 { "brkint", BRKINT, 0 },
105 { "-brkint", 0, BRKINT },
106 { "ignpar", IGNPAR, 0 },
107 { "-ignpar", 0, IGNPAR },
108 { "parmrk", PARMRK, 0 },
109 { "-parmrk", 0, PARMRK },
110 { "inpck", INPCK, 0 },
111 { "-inpck", 0, INPCK },
112 { "istrip", ISTRIP, 0 },
113 { "-istrip", 0, ISTRIP },
114 { "inlcr", INLCR, 0 },
115 { "-inlcr", 0, INLCR },
116 { "igncr", IGNCR, 0 },
117 { "-igncr", 0, IGNCR },
118 { "icrnl", ICRNL, 0 },
119 { "-icrnl", 0, ICRNL },
121 { "-ixon", 0, IXON },
123 { "-flow", 0, IXON },
124 { "ixoff", IXOFF, 0 },
125 { "-ixoff", 0, IXOFF },
126 { "tandem", IXOFF, 0 },
127 { "-tandem", 0, IXOFF },
128 { "ixany", IXANY, 0 },
129 { "-ixany", 0, IXANY },
130 { "decctlq", 0, IXANY },
131 { "-decctlq", IXANY, 0 },
132 { "imaxbel", IMAXBEL, 0 },
133 { "-imaxbel", 0, IMAXBEL },
137 struct modes lmodes[] = {
139 { "-echo", 0, ECHO },
140 { "echoe", ECHOE, 0 },
141 { "-echoe", 0, ECHOE },
142 { "crterase", ECHOE, 0 },
143 { "-crterase", 0, ECHOE },
144 { "crtbs", ECHOE, 0 }, /* crtbs not supported, close enough */
145 { "-crtbs", 0, ECHOE },
146 { "echok", ECHOK, 0 },
147 { "-echok", 0, ECHOK },
148 { "echoke", ECHOKE, 0 },
149 { "-echoke", 0, ECHOKE },
150 { "crtkill", ECHOKE, 0 },
151 { "-crtkill", 0, ECHOKE },
152 { "altwerase", ALTWERASE, 0 },
153 { "-altwerase", 0, ALTWERASE },
154 { "iexten", IEXTEN, 0 },
155 { "-iexten", 0, IEXTEN },
156 { "echonl", ECHONL, 0 },
157 { "-echonl", 0, ECHONL },
158 { "echoctl", ECHOCTL, 0 },
159 { "-echoctl", 0, ECHOCTL },
160 { "ctlecho", ECHOCTL, 0 },
161 { "-ctlecho", 0, ECHOCTL },
162 { "echoprt", ECHOPRT, 0 },
163 { "-echoprt", 0, ECHOPRT },
164 { "prterase", ECHOPRT, 0 },
165 { "-prterase", 0, ECHOPRT },
167 { "-isig", 0, ISIG },
168 { "icanon", ICANON, 0 },
169 { "-icanon", 0, ICANON },
170 { "noflsh", NOFLSH, 0 },
171 { "-noflsh", 0, NOFLSH },
172 { "tostop", TOSTOP, 0 },
173 { "-tostop", 0, TOSTOP },
174 { "flusho", FLUSHO, 0 },
175 { "-flusho", 0, FLUSHO },
176 { "pendin", PENDIN, 0 },
177 { "-pendin", 0, PENDIN },
178 { "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
179 { "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL },
180 { "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
181 { "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL },
182 { "nokerninfo", NOKERNINFO, 0 },
183 { "-nokerninfo",0, NOKERNINFO },
184 { "kerninfo", 0, NOKERNINFO },
185 { "-kerninfo", NOKERNINFO, 0 },
189 struct modes omodes[] = {
190 { "opost", OPOST, 0 },
191 { "-opost", 0, OPOST },
192 { "litout", 0, OPOST },
193 { "-litout", OPOST, 0 },
194 { "onlcr", ONLCR, 0 },
195 { "-onlcr", 0, ONLCR },
196 { "ocrnl", OCRNL, 0 },
197 { "-ocrnl", 0, OCRNL },
198 { "tabs", 0, OXTABS }, /* "preserve" tabs */
199 { "-tabs", OXTABS, 0 },
200 { "oxtabs", OXTABS, 0 },
201 { "-oxtabs", 0, OXTABS },
202 { "onocr", ONOCR, 0 },
203 { "-onocr", 0, ONOCR },
204 { "onlret", ONLRET, 0 },
205 { "-onlret", 0, ONLRET },
209 #define CHK(s) (*name == s[0] && !strcmp(name, s))
221 for (mp = cmodes; mp->name; ++mp)
223 ip->t.c_cflag &= ~mp->unset;
224 ip->t.c_cflag |= mp->set;
228 for (mp = imodes; mp->name; ++mp)
230 ip->t.c_iflag &= ~mp->unset;
231 ip->t.c_iflag |= mp->set;
235 for (mp = lmodes; mp->name; ++mp)
237 ip->t.c_lflag &= ~mp->unset;
238 ip->t.c_lflag |= mp->set;
242 for (mp = omodes; mp->name; ++mp)
244 ip->t.c_oflag &= ~mp->unset;
245 ip->t.c_oflag |= mp->set;