New sentence, new line.
[netbsd-mini2440.git] / usr.sbin / lpr / lpd / modes.c
blob06364990176be0c9c215a3e00b819044adf5f31c
1 /* $NetBSD: modes.c,v 1.6 2005/11/28 03:26:06 christos 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.6 2005/11/28 03:26:06 christos Exp $");
38 #endif
39 #endif /* not lint */
41 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <stddef.h>
44 #include <string.h>
45 #include <termios.h>
46 #include "extern.h"
48 struct modes {
49 const char *name;
50 long set;
51 long unset;
55 * The code in optlist() depends on minus options following regular
56 * options, i.e. "foo" must immediately precede "-foo".
58 const struct modes cmodes[] = {
59 { "cs5", CS5, CSIZE },
60 { "cs6", CS6, CSIZE },
61 { "cs7", CS7, CSIZE },
62 { "cs8", CS8, CSIZE },
63 { "cstopb", CSTOPB, 0 },
64 { "-cstopb", 0, CSTOPB },
65 { "cread", CREAD, 0 },
66 { "-cread", 0, CREAD },
67 { "parenb", PARENB, 0 },
68 { "-parenb", 0, PARENB },
69 { "parodd", PARODD, 0 },
70 { "-parodd", 0, PARODD },
71 { "parity", PARENB | CS7, PARODD | CSIZE },
72 { "-parity", CS8, PARODD | PARENB | CSIZE },
73 { "evenp", PARENB | CS7, PARODD | CSIZE },
74 { "-evenp", CS8, PARODD | PARENB | CSIZE },
75 { "oddp", PARENB | CS7 | PARODD, CSIZE },
76 { "-oddp", CS8, PARODD | PARENB | CSIZE },
77 { "pass8", CS8, PARODD | PARENB | CSIZE },
78 { "-pass8", PARENB | CS7, PARODD | CSIZE },
79 { "hupcl", HUPCL, 0 },
80 { "-hupcl", 0, HUPCL },
81 { "hup", HUPCL, 0 },
82 { "-hup", 0, HUPCL },
83 { "clocal", CLOCAL, 0 },
84 { "-clocal", 0, CLOCAL },
85 { "crtscts", CRTSCTS, 0 },
86 { "-crtscts", 0, CRTSCTS },
87 { "cdtrcts", CDTRCTS, 0 },
88 { "-cdtrcts", 0, CDTRCTS },
89 { "mdmbuf", MDMBUF, 0 },
90 { "-mdmbuf", 0, MDMBUF },
91 { .name = NULL },
94 const struct modes imodes[] = {
95 { "ignbrk", IGNBRK, 0 },
96 { "-ignbrk", 0, IGNBRK },
97 { "brkint", BRKINT, 0 },
98 { "-brkint", 0, BRKINT },
99 { "ignpar", IGNPAR, 0 },
100 { "-ignpar", 0, IGNPAR },
101 { "parmrk", PARMRK, 0 },
102 { "-parmrk", 0, PARMRK },
103 { "inpck", INPCK, 0 },
104 { "-inpck", 0, INPCK },
105 { "istrip", ISTRIP, 0 },
106 { "-istrip", 0, ISTRIP },
107 { "inlcr", INLCR, 0 },
108 { "-inlcr", 0, INLCR },
109 { "igncr", IGNCR, 0 },
110 { "-igncr", 0, IGNCR },
111 { "icrnl", ICRNL, 0 },
112 { "-icrnl", 0, ICRNL },
113 { "ixon", IXON, 0 },
114 { "-ixon", 0, IXON },
115 { "flow", IXON, 0 },
116 { "-flow", 0, IXON },
117 { "ixoff", IXOFF, 0 },
118 { "-ixoff", 0, IXOFF },
119 { "tandem", IXOFF, 0 },
120 { "-tandem", 0, IXOFF },
121 { "ixany", IXANY, 0 },
122 { "-ixany", 0, IXANY },
123 { "decctlq", 0, IXANY },
124 { "-decctlq", IXANY, 0 },
125 { "imaxbel", IMAXBEL, 0 },
126 { "-imaxbel", 0, IMAXBEL },
127 { .name = NULL },
130 const struct modes lmodes[] = {
131 { "echo", ECHO, 0 },
132 { "-echo", 0, ECHO },
133 { "echoe", ECHOE, 0 },
134 { "-echoe", 0, ECHOE },
135 { "crterase", ECHOE, 0 },
136 { "-crterase", 0, ECHOE },
137 { "crtbs", ECHOE, 0 }, /* crtbs not supported, close enough */
138 { "-crtbs", 0, ECHOE },
139 { "echok", ECHOK, 0 },
140 { "-echok", 0, ECHOK },
141 { "echoke", ECHOKE, 0 },
142 { "-echoke", 0, ECHOKE },
143 { "crtkill", ECHOKE, 0 },
144 { "-crtkill", 0, ECHOKE },
145 { "altwerase", ALTWERASE, 0 },
146 { "-altwerase", 0, ALTWERASE },
147 { "iexten", IEXTEN, 0 },
148 { "-iexten", 0, IEXTEN },
149 { "echonl", ECHONL, 0 },
150 { "-echonl", 0, ECHONL },
151 { "echoctl", ECHOCTL, 0 },
152 { "-echoctl", 0, ECHOCTL },
153 { "ctlecho", ECHOCTL, 0 },
154 { "-ctlecho", 0, ECHOCTL },
155 { "echoprt", ECHOPRT, 0 },
156 { "-echoprt", 0, ECHOPRT },
157 { "prterase", ECHOPRT, 0 },
158 { "-prterase", 0, ECHOPRT },
159 { "isig", ISIG, 0 },
160 { "-isig", 0, ISIG },
161 { "icanon", ICANON, 0 },
162 { "-icanon", 0, ICANON },
163 { "noflsh", NOFLSH, 0 },
164 { "-noflsh", 0, NOFLSH },
165 { "tostop", TOSTOP, 0 },
166 { "-tostop", 0, TOSTOP },
167 { "flusho", FLUSHO, 0 },
168 { "-flusho", 0, FLUSHO },
169 { "pendin", PENDIN, 0 },
170 { "-pendin", 0, PENDIN },
171 { "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
172 { "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL },
173 { "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
174 { "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL },
175 { "nokerninfo", NOKERNINFO, 0 },
176 { "-nokerninfo",0, NOKERNINFO },
177 { "kerninfo", 0, NOKERNINFO },
178 { "-kerninfo", NOKERNINFO, 0 },
179 { .name = NULL },
182 const struct modes omodes[] = {
183 { "opost", OPOST, 0 },
184 { "-opost", 0, OPOST },
185 { "litout", 0, OPOST },
186 { "-litout", OPOST, 0 },
187 { "onlcr", ONLCR, 0 },
188 { "-onlcr", 0, ONLCR },
189 { "tabs", 0, OXTABS }, /* "preserve" tabs */
190 { "-tabs", OXTABS, 0 },
191 { "oxtabs", OXTABS, 0 },
192 { "-oxtabs", 0, OXTABS },
193 { .name = NULL },
196 #define CHK(s) (*name == s[0] && !strcmp(name, s))
199 msearch(char ***argvp, struct info *ip)
201 const struct modes *mp;
202 char *name;
204 name = **argvp;
206 for (mp = cmodes; mp->name; ++mp)
207 if (CHK(mp->name)) {
208 ip->t.c_cflag &= ~mp->unset;
209 ip->t.c_cflag |= mp->set;
210 ip->set = 1;
211 return (1);
213 for (mp = imodes; mp->name; ++mp)
214 if (CHK(mp->name)) {
215 ip->t.c_iflag &= ~mp->unset;
216 ip->t.c_iflag |= mp->set;
217 ip->set = 1;
218 return (1);
220 for (mp = lmodes; mp->name; ++mp)
221 if (CHK(mp->name)) {
222 ip->t.c_lflag &= ~mp->unset;
223 ip->t.c_lflag |= mp->set;
224 ip->set = 1;
225 return (1);
227 for (mp = omodes; mp->name; ++mp)
228 if (CHK(mp->name)) {
229 ip->t.c_oflag &= ~mp->unset;
230 ip->t.c_oflag |= mp->set;
231 ip->set = 1;
232 return (1);
234 return (0);