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