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 34 #ifndef lint 35 #if 0 36 static char sccsid[] = "@(#)modes.c 8.3 (Berkeley) 4/2/94"; 37 #endif 38 static const char rcsid[] = 39 "$FreeBSD$"; 40 #endif /* not lint */ 41 42 #include <sys/types.h> 43 #include <stddef.h> 44 #include <string.h> 45 #include "stty.h" 46 47 struct modes { 48 char *name; 49 long set; 50 long unset; 51 }; 52 53 /* 54 * The code in optlist() depends on minus options following regular 55 * options, i.e. "foo" must immediately precede "-foo". 56 */ 57 struct modes cmodes[] = { 58 { "cs5", CS5, CSIZE }, 59 { "cs6", CS6, CSIZE }, 60 { "cs7", CS7, CSIZE }, 61 { "cs8", CS8, CSIZE }, 62 { "cstopb", CSTOPB, 0 }, 63 { "-cstopb", 0, CSTOPB }, 64 { "cread", CREAD, 0 }, 65 { "-cread", 0, CREAD }, 66 { "parenb", PARENB, 0 }, 67 { "-parenb", 0, PARENB }, 68 { "parodd", PARODD, 0 }, 69 { "-parodd", 0, PARODD }, 70 { "parity", PARENB | CS7, PARODD | CSIZE }, 71 { "-parity", CS8, PARODD | PARENB | CSIZE }, 72 { "evenp", PARENB | CS7, PARODD | CSIZE }, 73 { "-evenp", CS8, PARODD | PARENB | CSIZE }, 74 { "oddp", PARENB | CS7 | PARODD, CSIZE }, 75 { "-oddp", CS8, PARODD | PARENB | CSIZE }, 76 { "pass8", CS8, PARODD | PARENB | CSIZE }, 77 { "-pass8", PARENB | CS7, PARODD | CSIZE }, 78 { "hupcl", HUPCL, 0 }, 79 { "-hupcl", 0, HUPCL }, 80 { "hup", HUPCL, 0 }, 81 { "-hup", 0, HUPCL }, 82 { "clocal", CLOCAL, 0 }, 83 { "-clocal", 0, CLOCAL }, 84 { "crtscts", CRTSCTS, 0 }, 85 { "-crtscts", 0, CRTSCTS }, 86 { "ctsflow", CCTS_OFLOW, 0 }, 87 { "-ctsflow", 0, CCTS_OFLOW }, 88 { "dsrflow", CDSR_OFLOW, 0 }, 89 { "-dsrflow", 0, CDSR_OFLOW }, 90 { "dtrflow", CDTR_IFLOW, 0 }, 91 { "-dtrflow", 0, CDTR_IFLOW }, 92 { "rtsflow", CRTS_IFLOW, 0 }, 93 { "-rtsflow", 0, CRTS_IFLOW }, 94 { "mdmbuf", MDMBUF, 0 }, 95 { "-mdmbuf", 0, MDMBUF }, 96 { NULL }, 97 }; 98 99 struct modes imodes[] = { 100 { "ignbrk", IGNBRK, 0 }, 101 { "-ignbrk", 0, IGNBRK }, 102 { "brkint", BRKINT, 0 }, 103 { "-brkint", 0, BRKINT }, 104 { "ignpar", IGNPAR, 0 }, 105 { "-ignpar", 0, IGNPAR }, 106 { "parmrk", PARMRK, 0 }, 107 { "-parmrk", 0, PARMRK }, 108 { "inpck", INPCK, 0 }, 109 { "-inpck", 0, INPCK }, 110 { "istrip", ISTRIP, 0 }, 111 { "-istrip", 0, ISTRIP }, 112 { "inlcr", INLCR, 0 }, 113 { "-inlcr", 0, INLCR }, 114 { "igncr", IGNCR, 0 }, 115 { "-igncr", 0, IGNCR }, 116 { "icrnl", ICRNL, 0 }, 117 { "-icrnl", 0, ICRNL }, 118 { "ixon", IXON, 0 }, 119 { "-ixon", 0, IXON }, 120 { "flow", IXON, 0 }, 121 { "-flow", 0, IXON }, 122 { "ixoff", IXOFF, 0 }, 123 { "-ixoff", 0, IXOFF }, 124 { "tandem", IXOFF, 0 }, 125 { "-tandem", 0, IXOFF }, 126 { "ixany", IXANY, 0 }, 127 { "-ixany", 0, IXANY }, 128 { "decctlq", 0, IXANY }, 129 { "-decctlq", IXANY, 0 }, 130 { "imaxbel", IMAXBEL, 0 }, 131 { "-imaxbel", 0, IMAXBEL }, 132 { NULL }, 133 }; 134 135 struct modes lmodes[] = { 136 { "echo", ECHO, 0 }, 137 { "-echo", 0, ECHO }, 138 { "echoe", ECHOE, 0 }, 139 { "-echoe", 0, ECHOE }, 140 { "crterase", ECHOE, 0 }, 141 { "-crterase", 0, ECHOE }, 142 { "crtbs", ECHOE, 0 }, /* crtbs not supported, close enough */ 143 { "-crtbs", 0, ECHOE }, 144 { "echok", ECHOK, 0 }, 145 { "-echok", 0, ECHOK }, 146 { "echoke", ECHOKE, 0 }, 147 { "-echoke", 0, ECHOKE }, 148 { "crtkill", ECHOKE, 0 }, 149 { "-crtkill", 0, ECHOKE }, 150 { "altwerase", ALTWERASE, 0 }, 151 { "-altwerase", 0, ALTWERASE }, 152 { "iexten", IEXTEN, 0 }, 153 { "-iexten", 0, IEXTEN }, 154 { "echonl", ECHONL, 0 }, 155 { "-echonl", 0, ECHONL }, 156 { "echoctl", ECHOCTL, 0 }, 157 { "-echoctl", 0, ECHOCTL }, 158 { "ctlecho", ECHOCTL, 0 }, 159 { "-ctlecho", 0, ECHOCTL }, 160 { "echoprt", ECHOPRT, 0 }, 161 { "-echoprt", 0, ECHOPRT }, 162 { "prterase", ECHOPRT, 0 }, 163 { "-prterase", 0, ECHOPRT }, 164 { "isig", ISIG, 0 }, 165 { "-isig", 0, ISIG }, 166 { "icanon", ICANON, 0 }, 167 { "-icanon", 0, ICANON }, 168 { "noflsh", NOFLSH, 0 }, 169 { "-noflsh", 0, NOFLSH }, 170 { "tostop", TOSTOP, 0 }, 171 { "-tostop", 0, TOSTOP }, 172 { "flusho", FLUSHO, 0 }, 173 { "-flusho", 0, FLUSHO }, 174 { "pendin", PENDIN, 0 }, 175 { "-pendin", 0, PENDIN }, 176 { "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT }, 177 { "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL }, 178 { "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT }, 179 { "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL }, 180 { "nokerninfo", NOKERNINFO, 0 }, 181 { "-nokerninfo",0, NOKERNINFO }, 182 { "kerninfo", 0, NOKERNINFO }, 183 { "-kerninfo", NOKERNINFO, 0 }, 184 { NULL }, 185 }; 186 187 struct modes omodes[] = { 188 { "opost", OPOST, 0 }, 189 { "-opost", 0, OPOST }, 190 { "litout", 0, OPOST }, 191 { "-litout", OPOST, 0 }, 192 { "onlcr", ONLCR, 0 }, 193 { "-onlcr", 0, ONLCR }, 194 { "tabs", 0, OXTABS }, /* "preserve" tabs */ 195 { "-tabs", OXTABS, 0 }, 196 { "oxtabs", OXTABS, 0 }, 197 { "-oxtabs", 0, OXTABS }, 198 { NULL }, 199 }; 200 201 #define CHK(s) (*name == s[0] && !strcmp(name, s)) 202 203 int 204 msearch(argvp, ip) 205 char ***argvp; 206 struct info *ip; 207 { 208 struct modes *mp; 209 char *name; 210 211 name = **argvp; 212 213 for (mp = cmodes; mp->name; ++mp) 214 if (CHK(mp->name)) { 215 ip->t.c_cflag &= ~mp->unset; 216 ip->t.c_cflag |= mp->set; 217 ip->set = 1; 218 return (1); 219 } 220 for (mp = imodes; mp->name; ++mp) 221 if (CHK(mp->name)) { 222 ip->t.c_iflag &= ~mp->unset; 223 ip->t.c_iflag |= mp->set; 224 ip->set = 1; 225 return (1); 226 } 227 for (mp = lmodes; mp->name; ++mp) 228 if (CHK(mp->name)) { 229 ip->t.c_lflag &= ~mp->unset; 230 ip->t.c_lflag |= mp->set; 231 ip->set = 1; 232 return (1); 233 } 234 for (mp = omodes; mp->name; ++mp) 235 if (CHK(mp->name)) { 236 ip->t.c_oflag &= ~mp->unset; 237 ip->t.c_oflag |= mp->set; 238 ip->set = 1; 239 return (1); 240 } 241 return (0); 242 } 243