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