Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.sbin / lpr / lpd / modes.c
1 /*-
2  * Copyright (c) 1991, 1993, 1994
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
20  *
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
31  * SUCH DAMAGE.
32  *
33  * @(#)modes.c  8.3 (Berkeley) 4/2/94
34  * $FreeBSD: src/usr.sbin/lpr/lpd/modes.c,v 1.6.2.2 2001/06/25 00:37:28 gad Exp $
35  * $DragonFly: src/usr.sbin/lpr/lpd/modes.c,v 1.2 2003/06/17 04:29:56 dillon Exp $
36  */
37
38 #include <stddef.h>
39 #include <string.h>
40 #include <termios.h>
41 #include "lp.local.h"
42 #include "extern.h"
43
44 struct modes {
45         const char *name;
46         const long  set;
47         const long  unset;
48 };
49
50 /*
51  * The code in optlist() depends on minus options following regular
52  * options, i.e. "foo" must immediately precede "-foo".
53  */
54 struct modes cmodes[] = {
55         { "cs5",        CS5, CSIZE },
56         { "cs6",        CS6, CSIZE },
57         { "cs7",        CS7, CSIZE },
58         { "cs8",        CS8, CSIZE },
59         { "cstopb",     CSTOPB, 0 },
60         { "-cstopb",    0, CSTOPB },
61         { "cread",      CREAD, 0 },
62         { "-cread",     0, CREAD },
63         { "parenb",     PARENB, 0 },
64         { "-parenb",    0, PARENB },
65         { "parodd",     PARODD, 0 },
66         { "-parodd",    0, PARODD },
67         { "parity",     PARENB | CS7, PARODD | CSIZE },
68         { "-parity",    CS8, PARODD | PARENB | CSIZE },
69         { "evenp",      PARENB | CS7, PARODD | CSIZE },
70         { "-evenp",     CS8, PARODD | PARENB | CSIZE },
71         { "oddp",       PARENB | CS7 | PARODD, CSIZE },
72         { "-oddp",      CS8, PARODD | PARENB | CSIZE },
73         { "pass8",      CS8, PARODD | PARENB | CSIZE },
74         { "-pass8",     PARENB | CS7, PARODD | CSIZE },
75         { "hupcl",      HUPCL, 0 },
76         { "-hupcl",     0, HUPCL },
77         { "hup",        HUPCL, 0 },
78         { "-hup",       0, HUPCL },
79         { "clocal",     CLOCAL, 0 },
80         { "-clocal",    0, CLOCAL },
81         { "crtscts",    CRTSCTS, 0 },
82         { "-crtscts",   0, CRTSCTS },
83         { "ctsflow",    CCTS_OFLOW, 0 },
84         { "-ctsflow",   0, CCTS_OFLOW },
85         { "dsrflow",    CDSR_OFLOW, 0 },
86         { "-dsrflow",   0, CDSR_OFLOW },
87         { "dtrflow",    CDTR_IFLOW, 0 },
88         { "-dtrflow",   0, CDTR_IFLOW },
89         { "rtsflow",    CRTS_IFLOW, 0 },
90         { "-rtsflow",   0, CRTS_IFLOW },
91         { "mdmbuf",     MDMBUF, 0 },
92         { "-mdmbuf",    0, MDMBUF },
93         { NULL, 0, 0},
94 };
95
96 struct modes imodes[] = {
97         { "ignbrk",     IGNBRK, 0 },
98         { "-ignbrk",    0, IGNBRK },
99         { "brkint",     BRKINT, 0 },
100         { "-brkint",    0, BRKINT },
101         { "ignpar",     IGNPAR, 0 },
102         { "-ignpar",    0, IGNPAR },
103         { "parmrk",     PARMRK, 0 },
104         { "-parmrk",    0, PARMRK },
105         { "inpck",      INPCK, 0 },
106         { "-inpck",     0, INPCK },
107         { "istrip",     ISTRIP, 0 },
108         { "-istrip",    0, ISTRIP },
109         { "inlcr",      INLCR, 0 },
110         { "-inlcr",     0, INLCR },
111         { "igncr",      IGNCR, 0 },
112         { "-igncr",     0, IGNCR },
113         { "icrnl",      ICRNL, 0 },
114         { "-icrnl",     0, ICRNL },
115         { "ixon",       IXON, 0 },
116         { "-ixon",      0, IXON },
117         { "flow",       IXON, 0 },
118         { "-flow",      0, IXON },
119         { "ixoff",      IXOFF, 0 },
120         { "-ixoff",     0, IXOFF },
121         { "tandem",     IXOFF, 0 },
122         { "-tandem",    0, IXOFF },
123         { "ixany",      IXANY, 0 },
124         { "-ixany",     0, IXANY },
125         { "decctlq",    0, IXANY },
126         { "-decctlq",   IXANY, 0 },
127         { "imaxbel",    IMAXBEL, 0 },
128         { "-imaxbel",   0, IMAXBEL },
129         { NULL, 0, 0},
130 };
131
132 struct modes lmodes[] = {
133         { "echo",       ECHO, 0 },
134         { "-echo",      0, ECHO },
135         { "echoe",      ECHOE, 0 },
136         { "-echoe",     0, ECHOE },
137         { "crterase",   ECHOE, 0 },
138         { "-crterase",  0, ECHOE },
139         { "crtbs",      ECHOE, 0 },     /* crtbs not supported, close enough */
140         { "-crtbs",     0, ECHOE },
141         { "echok",      ECHOK, 0 },
142         { "-echok",     0, ECHOK },
143         { "echoke",     ECHOKE, 0 },
144         { "-echoke",    0, ECHOKE },
145         { "crtkill",    ECHOKE, 0 },
146         { "-crtkill",   0, ECHOKE },
147         { "altwerase",  ALTWERASE, 0 },
148         { "-altwerase", 0, ALTWERASE },
149         { "iexten",     IEXTEN, 0 },
150         { "-iexten",    0, IEXTEN },
151         { "echonl",     ECHONL, 0 },
152         { "-echonl",    0, ECHONL },
153         { "echoctl",    ECHOCTL, 0 },
154         { "-echoctl",   0, ECHOCTL },
155         { "ctlecho",    ECHOCTL, 0 },
156         { "-ctlecho",   0, ECHOCTL },
157         { "echoprt",    ECHOPRT, 0 },
158         { "-echoprt",   0, ECHOPRT },
159         { "prterase",   ECHOPRT, 0 },
160         { "-prterase",  0, ECHOPRT },
161         { "isig",       ISIG, 0 },
162         { "-isig",      0, ISIG },
163         { "icanon",     ICANON, 0 },
164         { "-icanon",    0, ICANON },
165         { "noflsh",     NOFLSH, 0 },
166         { "-noflsh",    0, NOFLSH },
167         { "tostop",     TOSTOP, 0 },
168         { "-tostop",    0, TOSTOP },
169         { "flusho",     FLUSHO, 0 },
170         { "-flusho",    0, FLUSHO },
171         { "pendin",     PENDIN, 0 },
172         { "-pendin",    0, PENDIN },
173         { "crt",        ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
174         { "-crt",       ECHOK, ECHOE|ECHOKE|ECHOCTL },
175         { "newcrt",     ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
176         { "-newcrt",    ECHOK, ECHOE|ECHOKE|ECHOCTL },
177         { "nokerninfo", NOKERNINFO, 0 },
178         { "-nokerninfo",0, NOKERNINFO },
179         { "kerninfo",   0, NOKERNINFO },
180         { "-kerninfo",  NOKERNINFO, 0 },
181         { NULL, 0, 0},
182 };
183
184 struct modes omodes[] = {
185         { "opost",      OPOST, 0 },
186         { "-opost",     0, OPOST },
187         { "litout",     0, OPOST },
188         { "-litout",    OPOST, 0 },
189         { "onlcr",      ONLCR, 0 },
190         { "-onlcr",     0, ONLCR },
191         { "tabs",       0, OXTABS },            /* "preserve" tabs */
192         { "-tabs",      OXTABS, 0 },
193         { "oxtabs",     OXTABS, 0 },
194         { "-oxtabs",    0, OXTABS },
195         { NULL, 0, 0},
196 };
197
198 #define CHK(name, s)    (*name == s[0] && !strcmp(name, s))
199
200 int
201 msearch(char *str, struct termios *ip)
202 {
203         struct modes *mp;
204
205         for (mp = cmodes; mp->name; ++mp)
206                 if (CHK(str, mp->name)) {
207                         ip->c_cflag &= ~mp->unset;
208                         ip->c_cflag |= mp->set;
209                         return (1);
210                 }
211         for (mp = imodes; mp->name; ++mp)
212                 if (CHK(str, mp->name)) {
213                         ip->c_iflag &= ~mp->unset;
214                         ip->c_iflag |= mp->set;
215                         return (1);
216                 }
217         for (mp = lmodes; mp->name; ++mp)
218                 if (CHK(str, mp->name)) {
219                         ip->c_lflag &= ~mp->unset;
220                         ip->c_lflag |= mp->set;
221                         return (1);
222                 }
223         for (mp = omodes; mp->name; ++mp)
224                 if (CHK(str, mp->name)) {
225                         ip->c_oflag &= ~mp->unset;
226                         ip->c_oflag |= mp->set;
227                         return (1);
228                 }
229         return (0);
230 }