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