Commit | Line | Data |
---|---|---|
a204b597 | 1 | /*- |
0217b2ba KB |
2 | * Copyright (c) 1991, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
a204b597 KB |
4 | * |
5 | * %sccs.include.redist.c% | |
6 | */ | |
7 | ||
8 | #ifndef lint | |
706c0358 | 9 | static char sccsid[] = "@(#)modes.c 8.2 (Berkeley) %G%"; |
a204b597 KB |
10 | #endif /* not lint */ |
11 | ||
12 | #include <sys/types.h> | |
a204b597 | 13 | #include <stddef.h> |
14cc5c1c | 14 | #include <string.h> |
a204b597 KB |
15 | #include "stty.h" |
16 | ||
3ac03562 KB |
17 | struct modes { |
18 | char *name; | |
19 | long set; | |
20 | long unset; | |
21 | }; | |
22 | ||
a204b597 KB |
23 | /* |
24 | * The code in optlist() depends on minus options following regular | |
25 | * options, i.e. "foo" must immediately precede "-foo". | |
26 | */ | |
27 | struct modes cmodes[] = { | |
6c4f457a KB |
28 | { "cs5", CS5, CSIZE }, |
29 | { "cs6", CS6, CSIZE }, | |
30 | { "cs7", CS7, CSIZE }, | |
31 | { "cs8", CS8, CSIZE }, | |
32 | { "cstopb", CSTOPB, 0 }, | |
33 | { "-cstopb", 0, CSTOPB }, | |
34 | { "cread", CREAD, 0 }, | |
35 | { "-cread", 0, CREAD }, | |
36 | { "parenb", PARENB, 0 }, | |
37 | { "-parenb", 0, PARENB }, | |
38 | { "parodd", PARODD, 0 }, | |
39 | { "-parodd", 0, PARODD }, | |
40 | { "parity", PARENB | CS7, PARODD | CSIZE }, | |
41 | { "-parity", CS8, PARODD | PARENB | CSIZE }, | |
42 | { "evenp", PARENB | CS7, PARODD | CSIZE }, | |
43 | { "-evenp", CS8, PARODD | PARENB | CSIZE }, | |
44 | { "oddp", PARENB | CS7 | PARODD, CSIZE }, | |
45 | { "-oddp", CS8, PARODD | PARENB | CSIZE }, | |
46 | { "pass8", CS8, PARODD | PARENB | CSIZE }, | |
47 | { "-pass8", PARENB | CS7, PARODD | CSIZE }, | |
48 | { "hupcl", HUPCL, 0 }, | |
49 | { "-hupcl", 0, HUPCL }, | |
50 | { "hup", HUPCL, 0 }, | |
51 | { "-hup", 0, HUPCL }, | |
52 | { "clocal", CLOCAL, 0 }, | |
53 | { "-clocal", 0, CLOCAL }, | |
54 | { "crtscts", CRTSCTS, 0 }, | |
55 | { "-crtscts", 0, CRTSCTS }, | |
56 | { "mdmbuf", MDMBUF, 0 }, | |
57 | { "-mdmbuf", 0, MDMBUF }, | |
58 | { NULL }, | |
a204b597 KB |
59 | }; |
60 | ||
61 | struct modes imodes[] = { | |
6c4f457a KB |
62 | { "ignbrk", IGNBRK, 0 }, |
63 | { "-ignbrk", 0, IGNBRK }, | |
64 | { "brkint", BRKINT, 0 }, | |
65 | { "-brkint", 0, BRKINT }, | |
66 | { "ignpar", IGNPAR, 0 }, | |
67 | { "-ignpar", 0, IGNPAR }, | |
68 | { "parmrk", PARMRK, 0 }, | |
69 | { "-parmrk", 0, PARMRK }, | |
70 | { "inpck", INPCK, 0 }, | |
71 | { "-inpck", 0, INPCK }, | |
72 | { "istrip", ISTRIP, 0 }, | |
73 | { "-istrip", 0, ISTRIP }, | |
74 | { "inlcr", INLCR, 0 }, | |
75 | { "-inlcr", 0, INLCR }, | |
76 | { "igncr", IGNCR, 0 }, | |
77 | { "-igncr", 0, IGNCR }, | |
78 | { "icrnl", ICRNL, 0 }, | |
79 | { "-icrnl", 0, ICRNL }, | |
80 | { "ixon", IXON, 0 }, | |
81 | { "-ixon", 0, IXON }, | |
82 | { "flow", IXON, 0 }, | |
83 | { "-flow", 0, IXON }, | |
84 | { "ixoff", IXOFF, 0 }, | |
85 | { "-ixoff", 0, IXOFF }, | |
86 | { "tandem", IXOFF, 0 }, | |
87 | { "-tandem", 0, IXOFF }, | |
88 | { "ixany", IXANY, 0 }, | |
89 | { "-ixany", 0, IXANY }, | |
90 | { "decctlq", 0, IXANY }, | |
91 | { "-decctlq", IXANY, 0 }, | |
92 | { "imaxbel", IMAXBEL, 0 }, | |
93 | { "-imaxbel", 0, IMAXBEL }, | |
94 | { NULL }, | |
a204b597 KB |
95 | }; |
96 | ||
97 | struct modes lmodes[] = { | |
6c4f457a KB |
98 | { "echo", ECHO, 0 }, |
99 | { "-echo", 0, ECHO }, | |
100 | { "echoe", ECHOE, 0 }, | |
101 | { "-echoe", 0, ECHOE }, | |
102 | { "crterase", ECHOE, 0 }, | |
103 | { "-crterase", 0, ECHOE }, | |
104 | { "crtbs", ECHOE, 0 }, /* crtbs not supported, close enough */ | |
105 | { "-crtbs", 0, ECHOE }, | |
106 | { "echok", ECHOK, 0 }, | |
107 | { "-echok", 0, ECHOK }, | |
108 | { "echoke", ECHOKE, 0 }, | |
109 | { "-echoke", 0, ECHOKE }, | |
110 | { "crtkill", ECHOKE, 0 }, | |
111 | { "-crtkill", 0, ECHOKE }, | |
112 | { "altwerase", ALTWERASE, 0 }, | |
113 | { "-altwerase", 0, ALTWERASE }, | |
114 | { "iexten", IEXTEN, 0 }, | |
115 | { "-iexten", 0, IEXTEN }, | |
116 | { "echonl", ECHONL, 0 }, | |
117 | { "-echonl", 0, ECHONL }, | |
118 | { "echoctl", ECHOCTL, 0 }, | |
119 | { "-echoctl", 0, ECHOCTL }, | |
120 | { "ctlecho", ECHOCTL, 0 }, | |
121 | { "-ctlecho", 0, ECHOCTL }, | |
122 | { "echoprt", ECHOPRT, 0 }, | |
123 | { "-echoprt", 0, ECHOPRT }, | |
124 | { "prterase", ECHOPRT, 0 }, | |
125 | { "-prterase", 0, ECHOPRT }, | |
126 | { "isig", ISIG, 0 }, | |
127 | { "-isig", 0, ISIG }, | |
128 | { "icanon", ICANON, 0 }, | |
129 | { "-icanon", 0, ICANON }, | |
130 | { "noflsh", NOFLSH, 0 }, | |
131 | { "-noflsh", 0, NOFLSH }, | |
132 | { "tostop", TOSTOP, 0 }, | |
133 | { "-tostop", 0, TOSTOP }, | |
134 | { "flusho", FLUSHO, 0 }, | |
135 | { "-flusho", 0, FLUSHO }, | |
136 | { "pendin", PENDIN, 0 }, | |
137 | { "-pendin", 0, PENDIN }, | |
138 | { "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT }, | |
139 | { "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL }, | |
140 | { "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT }, | |
141 | { "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL }, | |
142 | { "nokerninfo", NOKERNINFO, 0 }, | |
143 | { "-nokerninfo",0, NOKERNINFO }, | |
144 | { "kerninfo", 0, NOKERNINFO }, | |
145 | { "-kerninfo", NOKERNINFO, 0 }, | |
146 | { NULL }, | |
a204b597 KB |
147 | }; |
148 | ||
149 | struct modes omodes[] = { | |
6c4f457a KB |
150 | { "opost", OPOST, 0 }, |
151 | { "-opost", 0, OPOST }, | |
152 | { "litout", 0, OPOST }, | |
153 | { "-litout", OPOST, 0 }, | |
154 | { "onlcr", ONLCR, 0 }, | |
155 | { "-onlcr", 0, ONLCR }, | |
156 | { "tabs", 0, OXTABS }, /* "preserve" tabs */ | |
157 | { "-tabs", OXTABS, 0 }, | |
158 | { "oxtabs", OXTABS, 0 }, | |
159 | { "-oxtabs", 0, OXTABS }, | |
160 | { NULL }, | |
a204b597 | 161 | }; |
14cc5c1c KB |
162 | |
163 | #define CHK(s) (*name == s[0] && !strcmp(name, s)) | |
164 | ||
6c4f457a | 165 | int |
14cc5c1c KB |
166 | msearch(argvp, ip) |
167 | char ***argvp; | |
168 | struct info *ip; | |
169 | { | |
706c0358 JSP |
170 | struct modes *mp; |
171 | char *name; | |
14cc5c1c KB |
172 | |
173 | name = **argvp; | |
174 | ||
175 | for (mp = cmodes; mp->name; ++mp) | |
176 | if (CHK(mp->name)) { | |
177 | ip->t.c_cflag &= ~mp->unset; | |
178 | ip->t.c_cflag |= mp->set; | |
179 | ip->set = 1; | |
6c4f457a | 180 | return (1); |
14cc5c1c KB |
181 | } |
182 | for (mp = imodes; mp->name; ++mp) | |
183 | if (CHK(mp->name)) { | |
184 | ip->t.c_iflag &= ~mp->unset; | |
185 | ip->t.c_iflag |= mp->set; | |
186 | ip->set = 1; | |
6c4f457a | 187 | return (1); |
14cc5c1c KB |
188 | } |
189 | for (mp = lmodes; mp->name; ++mp) | |
190 | if (CHK(mp->name)) { | |
191 | ip->t.c_lflag &= ~mp->unset; | |
192 | ip->t.c_lflag |= mp->set; | |
193 | ip->set = 1; | |
6c4f457a | 194 | return (1); |
14cc5c1c KB |
195 | } |
196 | for (mp = omodes; mp->name; ++mp) | |
197 | if (CHK(mp->name)) { | |
198 | ip->t.c_oflag &= ~mp->unset; | |
199 | ip->t.c_oflag |= mp->set; | |
200 | ip->set = 1; | |
6c4f457a | 201 | return (1); |
14cc5c1c | 202 | } |
6c4f457a | 203 | return (0); |
14cc5c1c | 204 | } |