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. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #ifndef lint 31 #if 0 32 static char sccsid[] = "@(#)modes.c 8.3 (Berkeley) 4/2/94"; 33 #endif 34 #endif /* not lint */ 35 #include <sys/cdefs.h> 36 #include <sys/types.h> 37 #include <string.h> 38 #include "stty.h" 39 40 int msearch(char ***, struct info *); 41 42 struct modes { 43 const char *name; 44 long set; 45 long unset; 46 }; 47 48 /* 49 * The code in optlist() depends on minus options following regular 50 * options, i.e. "foo" must immediately precede "-foo". 51 */ 52 static const struct modes cmodes[] = { 53 { "cs5", CS5, CSIZE }, 54 { "cs6", CS6, CSIZE }, 55 { "cs7", CS7, CSIZE }, 56 { "cs8", CS8, CSIZE }, 57 { "cstopb", CSTOPB, 0 }, 58 { "-cstopb", 0, CSTOPB }, 59 { "cread", CREAD, 0 }, 60 { "-cread", 0, CREAD }, 61 { "parenb", PARENB, 0 }, 62 { "-parenb", 0, PARENB }, 63 { "parodd", PARODD, 0 }, 64 { "-parodd", 0, PARODD }, 65 { "parity", PARENB | CS7, PARODD | CSIZE }, 66 { "-parity", CS8, PARODD | PARENB | CSIZE }, 67 { "evenp", PARENB | CS7, PARODD | CSIZE }, 68 { "-evenp", CS8, PARODD | PARENB | CSIZE }, 69 { "oddp", PARENB | CS7 | PARODD, CSIZE }, 70 { "-oddp", CS8, PARODD | PARENB | CSIZE }, 71 { "pass8", CS8, PARODD | PARENB | CSIZE }, 72 { "-pass8", PARENB | CS7, PARODD | CSIZE }, 73 { "hupcl", HUPCL, 0 }, 74 { "-hupcl", 0, HUPCL }, 75 { "hup", HUPCL, 0 }, 76 { "-hup", 0, HUPCL }, 77 { "clocal", CLOCAL, 0 }, 78 { "-clocal", 0, CLOCAL }, 79 { "crtscts", CRTSCTS, 0 }, 80 { "-crtscts", 0, CRTSCTS }, 81 { "ctsflow", CCTS_OFLOW, 0 }, 82 { "-ctsflow", 0, CCTS_OFLOW }, 83 { "dsrflow", CDSR_OFLOW, 0 }, 84 { "-dsrflow", 0, CDSR_OFLOW }, 85 { "dtrflow", CDTR_IFLOW, 0 }, 86 { "-dtrflow", 0, CDTR_IFLOW }, 87 { "rtsflow", CRTS_IFLOW, 0 }, 88 { "-rtsflow", 0, CRTS_IFLOW }, 89 { "mdmbuf", MDMBUF, 0 }, 90 { "-mdmbuf", 0, MDMBUF }, 91 { "rtsdtr", 0, CNO_RTSDTR }, 92 { "-rtsdtr", CNO_RTSDTR, 0 }, 93 { NULL, 0, 0 }, 94 }; 95 96 static const 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 { "ixon", IXON, 0 }, 116 { "-ixon", 0, IXON }, 117 { "flow", IXON, 0 }, 118 { "-flow", 0, IXON }, 119 { "ixoff", IXOFF, 0 }, 120 { "-ixoff", 0, IXOFF }, 121 { "tandem", IXOFF, 0 }, 122 { "-tandem", 0, IXOFF }, 123 { "ixany", IXANY, 0 }, 124 { "-ixany", 0, IXANY }, 125 { "decctlq", 0, IXANY }, 126 { "-decctlq", IXANY, 0 }, 127 { "imaxbel", IMAXBEL, 0 }, 128 { "-imaxbel", 0, IMAXBEL }, 129 { "iutf8", IUTF8, 0 }, 130 { "-iutf8", 0, IUTF8 }, 131 { NULL, 0, 0 }, 132 }; 133 134 static const 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 { NULL, 0, 0 }, 184 }; 185 186 static const struct modes omodes[] = { 187 { "opost", OPOST, 0 }, 188 { "-opost", 0, OPOST }, 189 { "litout", 0, OPOST }, 190 { "-litout", OPOST, 0 }, 191 { "onlcr", ONLCR, 0 }, 192 { "-onlcr", 0, ONLCR }, 193 { "ocrnl", OCRNL, 0 }, 194 { "-ocrnl", 0, OCRNL }, 195 { "tabs", TAB0, TABDLY }, /* "preserve" tabs */ 196 { "-tabs", TAB3, TABDLY }, 197 { "oxtabs", TAB3, TABDLY }, 198 { "-oxtabs", TAB0, TABDLY }, 199 { "tab0", TAB0, TABDLY }, 200 { "tab3", TAB3, TABDLY }, 201 { "onocr", ONOCR, 0 }, 202 { "-onocr", 0, ONOCR }, 203 { "onlret", ONLRET, 0 }, 204 { "-onlret", 0, ONLRET }, 205 { NULL, 0, 0 }, 206 }; 207 208 #define CHK(s) (*name == s[0] && !strcmp(name, s)) 209 210 int 211 msearch(char ***argvp, struct info *ip) 212 { 213 const struct modes *mp; 214 char *name; 215 216 name = **argvp; 217 218 for (mp = cmodes; mp->name; ++mp) 219 if (CHK(mp->name)) { 220 ip->t.c_cflag &= ~mp->unset; 221 ip->t.c_cflag |= mp->set; 222 ip->set = 1; 223 return (1); 224 } 225 for (mp = imodes; mp->name; ++mp) 226 if (CHK(mp->name)) { 227 ip->t.c_iflag &= ~mp->unset; 228 ip->t.c_iflag |= mp->set; 229 ip->set = 1; 230 return (1); 231 } 232 for (mp = lmodes; mp->name; ++mp) 233 if (CHK(mp->name)) { 234 ip->t.c_lflag &= ~mp->unset; 235 ip->t.c_lflag |= mp->set; 236 ip->set = 1; 237 return (1); 238 } 239 for (mp = omodes; mp->name; ++mp) 240 if (CHK(mp->name)) { 241 ip->t.c_oflag &= ~mp->unset; 242 ip->t.c_oflag |= mp->set; 243 ip->set = 1; 244 return (1); 245 } 246 return (0); 247 } 248