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