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