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