1 /*- 2 * Copyright (c) 1991 The Regents of the University of California. 3 * 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 5.4 (Berkeley) 6/10/91";*/ 36 static char rcsid[] = "$Id: modes.c,v 1.5 1993/08/01 18:57:36 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 "hupcl", HUPCL, 0, 75 "-hupcl", 0, HUPCL, 76 "hup", HUPCL, 0, 77 "-hup", 0, HUPCL, 78 "clocal", CLOCAL, 0, 79 "-clocal", 0, CLOCAL, 80 "crtscts", CRTSCTS, 0, 81 "-crtscts", 0, CRTSCTS, 82 NULL 83 }; 84 85 struct modes imodes[] = { 86 "ignbrk", IGNBRK, 0, 87 "-ignbrk", 0, IGNBRK, 88 "brkint", BRKINT, 0, 89 "-brkint", 0, BRKINT, 90 "ignpar", IGNPAR, 0, 91 "-ignpar", 0, IGNPAR, 92 "parmrk", PARMRK, 0, 93 "-parmrk", 0, PARMRK, 94 "inpck", INPCK, 0, 95 "-inpck", 0, INPCK, 96 "istrip", ISTRIP, 0, 97 "-istrip", 0, ISTRIP, 98 "inlcr", INLCR, 0, 99 "-inlcr", 0, INLCR, 100 "igncr", IGNCR, 0, 101 "-igncr", 0, IGNCR, 102 "icrnl", ICRNL, 0, 103 "-icrnl", 0, ICRNL, 104 "ixon", IXON, 0, 105 "-ixon", 0, IXON, 106 "flow", IXON, 0, 107 "-flow", 0, IXON, 108 "ixoff", IXOFF, 0, 109 "-ixoff", 0, IXOFF, 110 "tandem", IXOFF, 0, 111 "-tandem", 0, IXOFF, 112 "ixany", IXANY, 0, 113 "-ixany", 0, IXANY, 114 "decctlq", 0, IXANY, 115 "-decctlq", IXANY, 0, 116 "imaxbel", IMAXBEL, 0, 117 "-imaxbel", 0, IMAXBEL, 118 NULL 119 }; 120 121 struct modes lmodes[] = { 122 "echo", ECHO, 0, 123 "-echo", 0, ECHO, 124 "echoe", ECHOE, 0, 125 "-echoe", 0, ECHOE, 126 "crterase", ECHOE, 0, 127 "-crterase", 0, ECHOE, 128 "crtbs", ECHOE, 0, /* crtbs not supported, close enough */ 129 "-crtbs", 0, ECHOE, 130 "echok", ECHOK, 0, 131 "-echok", 0, ECHOK, 132 "echoke", ECHOKE, 0, 133 "-echoke", 0, ECHOKE, 134 "crtkill", ECHOKE, 0, 135 "-crtkill", 0, ECHOKE, 136 "altwerase", ALTWERASE, 0, 137 "-altwerase", 0, ALTWERASE, 138 "iexten", IEXTEN, 0, 139 "-iexten", 0, IEXTEN, 140 "echonl", ECHONL, 0, 141 "-echonl", 0, ECHONL, 142 "echoctl", ECHOCTL, 0, 143 "-echoctl", 0, ECHOCTL, 144 "ctlecho", ECHOCTL, 0, 145 "-ctlecho", 0, ECHOCTL, 146 "echoprt", ECHOPRT, 0, 147 "-echoprt", 0, ECHOPRT, 148 "prterase", ECHOPRT, 0, 149 "-prterase", 0, ECHOPRT, 150 "isig", ISIG, 0, 151 "-isig", 0, ISIG, 152 "icanon", ICANON, 0, 153 "-icanon", 0, ICANON, 154 "noflsh", NOFLSH, 0, 155 "-noflsh", 0, NOFLSH, 156 "tostop", TOSTOP, 0, 157 "-tostop", 0, TOSTOP, 158 "mdmbuf", MDMBUF, 0, 159 "-mdmbuf", 0, MDMBUF, 160 "flusho", FLUSHO, 0, 161 "-flusho", 0, FLUSHO, 162 "pendin", PENDIN, 0, 163 "-pendin", 0, PENDIN, 164 "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT, 165 "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL, 166 "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT, 167 "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL, 168 "nokerninfo", NOKERNINFO, 0, 169 "-nokerninfo", 0, NOKERNINFO, 170 "kerninfo", 0, NOKERNINFO, 171 "-kerninfo", NOKERNINFO, 0, 172 NULL 173 }; 174 175 struct modes omodes[] = { 176 "opost", OPOST, 0, 177 "-opost", 0, OPOST, 178 "litout", 0, OPOST, 179 "-litout", OPOST, 0, 180 "onlcr", ONLCR, 0, 181 "-onlcr", 0, ONLCR, 182 "tabs", 0, OXTABS, /* "preserve" tabs */ 183 "-tabs", OXTABS, 0, 184 "xtabs", OXTABS, 0, 185 "-xtabs", 0, OXTABS, 186 "oxtabs", OXTABS, 0, 187 "-oxtabs", 0, OXTABS, 188 NULL 189 }; 190 191 #define CHK(s) (*name == s[0] && !strcmp(name, s)) 192 193 msearch(argvp, ip) 194 char ***argvp; 195 struct info *ip; 196 { 197 register struct modes *mp; 198 register 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