xref: /csrg-svn/bin/stty/modes.c (revision 66642)
148941Sbostic /*-
2*66642Spendry  * Copyright (c) 1991, 1993, 1994
360721Sbostic  *	The Regents of the University of California.  All rights reserved.
448941Sbostic  *
548941Sbostic  * %sccs.include.redist.c%
648941Sbostic  */
748941Sbostic 
848941Sbostic #ifndef lint
9*66642Spendry static char sccsid[] = "@(#)modes.c	8.3 (Berkeley) 04/02/94";
1048941Sbostic #endif /* not lint */
1148941Sbostic 
1248941Sbostic #include <sys/types.h>
1348941Sbostic #include <stddef.h>
1450010Sbostic #include <string.h>
1548941Sbostic #include "stty.h"
1648941Sbostic 
1750041Sbostic struct modes {
1850041Sbostic 	char *name;
1950041Sbostic 	long set;
2050041Sbostic 	long unset;
2150041Sbostic };
2250041Sbostic 
2348941Sbostic /*
2448941Sbostic  * The code in optlist() depends on minus options following regular
2548941Sbostic  * options, i.e. "foo" must immediately precede "-foo".
2648941Sbostic  */
2748941Sbostic struct modes cmodes[] = {
2859522Sbostic 	{ "cs5",	CS5, CSIZE },
2959522Sbostic 	{ "cs6",	CS6, CSIZE },
3059522Sbostic 	{ "cs7",	CS7, CSIZE },
3159522Sbostic 	{ "cs8",	CS8, CSIZE },
3259522Sbostic 	{ "cstopb",	CSTOPB, 0 },
3359522Sbostic 	{ "-cstopb",	0, CSTOPB },
3459522Sbostic 	{ "cread",	CREAD, 0 },
3559522Sbostic 	{ "-cread",	0, CREAD },
3659522Sbostic 	{ "parenb",	PARENB, 0 },
3759522Sbostic 	{ "-parenb",	0, PARENB },
3859522Sbostic 	{ "parodd",	PARODD, 0 },
3959522Sbostic 	{ "-parodd",	0, PARODD },
4059522Sbostic 	{ "parity",	PARENB | CS7, PARODD | CSIZE },
4159522Sbostic 	{ "-parity",	CS8, PARODD | PARENB | CSIZE },
4259522Sbostic 	{ "evenp",	PARENB | CS7, PARODD | CSIZE },
4359522Sbostic 	{ "-evenp",	CS8, PARODD | PARENB | CSIZE },
4459522Sbostic 	{ "oddp",	PARENB | CS7 | PARODD, CSIZE },
4559522Sbostic 	{ "-oddp",	CS8, PARODD | PARENB | CSIZE },
4659522Sbostic 	{ "pass8",	CS8, PARODD | PARENB | CSIZE },
4759522Sbostic 	{ "-pass8",	PARENB | CS7, PARODD | CSIZE },
4859522Sbostic 	{ "hupcl",	HUPCL, 0 },
4959522Sbostic 	{ "-hupcl",	0, HUPCL },
5059522Sbostic 	{ "hup",	HUPCL, 0 },
5159522Sbostic 	{ "-hup",	0, HUPCL },
5259522Sbostic 	{ "clocal",	CLOCAL, 0 },
5359522Sbostic 	{ "-clocal",	0, CLOCAL },
5459522Sbostic 	{ "crtscts",	CRTSCTS, 0 },
5559522Sbostic 	{ "-crtscts",	0, CRTSCTS },
5659522Sbostic 	{ "mdmbuf",	MDMBUF, 0 },
5759522Sbostic 	{ "-mdmbuf",	0, MDMBUF },
5859522Sbostic 	{ NULL },
5948941Sbostic };
6048941Sbostic 
6148941Sbostic struct modes imodes[] = {
6259522Sbostic 	{ "ignbrk",	IGNBRK, 0 },
6359522Sbostic 	{ "-ignbrk",	0, IGNBRK },
6459522Sbostic 	{ "brkint",	BRKINT, 0 },
6559522Sbostic 	{ "-brkint",	0, BRKINT },
6659522Sbostic 	{ "ignpar",	IGNPAR, 0 },
6759522Sbostic 	{ "-ignpar",	0, IGNPAR },
6859522Sbostic 	{ "parmrk",	PARMRK, 0 },
6959522Sbostic 	{ "-parmrk",	0, PARMRK },
7059522Sbostic 	{ "inpck",	INPCK, 0 },
7159522Sbostic 	{ "-inpck",	0, INPCK },
7259522Sbostic 	{ "istrip",	ISTRIP, 0 },
7359522Sbostic 	{ "-istrip",	0, ISTRIP },
7459522Sbostic 	{ "inlcr",	INLCR, 0 },
7559522Sbostic 	{ "-inlcr",	0, INLCR },
7659522Sbostic 	{ "igncr",	IGNCR, 0 },
7759522Sbostic 	{ "-igncr",	0, IGNCR },
7859522Sbostic 	{ "icrnl",	ICRNL, 0 },
7959522Sbostic 	{ "-icrnl",	0, ICRNL },
8059522Sbostic 	{ "ixon",	IXON, 0 },
8159522Sbostic 	{ "-ixon",	0, IXON },
8259522Sbostic 	{ "flow",	IXON, 0 },
8359522Sbostic 	{ "-flow",	0, IXON },
8459522Sbostic 	{ "ixoff",	IXOFF, 0 },
8559522Sbostic 	{ "-ixoff",	0, IXOFF },
8659522Sbostic 	{ "tandem",	IXOFF, 0 },
8759522Sbostic 	{ "-tandem",	0, IXOFF },
8859522Sbostic 	{ "ixany",	IXANY, 0 },
8959522Sbostic 	{ "-ixany",	0, IXANY },
9059522Sbostic 	{ "decctlq",	0, IXANY },
9159522Sbostic 	{ "-decctlq",	IXANY, 0 },
9259522Sbostic 	{ "imaxbel",	IMAXBEL, 0 },
9359522Sbostic 	{ "-imaxbel",	0, IMAXBEL },
9459522Sbostic 	{ NULL },
9548941Sbostic };
9648941Sbostic 
9748941Sbostic struct modes lmodes[] = {
9859522Sbostic 	{ "echo",	ECHO, 0 },
9959522Sbostic 	{ "-echo",	0, ECHO },
10059522Sbostic 	{ "echoe",	ECHOE, 0 },
10159522Sbostic 	{ "-echoe",	0, ECHOE },
10259522Sbostic 	{ "crterase",	ECHOE, 0 },
10359522Sbostic 	{ "-crterase",	0, ECHOE },
10459522Sbostic 	{ "crtbs",	ECHOE, 0 },	/* crtbs not supported, close enough */
10559522Sbostic 	{ "-crtbs",	0, ECHOE },
10659522Sbostic 	{ "echok",	ECHOK, 0 },
10759522Sbostic 	{ "-echok",	0, ECHOK },
10859522Sbostic 	{ "echoke",	ECHOKE, 0 },
10959522Sbostic 	{ "-echoke",	0, ECHOKE },
11059522Sbostic 	{ "crtkill",	ECHOKE, 0 },
11159522Sbostic 	{ "-crtkill",	0, ECHOKE },
11259522Sbostic 	{ "altwerase",	ALTWERASE, 0 },
11359522Sbostic 	{ "-altwerase",	0, ALTWERASE },
11459522Sbostic 	{ "iexten",	IEXTEN, 0 },
11559522Sbostic 	{ "-iexten",	0, IEXTEN },
11659522Sbostic 	{ "echonl",	ECHONL, 0 },
11759522Sbostic 	{ "-echonl",	0, ECHONL },
11859522Sbostic 	{ "echoctl",	ECHOCTL, 0 },
11959522Sbostic 	{ "-echoctl",	0, ECHOCTL },
12059522Sbostic 	{ "ctlecho",	ECHOCTL, 0 },
12159522Sbostic 	{ "-ctlecho",	0, ECHOCTL },
12259522Sbostic 	{ "echoprt",	ECHOPRT, 0 },
12359522Sbostic 	{ "-echoprt",	0, ECHOPRT },
12459522Sbostic 	{ "prterase",	ECHOPRT, 0 },
12559522Sbostic 	{ "-prterase",	0, ECHOPRT },
12659522Sbostic 	{ "isig",	ISIG, 0 },
12759522Sbostic 	{ "-isig",	0, ISIG },
12859522Sbostic 	{ "icanon",	ICANON, 0 },
12959522Sbostic 	{ "-icanon",	0, ICANON },
13059522Sbostic 	{ "noflsh",	NOFLSH, 0 },
13159522Sbostic 	{ "-noflsh",	0, NOFLSH },
13259522Sbostic 	{ "tostop",	TOSTOP, 0 },
13359522Sbostic 	{ "-tostop",	0, TOSTOP },
13459522Sbostic 	{ "flusho",	FLUSHO, 0 },
13559522Sbostic 	{ "-flusho",	0, FLUSHO },
13659522Sbostic 	{ "pendin",	PENDIN, 0 },
13759522Sbostic 	{ "-pendin",	0, PENDIN },
13859522Sbostic 	{ "crt",	ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
13959522Sbostic 	{ "-crt",	ECHOK, ECHOE|ECHOKE|ECHOCTL },
14059522Sbostic 	{ "newcrt",	ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
14159522Sbostic 	{ "-newcrt",	ECHOK, ECHOE|ECHOKE|ECHOCTL },
14259522Sbostic 	{ "nokerninfo",	NOKERNINFO, 0 },
14359522Sbostic 	{ "-nokerninfo",0, NOKERNINFO },
14459522Sbostic 	{ "kerninfo",	0, NOKERNINFO },
14559522Sbostic 	{ "-kerninfo",	NOKERNINFO, 0 },
14659522Sbostic 	{ NULL },
14748941Sbostic };
14848941Sbostic 
14948941Sbostic struct modes omodes[] = {
15059522Sbostic 	{ "opost",	OPOST, 0 },
15159522Sbostic 	{ "-opost",	0, OPOST },
15259522Sbostic 	{ "litout",	0, OPOST },
15359522Sbostic 	{ "-litout",	OPOST, 0 },
15459522Sbostic 	{ "onlcr",	ONLCR, 0 },
15559522Sbostic 	{ "-onlcr",	0, ONLCR },
15659522Sbostic 	{ "tabs",	0, OXTABS },		/* "preserve" tabs */
15759522Sbostic 	{ "-tabs",	OXTABS, 0 },
15859522Sbostic 	{ "oxtabs",	OXTABS, 0 },
15959522Sbostic 	{ "-oxtabs",	0, OXTABS },
16059522Sbostic 	{ NULL },
16148941Sbostic };
16250010Sbostic 
16350010Sbostic #define	CHK(s)	(*name == s[0] && !strcmp(name, s))
16450010Sbostic 
16559522Sbostic int
msearch(argvp,ip)16650010Sbostic msearch(argvp, ip)
16750010Sbostic 	char ***argvp;
16850010Sbostic 	struct info *ip;
16950010Sbostic {
17066564Spendry 	struct modes *mp;
17166564Spendry 	char *name;
17250010Sbostic 
17350010Sbostic 	name = **argvp;
17450010Sbostic 
17550010Sbostic 	for (mp = cmodes; mp->name; ++mp)
17650010Sbostic 		if (CHK(mp->name)) {
17750010Sbostic 			ip->t.c_cflag &= ~mp->unset;
17850010Sbostic 			ip->t.c_cflag |= mp->set;
17950010Sbostic 			ip->set = 1;
18059522Sbostic 			return (1);
18150010Sbostic 		}
18250010Sbostic 	for (mp = imodes; mp->name; ++mp)
18350010Sbostic 		if (CHK(mp->name)) {
18450010Sbostic 			ip->t.c_iflag &= ~mp->unset;
18550010Sbostic 			ip->t.c_iflag |= mp->set;
18650010Sbostic 			ip->set = 1;
18759522Sbostic 			return (1);
18850010Sbostic 		}
18950010Sbostic 	for (mp = lmodes; mp->name; ++mp)
19050010Sbostic 		if (CHK(mp->name)) {
19150010Sbostic 			ip->t.c_lflag &= ~mp->unset;
19250010Sbostic 			ip->t.c_lflag |= mp->set;
19350010Sbostic 			ip->set = 1;
19459522Sbostic 			return (1);
19550010Sbostic 		}
19650010Sbostic 	for (mp = omodes; mp->name; ++mp)
19750010Sbostic 		if (CHK(mp->name)) {
19850010Sbostic 			ip->t.c_oflag &= ~mp->unset;
19950010Sbostic 			ip->t.c_oflag |= mp->set;
20050010Sbostic 			ip->set = 1;
20159522Sbostic 			return (1);
20250010Sbostic 		}
20359522Sbostic 	return (0);
20450010Sbostic }
205