Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* stty -- change and print terminal line settings |
| 3 | Copyright (C) 1990-1999 Free Software Foundation, Inc. |
| 4 | |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 5 | Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Bernhard Reutner-Fischer | 86f5c99 | 2006-01-22 22:55:11 +0000 | [diff] [blame] | 6 | */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 7 | /* Usage: stty [-ag] [-F device] [setting...] |
| 8 | |
| 9 | Options: |
| 10 | -a Write all current settings to stdout in human-readable form. |
| 11 | -g Write all current settings to stdout in stty-readable form. |
| 12 | -F Open and use the specified device instead of stdin |
| 13 | |
| 14 | If no args are given, write to stdout the baud rate and settings that |
| 15 | have been changed from their defaults. Mode reading and changes |
| 16 | are done on the specified device, or stdin if none was specified. |
| 17 | |
| 18 | David MacKenzie <djm@gnu.ai.mit.edu> |
| 19 | |
Eric Andersen | 7467c8d | 2001-07-12 20:26:32 +0000 | [diff] [blame] | 20 | Special for busybox ported by Vladimir Oleynik <dzo@simtreas.ru> 2001 |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 21 | |
| 22 | */ |
| 23 | |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 24 | //usage:#define stty_trivial_usage |
| 25 | //usage: "[-a|g] [-F DEVICE] [SETTING]..." |
| 26 | //usage:#define stty_full_usage "\n\n" |
| 27 | //usage: "Without arguments, prints baud rate, line discipline,\n" |
| 28 | //usage: "and deviations from stty sane\n" |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 29 | //usage: "\n -F DEVICE Open device instead of stdin" |
| 30 | //usage: "\n -a Print all current settings in human-readable form" |
| 31 | //usage: "\n -g Print in stty-readable form" |
| 32 | //usage: "\n [SETTING] See manpage" |
| 33 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 34 | #include "libbb.h" |
Denys Vlasenko | e6a2f4c | 2016-04-21 16:26:30 +0200 | [diff] [blame] | 35 | #include "common_bufsiz.h" |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 36 | |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 37 | #ifndef _POSIX_VDISABLE |
| 38 | # define _POSIX_VDISABLE ((unsigned char) 0) |
| 39 | #endif |
| 40 | |
| 41 | #define Control(c) ((c) & 0x1f) |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 42 | /* Canonical values for control characters */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 43 | #ifndef CINTR |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 44 | # define CINTR Control('c') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 45 | #endif |
| 46 | #ifndef CQUIT |
| 47 | # define CQUIT 28 |
| 48 | #endif |
| 49 | #ifndef CERASE |
| 50 | # define CERASE 127 |
| 51 | #endif |
| 52 | #ifndef CKILL |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 53 | # define CKILL Control('u') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 54 | #endif |
| 55 | #ifndef CEOF |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 56 | # define CEOF Control('d') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 57 | #endif |
| 58 | #ifndef CEOL |
| 59 | # define CEOL _POSIX_VDISABLE |
| 60 | #endif |
| 61 | #ifndef CSTART |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 62 | # define CSTART Control('q') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 63 | #endif |
| 64 | #ifndef CSTOP |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 65 | # define CSTOP Control('s') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 66 | #endif |
| 67 | #ifndef CSUSP |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 68 | # define CSUSP Control('z') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 69 | #endif |
| 70 | #if defined(VEOL2) && !defined(CEOL2) |
| 71 | # define CEOL2 _POSIX_VDISABLE |
| 72 | #endif |
Denys Vlasenko | 271c0ce | 2011-01-24 16:36:15 +0100 | [diff] [blame] | 73 | /* glibc-2.12.1 uses only VSWTC name */ |
| 74 | #if defined(VSWTC) && !defined(VSWTCH) |
| 75 | # define VSWTCH VSWTC |
| 76 | #endif |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 77 | /* ISC renamed swtch to susp for termios, but we'll accept either name */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 78 | #if defined(VSUSP) && !defined(VSWTCH) |
| 79 | # define VSWTCH VSUSP |
| 80 | # define CSWTCH CSUSP |
| 81 | #endif |
| 82 | #if defined(VSWTCH) && !defined(CSWTCH) |
| 83 | # define CSWTCH _POSIX_VDISABLE |
| 84 | #endif |
| 85 | |
Denis Vlasenko | 79deb66 | 2006-09-19 15:12:12 +0000 | [diff] [blame] | 86 | /* SunOS 5.3 loses (^Z doesn't work) if 'swtch' is the same as 'susp'. |
| 87 | So the default is to disable 'swtch.' */ |
Denis Vlasenko | ff131b9 | 2007-04-10 15:42:06 +0000 | [diff] [blame] | 88 | #if defined(__sparc__) && defined(__svr4__) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 89 | # undef CSWTCH |
| 90 | # define CSWTCH _POSIX_VDISABLE |
| 91 | #endif |
| 92 | |
Denis Vlasenko | ff131b9 | 2007-04-10 15:42:06 +0000 | [diff] [blame] | 93 | #if defined(VWERSE) && !defined(VWERASE) /* AIX-3.2.5 */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 94 | # define VWERASE VWERSE |
| 95 | #endif |
Denis Vlasenko | ff131b9 | 2007-04-10 15:42:06 +0000 | [diff] [blame] | 96 | #if defined(VDSUSP) && !defined(CDSUSP) |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 97 | # define CDSUSP Control('y') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 98 | #endif |
Mark Whitley | 446dd27 | 2001-03-02 20:00:54 +0000 | [diff] [blame] | 99 | #if !defined(VREPRINT) && defined(VRPRNT) /* Irix 4.0.5 */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 100 | # define VREPRINT VRPRNT |
| 101 | #endif |
| 102 | #if defined(VREPRINT) && !defined(CRPRNT) |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 103 | # define CRPRNT Control('r') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 104 | #endif |
| 105 | #if defined(VWERASE) && !defined(CWERASE) |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 106 | # define CWERASE Control('w') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 107 | #endif |
| 108 | #if defined(VLNEXT) && !defined(CLNEXT) |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 109 | # define CLNEXT Control('v') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 110 | #endif |
| 111 | #if defined(VDISCARD) && !defined(VFLUSHO) |
| 112 | # define VFLUSHO VDISCARD |
| 113 | #endif |
Mark Whitley | 446dd27 | 2001-03-02 20:00:54 +0000 | [diff] [blame] | 114 | #if defined(VFLUSH) && !defined(VFLUSHO) /* Ultrix 4.2 */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 115 | # define VFLUSHO VFLUSH |
| 116 | #endif |
Mark Whitley | 446dd27 | 2001-03-02 20:00:54 +0000 | [diff] [blame] | 117 | #if defined(CTLECH) && !defined(ECHOCTL) /* Ultrix 4.3 */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 118 | # define ECHOCTL CTLECH |
| 119 | #endif |
Mark Whitley | 446dd27 | 2001-03-02 20:00:54 +0000 | [diff] [blame] | 120 | #if defined(TCTLECH) && !defined(ECHOCTL) /* Ultrix 4.2 */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 121 | # define ECHOCTL TCTLECH |
| 122 | #endif |
Mark Whitley | 446dd27 | 2001-03-02 20:00:54 +0000 | [diff] [blame] | 123 | #if defined(CRTKIL) && !defined(ECHOKE) /* Ultrix 4.2 and 4.3 */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 124 | # define ECHOKE CRTKIL |
| 125 | #endif |
| 126 | #if defined(VFLUSHO) && !defined(CFLUSHO) |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 127 | # define CFLUSHO Control('o') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 128 | #endif |
| 129 | #if defined(VSTATUS) && !defined(CSTATUS) |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 130 | # define CSTATUS Control('t') |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 131 | #endif |
| 132 | |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 133 | /* Save us from #ifdef forest plague */ |
| 134 | #ifndef BSDLY |
| 135 | # define BSDLY 0 |
| 136 | #endif |
| 137 | #ifndef CIBAUD |
| 138 | # define CIBAUD 0 |
| 139 | #endif |
| 140 | #ifndef CRDLY |
| 141 | # define CRDLY 0 |
| 142 | #endif |
| 143 | #ifndef CRTSCTS |
| 144 | # define CRTSCTS 0 |
| 145 | #endif |
| 146 | #ifndef ECHOCTL |
| 147 | # define ECHOCTL 0 |
| 148 | #endif |
| 149 | #ifndef ECHOKE |
| 150 | # define ECHOKE 0 |
| 151 | #endif |
| 152 | #ifndef ECHOPRT |
| 153 | # define ECHOPRT 0 |
| 154 | #endif |
| 155 | #ifndef FFDLY |
| 156 | # define FFDLY 0 |
| 157 | #endif |
| 158 | #ifndef IEXTEN |
| 159 | # define IEXTEN 0 |
| 160 | #endif |
| 161 | #ifndef IMAXBEL |
| 162 | # define IMAXBEL 0 |
| 163 | #endif |
| 164 | #ifndef IUCLC |
| 165 | # define IUCLC 0 |
| 166 | #endif |
| 167 | #ifndef IXANY |
| 168 | # define IXANY 0 |
| 169 | #endif |
| 170 | #ifndef NLDLY |
| 171 | # define NLDLY 0 |
| 172 | #endif |
| 173 | #ifndef OCRNL |
| 174 | # define OCRNL 0 |
| 175 | #endif |
| 176 | #ifndef OFDEL |
| 177 | # define OFDEL 0 |
| 178 | #endif |
| 179 | #ifndef OFILL |
| 180 | # define OFILL 0 |
| 181 | #endif |
| 182 | #ifndef OLCUC |
| 183 | # define OLCUC 0 |
| 184 | #endif |
| 185 | #ifndef ONLCR |
| 186 | # define ONLCR 0 |
| 187 | #endif |
| 188 | #ifndef ONLRET |
| 189 | # define ONLRET 0 |
| 190 | #endif |
| 191 | #ifndef ONOCR |
| 192 | # define ONOCR 0 |
| 193 | #endif |
| 194 | #ifndef OXTABS |
| 195 | # define OXTABS 0 |
| 196 | #endif |
| 197 | #ifndef TABDLY |
| 198 | # define TABDLY 0 |
| 199 | #endif |
| 200 | #ifndef TAB1 |
| 201 | # define TAB1 0 |
| 202 | #endif |
| 203 | #ifndef TAB2 |
| 204 | # define TAB2 0 |
| 205 | #endif |
| 206 | #ifndef TOSTOP |
| 207 | # define TOSTOP 0 |
| 208 | #endif |
| 209 | #ifndef VDSUSP |
| 210 | # define VDSUSP 0 |
| 211 | #endif |
| 212 | #ifndef VEOL2 |
| 213 | # define VEOL2 0 |
| 214 | #endif |
| 215 | #ifndef VFLUSHO |
| 216 | # define VFLUSHO 0 |
| 217 | #endif |
| 218 | #ifndef VLNEXT |
| 219 | # define VLNEXT 0 |
| 220 | #endif |
| 221 | #ifndef VREPRINT |
| 222 | # define VREPRINT 0 |
| 223 | #endif |
| 224 | #ifndef VSTATUS |
| 225 | # define VSTATUS 0 |
| 226 | #endif |
| 227 | #ifndef VSWTCH |
| 228 | # define VSWTCH 0 |
| 229 | #endif |
| 230 | #ifndef VTDLY |
| 231 | # define VTDLY 0 |
| 232 | #endif |
| 233 | #ifndef VWERASE |
| 234 | # define VWERASE 0 |
| 235 | #endif |
| 236 | #ifndef XCASE |
| 237 | # define XCASE 0 |
| 238 | #endif |
Denys Vlasenko | 271c0ce | 2011-01-24 16:36:15 +0100 | [diff] [blame] | 239 | #ifndef IUTF8 |
| 240 | # define IUTF8 0 |
| 241 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 242 | |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 243 | /* Which speeds to set */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 244 | enum speed_setting { |
| 245 | input_speed, output_speed, both_speeds |
| 246 | }; |
| 247 | |
Denis Vlasenko | 79deb66 | 2006-09-19 15:12:12 +0000 | [diff] [blame] | 248 | /* Which member(s) of 'struct termios' a mode uses */ |
Denis Vlasenko | 20b253d | 2006-09-19 14:24:23 +0000 | [diff] [blame] | 249 | enum { |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 250 | control, input, output, local, combination |
| 251 | }; |
Denys Vlasenko | e9581b6 | 2013-05-17 18:06:49 +0200 | [diff] [blame] | 252 | static tcflag_t *get_ptr_to_tcflag(unsigned type, const struct termios *mode) |
| 253 | { |
| 254 | static const uint8_t tcflag_offsets[] ALIGN1 = { |
| 255 | offsetof(struct termios, c_cflag), /* control */ |
| 256 | offsetof(struct termios, c_iflag), /* input */ |
| 257 | offsetof(struct termios, c_oflag), /* output */ |
| 258 | offsetof(struct termios, c_lflag) /* local */ |
| 259 | }; |
| 260 | if (type <= local) { |
| 261 | return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]); |
| 262 | } |
| 263 | return NULL; |
| 264 | } |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 265 | |
Denis Vlasenko | 79deb66 | 2006-09-19 15:12:12 +0000 | [diff] [blame] | 266 | /* Flags for 'struct mode_info' */ |
| 267 | #define SANE_SET 1 /* Set in 'sane' mode */ |
| 268 | #define SANE_UNSET 2 /* Unset in 'sane' mode */ |
| 269 | #define REV 4 /* Can be turned off by prepending '-' */ |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 270 | #define OMIT 8 /* Don't display value */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 271 | |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 272 | |
| 273 | /* Each mode. |
| 274 | * This structure should be kept as small as humanly possible. |
| 275 | */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 276 | struct mode_info { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 277 | const uint8_t type; /* Which structure element to change */ |
| 278 | const uint8_t flags; /* Setting and display options */ |
| 279 | /* only these values are ever used, so... */ |
| 280 | #if (CSIZE | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY) < 0x100 |
| 281 | const uint8_t mask; |
| 282 | #elif (CSIZE | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY) < 0x10000 |
| 283 | const uint16_t mask; |
| 284 | #else |
Bernhard Reutner-Fischer | 21fc740 | 2007-01-17 19:44:24 +0000 | [diff] [blame] | 285 | const tcflag_t mask; /* Other bits to turn off for this mode */ |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 286 | #endif |
| 287 | /* was using short here, but ppc32 was unhappy */ |
Bernhard Reutner-Fischer | 21fc740 | 2007-01-17 19:44:24 +0000 | [diff] [blame] | 288 | const tcflag_t bits; /* Bits to set for this mode */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 289 | }; |
| 290 | |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 291 | enum { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 292 | /* Must match mode_name[] and mode_info[] order! */ |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 293 | IDX_evenp = 0, |
| 294 | IDX_parity, |
| 295 | IDX_oddp, |
| 296 | IDX_nl, |
| 297 | IDX_ek, |
| 298 | IDX_sane, |
| 299 | IDX_cooked, |
| 300 | IDX_raw, |
| 301 | IDX_pass8, |
| 302 | IDX_litout, |
| 303 | IDX_cbreak, |
| 304 | IDX_crt, |
| 305 | IDX_dec, |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 306 | #if IXANY |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 307 | IDX_decctlq, |
| 308 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 309 | #if TABDLY || OXTABS |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 310 | IDX_tabs, |
| 311 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 312 | #if XCASE && IUCLC && OLCUC |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 313 | IDX_lcase, |
| 314 | IDX_LCASE, |
| 315 | #endif |
| 316 | }; |
Denis Vlasenko | b2abef3 | 2007-01-01 18:18:04 +0000 | [diff] [blame] | 317 | |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 318 | #define MI_ENTRY(N,T,F,B,M) N "\0" |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 319 | |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 320 | /* Mode names given on command line */ |
Denys Vlasenko | 3e134eb | 2016-04-22 18:09:21 +0200 | [diff] [blame] | 321 | static const char mode_name[] ALIGN1 = |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 322 | MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) |
| 323 | MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) |
| 324 | MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 ) |
| 325 | MI_ENTRY("nl", combination, REV | OMIT, 0, 0 ) |
| 326 | MI_ENTRY("ek", combination, OMIT, 0, 0 ) |
| 327 | MI_ENTRY("sane", combination, OMIT, 0, 0 ) |
| 328 | MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 ) |
| 329 | MI_ENTRY("raw", combination, REV | OMIT, 0, 0 ) |
| 330 | MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 ) |
| 331 | MI_ENTRY("litout", combination, REV | OMIT, 0, 0 ) |
| 332 | MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 ) |
| 333 | MI_ENTRY("crt", combination, OMIT, 0, 0 ) |
| 334 | MI_ENTRY("dec", combination, OMIT, 0, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 335 | #if IXANY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 336 | MI_ENTRY("decctlq", combination, REV | OMIT, 0, 0 ) |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 337 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 338 | #if TABDLY || OXTABS |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 339 | MI_ENTRY("tabs", combination, REV | OMIT, 0, 0 ) |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 340 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 341 | #if XCASE && IUCLC && OLCUC |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 342 | MI_ENTRY("lcase", combination, REV | OMIT, 0, 0 ) |
| 343 | MI_ENTRY("LCASE", combination, REV | OMIT, 0, 0 ) |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 344 | #endif |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 345 | MI_ENTRY("parenb", control, REV, PARENB, 0 ) |
| 346 | MI_ENTRY("parodd", control, REV, PARODD, 0 ) |
| 347 | MI_ENTRY("cs5", control, 0, CS5, CSIZE) |
| 348 | MI_ENTRY("cs6", control, 0, CS6, CSIZE) |
| 349 | MI_ENTRY("cs7", control, 0, CS7, CSIZE) |
| 350 | MI_ENTRY("cs8", control, 0, CS8, CSIZE) |
| 351 | MI_ENTRY("hupcl", control, REV, HUPCL, 0 ) |
| 352 | MI_ENTRY("hup", control, REV | OMIT, HUPCL, 0 ) |
| 353 | MI_ENTRY("cstopb", control, REV, CSTOPB, 0 ) |
| 354 | MI_ENTRY("cread", control, SANE_SET | REV, CREAD, 0 ) |
| 355 | MI_ENTRY("clocal", control, REV, CLOCAL, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 356 | #if CRTSCTS |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 357 | MI_ENTRY("crtscts", control, REV, CRTSCTS, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 358 | #endif |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 359 | MI_ENTRY("ignbrk", input, SANE_UNSET | REV, IGNBRK, 0 ) |
| 360 | MI_ENTRY("brkint", input, SANE_SET | REV, BRKINT, 0 ) |
| 361 | MI_ENTRY("ignpar", input, REV, IGNPAR, 0 ) |
| 362 | MI_ENTRY("parmrk", input, REV, PARMRK, 0 ) |
| 363 | MI_ENTRY("inpck", input, REV, INPCK, 0 ) |
| 364 | MI_ENTRY("istrip", input, REV, ISTRIP, 0 ) |
| 365 | MI_ENTRY("inlcr", input, SANE_UNSET | REV, INLCR, 0 ) |
| 366 | MI_ENTRY("igncr", input, SANE_UNSET | REV, IGNCR, 0 ) |
| 367 | MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 ) |
| 368 | MI_ENTRY("ixon", input, REV, IXON, 0 ) |
| 369 | MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 ) |
Denys Vlasenko | e3d4c03 | 2011-01-26 11:58:37 +0100 | [diff] [blame] | 370 | MI_ENTRY("tandem", input, OMIT | REV, IXOFF, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 371 | #if IUCLC |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 372 | MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 373 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 374 | #if IXANY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 375 | MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 376 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 377 | #if IMAXBEL |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 378 | MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 379 | #endif |
Denys Vlasenko | 271c0ce | 2011-01-24 16:36:15 +0100 | [diff] [blame] | 380 | #if IUTF8 |
| 381 | MI_ENTRY("iutf8", input, SANE_UNSET | REV, IUTF8, 0 ) |
| 382 | #endif |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 383 | MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 384 | #if OLCUC |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 385 | MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 386 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 387 | #if OCRNL |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 388 | MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 389 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 390 | #if ONLCR |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 391 | MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 392 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 393 | #if ONOCR |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 394 | MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 395 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 396 | #if ONLRET |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 397 | MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 398 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 399 | #if OFILL |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 400 | MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 401 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 402 | #if OFDEL |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 403 | MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 404 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 405 | #if NLDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 406 | MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY) |
| 407 | MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 408 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 409 | #if CRDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 410 | MI_ENTRY("cr3", output, SANE_UNSET, CR3, CRDLY) |
| 411 | MI_ENTRY("cr2", output, SANE_UNSET, CR2, CRDLY) |
| 412 | MI_ENTRY("cr1", output, SANE_UNSET, CR1, CRDLY) |
| 413 | MI_ENTRY("cr0", output, SANE_SET, CR0, CRDLY) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 414 | #endif |
Mark Whitley | 446dd27 | 2001-03-02 20:00:54 +0000 | [diff] [blame] | 415 | |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 416 | #if TABDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 417 | MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 418 | # if TAB2 |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 419 | MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 420 | # endif |
| 421 | # if TAB1 |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 422 | MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 423 | # endif |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 424 | MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 425 | #else |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 426 | # if OXTABS |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 427 | MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 428 | # endif |
| 429 | #endif |
Mark Whitley | 446dd27 | 2001-03-02 20:00:54 +0000 | [diff] [blame] | 430 | |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 431 | #if BSDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 432 | MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY) |
| 433 | MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 434 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 435 | #if VTDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 436 | MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY) |
| 437 | MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 438 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 439 | #if FFDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 440 | MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY) |
| 441 | MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 442 | #endif |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 443 | MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 ) |
| 444 | MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 445 | #if IEXTEN |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 446 | MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 447 | #endif |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 448 | MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) |
| 449 | MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ) |
Denys Vlasenko | e3d4c03 | 2011-01-26 11:58:37 +0100 | [diff] [blame] | 450 | MI_ENTRY("crterase", local, OMIT | REV, ECHOE, 0 ) |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 451 | MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) |
| 452 | MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 ) |
| 453 | MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 454 | #if XCASE |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 455 | MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 456 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 457 | #if TOSTOP |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 458 | MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 459 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 460 | #if ECHOPRT |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 461 | MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 ) |
Denys Vlasenko | e3d4c03 | 2011-01-26 11:58:37 +0100 | [diff] [blame] | 462 | MI_ENTRY("prterase", local, OMIT | REV, ECHOPRT, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 463 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 464 | #if ECHOCTL |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 465 | MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 ) |
Denys Vlasenko | e3d4c03 | 2011-01-26 11:58:37 +0100 | [diff] [blame] | 466 | MI_ENTRY("ctlecho", local, OMIT | REV, ECHOCTL, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 467 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 468 | #if ECHOKE |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 469 | MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ) |
Denys Vlasenko | e3d4c03 | 2011-01-26 11:58:37 +0100 | [diff] [blame] | 470 | MI_ENTRY("crtkill", local, OMIT | REV, ECHOKE, 0 ) |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 471 | #endif |
| 472 | ; |
| 473 | |
| 474 | #undef MI_ENTRY |
| 475 | #define MI_ENTRY(N,T,F,B,M) { T, F, M, B }, |
| 476 | |
| 477 | static const struct mode_info mode_info[] = { |
| 478 | /* This should be verbatim cut-n-paste copy of the above MI_ENTRYs */ |
| 479 | MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) |
| 480 | MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) |
| 481 | MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 ) |
| 482 | MI_ENTRY("nl", combination, REV | OMIT, 0, 0 ) |
| 483 | MI_ENTRY("ek", combination, OMIT, 0, 0 ) |
| 484 | MI_ENTRY("sane", combination, OMIT, 0, 0 ) |
| 485 | MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 ) |
| 486 | MI_ENTRY("raw", combination, REV | OMIT, 0, 0 ) |
| 487 | MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 ) |
| 488 | MI_ENTRY("litout", combination, REV | OMIT, 0, 0 ) |
| 489 | MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 ) |
| 490 | MI_ENTRY("crt", combination, OMIT, 0, 0 ) |
| 491 | MI_ENTRY("dec", combination, OMIT, 0, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 492 | #if IXANY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 493 | MI_ENTRY("decctlq", combination, REV | OMIT, 0, 0 ) |
| 494 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 495 | #if TABDLY || OXTABS |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 496 | MI_ENTRY("tabs", combination, REV | OMIT, 0, 0 ) |
| 497 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 498 | #if XCASE && IUCLC && OLCUC |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 499 | MI_ENTRY("lcase", combination, REV | OMIT, 0, 0 ) |
| 500 | MI_ENTRY("LCASE", combination, REV | OMIT, 0, 0 ) |
| 501 | #endif |
| 502 | MI_ENTRY("parenb", control, REV, PARENB, 0 ) |
| 503 | MI_ENTRY("parodd", control, REV, PARODD, 0 ) |
| 504 | MI_ENTRY("cs5", control, 0, CS5, CSIZE) |
| 505 | MI_ENTRY("cs6", control, 0, CS6, CSIZE) |
| 506 | MI_ENTRY("cs7", control, 0, CS7, CSIZE) |
| 507 | MI_ENTRY("cs8", control, 0, CS8, CSIZE) |
| 508 | MI_ENTRY("hupcl", control, REV, HUPCL, 0 ) |
| 509 | MI_ENTRY("hup", control, REV | OMIT, HUPCL, 0 ) |
| 510 | MI_ENTRY("cstopb", control, REV, CSTOPB, 0 ) |
| 511 | MI_ENTRY("cread", control, SANE_SET | REV, CREAD, 0 ) |
| 512 | MI_ENTRY("clocal", control, REV, CLOCAL, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 513 | #if CRTSCTS |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 514 | MI_ENTRY("crtscts", control, REV, CRTSCTS, 0 ) |
| 515 | #endif |
| 516 | MI_ENTRY("ignbrk", input, SANE_UNSET | REV, IGNBRK, 0 ) |
| 517 | MI_ENTRY("brkint", input, SANE_SET | REV, BRKINT, 0 ) |
| 518 | MI_ENTRY("ignpar", input, REV, IGNPAR, 0 ) |
| 519 | MI_ENTRY("parmrk", input, REV, PARMRK, 0 ) |
| 520 | MI_ENTRY("inpck", input, REV, INPCK, 0 ) |
| 521 | MI_ENTRY("istrip", input, REV, ISTRIP, 0 ) |
| 522 | MI_ENTRY("inlcr", input, SANE_UNSET | REV, INLCR, 0 ) |
| 523 | MI_ENTRY("igncr", input, SANE_UNSET | REV, IGNCR, 0 ) |
| 524 | MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 ) |
| 525 | MI_ENTRY("ixon", input, REV, IXON, 0 ) |
| 526 | MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 ) |
Denys Vlasenko | e3d4c03 | 2011-01-26 11:58:37 +0100 | [diff] [blame] | 527 | MI_ENTRY("tandem", input, OMIT | REV, IXOFF, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 528 | #if IUCLC |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 529 | MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 ) |
| 530 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 531 | #if IXANY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 532 | MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 ) |
| 533 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 534 | #if IMAXBEL |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 535 | MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 ) |
| 536 | #endif |
Denys Vlasenko | 271c0ce | 2011-01-24 16:36:15 +0100 | [diff] [blame] | 537 | #if IUTF8 |
| 538 | MI_ENTRY("iutf8", input, SANE_UNSET | REV, IUTF8, 0 ) |
| 539 | #endif |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 540 | MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 541 | #if OLCUC |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 542 | MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 ) |
| 543 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 544 | #if OCRNL |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 545 | MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 ) |
| 546 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 547 | #if ONLCR |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 548 | MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 ) |
| 549 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 550 | #if ONOCR |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 551 | MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 ) |
| 552 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 553 | #if ONLRET |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 554 | MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 ) |
| 555 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 556 | #if OFILL |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 557 | MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 ) |
| 558 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 559 | #if OFDEL |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 560 | MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 ) |
| 561 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 562 | #if NLDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 563 | MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY) |
| 564 | MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY) |
| 565 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 566 | #if CRDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 567 | MI_ENTRY("cr3", output, SANE_UNSET, CR3, CRDLY) |
| 568 | MI_ENTRY("cr2", output, SANE_UNSET, CR2, CRDLY) |
| 569 | MI_ENTRY("cr1", output, SANE_UNSET, CR1, CRDLY) |
| 570 | MI_ENTRY("cr0", output, SANE_SET, CR0, CRDLY) |
| 571 | #endif |
| 572 | |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 573 | #if TABDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 574 | MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 575 | # if TAB2 |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 576 | MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 577 | # endif |
| 578 | # if TAB1 |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 579 | MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 580 | # endif |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 581 | MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY) |
| 582 | #else |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 583 | # if OXTABS |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 584 | MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 ) |
| 585 | # endif |
| 586 | #endif |
| 587 | |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 588 | #if BSDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 589 | MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY) |
| 590 | MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY) |
| 591 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 592 | #if VTDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 593 | MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY) |
| 594 | MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY) |
| 595 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 596 | #if FFDLY |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 597 | MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY) |
| 598 | MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY) |
| 599 | #endif |
| 600 | MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 ) |
| 601 | MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 602 | #if IEXTEN |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 603 | MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ) |
| 604 | #endif |
| 605 | MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) |
| 606 | MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ) |
Denys Vlasenko | e3d4c03 | 2011-01-26 11:58:37 +0100 | [diff] [blame] | 607 | MI_ENTRY("crterase", local, OMIT | REV, ECHOE, 0 ) |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 608 | MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) |
| 609 | MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 ) |
| 610 | MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 611 | #if XCASE |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 612 | MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 ) |
| 613 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 614 | #if TOSTOP |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 615 | MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 ) |
| 616 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 617 | #if ECHOPRT |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 618 | MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 ) |
Denys Vlasenko | e3d4c03 | 2011-01-26 11:58:37 +0100 | [diff] [blame] | 619 | MI_ENTRY("prterase", local, OMIT | REV, ECHOPRT, 0 ) |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 620 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 621 | #if ECHOCTL |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 622 | MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 ) |
Denys Vlasenko | e3d4c03 | 2011-01-26 11:58:37 +0100 | [diff] [blame] | 623 | MI_ENTRY("ctlecho", local, OMIT | REV, ECHOCTL, 0 ) |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 624 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 625 | #if ECHOKE |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 626 | MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ) |
Denys Vlasenko | e3d4c03 | 2011-01-26 11:58:37 +0100 | [diff] [blame] | 627 | MI_ENTRY("crtkill", local, OMIT | REV, ECHOKE, 0 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 628 | #endif |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 629 | }; |
| 630 | |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 631 | enum { |
Denis Vlasenko | 80b8b39 | 2007-06-25 10:55:35 +0000 | [diff] [blame] | 632 | NUM_mode_info = ARRAY_SIZE(mode_info) |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 633 | }; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 634 | |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 635 | |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 636 | /* Control characters */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 637 | struct control_info { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 638 | const uint8_t saneval; /* Value to set for 'stty sane' */ |
| 639 | const uint8_t offset; /* Offset in c_cc */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 640 | }; |
| 641 | |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 642 | enum { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 643 | /* Must match control_name[] and control_info[] order! */ |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 644 | CIDX_intr = 0, |
| 645 | CIDX_quit, |
| 646 | CIDX_erase, |
| 647 | CIDX_kill, |
| 648 | CIDX_eof, |
| 649 | CIDX_eol, |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 650 | #if VEOL2 |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 651 | CIDX_eol2, |
| 652 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 653 | #if VSWTCH |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 654 | CIDX_swtch, |
| 655 | #endif |
| 656 | CIDX_start, |
| 657 | CIDX_stop, |
| 658 | CIDX_susp, |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 659 | #if VDSUSP |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 660 | CIDX_dsusp, |
| 661 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 662 | #if VREPRINT |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 663 | CIDX_rprnt, |
| 664 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 665 | #if VWERASE |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 666 | CIDX_werase, |
| 667 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 668 | #if VLNEXT |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 669 | CIDX_lnext, |
| 670 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 671 | #if VFLUSHO |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 672 | CIDX_flush, |
| 673 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 674 | #if VSTATUS |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 675 | CIDX_status, |
| 676 | #endif |
| 677 | CIDX_min, |
| 678 | CIDX_time, |
| 679 | }; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 680 | |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 681 | #define CI_ENTRY(n,s,o) n "\0" |
| 682 | |
| 683 | /* Name given on command line */ |
Denys Vlasenko | 3e134eb | 2016-04-22 18:09:21 +0200 | [diff] [blame] | 684 | static const char control_name[] ALIGN1 = |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 685 | CI_ENTRY("intr", CINTR, VINTR ) |
| 686 | CI_ENTRY("quit", CQUIT, VQUIT ) |
| 687 | CI_ENTRY("erase", CERASE, VERASE ) |
| 688 | CI_ENTRY("kill", CKILL, VKILL ) |
| 689 | CI_ENTRY("eof", CEOF, VEOF ) |
| 690 | CI_ENTRY("eol", CEOL, VEOL ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 691 | #if VEOL2 |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 692 | CI_ENTRY("eol2", CEOL2, VEOL2 ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 693 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 694 | #if VSWTCH |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 695 | CI_ENTRY("swtch", CSWTCH, VSWTCH ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 696 | #endif |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 697 | CI_ENTRY("start", CSTART, VSTART ) |
| 698 | CI_ENTRY("stop", CSTOP, VSTOP ) |
| 699 | CI_ENTRY("susp", CSUSP, VSUSP ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 700 | #if VDSUSP |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 701 | CI_ENTRY("dsusp", CDSUSP, VDSUSP ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 702 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 703 | #if VREPRINT |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 704 | CI_ENTRY("rprnt", CRPRNT, VREPRINT) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 705 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 706 | #if VWERASE |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 707 | CI_ENTRY("werase", CWERASE, VWERASE ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 708 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 709 | #if VLNEXT |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 710 | CI_ENTRY("lnext", CLNEXT, VLNEXT ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 711 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 712 | #if VFLUSHO |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 713 | CI_ENTRY("flush", CFLUSHO, VFLUSHO ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 714 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 715 | #if VSTATUS |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 716 | CI_ENTRY("status", CSTATUS, VSTATUS ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 717 | #endif |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 718 | /* These must be last because of the display routines */ |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 719 | CI_ENTRY("min", 1, VMIN ) |
| 720 | CI_ENTRY("time", 0, VTIME ) |
| 721 | ; |
| 722 | |
| 723 | #undef CI_ENTRY |
| 724 | #define CI_ENTRY(n,s,o) { s, o }, |
| 725 | |
Denys Vlasenko | 3e134eb | 2016-04-22 18:09:21 +0200 | [diff] [blame] | 726 | static const struct control_info control_info[] ALIGN2 = { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 727 | /* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */ |
| 728 | CI_ENTRY("intr", CINTR, VINTR ) |
| 729 | CI_ENTRY("quit", CQUIT, VQUIT ) |
| 730 | CI_ENTRY("erase", CERASE, VERASE ) |
| 731 | CI_ENTRY("kill", CKILL, VKILL ) |
| 732 | CI_ENTRY("eof", CEOF, VEOF ) |
| 733 | CI_ENTRY("eol", CEOL, VEOL ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 734 | #if VEOL2 |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 735 | CI_ENTRY("eol2", CEOL2, VEOL2 ) |
| 736 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 737 | #if VSWTCH |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 738 | CI_ENTRY("swtch", CSWTCH, VSWTCH ) |
| 739 | #endif |
| 740 | CI_ENTRY("start", CSTART, VSTART ) |
| 741 | CI_ENTRY("stop", CSTOP, VSTOP ) |
| 742 | CI_ENTRY("susp", CSUSP, VSUSP ) |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 743 | #if VDSUSP |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 744 | CI_ENTRY("dsusp", CDSUSP, VDSUSP ) |
| 745 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 746 | #if VREPRINT |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 747 | CI_ENTRY("rprnt", CRPRNT, VREPRINT) |
| 748 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 749 | #if VWERASE |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 750 | CI_ENTRY("werase", CWERASE, VWERASE ) |
| 751 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 752 | #if VLNEXT |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 753 | CI_ENTRY("lnext", CLNEXT, VLNEXT ) |
| 754 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 755 | #if VFLUSHO |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 756 | CI_ENTRY("flush", CFLUSHO, VFLUSHO ) |
| 757 | #endif |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 758 | #if VSTATUS |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 759 | CI_ENTRY("status", CSTATUS, VSTATUS ) |
| 760 | #endif |
| 761 | /* These must be last because of the display routines */ |
| 762 | CI_ENTRY("min", 1, VMIN ) |
| 763 | CI_ENTRY("time", 0, VTIME ) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 764 | }; |
| 765 | |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 766 | enum { |
Denis Vlasenko | 80b8b39 | 2007-06-25 10:55:35 +0000 | [diff] [blame] | 767 | NUM_control_info = ARRAY_SIZE(control_info) |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 768 | }; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 769 | |
Bernhard Reutner-Fischer | 3a60244 | 2007-04-04 13:59:49 +0000 | [diff] [blame] | 770 | |
| 771 | struct globals { |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 772 | const char *device_name; |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 773 | /* The width of the screen, for output wrapping */ |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 774 | unsigned max_col; |
Bernhard Reutner-Fischer | 3a60244 | 2007-04-04 13:59:49 +0000 | [diff] [blame] | 775 | /* Current position, to know when to wrap */ |
| 776 | unsigned current_col; |
| 777 | char buf[10]; |
Denys Vlasenko | 98a4c7c | 2010-02-04 15:00:15 +0100 | [diff] [blame] | 778 | } FIX_ALIASING; |
Denys Vlasenko | e6a2f4c | 2016-04-21 16:26:30 +0200 | [diff] [blame] | 779 | #define G (*(struct globals*)bb_common_bufsiz1) |
Denis Vlasenko | 7049ff8 | 2008-06-25 09:53:17 +0000 | [diff] [blame] | 780 | #define INIT_G() do { \ |
| 781 | G.device_name = bb_msg_standard_input; \ |
| 782 | G.max_col = 80; \ |
| 783 | } while (0) |
Bernhard Reutner-Fischer | 3a60244 | 2007-04-04 13:59:49 +0000 | [diff] [blame] | 784 | |
Denis Vlasenko | c7cc5a9 | 2009-04-19 01:27:20 +0000 | [diff] [blame] | 785 | static void set_speed_or_die(enum speed_setting type, const char *arg, |
| 786 | struct termios *mode) |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 787 | { |
| 788 | speed_t baud; |
| 789 | |
Bernhard Reutner-Fischer | 4950f01 | 2007-01-17 19:44:59 +0000 | [diff] [blame] | 790 | baud = tty_value_to_baud(xatou(arg)); |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 791 | |
| 792 | if (type != output_speed) { /* either input or both */ |
| 793 | cfsetispeed(mode, baud); |
| 794 | } |
| 795 | if (type != input_speed) { /* either output or both */ |
| 796 | cfsetospeed(mode, baud); |
| 797 | } |
| 798 | } |
| 799 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 800 | static NORETURN void perror_on_device_and_die(const char *fmt) |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 801 | { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 802 | bb_perror_msg_and_die(fmt, G.device_name); |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Denis Vlasenko | 20b253d | 2006-09-19 14:24:23 +0000 | [diff] [blame] | 805 | static void perror_on_device(const char *fmt) |
| 806 | { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 807 | bb_perror_msg(fmt, G.device_name); |
Denis Vlasenko | 20b253d | 2006-09-19 14:24:23 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 810 | /* Print format string MESSAGE and optional args. |
| 811 | Wrap to next line first if it won't fit. |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 812 | Print a space first unless MESSAGE will start a new line */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 813 | static void wrapf(const char *message, ...) |
| 814 | { |
Denis Vlasenko | e40c04b | 2006-09-19 14:19:42 +0000 | [diff] [blame] | 815 | char buf[128]; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 816 | va_list args; |
Denis Vlasenko | 77ad97f | 2008-05-13 02:27:31 +0000 | [diff] [blame] | 817 | unsigned buflen; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 818 | |
| 819 | va_start(args, message); |
Bernhard Reutner-Fischer | 8eb0549 | 2007-01-17 19:46:33 +0000 | [diff] [blame] | 820 | buflen = vsnprintf(buf, sizeof(buf), message, args); |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 821 | va_end(args); |
Bernhard Reutner-Fischer | 1a250d9 | 2007-01-18 08:41:22 +0000 | [diff] [blame] | 822 | /* We seem to be called only with suitable lengths, but check if |
| 823 | somebody failed to adhere to this assumption just to be sure. */ |
| 824 | if (!buflen || buflen >= sizeof(buf)) return; |
Denis Vlasenko | e40c04b | 2006-09-19 14:19:42 +0000 | [diff] [blame] | 825 | |
Bernhard Reutner-Fischer | 3a60244 | 2007-04-04 13:59:49 +0000 | [diff] [blame] | 826 | if (G.current_col > 0) { |
| 827 | G.current_col++; |
Denis Vlasenko | 79deb66 | 2006-09-19 15:12:12 +0000 | [diff] [blame] | 828 | if (buf[0] != '\n') { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 829 | if (G.current_col + buflen >= G.max_col) { |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 830 | bb_putchar('\n'); |
Bernhard Reutner-Fischer | 3a60244 | 2007-04-04 13:59:49 +0000 | [diff] [blame] | 831 | G.current_col = 0; |
Denis Vlasenko | 79deb66 | 2006-09-19 15:12:12 +0000 | [diff] [blame] | 832 | } else |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 833 | bb_putchar(' '); |
Denis Vlasenko | 79deb66 | 2006-09-19 15:12:12 +0000 | [diff] [blame] | 834 | } |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 835 | } |
| 836 | fputs(buf, stdout); |
Bernhard Reutner-Fischer | 3a60244 | 2007-04-04 13:59:49 +0000 | [diff] [blame] | 837 | G.current_col += buflen; |
Denis Vlasenko | e40c04b | 2006-09-19 14:19:42 +0000 | [diff] [blame] | 838 | if (buf[buflen-1] == '\n') |
Bernhard Reutner-Fischer | 3a60244 | 2007-04-04 13:59:49 +0000 | [diff] [blame] | 839 | G.current_col = 0; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 842 | static void newline(void) |
| 843 | { |
| 844 | if (G.current_col != 0) |
| 845 | wrapf("\n"); |
| 846 | } |
| 847 | |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 848 | #ifdef TIOCGWINSZ |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 849 | static void set_window_size(int rows, int cols) |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 850 | { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 851 | struct winsize win = { 0, 0, 0, 0 }; |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 852 | |
Bernhard Reutner-Fischer | d4a745c | 2007-01-17 19:45:36 +0000 | [diff] [blame] | 853 | if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win)) { |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 854 | if (errno != EINVAL) { |
Bernhard Reutner-Fischer | d4a745c | 2007-01-17 19:45:36 +0000 | [diff] [blame] | 855 | goto bail; |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 856 | } |
| 857 | memset(&win, 0, sizeof(win)); |
| 858 | } |
| 859 | |
| 860 | if (rows >= 0) |
| 861 | win.ws_row = rows; |
| 862 | if (cols >= 0) |
| 863 | win.ws_col = cols; |
| 864 | |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 865 | if (ioctl(STDIN_FILENO, TIOCSWINSZ, (char *) &win)) |
Bernhard Reutner-Fischer | d4a745c | 2007-01-17 19:45:36 +0000 | [diff] [blame] | 866 | bail: |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 867 | perror_on_device("%s"); |
| 868 | } |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 869 | #endif |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 870 | |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 871 | static void display_window_size(int fancy) |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 872 | { |
| 873 | const char *fmt_str = "%s\0%s: no size information for this device"; |
Bernhard Reutner-Fischer | d4a745c | 2007-01-17 19:45:36 +0000 | [diff] [blame] | 874 | unsigned width, height; |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 875 | |
Bernhard Reutner-Fischer | d4a745c | 2007-01-17 19:45:36 +0000 | [diff] [blame] | 876 | if (get_terminal_width_height(STDIN_FILENO, &width, &height)) { |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 877 | if ((errno != EINVAL) || ((fmt_str += 2), !fancy)) { |
| 878 | perror_on_device(fmt_str); |
| 879 | } |
| 880 | } else { |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 881 | wrapf(fancy ? "rows %u; columns %u;" : "%u %u\n", |
Bernhard Reutner-Fischer | d4a745c | 2007-01-17 19:45:36 +0000 | [diff] [blame] | 882 | height, width); |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 886 | static const struct suffix_mult stty_suffixes[] = { |
Denis Vlasenko | f868963 | 2007-07-27 15:06:25 +0000 | [diff] [blame] | 887 | { "b", 512 }, |
| 888 | { "k", 1024 }, |
| 889 | { "B", 1024 }, |
Denys Vlasenko | 043b1e5 | 2009-09-06 12:47:55 +0200 | [diff] [blame] | 890 | { "", 0 } |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 891 | }; |
| 892 | |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 893 | static const struct mode_info *find_mode(const char *name) |
| 894 | { |
Denis Vlasenko | da42bd5 | 2008-01-27 23:24:31 +0000 | [diff] [blame] | 895 | int i = index_in_strings(mode_name, name); |
| 896 | return i >= 0 ? &mode_info[i] : NULL; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | static const struct control_info *find_control(const char *name) |
| 900 | { |
Denis Vlasenko | da42bd5 | 2008-01-27 23:24:31 +0000 | [diff] [blame] | 901 | int i = index_in_strings(control_name, name); |
| 902 | return i >= 0 ? &control_info[i] : NULL; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | enum { |
| 906 | param_need_arg = 0x80, |
Denis Vlasenko | 9ace613 | 2007-04-19 19:55:54 +0000 | [diff] [blame] | 907 | param_line = 1 | 0x80, |
| 908 | param_rows = 2 | 0x80, |
| 909 | param_cols = 3 | 0x80, |
| 910 | param_columns = 4 | 0x80, |
| 911 | param_size = 5, |
| 912 | param_speed = 6, |
| 913 | param_ispeed = 7 | 0x80, |
| 914 | param_ospeed = 8 | 0x80, |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 915 | }; |
| 916 | |
Denis Vlasenko | c7cc5a9 | 2009-04-19 01:27:20 +0000 | [diff] [blame] | 917 | static int find_param(const char *name) |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 918 | { |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 919 | static const char params[] ALIGN1 = |
Denis Vlasenko | 990d0f6 | 2007-07-24 15:54:42 +0000 | [diff] [blame] | 920 | "line\0" /* 1 */ |
| 921 | "rows\0" /* 2 */ |
| 922 | "cols\0" /* 3 */ |
| 923 | "columns\0" /* 4 */ |
| 924 | "size\0" /* 5 */ |
| 925 | "speed\0" /* 6 */ |
| 926 | "ispeed\0" |
| 927 | "ospeed\0"; |
| 928 | int i = index_in_strings(params, name) + 1; |
Bernhard Reutner-Fischer | 3a60244 | 2007-04-04 13:59:49 +0000 | [diff] [blame] | 929 | if (i == 0) |
Bernhard Reutner-Fischer | cbd6e65 | 2007-02-04 11:13:57 +0000 | [diff] [blame] | 930 | return 0; |
Denis Vlasenko | 9ace613 | 2007-04-19 19:55:54 +0000 | [diff] [blame] | 931 | if (i != 5 && i != 6) |
Bernhard Reutner-Fischer | cbd6e65 | 2007-02-04 11:13:57 +0000 | [diff] [blame] | 932 | i |= 0x80; |
Bernhard Reutner-Fischer | a6e31ad | 2007-01-17 19:45:14 +0000 | [diff] [blame] | 933 | return i; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 934 | } |
| 935 | |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 936 | static int recover_mode(const char *arg, struct termios *mode) |
| 937 | { |
| 938 | int i, n; |
Denis Vlasenko | 240a1cf | 2007-04-08 16:07:02 +0000 | [diff] [blame] | 939 | unsigned chr; |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 940 | unsigned long iflag, oflag, cflag, lflag; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 941 | |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 942 | /* Scan into temporaries since it is too much trouble to figure out |
| 943 | the right format for 'tcflag_t' */ |
| 944 | if (sscanf(arg, "%lx:%lx:%lx:%lx%n", |
| 945 | &iflag, &oflag, &cflag, &lflag, &n) != 4) |
| 946 | return 0; |
| 947 | mode->c_iflag = iflag; |
| 948 | mode->c_oflag = oflag; |
| 949 | mode->c_cflag = cflag; |
| 950 | mode->c_lflag = lflag; |
| 951 | arg += n; |
| 952 | for (i = 0; i < NCCS; ++i) { |
| 953 | if (sscanf(arg, ":%x%n", &chr, &n) != 1) |
| 954 | return 0; |
| 955 | mode->c_cc[i] = chr; |
| 956 | arg += n; |
| 957 | } |
| 958 | |
| 959 | /* Fail if there are too many fields */ |
| 960 | if (*arg != '\0') |
| 961 | return 0; |
| 962 | |
| 963 | return 1; |
| 964 | } |
| 965 | |
Bernhard Reutner-Fischer | 94feb1c | 2007-01-17 19:46:12 +0000 | [diff] [blame] | 966 | static void display_recoverable(const struct termios *mode, |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 967 | int UNUSED_PARAM dummy) |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 968 | { |
| 969 | int i; |
| 970 | printf("%lx:%lx:%lx:%lx", |
| 971 | (unsigned long) mode->c_iflag, (unsigned long) mode->c_oflag, |
| 972 | (unsigned long) mode->c_cflag, (unsigned long) mode->c_lflag); |
| 973 | for (i = 0; i < NCCS; ++i) |
| 974 | printf(":%x", (unsigned int) mode->c_cc[i]); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 975 | bb_putchar('\n'); |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | static void display_speed(const struct termios *mode, int fancy) |
| 979 | { |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 980 | //____________________ 01234567 8 9 |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 981 | const char *fmt_str = "%lu %lu\n\0ispeed %lu baud; ospeed %lu baud;"; |
| 982 | unsigned long ispeed, ospeed; |
| 983 | |
Denys Vlasenko | e54cfc5 | 2011-01-24 18:30:35 +0100 | [diff] [blame] | 984 | ispeed = cfgetispeed(mode); |
| 985 | ospeed = cfgetospeed(mode); |
| 986 | if (ispeed == 0 || ispeed == ospeed) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 987 | ispeed = ospeed; /* in case ispeed was 0 */ |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 988 | //________ 0123 4 5 6 7 8 9 |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 989 | fmt_str = "%lu\n\0\0\0\0\0speed %lu baud;"; |
| 990 | } |
| 991 | if (fancy) fmt_str += 9; |
| 992 | wrapf(fmt_str, tty_baud_to_value(ispeed), tty_baud_to_value(ospeed)); |
| 993 | } |
| 994 | |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 995 | static void do_display(const struct termios *mode, int all) |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 996 | { |
| 997 | int i; |
| 998 | tcflag_t *bitsp; |
| 999 | unsigned long mask; |
| 1000 | int prev_type = control; |
| 1001 | |
| 1002 | display_speed(mode, 1); |
Bernhard Reutner-Fischer | 94feb1c | 2007-01-17 19:46:12 +0000 | [diff] [blame] | 1003 | if (all) |
| 1004 | display_window_size(1); |
Denys Vlasenko | e54cfc5 | 2011-01-24 18:30:35 +0100 | [diff] [blame] | 1005 | #ifdef __linux__ |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 1006 | wrapf("line = %u;\n", mode->c_line); |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1007 | #else |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 1008 | newline(); |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1009 | #endif |
| 1010 | |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1011 | for (i = 0; i != CIDX_min; ++i) { |
Bartosz Golaszewski | 79c618c | 2013-07-30 06:29:42 +0200 | [diff] [blame] | 1012 | char ch; |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1013 | /* If swtch is the same as susp, don't print both */ |
| 1014 | #if VSWTCH == VSUSP |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1015 | if (i == CIDX_swtch) |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1016 | continue; |
| 1017 | #endif |
| 1018 | /* If eof uses the same slot as min, only print whichever applies */ |
| 1019 | #if VEOF == VMIN |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 1020 | if (!(mode->c_lflag & ICANON) |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1021 | && (i == CIDX_eof || i == CIDX_eol) |
| 1022 | ) { |
| 1023 | continue; |
| 1024 | } |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1025 | #endif |
Bartosz Golaszewski | 79c618c | 2013-07-30 06:29:42 +0200 | [diff] [blame] | 1026 | ch = mode->c_cc[control_info[i].offset]; |
| 1027 | if (ch == _POSIX_VDISABLE) |
| 1028 | strcpy(G.buf, "<undef>"); |
| 1029 | else |
| 1030 | visible(ch, G.buf, 0); |
| 1031 | wrapf("%s = %s;", nth_string(control_name, i), G.buf); |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1032 | } |
| 1033 | #if VEOF == VMIN |
| 1034 | if ((mode->c_lflag & ICANON) == 0) |
| 1035 | #endif |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 1036 | wrapf("min = %u; time = %u;", mode->c_cc[VMIN], mode->c_cc[VTIME]); |
| 1037 | newline(); |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1038 | |
| 1039 | for (i = 0; i < NUM_mode_info; ++i) { |
| 1040 | if (mode_info[i].flags & OMIT) |
| 1041 | continue; |
| 1042 | if (mode_info[i].type != prev_type) { |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 1043 | newline(); |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1044 | prev_type = mode_info[i].type; |
| 1045 | } |
| 1046 | |
Denys Vlasenko | e9581b6 | 2013-05-17 18:06:49 +0200 | [diff] [blame] | 1047 | bitsp = get_ptr_to_tcflag(mode_info[i].type, mode); |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1048 | mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; |
Bernhard Reutner-Fischer | 94feb1c | 2007-01-17 19:46:12 +0000 | [diff] [blame] | 1049 | if ((*bitsp & mask) == mode_info[i].bits) { |
| 1050 | if (all || (mode_info[i].flags & SANE_UNSET)) |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 1051 | wrapf("-%s"+1, nth_string(mode_name, i)); |
Bernhard Reutner-Fischer | 94feb1c | 2007-01-17 19:46:12 +0000 | [diff] [blame] | 1052 | } else { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 1053 | if ((all && mode_info[i].flags & REV) |
| 1054 | || (!all && (mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)) |
| 1055 | ) { |
| 1056 | wrapf("-%s", nth_string(mode_name, i)); |
| 1057 | } |
Bernhard Reutner-Fischer | 94feb1c | 2007-01-17 19:46:12 +0000 | [diff] [blame] | 1058 | } |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1059 | } |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 1060 | newline(); |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | static void sane_mode(struct termios *mode) |
| 1064 | { |
| 1065 | int i; |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1066 | |
| 1067 | for (i = 0; i < NUM_control_info; ++i) { |
| 1068 | #if VMIN == VEOF |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1069 | if (i == CIDX_min) |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1070 | break; |
| 1071 | #endif |
| 1072 | mode->c_cc[control_info[i].offset] = control_info[i].saneval; |
| 1073 | } |
| 1074 | |
| 1075 | for (i = 0; i < NUM_mode_info; ++i) { |
Denys Vlasenko | e9581b6 | 2013-05-17 18:06:49 +0200 | [diff] [blame] | 1076 | tcflag_t val; |
| 1077 | tcflag_t *bitsp = get_ptr_to_tcflag(mode_info[i].type, mode); |
| 1078 | |
| 1079 | if (!bitsp) |
| 1080 | continue; |
| 1081 | val = *bitsp & ~((unsigned long)mode_info[i].mask); |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1082 | if (mode_info[i].flags & SANE_SET) { |
Denys Vlasenko | e9581b6 | 2013-05-17 18:06:49 +0200 | [diff] [blame] | 1083 | *bitsp = val | mode_info[i].bits; |
| 1084 | } else |
| 1085 | if (mode_info[i].flags & SANE_UNSET) { |
| 1086 | *bitsp = val & ~mode_info[i].bits; |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | } |
| 1090 | |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1091 | static void set_mode(const struct mode_info *info, int reversed, |
| 1092 | struct termios *mode) |
| 1093 | { |
| 1094 | tcflag_t *bitsp; |
| 1095 | |
Denys Vlasenko | e9581b6 | 2013-05-17 18:06:49 +0200 | [diff] [blame] | 1096 | bitsp = get_ptr_to_tcflag(info->type, mode); |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1097 | |
| 1098 | if (bitsp) { |
Denys Vlasenko | e9581b6 | 2013-05-17 18:06:49 +0200 | [diff] [blame] | 1099 | tcflag_t val = *bitsp & ~info->mask; |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1100 | if (reversed) |
Denys Vlasenko | e9581b6 | 2013-05-17 18:06:49 +0200 | [diff] [blame] | 1101 | *bitsp = val & ~info->bits; |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1102 | else |
Denys Vlasenko | e9581b6 | 2013-05-17 18:06:49 +0200 | [diff] [blame] | 1103 | *bitsp = val | info->bits; |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1104 | return; |
| 1105 | } |
| 1106 | |
Denys Vlasenko | e9581b6 | 2013-05-17 18:06:49 +0200 | [diff] [blame] | 1107 | /* !bitsp - it's a "combination" mode */ |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1108 | if (info == &mode_info[IDX_evenp] || info == &mode_info[IDX_parity]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1109 | if (reversed) |
| 1110 | mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8; |
| 1111 | else |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 1112 | mode->c_cflag = (mode->c_cflag & ~PARODD & ~CSIZE) | PARENB | CS7; |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1113 | } else if (info == &mode_info[IDX_oddp]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1114 | if (reversed) |
| 1115 | mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8; |
| 1116 | else |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 1117 | mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARODD | PARENB; |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1118 | } else if (info == &mode_info[IDX_nl]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1119 | if (reversed) { |
| 1120 | mode->c_iflag = (mode->c_iflag | ICRNL) & ~INLCR & ~IGNCR; |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 1121 | mode->c_oflag = (mode->c_oflag | ONLCR) & ~OCRNL & ~ONLRET; |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1122 | } else { |
| 1123 | mode->c_iflag = mode->c_iflag & ~ICRNL; |
| 1124 | if (ONLCR) mode->c_oflag = mode->c_oflag & ~ONLCR; |
| 1125 | } |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1126 | } else if (info == &mode_info[IDX_ek]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1127 | mode->c_cc[VERASE] = CERASE; |
| 1128 | mode->c_cc[VKILL] = CKILL; |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1129 | } else if (info == &mode_info[IDX_sane]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1130 | sane_mode(mode); |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1131 | } else if (info == &mode_info[IDX_cbreak]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1132 | if (reversed) |
| 1133 | mode->c_lflag |= ICANON; |
| 1134 | else |
| 1135 | mode->c_lflag &= ~ICANON; |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1136 | } else if (info == &mode_info[IDX_pass8]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1137 | if (reversed) { |
| 1138 | mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARENB; |
| 1139 | mode->c_iflag |= ISTRIP; |
| 1140 | } else { |
| 1141 | mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8; |
| 1142 | mode->c_iflag &= ~ISTRIP; |
| 1143 | } |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1144 | } else if (info == &mode_info[IDX_litout]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1145 | if (reversed) { |
| 1146 | mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARENB; |
| 1147 | mode->c_iflag |= ISTRIP; |
| 1148 | mode->c_oflag |= OPOST; |
| 1149 | } else { |
| 1150 | mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8; |
| 1151 | mode->c_iflag &= ~ISTRIP; |
| 1152 | mode->c_oflag &= ~OPOST; |
| 1153 | } |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1154 | } else if (info == &mode_info[IDX_raw] || info == &mode_info[IDX_cooked]) { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 1155 | if ((info == &mode_info[IDX_raw] && reversed) |
| 1156 | || (info == &mode_info[IDX_cooked] && !reversed) |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1157 | ) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1158 | /* Cooked mode */ |
| 1159 | mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON; |
| 1160 | mode->c_oflag |= OPOST; |
| 1161 | mode->c_lflag |= ISIG | ICANON; |
| 1162 | #if VMIN == VEOF |
| 1163 | mode->c_cc[VEOF] = CEOF; |
| 1164 | #endif |
| 1165 | #if VTIME == VEOL |
| 1166 | mode->c_cc[VEOL] = CEOL; |
| 1167 | #endif |
| 1168 | } else { |
| 1169 | /* Raw mode */ |
| 1170 | mode->c_iflag = 0; |
| 1171 | mode->c_oflag &= ~OPOST; |
| 1172 | mode->c_lflag &= ~(ISIG | ICANON | XCASE); |
| 1173 | mode->c_cc[VMIN] = 1; |
| 1174 | mode->c_cc[VTIME] = 0; |
| 1175 | } |
| 1176 | } |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 1177 | #if IXANY |
| 1178 | else if (info == &mode_info[IDX_decctlq]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1179 | if (reversed) |
| 1180 | mode->c_iflag |= IXANY; |
| 1181 | else |
| 1182 | mode->c_iflag &= ~IXANY; |
| 1183 | } |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 1184 | #endif |
| 1185 | #if TABDLY |
| 1186 | else if (info == &mode_info[IDX_tabs]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1187 | if (reversed) |
| 1188 | mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB3; |
| 1189 | else |
| 1190 | mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB0; |
| 1191 | } |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 1192 | #endif |
| 1193 | #if OXTABS |
| 1194 | else if (info == &mode_info[IDX_tabs]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1195 | if (reversed) |
| 1196 | mode->c_oflag |= OXTABS; |
| 1197 | else |
| 1198 | mode->c_oflag &= ~OXTABS; |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 1199 | } |
| 1200 | #endif |
| 1201 | #if XCASE && IUCLC && OLCUC |
| 1202 | else if (info==&mode_info[IDX_lcase] || info==&mode_info[IDX_LCASE]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1203 | if (reversed) { |
| 1204 | mode->c_lflag &= ~XCASE; |
| 1205 | mode->c_iflag &= ~IUCLC; |
| 1206 | mode->c_oflag &= ~OLCUC; |
| 1207 | } else { |
| 1208 | mode->c_lflag |= XCASE; |
| 1209 | mode->c_iflag |= IUCLC; |
| 1210 | mode->c_oflag |= OLCUC; |
| 1211 | } |
Jeremie Koenig | 138ce54 | 2010-07-30 06:01:37 +0200 | [diff] [blame] | 1212 | } |
| 1213 | #endif |
| 1214 | else if (info == &mode_info[IDX_crt]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1215 | mode->c_lflag |= ECHOE | ECHOCTL | ECHOKE; |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1216 | } else if (info == &mode_info[IDX_dec]) { |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1217 | mode->c_cc[VINTR] = 3; /* ^C */ |
| 1218 | mode->c_cc[VERASE] = 127; /* DEL */ |
| 1219 | mode->c_cc[VKILL] = 21; /* ^U */ |
| 1220 | mode->c_lflag |= ECHOE | ECHOCTL | ECHOKE; |
| 1221 | if (IXANY) mode->c_iflag &= ~IXANY; |
| 1222 | } |
| 1223 | } |
| 1224 | |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 1225 | static void set_control_char_or_die(const struct control_info *info, |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1226 | const char *arg, struct termios *mode) |
| 1227 | { |
| 1228 | unsigned char value; |
| 1229 | |
Denis Vlasenko | 2ea8c40 | 2007-10-11 16:02:36 +0000 | [diff] [blame] | 1230 | if (info == &control_info[CIDX_min] || info == &control_info[CIDX_time]) |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1231 | value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes); |
| 1232 | else if (arg[0] == '\0' || arg[1] == '\0') |
| 1233 | value = arg[0]; |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 1234 | else if (strcmp(arg, "^-") == 0 || strcmp(arg, "undef") == 0) |
Denis Vlasenko | f8abc10 | 2007-01-12 21:02:04 +0000 | [diff] [blame] | 1235 | value = _POSIX_VDISABLE; |
| 1236 | else if (arg[0] == '^') { /* Ignore any trailing junk (^Cjunk) */ |
| 1237 | value = arg[1] & 0x1f; /* Non-letters get weird results */ |
| 1238 | if (arg[1] == '?') |
| 1239 | value = 127; |
| 1240 | } else |
| 1241 | value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes); |
| 1242 | mode->c_cc[info->offset] = value; |
| 1243 | } |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 1244 | |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 1245 | #define STTY_require_set_attr (1 << 0) |
| 1246 | #define STTY_speed_was_set (1 << 1) |
| 1247 | #define STTY_verbose_output (1 << 2) |
| 1248 | #define STTY_recoverable_output (1 << 3) |
| 1249 | #define STTY_noargs (1 << 4) |
| 1250 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 1251 | int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 1252 | int stty_main(int argc UNUSED_PARAM, char **argv) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1253 | { |
| 1254 | struct termios mode; |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 1255 | void (*output_func)(const struct termios *, int); |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1256 | const char *file_name = NULL; |
Bernhard Reutner-Fischer | 94feb1c | 2007-01-17 19:46:12 +0000 | [diff] [blame] | 1257 | int display_all = 0; |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1258 | int stty_state; |
| 1259 | int k; |
| 1260 | |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 1261 | INIT_G(); |
| 1262 | |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1263 | stty_state = STTY_noargs; |
Bernhard Reutner-Fischer | 94feb1c | 2007-01-17 19:46:12 +0000 | [diff] [blame] | 1264 | output_func = do_display; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1265 | |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1266 | /* First pass: only parse/verify command line params */ |
| 1267 | k = 0; |
| 1268 | while (argv[++k]) { |
| 1269 | const struct mode_info *mp; |
| 1270 | const struct control_info *cp; |
| 1271 | const char *arg = argv[k]; |
| 1272 | const char *argnext = argv[k+1]; |
| 1273 | int param; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1274 | |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1275 | if (arg[0] == '-') { |
| 1276 | int i; |
| 1277 | mp = find_mode(arg+1); |
| 1278 | if (mp) { |
| 1279 | if (!(mp->flags & REV)) |
Bernhard Reutner-Fischer | 4fa566d | 2007-01-17 19:42:30 +0000 | [diff] [blame] | 1280 | goto invalid_argument; |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1281 | stty_state &= ~STTY_noargs; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1282 | continue; |
| 1283 | } |
| 1284 | /* It is an option - parse it */ |
| 1285 | i = 0; |
| 1286 | while (arg[++i]) { |
| 1287 | switch (arg[i]) { |
| 1288 | case 'a': |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1289 | stty_state |= STTY_verbose_output; |
Bernhard Reutner-Fischer | 94feb1c | 2007-01-17 19:46:12 +0000 | [diff] [blame] | 1290 | output_func = do_display; |
| 1291 | display_all = 1; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1292 | break; |
| 1293 | case 'g': |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1294 | stty_state |= STTY_recoverable_output; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1295 | output_func = display_recoverable; |
| 1296 | break; |
| 1297 | case 'F': |
| 1298 | if (file_name) |
| 1299 | bb_error_msg_and_die("only one device may be specified"); |
| 1300 | file_name = &arg[i+1]; /* "-Fdevice" ? */ |
| 1301 | if (!file_name[0]) { /* nope, "-F device" */ |
| 1302 | int p = k+1; /* argv[p] is argnext */ |
| 1303 | file_name = argnext; |
| 1304 | if (!file_name) |
| 1305 | bb_error_msg_and_die(bb_msg_requires_arg, "-F"); |
| 1306 | /* remove -F param from arg[vc] */ |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 1307 | while (argv[p]) { |
| 1308 | argv[p] = argv[p+1]; |
| 1309 | ++p; |
| 1310 | } |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1311 | } |
| 1312 | goto end_option; |
| 1313 | default: |
Bernhard Reutner-Fischer | 4fa566d | 2007-01-17 19:42:30 +0000 | [diff] [blame] | 1314 | goto invalid_argument; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1315 | } |
| 1316 | } |
Denis Vlasenko | 240a1cf | 2007-04-08 16:07:02 +0000 | [diff] [blame] | 1317 | end_option: |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1318 | continue; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1321 | mp = find_mode(arg); |
| 1322 | if (mp) { |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1323 | stty_state &= ~STTY_noargs; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1324 | continue; |
| 1325 | } |
| 1326 | |
| 1327 | cp = find_control(arg); |
| 1328 | if (cp) { |
| 1329 | if (!argnext) |
| 1330 | bb_error_msg_and_die(bb_msg_requires_arg, arg); |
Denis Vlasenko | 20b253d | 2006-09-19 14:24:23 +0000 | [diff] [blame] | 1331 | /* called for the side effect of xfunc death only */ |
| 1332 | set_control_char_or_die(cp, argnext, &mode); |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1333 | stty_state &= ~STTY_noargs; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1334 | ++k; |
| 1335 | continue; |
| 1336 | } |
| 1337 | |
| 1338 | param = find_param(arg); |
| 1339 | if (param & param_need_arg) { |
| 1340 | if (!argnext) |
| 1341 | bb_error_msg_and_die(bb_msg_requires_arg, arg); |
| 1342 | ++k; |
| 1343 | } |
| 1344 | |
| 1345 | switch (param) { |
Denys Vlasenko | e54cfc5 | 2011-01-24 18:30:35 +0100 | [diff] [blame] | 1346 | #ifdef __linux__ |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1347 | case param_line: |
Denis Vlasenko | e40c04b | 2006-09-19 14:19:42 +0000 | [diff] [blame] | 1348 | # ifndef TIOCGWINSZ |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 1349 | xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes); |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1350 | break; |
Denis Vlasenko | e40c04b | 2006-09-19 14:19:42 +0000 | [diff] [blame] | 1351 | # endif /* else fall-through */ |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1352 | #endif |
| 1353 | #ifdef TIOCGWINSZ |
| 1354 | case param_rows: |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1355 | case param_cols: |
Denis Vlasenko | 9ace613 | 2007-04-19 19:55:54 +0000 | [diff] [blame] | 1356 | case param_columns: |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 1357 | xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes); |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1358 | break; |
| 1359 | case param_size: |
| 1360 | #endif |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1361 | case param_speed: |
| 1362 | break; |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 1363 | case param_ispeed: |
| 1364 | /* called for the side effect of xfunc death only */ |
| 1365 | set_speed_or_die(input_speed, argnext, &mode); |
| 1366 | break; |
| 1367 | case param_ospeed: |
| 1368 | /* called for the side effect of xfunc death only */ |
| 1369 | set_speed_or_die(output_speed, argnext, &mode); |
| 1370 | break; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1371 | default: |
| 1372 | if (recover_mode(arg, &mode) == 1) break; |
Bernhard Reutner-Fischer | 4950f01 | 2007-01-17 19:44:59 +0000 | [diff] [blame] | 1373 | if (tty_value_to_baud(xatou(arg)) != (speed_t) -1) break; |
Denis Vlasenko | 240a1cf | 2007-04-08 16:07:02 +0000 | [diff] [blame] | 1374 | invalid_argument: |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1375 | bb_error_msg_and_die("invalid argument '%s'", arg); |
| 1376 | } |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1377 | stty_state &= ~STTY_noargs; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1380 | /* Specifying both -a and -g is an error */ |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1381 | if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) == |
Denys Vlasenko | 5dd1f47 | 2011-10-21 19:45:13 +0200 | [diff] [blame] | 1382 | (STTY_verbose_output | STTY_recoverable_output) |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 1383 | ) { |
Denys Vlasenko | 5dd1f47 | 2011-10-21 19:45:13 +0200 | [diff] [blame] | 1384 | bb_error_msg_and_die("-a and -g are mutually exclusive"); |
| 1385 | } |
| 1386 | /* Specifying -a or -g with non-options is an error */ |
| 1387 | if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) |
| 1388 | && !(stty_state & STTY_noargs) |
| 1389 | ) { |
| 1390 | bb_error_msg_and_die("modes may not be set when -a or -g is used"); |
Denys Vlasenko | 800ff7c | 2009-12-11 15:00:17 +0100 | [diff] [blame] | 1391 | } |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1392 | |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1393 | /* Now it is safe to start doing things */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1394 | if (file_name) { |
Denis Vlasenko | dd8bbfd | 2007-11-24 04:32:49 +0000 | [diff] [blame] | 1395 | G.device_name = file_name; |
Denys Vlasenko | ab19ede | 2009-11-11 21:05:42 +0100 | [diff] [blame] | 1396 | xmove_fd(xopen_nonblocking(G.device_name), STDIN_FILENO); |
| 1397 | ndelay_off(STDIN_FILENO); |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /* Initialize to all zeroes so there is no risk memcmp will report a |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 1401 | spurious difference in an uninitialized portion of the structure */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1402 | memset(&mode, 0, sizeof(mode)); |
"Vladimir N. Oleynik" | 9b9a920 | 2006-01-30 12:23:46 +0000 | [diff] [blame] | 1403 | if (tcgetattr(STDIN_FILENO, &mode)) |
Denis Vlasenko | 20b253d | 2006-09-19 14:24:23 +0000 | [diff] [blame] | 1404 | perror_on_device_and_die("%s"); |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1405 | |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1406 | if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) { |
Denys Vlasenko | 641caae | 2015-10-23 01:44:22 +0200 | [diff] [blame] | 1407 | G.max_col = get_terminal_width(STDOUT_FILENO); |
Bernhard Reutner-Fischer | 94feb1c | 2007-01-17 19:46:12 +0000 | [diff] [blame] | 1408 | output_func(&mode, display_all); |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1409 | return EXIT_SUCCESS; |
| 1410 | } |
| 1411 | |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1412 | /* Second pass: perform actions */ |
Eric Andersen | fc05909 | 2002-06-06 11:35:29 +0000 | [diff] [blame] | 1413 | k = 0; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1414 | while (argv[++k]) { |
| 1415 | const struct mode_info *mp; |
| 1416 | const struct control_info *cp; |
| 1417 | const char *arg = argv[k]; |
| 1418 | const char *argnext = argv[k+1]; |
| 1419 | int param; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1420 | |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1421 | if (arg[0] == '-') { |
| 1422 | mp = find_mode(arg+1); |
| 1423 | if (mp) { |
| 1424 | set_mode(mp, 1 /* reversed */, &mode); |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1425 | stty_state |= STTY_require_set_attr; |
Eric Andersen | fc05909 | 2002-06-06 11:35:29 +0000 | [diff] [blame] | 1426 | } |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1427 | /* It is an option - already parsed. Skip it */ |
| 1428 | continue; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1429 | } |
Mark Whitley | 446dd27 | 2001-03-02 20:00:54 +0000 | [diff] [blame] | 1430 | |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1431 | mp = find_mode(arg); |
| 1432 | if (mp) { |
| 1433 | set_mode(mp, 0 /* non-reversed */, &mode); |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1434 | stty_state |= STTY_require_set_attr; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1435 | continue; |
| 1436 | } |
Mark Whitley | 446dd27 | 2001-03-02 20:00:54 +0000 | [diff] [blame] | 1437 | |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1438 | cp = find_control(arg); |
| 1439 | if (cp) { |
| 1440 | ++k; |
Denis Vlasenko | 20b253d | 2006-09-19 14:24:23 +0000 | [diff] [blame] | 1441 | set_control_char_or_die(cp, argnext, &mode); |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1442 | stty_state |= STTY_require_set_attr; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1443 | continue; |
| 1444 | } |
Mark Whitley | 446dd27 | 2001-03-02 20:00:54 +0000 | [diff] [blame] | 1445 | |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1446 | param = find_param(arg); |
| 1447 | if (param & param_need_arg) { |
| 1448 | ++k; |
| 1449 | } |
| 1450 | |
| 1451 | switch (param) { |
Denys Vlasenko | e54cfc5 | 2011-01-24 18:30:35 +0100 | [diff] [blame] | 1452 | #ifdef __linux__ |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1453 | case param_line: |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 1454 | mode.c_line = xatoul_sfx(argnext, stty_suffixes); |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1455 | stty_state |= STTY_require_set_attr; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1456 | break; |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1457 | #endif |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1458 | #ifdef TIOCGWINSZ |
| 1459 | case param_cols: |
Denys Vlasenko | 9f5a577 | 2009-12-11 14:17:02 +0100 | [diff] [blame] | 1460 | case param_columns: |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 1461 | set_window_size(-1, xatoul_sfx(argnext, stty_suffixes)); |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1462 | break; |
| 1463 | case param_size: |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1464 | display_window_size(0); |
| 1465 | break; |
| 1466 | case param_rows: |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 1467 | set_window_size(xatoul_sfx(argnext, stty_suffixes), -1); |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1468 | break; |
| 1469 | #endif |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1470 | case param_speed: |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1471 | display_speed(&mode, 0); |
| 1472 | break; |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 1473 | case param_ispeed: |
| 1474 | set_speed_or_die(input_speed, argnext, &mode); |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1475 | stty_state |= (STTY_require_set_attr | STTY_speed_was_set); |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 1476 | break; |
| 1477 | case param_ospeed: |
| 1478 | set_speed_or_die(output_speed, argnext, &mode); |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1479 | stty_state |= (STTY_require_set_attr | STTY_speed_was_set); |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 1480 | break; |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1481 | default: |
| 1482 | if (recover_mode(arg, &mode) == 1) |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1483 | stty_state |= STTY_require_set_attr; |
Bernhard Reutner-Fischer | 4950f01 | 2007-01-17 19:44:59 +0000 | [diff] [blame] | 1484 | else /* true: if (tty_value_to_baud(xatou(arg)) != (speed_t) -1) */{ |
Denis Vlasenko | debaf2f | 2006-09-19 14:31:44 +0000 | [diff] [blame] | 1485 | set_speed_or_die(both_speeds, arg, &mode); |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1486 | stty_state |= (STTY_require_set_attr | STTY_speed_was_set); |
Denis Vlasenko | 7eab79a | 2006-09-19 14:16:28 +0000 | [diff] [blame] | 1487 | } /* else - impossible (caught in the first pass): |
| 1488 | bb_error_msg_and_die("invalid argument '%s'", arg); */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1489 | } |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1492 | if (stty_state & STTY_require_set_attr) { |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1493 | struct termios new_mode; |
| 1494 | |
"Vladimir N. Oleynik" | 9b9a920 | 2006-01-30 12:23:46 +0000 | [diff] [blame] | 1495 | if (tcsetattr(STDIN_FILENO, TCSADRAIN, &mode)) |
Denis Vlasenko | 20b253d | 2006-09-19 14:24:23 +0000 | [diff] [blame] | 1496 | perror_on_device_and_die("%s"); |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1497 | |
| 1498 | /* POSIX (according to Zlotnick's book) tcsetattr returns zero if |
| 1499 | it performs *any* of the requested operations. This means it |
Denis Vlasenko | 79deb66 | 2006-09-19 15:12:12 +0000 | [diff] [blame] | 1500 | can report 'success' when it has actually failed to perform |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1501 | some proper subset of the requested operations. To detect |
| 1502 | this partial failure, get the current terminal attributes and |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 1503 | compare them to the requested ones */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1504 | |
| 1505 | /* Initialize to all zeroes so there is no risk memcmp will report a |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 1506 | spurious difference in an uninitialized portion of the structure */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1507 | memset(&new_mode, 0, sizeof(new_mode)); |
"Vladimir N. Oleynik" | 9b9a920 | 2006-01-30 12:23:46 +0000 | [diff] [blame] | 1508 | if (tcgetattr(STDIN_FILENO, &new_mode)) |
Denis Vlasenko | 20b253d | 2006-09-19 14:24:23 +0000 | [diff] [blame] | 1509 | perror_on_device_and_die("%s"); |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1510 | |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1511 | if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) { |
Denys Vlasenko | ae0cf2a | 2013-05-17 20:08:12 +0200 | [diff] [blame] | 1512 | /* |
| 1513 | * I think the below chunk is not necessary on Linux. |
| 1514 | * If you are deleting it, also delete STTY_speed_was_set bit - |
| 1515 | * it is only ever checked here. |
| 1516 | */ |
| 1517 | #if 0 /* was "if CIBAUD" */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1518 | /* SunOS 4.1.3 (at least) has the problem that after this sequence, |
| 1519 | tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2); |
| 1520 | sometimes (m1 != m2). The only difference is in the four bits |
| 1521 | of the c_cflag field corresponding to the baud rate. To save |
| 1522 | Sun users a little confusion, don't report an error if this |
| 1523 | happens. But suppress the error only if we haven't tried to |
| 1524 | set the baud rate explicitly -- otherwise we'd never give an |
Denis Vlasenko | 9efb070 | 2006-09-19 14:17:10 +0000 | [diff] [blame] | 1525 | error for a true failure to set the baud rate */ |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1526 | |
| 1527 | new_mode.c_cflag &= (~CIBAUD); |
Denis Vlasenko | 41aaefc | 2007-01-18 00:53:35 +0000 | [diff] [blame] | 1528 | if ((stty_state & STTY_speed_was_set) |
| 1529 | || memcmp(&mode, &new_mode, sizeof(mode)) != 0) |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1530 | #endif |
Denis Vlasenko | 89f0b34 | 2006-11-18 22:04:09 +0000 | [diff] [blame] | 1531 | perror_on_device_and_die("%s: cannot perform all requested operations"); |
Eric Andersen | 98e599c | 2001-02-14 18:47:33 +0000 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | return EXIT_SUCCESS; |
| 1536 | } |