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