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