Home | History | Annotate | Line # | Download | only in stty
modes.c revision 1.9
      1 /*	$NetBSD: modes.c,v 1.9 1996/05/07 18:20:09 jtc Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1991, 1993, 1994
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      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. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #ifndef lint
     37 #if 0
     38 static char sccsid[] = "@(#)modes.c	8.3 (Berkeley) 4/2/94";
     39 #else
     40 static char rcsid[] = "$NetBSD: modes.c,v 1.9 1996/05/07 18:20:09 jtc Exp $";
     41 #endif
     42 #endif /* not lint */
     43 
     44 #include <sys/types.h>
     45 #include <stddef.h>
     46 #include <string.h>
     47 #include "stty.h"
     48 
     49 struct modes {
     50 	const char *name;
     51 	long set;
     52 	long unset;
     53 };
     54 
     55 /*
     56  * The code in optlist() depends on minus options following regular
     57  * options, i.e. "foo" must immediately precede "-foo".
     58  */
     59 const struct modes cmodes[] = {
     60 	{ "cs5",	CS5, CSIZE },
     61 	{ "cs6",	CS6, CSIZE },
     62 	{ "cs7",	CS7, CSIZE },
     63 	{ "cs8",	CS8, CSIZE },
     64 	{ "cstopb",	CSTOPB, 0 },
     65 	{ "-cstopb",	0, CSTOPB },
     66 	{ "cread",	CREAD, 0 },
     67 	{ "-cread",	0, CREAD },
     68 	{ "parenb",	PARENB, 0 },
     69 	{ "-parenb",	0, PARENB },
     70 	{ "parodd",	PARODD, 0 },
     71 	{ "-parodd",	0, PARODD },
     72 	{ "parity",	PARENB | CS7, PARODD | CSIZE },
     73 	{ "-parity",	CS8, PARODD | PARENB | CSIZE },
     74 	{ "evenp",	PARENB | CS7, PARODD | CSIZE },
     75 	{ "-evenp",	CS8, PARODD | PARENB | CSIZE },
     76 	{ "oddp",	PARENB | CS7 | PARODD, CSIZE },
     77 	{ "-oddp",	CS8, PARODD | PARENB | CSIZE },
     78 	{ "pass8",	CS8, PARODD | PARENB | CSIZE },
     79 	{ "-pass8",	PARENB | CS7, PARODD | CSIZE },
     80 	{ "hupcl",	HUPCL, 0 },
     81 	{ "-hupcl",	0, HUPCL },
     82 	{ "hup",	HUPCL, 0 },
     83 	{ "-hup",	0, HUPCL },
     84 	{ "clocal",	CLOCAL, 0 },
     85 	{ "-clocal",	0, CLOCAL },
     86 	{ "crtscts",	CRTSCTS, 0 },
     87 	{ "-crtscts",	0, CRTSCTS },
     88 	{ "mdmbuf",	MDMBUF, 0 },
     89 	{ "-mdmbuf",	0, MDMBUF },
     90 	{ NULL },
     91 };
     92 
     93 const struct modes imodes[] = {
     94 	{ "ignbrk",	IGNBRK, 0 },
     95 	{ "-ignbrk",	0, IGNBRK },
     96 	{ "brkint",	BRKINT, 0 },
     97 	{ "-brkint",	0, BRKINT },
     98 	{ "ignpar",	IGNPAR, 0 },
     99 	{ "-ignpar",	0, IGNPAR },
    100 	{ "parmrk",	PARMRK, 0 },
    101 	{ "-parmrk",	0, PARMRK },
    102 	{ "inpck",	INPCK, 0 },
    103 	{ "-inpck",	0, INPCK },
    104 	{ "istrip",	ISTRIP, 0 },
    105 	{ "-istrip",	0, ISTRIP },
    106 	{ "inlcr",	INLCR, 0 },
    107 	{ "-inlcr",	0, INLCR },
    108 	{ "igncr",	IGNCR, 0 },
    109 	{ "-igncr",	0, IGNCR },
    110 	{ "icrnl",	ICRNL, 0 },
    111 	{ "-icrnl",	0, ICRNL },
    112 	{ "ixon",	IXON, 0 },
    113 	{ "-ixon",	0, IXON },
    114 	{ "flow",	IXON, 0 },
    115 	{ "-flow",	0, IXON },
    116 	{ "ixoff",	IXOFF, 0 },
    117 	{ "-ixoff",	0, IXOFF },
    118 	{ "tandem",	IXOFF, 0 },
    119 	{ "-tandem",	0, IXOFF },
    120 	{ "ixany",	IXANY, 0 },
    121 	{ "-ixany",	0, IXANY },
    122 	{ "decctlq",	0, IXANY },
    123 	{ "-decctlq",	IXANY, 0 },
    124 	{ "imaxbel",	IMAXBEL, 0 },
    125 	{ "-imaxbel",	0, IMAXBEL },
    126 	{ NULL },
    127 };
    128 
    129 const struct modes lmodes[] = {
    130 	{ "echo",	ECHO, 0 },
    131 	{ "-echo",	0, ECHO },
    132 	{ "echoe",	ECHOE, 0 },
    133 	{ "-echoe",	0, ECHOE },
    134 	{ "crterase",	ECHOE, 0 },
    135 	{ "-crterase",	0, ECHOE },
    136 	{ "crtbs",	ECHOE, 0 },	/* crtbs not supported, close enough */
    137 	{ "-crtbs",	0, ECHOE },
    138 	{ "echok",	ECHOK, 0 },
    139 	{ "-echok",	0, ECHOK },
    140 	{ "echoke",	ECHOKE, 0 },
    141 	{ "-echoke",	0, ECHOKE },
    142 	{ "crtkill",	ECHOKE, 0 },
    143 	{ "-crtkill",	0, ECHOKE },
    144 	{ "altwerase",	ALTWERASE, 0 },
    145 	{ "-altwerase",	0, ALTWERASE },
    146 	{ "iexten",	IEXTEN, 0 },
    147 	{ "-iexten",	0, IEXTEN },
    148 	{ "echonl",	ECHONL, 0 },
    149 	{ "-echonl",	0, ECHONL },
    150 	{ "echoctl",	ECHOCTL, 0 },
    151 	{ "-echoctl",	0, ECHOCTL },
    152 	{ "ctlecho",	ECHOCTL, 0 },
    153 	{ "-ctlecho",	0, ECHOCTL },
    154 	{ "echoprt",	ECHOPRT, 0 },
    155 	{ "-echoprt",	0, ECHOPRT },
    156 	{ "prterase",	ECHOPRT, 0 },
    157 	{ "-prterase",	0, ECHOPRT },
    158 	{ "isig",	ISIG, 0 },
    159 	{ "-isig",	0, ISIG },
    160 	{ "icanon",	ICANON, 0 },
    161 	{ "-icanon",	0, ICANON },
    162 	{ "noflsh",	NOFLSH, 0 },
    163 	{ "-noflsh",	0, NOFLSH },
    164 	{ "tostop",	TOSTOP, 0 },
    165 	{ "-tostop",	0, TOSTOP },
    166 	{ "flusho",	FLUSHO, 0 },
    167 	{ "-flusho",	0, FLUSHO },
    168 	{ "pendin",	PENDIN, 0 },
    169 	{ "-pendin",	0, PENDIN },
    170 	{ "crt",	ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
    171 	{ "-crt",	ECHOK, ECHOE|ECHOKE|ECHOCTL },
    172 	{ "newcrt",	ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
    173 	{ "-newcrt",	ECHOK, ECHOE|ECHOKE|ECHOCTL },
    174 	{ "nokerninfo",	NOKERNINFO, 0 },
    175 	{ "-nokerninfo",0, NOKERNINFO },
    176 	{ "kerninfo",	0, NOKERNINFO },
    177 	{ "-kerninfo",	NOKERNINFO, 0 },
    178 	{ NULL },
    179 };
    180 
    181 const struct modes omodes[] = {
    182 	{ "opost",	OPOST, 0 },
    183 	{ "-opost",	0, OPOST },
    184 	{ "litout",	0, OPOST },
    185 	{ "-litout",	OPOST, 0 },
    186 	{ "onlcr",	ONLCR, 0 },
    187 	{ "-onlcr",	0, ONLCR },
    188 	{ "tabs",	0, OXTABS },		/* "preserve" tabs */
    189 	{ "-tabs",	OXTABS, 0 },
    190 	{ "oxtabs",	OXTABS, 0 },
    191 	{ "-oxtabs",	0, OXTABS },
    192 	{ NULL },
    193 };
    194 
    195 #define	CHK(s)	(!strcmp(name, s))
    196 
    197 int
    198 msearch(argvp, ip)
    199 	char ***argvp;
    200 	struct info *ip;
    201 {
    202 	const struct modes *mp;
    203 	char *name;
    204 
    205 	name = **argvp;
    206 
    207 	for (mp = cmodes; mp->name; ++mp)
    208 		if (CHK(mp->name)) {
    209 			ip->t.c_cflag &= ~mp->unset;
    210 			ip->t.c_cflag |= mp->set;
    211 			ip->set = 1;
    212 			return (1);
    213 		}
    214 	for (mp = imodes; mp->name; ++mp)
    215 		if (CHK(mp->name)) {
    216 			ip->t.c_iflag &= ~mp->unset;
    217 			ip->t.c_iflag |= mp->set;
    218 			ip->set = 1;
    219 			return (1);
    220 		}
    221 	for (mp = lmodes; mp->name; ++mp)
    222 		if (CHK(mp->name)) {
    223 			ip->t.c_lflag &= ~mp->unset;
    224 			ip->t.c_lflag |= mp->set;
    225 			ip->set = 1;
    226 			return (1);
    227 		}
    228 	for (mp = omodes; mp->name; ++mp)
    229 		if (CHK(mp->name)) {
    230 			ip->t.c_oflag &= ~mp->unset;
    231 			ip->t.c_oflag |= mp->set;
    232 			ip->set = 1;
    233 			return (1);
    234 		}
    235 	return (0);
    236 }
    237