115032Ssef/*-
215032Ssef * Copyright (c) 1991, 1993, 1994
315032Ssef *	The Regents of the University of California.  All rights reserved.
415032Ssef *
515032Ssef * Redistribution and use in source and binary forms, with or without
615032Ssef * modification, are permitted provided that the following conditions
715032Ssef * are met:
815032Ssef * 1. Redistributions of source code must retain the above copyright
915032Ssef *    notice, this list of conditions and the following disclaimer.
1015032Ssef * 2. Redistributions in binary form must reproduce the above copyright
1115032Ssef *    notice, this list of conditions and the following disclaimer in the
1215032Ssef *    documentation and/or other materials provided with the distribution.
1315032Ssef * 4. Neither the name of the University nor the names of its contributors
1415032Ssef *    may be used to endorse or promote products derived from this software
1515032Ssef *    without specific prior written permission.
1615032Ssef *
1715032Ssef * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1815032Ssef * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1915032Ssef * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2015032Ssef * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2115032Ssef * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2215032Ssef * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2315032Ssef * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2415032Ssef * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2515032Ssef * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2615032Ssef * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2715032Ssef * SUCH DAMAGE.
2815032Ssef */
2915032Ssef
30117554Sgad#if 0
31117587Sgad#ifndef lint
3215032Ssefstatic char sccsid[] = "@(#)modes.c	8.3 (Berkeley) 4/2/94";
33117587Sgad#endif /* not lint */
34117554Sgad#endif
3515032Ssef
36117554Sgad#include "lp.cdefs.h"		/* A cross-platform version of <sys/cdefs.h> */
37117554Sgad__FBSDID("$FreeBSD$");
38117554Sgad
3915032Ssef#include <stddef.h>
4015032Ssef#include <string.h>
4115032Ssef#include <termios.h>
4239084Swollman#include "lp.local.h"
4339084Swollman#include "extern.h"
4415032Ssef
4515032Ssefstruct modes {
4674367Sgad	const char *name;
4778146Sgad	const long  set;
4878146Sgad	const long  unset;
4915032Ssef};
5015032Ssef
5115032Ssef/*
5215032Ssef * The code in optlist() depends on minus options following regular
5315032Ssef * options, i.e. "foo" must immediately precede "-foo".
5415032Ssef */
5515032Ssefstruct modes cmodes[] = {
5615032Ssef	{ "cs5",	CS5, CSIZE },
5715032Ssef	{ "cs6",	CS6, CSIZE },
5815032Ssef	{ "cs7",	CS7, CSIZE },
5915032Ssef	{ "cs8",	CS8, CSIZE },
6015032Ssef	{ "cstopb",	CSTOPB, 0 },
6115032Ssef	{ "-cstopb",	0, CSTOPB },
6215032Ssef	{ "cread",	CREAD, 0 },
6315032Ssef	{ "-cread",	0, CREAD },
6415032Ssef	{ "parenb",	PARENB, 0 },
6515032Ssef	{ "-parenb",	0, PARENB },
6615032Ssef	{ "parodd",	PARODD, 0 },
6715032Ssef	{ "-parodd",	0, PARODD },
6815032Ssef	{ "parity",	PARENB | CS7, PARODD | CSIZE },
6915032Ssef	{ "-parity",	CS8, PARODD | PARENB | CSIZE },
7015032Ssef	{ "evenp",	PARENB | CS7, PARODD | CSIZE },
7115032Ssef	{ "-evenp",	CS8, PARODD | PARENB | CSIZE },
7215032Ssef	{ "oddp",	PARENB | CS7 | PARODD, CSIZE },
7315032Ssef	{ "-oddp",	CS8, PARODD | PARENB | CSIZE },
7415032Ssef	{ "pass8",	CS8, PARODD | PARENB | CSIZE },
7515032Ssef	{ "-pass8",	PARENB | CS7, PARODD | CSIZE },
7615032Ssef	{ "hupcl",	HUPCL, 0 },
7715032Ssef	{ "-hupcl",	0, HUPCL },
7815032Ssef	{ "hup",	HUPCL, 0 },
7915032Ssef	{ "-hup",	0, HUPCL },
8015032Ssef	{ "clocal",	CLOCAL, 0 },
8115032Ssef	{ "-clocal",	0, CLOCAL },
8215032Ssef	{ "crtscts",	CRTSCTS, 0 },
8315032Ssef	{ "-crtscts",	0, CRTSCTS },
8415032Ssef	{ "ctsflow",	CCTS_OFLOW, 0 },
8515032Ssef	{ "-ctsflow",	0, CCTS_OFLOW },
8615032Ssef	{ "dsrflow",	CDSR_OFLOW, 0 },
8715032Ssef	{ "-dsrflow",	0, CDSR_OFLOW },
8815032Ssef	{ "dtrflow",	CDTR_IFLOW, 0 },
8915032Ssef	{ "-dtrflow",	0, CDTR_IFLOW },
9015032Ssef	{ "rtsflow",	CRTS_IFLOW, 0 },
9115032Ssef	{ "-rtsflow",	0, CRTS_IFLOW },
9215032Ssef	{ "mdmbuf",	MDMBUF, 0 },
9315032Ssef	{ "-mdmbuf",	0, MDMBUF },
9474367Sgad	{ NULL, 0, 0},
9515032Ssef};
9615032Ssef
9715032Ssefstruct modes imodes[] = {
9815032Ssef	{ "ignbrk",	IGNBRK, 0 },
9915032Ssef	{ "-ignbrk",	0, IGNBRK },
10015032Ssef	{ "brkint",	BRKINT, 0 },
10115032Ssef	{ "-brkint",	0, BRKINT },
10215032Ssef	{ "ignpar",	IGNPAR, 0 },
10315032Ssef	{ "-ignpar",	0, IGNPAR },
10415032Ssef	{ "parmrk",	PARMRK, 0 },
10515032Ssef	{ "-parmrk",	0, PARMRK },
10615032Ssef	{ "inpck",	INPCK, 0 },
10715032Ssef	{ "-inpck",	0, INPCK },
10815032Ssef	{ "istrip",	ISTRIP, 0 },
10915032Ssef	{ "-istrip",	0, ISTRIP },
11015032Ssef	{ "inlcr",	INLCR, 0 },
11115032Ssef	{ "-inlcr",	0, INLCR },
11215032Ssef	{ "igncr",	IGNCR, 0 },
11315032Ssef	{ "-igncr",	0, IGNCR },
11415032Ssef	{ "icrnl",	ICRNL, 0 },
11515032Ssef	{ "-icrnl",	0, ICRNL },
11615032Ssef	{ "ixon",	IXON, 0 },
11715032Ssef	{ "-ixon",	0, IXON },
11815032Ssef	{ "flow",	IXON, 0 },
11915032Ssef	{ "-flow",	0, IXON },
12015032Ssef	{ "ixoff",	IXOFF, 0 },
12115032Ssef	{ "-ixoff",	0, IXOFF },
12215032Ssef	{ "tandem",	IXOFF, 0 },
12315032Ssef	{ "-tandem",	0, IXOFF },
12415032Ssef	{ "ixany",	IXANY, 0 },
12515032Ssef	{ "-ixany",	0, IXANY },
12615032Ssef	{ "decctlq",	0, IXANY },
12715032Ssef	{ "-decctlq",	IXANY, 0 },
12815032Ssef	{ "imaxbel",	IMAXBEL, 0 },
12915032Ssef	{ "-imaxbel",	0, IMAXBEL },
13074367Sgad	{ NULL, 0, 0},
13115032Ssef};
13215032Ssef
13315032Ssefstruct modes lmodes[] = {
13415032Ssef	{ "echo",	ECHO, 0 },
13515032Ssef	{ "-echo",	0, ECHO },
13615032Ssef	{ "echoe",	ECHOE, 0 },
13715032Ssef	{ "-echoe",	0, ECHOE },
13815032Ssef	{ "crterase",	ECHOE, 0 },
13915032Ssef	{ "-crterase",	0, ECHOE },
14015032Ssef	{ "crtbs",	ECHOE, 0 },	/* crtbs not supported, close enough */
14115032Ssef	{ "-crtbs",	0, ECHOE },
14215032Ssef	{ "echok",	ECHOK, 0 },
14315032Ssef	{ "-echok",	0, ECHOK },
14415032Ssef	{ "echoke",	ECHOKE, 0 },
14515032Ssef	{ "-echoke",	0, ECHOKE },
14615032Ssef	{ "crtkill",	ECHOKE, 0 },
14715032Ssef	{ "-crtkill",	0, ECHOKE },
14815032Ssef	{ "altwerase",	ALTWERASE, 0 },
14915032Ssef	{ "-altwerase",	0, ALTWERASE },
15015032Ssef	{ "iexten",	IEXTEN, 0 },
15115032Ssef	{ "-iexten",	0, IEXTEN },
15215032Ssef	{ "echonl",	ECHONL, 0 },
15315032Ssef	{ "-echonl",	0, ECHONL },
15415032Ssef	{ "echoctl",	ECHOCTL, 0 },
15515032Ssef	{ "-echoctl",	0, ECHOCTL },
15615032Ssef	{ "ctlecho",	ECHOCTL, 0 },
15715032Ssef	{ "-ctlecho",	0, ECHOCTL },
15815032Ssef	{ "echoprt",	ECHOPRT, 0 },
15915032Ssef	{ "-echoprt",	0, ECHOPRT },
16015032Ssef	{ "prterase",	ECHOPRT, 0 },
16115032Ssef	{ "-prterase",	0, ECHOPRT },
16215032Ssef	{ "isig",	ISIG, 0 },
16315032Ssef	{ "-isig",	0, ISIG },
16415032Ssef	{ "icanon",	ICANON, 0 },
16515032Ssef	{ "-icanon",	0, ICANON },
16615032Ssef	{ "noflsh",	NOFLSH, 0 },
16715032Ssef	{ "-noflsh",	0, NOFLSH },
16815032Ssef	{ "tostop",	TOSTOP, 0 },
16915032Ssef	{ "-tostop",	0, TOSTOP },
17015032Ssef	{ "flusho",	FLUSHO, 0 },
17115032Ssef	{ "-flusho",	0, FLUSHO },
17215032Ssef	{ "pendin",	PENDIN, 0 },
17315032Ssef	{ "-pendin",	0, PENDIN },
17415032Ssef	{ "crt",	ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
17515032Ssef	{ "-crt",	ECHOK, ECHOE|ECHOKE|ECHOCTL },
17615032Ssef	{ "newcrt",	ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
17715032Ssef	{ "-newcrt",	ECHOK, ECHOE|ECHOKE|ECHOCTL },
17815032Ssef	{ "nokerninfo",	NOKERNINFO, 0 },
17915032Ssef	{ "-nokerninfo",0, NOKERNINFO },
18015032Ssef	{ "kerninfo",	0, NOKERNINFO },
18115032Ssef	{ "-kerninfo",	NOKERNINFO, 0 },
18274367Sgad	{ NULL, 0, 0},
18315032Ssef};
18415032Ssef
18515032Ssefstruct modes omodes[] = {
18615032Ssef	{ "opost",	OPOST, 0 },
18715032Ssef	{ "-opost",	0, OPOST },
18815032Ssef	{ "litout",	0, OPOST },
18915032Ssef	{ "-litout",	OPOST, 0 },
19015032Ssef	{ "onlcr",	ONLCR, 0 },
19115032Ssef	{ "-onlcr",	0, ONLCR },
19215032Ssef	{ "tabs",	0, OXTABS },		/* "preserve" tabs */
19315032Ssef	{ "-tabs",	OXTABS, 0 },
19415032Ssef	{ "oxtabs",	OXTABS, 0 },
19515032Ssef	{ "-oxtabs",	0, OXTABS },
19674367Sgad	{ NULL, 0, 0},
19715032Ssef};
19815032Ssef
19915032Ssef#define	CHK(name, s)	(*name == s[0] && !strcmp(name, s))
20015032Ssef
20115032Ssefint
20278146Sgadmsearch(char *str, struct termios *ip)
20315032Ssef{
20415032Ssef	struct modes *mp;
20515032Ssef
20615032Ssef	for (mp = cmodes; mp->name; ++mp)
20715032Ssef		if (CHK(str, mp->name)) {
20815032Ssef			ip->c_cflag &= ~mp->unset;
20915032Ssef			ip->c_cflag |= mp->set;
21015032Ssef			return (1);
21115032Ssef		}
21215032Ssef	for (mp = imodes; mp->name; ++mp)
21315032Ssef		if (CHK(str, mp->name)) {
21415032Ssef			ip->c_iflag &= ~mp->unset;
21515032Ssef			ip->c_iflag |= mp->set;
21615032Ssef			return (1);
21715032Ssef		}
21815032Ssef	for (mp = lmodes; mp->name; ++mp)
21915032Ssef		if (CHK(str, mp->name)) {
22015032Ssef			ip->c_lflag &= ~mp->unset;
22115032Ssef			ip->c_lflag |= mp->set;
22215032Ssef			return (1);
22315032Ssef		}
22415032Ssef	for (mp = omodes; mp->name; ++mp)
22515032Ssef		if (CHK(str, mp->name)) {
22615032Ssef			ip->c_oflag &= ~mp->unset;
22715032Ssef			ip->c_oflag |= mp->set;
22815032Ssef			return (1);
22915032Ssef		}
23015032Ssef	return (0);
23115032Ssef}
232