1 /*- 2 * Copyright (c) 1991 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)modes.c 5.6 (Berkeley) 08/24/92"; 10 #endif /* not lint */ 11 12 #include <sys/types.h> 13 #include <stddef.h> 14 #include <string.h> 15 #include "stty.h" 16 17 struct modes { 18 char *name; 19 long set; 20 long unset; 21 }; 22 23 /* 24 * The code in optlist() depends on minus options following regular 25 * options, i.e. "foo" must immediately precede "-foo". 26 */ 27 struct modes cmodes[] = { 28 "cs5", CS5, CSIZE, 29 "cs6", CS6, CSIZE, 30 "cs7", CS7, CSIZE, 31 "cs8", CS8, CSIZE, 32 "cstopb", CSTOPB, 0, 33 "-cstopb", 0, CSTOPB, 34 "cread", CREAD, 0, 35 "-cread", 0, CREAD, 36 "parenb", PARENB, 0, 37 "-parenb", 0, PARENB, 38 "parodd", PARODD, 0, 39 "-parodd", 0, PARODD, 40 "parity", PARENB | CS7, PARODD | CSIZE, 41 "-parity", CS8, PARODD | PARENB | CSIZE, 42 "evenp", PARENB | CS7, PARODD | CSIZE, 43 "-evenp", CS8, PARODD | PARENB | CSIZE, 44 "oddp", PARENB | CS7 | PARODD, CSIZE, 45 "-oddp", CS8, PARODD | PARENB | CSIZE, 46 "pass8", CS8, PARODD | PARENB | CSIZE, 47 "-pass8", PARENB | CS7, PARODD | CSIZE, 48 "hupcl", HUPCL, 0, 49 "-hupcl", 0, HUPCL, 50 "hup", HUPCL, 0, 51 "-hup", 0, HUPCL, 52 "clocal", CLOCAL, 0, 53 "-clocal", 0, CLOCAL, 54 "crtscts", CRTSCTS, 0, 55 "-crtscts", 0, CRTSCTS, 56 "mdmbuf", MDMBUF, 0, 57 "-mdmbuf", 0, MDMBUF, 58 NULL 59 }; 60 61 struct modes imodes[] = { 62 "ignbrk", IGNBRK, 0, 63 "-ignbrk", 0, IGNBRK, 64 "brkint", BRKINT, 0, 65 "-brkint", 0, BRKINT, 66 "ignpar", IGNPAR, 0, 67 "-ignpar", 0, IGNPAR, 68 "parmrk", PARMRK, 0, 69 "-parmrk", 0, PARMRK, 70 "inpck", INPCK, 0, 71 "-inpck", 0, INPCK, 72 "istrip", ISTRIP, 0, 73 "-istrip", 0, ISTRIP, 74 "inlcr", INLCR, 0, 75 "-inlcr", 0, INLCR, 76 "igncr", IGNCR, 0, 77 "-igncr", 0, IGNCR, 78 "icrnl", ICRNL, 0, 79 "-icrnl", 0, ICRNL, 80 "ixon", IXON, 0, 81 "-ixon", 0, IXON, 82 "flow", IXON, 0, 83 "-flow", 0, IXON, 84 "ixoff", IXOFF, 0, 85 "-ixoff", 0, IXOFF, 86 "tandem", IXOFF, 0, 87 "-tandem", 0, IXOFF, 88 "ixany", IXANY, 0, 89 "-ixany", 0, IXANY, 90 "decctlq", 0, IXANY, 91 "-decctlq", IXANY, 0, 92 "imaxbel", IMAXBEL, 0, 93 "-imaxbel", 0, IMAXBEL, 94 NULL 95 }; 96 97 struct modes lmodes[] = { 98 "echo", ECHO, 0, 99 "-echo", 0, ECHO, 100 "echoe", ECHOE, 0, 101 "-echoe", 0, ECHOE, 102 "crterase", ECHOE, 0, 103 "-crterase", 0, ECHOE, 104 "crtbs", ECHOE, 0, /* crtbs not supported, close enough */ 105 "-crtbs", 0, ECHOE, 106 "echok", ECHOK, 0, 107 "-echok", 0, ECHOK, 108 "echoke", ECHOKE, 0, 109 "-echoke", 0, ECHOKE, 110 "crtkill", ECHOKE, 0, 111 "-crtkill", 0, ECHOKE, 112 "altwerase", ALTWERASE, 0, 113 "-altwerase", 0, ALTWERASE, 114 "iexten", IEXTEN, 0, 115 "-iexten", 0, IEXTEN, 116 "echonl", ECHONL, 0, 117 "-echonl", 0, ECHONL, 118 "echoctl", ECHOCTL, 0, 119 "-echoctl", 0, ECHOCTL, 120 "ctlecho", ECHOCTL, 0, 121 "-ctlecho", 0, ECHOCTL, 122 "echoprt", ECHOPRT, 0, 123 "-echoprt", 0, ECHOPRT, 124 "prterase", ECHOPRT, 0, 125 "-prterase", 0, ECHOPRT, 126 "isig", ISIG, 0, 127 "-isig", 0, ISIG, 128 "icanon", ICANON, 0, 129 "-icanon", 0, ICANON, 130 "noflsh", NOFLSH, 0, 131 "-noflsh", 0, NOFLSH, 132 "tostop", TOSTOP, 0, 133 "-tostop", 0, TOSTOP, 134 "flusho", FLUSHO, 0, 135 "-flusho", 0, FLUSHO, 136 "pendin", PENDIN, 0, 137 "-pendin", 0, PENDIN, 138 "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT, 139 "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL, 140 "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT, 141 "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL, 142 "nokerninfo", NOKERNINFO, 0, 143 "-nokerninfo", 0, NOKERNINFO, 144 "kerninfo", 0, NOKERNINFO, 145 "-kerninfo", NOKERNINFO, 0, 146 NULL 147 }; 148 149 struct modes omodes[] = { 150 "opost", OPOST, 0, 151 "-opost", 0, OPOST, 152 "litout", 0, OPOST, 153 "-litout", OPOST, 0, 154 "onlcr", ONLCR, 0, 155 "-onlcr", 0, ONLCR, 156 "tabs", 0, OXTABS, /* "preserve" tabs */ 157 "-tabs", OXTABS, 0, 158 "oxtabs", OXTABS, 0, 159 "-oxtabs", 0, OXTABS, 160 NULL 161 }; 162 163 #define CHK(s) (*name == s[0] && !strcmp(name, s)) 164 165 msearch(argvp, ip) 166 char ***argvp; 167 struct info *ip; 168 { 169 register struct modes *mp; 170 register char *name; 171 172 name = **argvp; 173 174 for (mp = cmodes; mp->name; ++mp) 175 if (CHK(mp->name)) { 176 ip->t.c_cflag &= ~mp->unset; 177 ip->t.c_cflag |= mp->set; 178 ip->set = 1; 179 return(1); 180 } 181 for (mp = imodes; mp->name; ++mp) 182 if (CHK(mp->name)) { 183 ip->t.c_iflag &= ~mp->unset; 184 ip->t.c_iflag |= mp->set; 185 ip->set = 1; 186 return(1); 187 } 188 for (mp = lmodes; mp->name; ++mp) 189 if (CHK(mp->name)) { 190 ip->t.c_lflag &= ~mp->unset; 191 ip->t.c_lflag |= mp->set; 192 ip->set = 1; 193 return(1); 194 } 195 for (mp = omodes; mp->name; ++mp) 196 if (CHK(mp->name)) { 197 ip->t.c_oflag &= ~mp->unset; 198 ip->t.c_oflag |= mp->set; 199 ip->set = 1; 200 return(1); 201 } 202 return(0); 203 } 204