Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/stty.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/coreutils/stty.c
r1765 r2725 3 3 Copyright (C) 1990-1999 Free Software Foundation, Inc. 4 4 5 Licensed under the GPL v2 or later, see the file LICENSE in this tarball.5 Licensed under GPLv2 or later, see file LICENSE in this source tree. 6 6 */ 7 7 /* Usage: stty [-ag] [-F device] [setting...] … … 114 114 #if defined(VSTATUS) && !defined(CSTATUS) 115 115 # define CSTATUS Control('t') 116 #endif 117 118 /* Save us from #ifdef forest plague */ 119 #ifndef BSDLY 120 # define BSDLY 0 121 #endif 122 #ifndef CIBAUD 123 # define CIBAUD 0 124 #endif 125 #ifndef CRDLY 126 # define CRDLY 0 127 #endif 128 #ifndef CRTSCTS 129 # define CRTSCTS 0 130 #endif 131 #ifndef ECHOCTL 132 # define ECHOCTL 0 133 #endif 134 #ifndef ECHOKE 135 # define ECHOKE 0 136 #endif 137 #ifndef ECHOPRT 138 # define ECHOPRT 0 139 #endif 140 #ifndef FFDLY 141 # define FFDLY 0 142 #endif 143 #ifndef IEXTEN 144 # define IEXTEN 0 145 #endif 146 #ifndef IMAXBEL 147 # define IMAXBEL 0 148 #endif 149 #ifndef IUCLC 150 # define IUCLC 0 151 #endif 152 #ifndef IXANY 153 # define IXANY 0 154 #endif 155 #ifndef NLDLY 156 # define NLDLY 0 157 #endif 158 #ifndef OCRNL 159 # define OCRNL 0 160 #endif 161 #ifndef OFDEL 162 # define OFDEL 0 163 #endif 164 #ifndef OFILL 165 # define OFILL 0 166 #endif 167 #ifndef OLCUC 168 # define OLCUC 0 169 #endif 170 #ifndef ONLCR 171 # define ONLCR 0 172 #endif 173 #ifndef ONLRET 174 # define ONLRET 0 175 #endif 176 #ifndef ONOCR 177 # define ONOCR 0 178 #endif 179 #ifndef OXTABS 180 # define OXTABS 0 181 #endif 182 #ifndef TABDLY 183 # define TABDLY 0 184 #endif 185 #ifndef TAB1 186 # define TAB1 0 187 #endif 188 #ifndef TAB2 189 # define TAB2 0 190 #endif 191 #ifndef TOSTOP 192 # define TOSTOP 0 193 #endif 194 #ifndef VDSUSP 195 # define VDSUSP 0 196 #endif 197 #ifndef VEOL2 198 # define VEOL2 0 199 #endif 200 #ifndef VFLUSHO 201 # define VFLUSHO 0 202 #endif 203 #ifndef VLNEXT 204 # define VLNEXT 0 205 #endif 206 #ifndef VREPRINT 207 # define VREPRINT 0 208 #endif 209 #ifndef VSTATUS 210 # define VSTATUS 0 211 #endif 212 #ifndef VSWTCH 213 # define VSWTCH 0 214 #endif 215 #ifndef VTDLY 216 # define VTDLY 0 217 #endif 218 #ifndef VWERASE 219 # define VWERASE 0 220 #endif 221 #ifndef XCASE 222 # define XCASE 0 116 223 #endif 117 224 … … 128 235 }; 129 236 130 static const char evenp [] ALIGN1 = "evenp";131 static const char raw [] ALIGN1 = "raw";132 static const char stty_min [] ALIGN1 = "min";133 static const char stty_time [] ALIGN1 = "time";134 static const char stty_swtch[] ALIGN1 = "swtch";135 static const char stty_eol [] ALIGN1 = "eol";136 static const char stty_eof [] ALIGN1 = "eof";137 static const char parity [] ALIGN1 = "parity";138 static const char stty_oddp [] ALIGN1 = "oddp";139 static const char stty_nl [] ALIGN1 = "nl";140 static const char stty_ek [] ALIGN1 = "ek";141 static const char stty_sane [] ALIGN1 = "sane";142 static const char cbreak [] ALIGN1 = "cbreak";143 static const char stty_pass8[] ALIGN1 = "pass8";144 static const char litout [] ALIGN1 = "litout";145 static const char cooked [] ALIGN1 = "cooked";146 static const char decctlq [] ALIGN1 = "decctlq";147 static const char stty_tabs [] ALIGN1 = "tabs";148 static const char stty_lcase[] ALIGN1 = "lcase";149 static const char stty_LCASE[] ALIGN1 = "LCASE";150 static const char stty_crt [] ALIGN1 = "crt";151 static const char stty_dec [] ALIGN1 = "dec";152 153 237 /* Flags for 'struct mode_info' */ 154 238 #define SANE_SET 1 /* Set in 'sane' mode */ … … 157 241 #define OMIT 8 /* Don't display value */ 158 242 159 /* Each mode */ 243 244 /* Each mode. 245 * This structure should be kept as small as humanly possible. 246 */ 160 247 struct mode_info { 161 const char *const name; /* Name given on command line */ 162 const unsigned char type; /* Which structure element to change */ 163 const unsigned char flags; /* Setting and display options */ 164 /* were using short here, but ppc32 was unhappy: */ 248 const uint8_t type; /* Which structure element to change */ 249 const uint8_t flags; /* Setting and display options */ 250 /* only these values are ever used, so... */ 251 #if (CSIZE | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY) < 0x100 252 const uint8_t mask; 253 #elif (CSIZE | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY) < 0x10000 254 const uint16_t mask; 255 #else 165 256 const tcflag_t mask; /* Other bits to turn off for this mode */ 257 #endif 258 /* was using short here, but ppc32 was unhappy */ 166 259 const tcflag_t bits; /* Bits to set for this mode */ 167 260 }; 168 261 169 /* We can optimize it further by using name[8] instead of char *name */ 170 /* but beware of "if (info->name == evenp)" checks! */ 171 /* Need to replace them with "if (info == &mode_info[EVENP_INDX])" */ 172 173 #define MI_ENTRY(N,T,F,B,M) { N, T, F, M, B } 262 enum { 263 /* Must match mode_name[] and mode_info[] order! */ 264 IDX_evenp = 0, 265 IDX_parity, 266 IDX_oddp, 267 IDX_nl, 268 IDX_ek, 269 IDX_sane, 270 IDX_cooked, 271 IDX_raw, 272 IDX_pass8, 273 IDX_litout, 274 IDX_cbreak, 275 IDX_crt, 276 IDX_dec, 277 #if IXANY 278 IDX_decctlq, 279 #endif 280 #if TABDLY || OXTABS 281 IDX_tabs, 282 #endif 283 #if XCASE && IUCLC && OLCUC 284 IDX_lcase, 285 IDX_LCASE, 286 #endif 287 }; 288 289 #define MI_ENTRY(N,T,F,B,M) N "\0" 290 291 /* Mode names given on command line */ 292 static const char mode_name[] = 293 MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) 294 MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) 295 MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 ) 296 MI_ENTRY("nl", combination, REV | OMIT, 0, 0 ) 297 MI_ENTRY("ek", combination, OMIT, 0, 0 ) 298 MI_ENTRY("sane", combination, OMIT, 0, 0 ) 299 MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 ) 300 MI_ENTRY("raw", combination, REV | OMIT, 0, 0 ) 301 MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 ) 302 MI_ENTRY("litout", combination, REV | OMIT, 0, 0 ) 303 MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 ) 304 MI_ENTRY("crt", combination, OMIT, 0, 0 ) 305 MI_ENTRY("dec", combination, OMIT, 0, 0 ) 306 #if IXANY 307 MI_ENTRY("decctlq", combination, REV | OMIT, 0, 0 ) 308 #endif 309 #if TABDLY || OXTABS 310 MI_ENTRY("tabs", combination, REV | OMIT, 0, 0 ) 311 #endif 312 #if XCASE && IUCLC && OLCUC 313 MI_ENTRY("lcase", combination, REV | OMIT, 0, 0 ) 314 MI_ENTRY("LCASE", combination, REV | OMIT, 0, 0 ) 315 #endif 316 MI_ENTRY("parenb", control, REV, PARENB, 0 ) 317 MI_ENTRY("parodd", control, REV, PARODD, 0 ) 318 MI_ENTRY("cs5", control, 0, CS5, CSIZE) 319 MI_ENTRY("cs6", control, 0, CS6, CSIZE) 320 MI_ENTRY("cs7", control, 0, CS7, CSIZE) 321 MI_ENTRY("cs8", control, 0, CS8, CSIZE) 322 MI_ENTRY("hupcl", control, REV, HUPCL, 0 ) 323 MI_ENTRY("hup", control, REV | OMIT, HUPCL, 0 ) 324 MI_ENTRY("cstopb", control, REV, CSTOPB, 0 ) 325 MI_ENTRY("cread", control, SANE_SET | REV, CREAD, 0 ) 326 MI_ENTRY("clocal", control, REV, CLOCAL, 0 ) 327 #if CRTSCTS 328 MI_ENTRY("crtscts", control, REV, CRTSCTS, 0 ) 329 #endif 330 MI_ENTRY("ignbrk", input, SANE_UNSET | REV, IGNBRK, 0 ) 331 MI_ENTRY("brkint", input, SANE_SET | REV, BRKINT, 0 ) 332 MI_ENTRY("ignpar", input, REV, IGNPAR, 0 ) 333 MI_ENTRY("parmrk", input, REV, PARMRK, 0 ) 334 MI_ENTRY("inpck", input, REV, INPCK, 0 ) 335 MI_ENTRY("istrip", input, REV, ISTRIP, 0 ) 336 MI_ENTRY("inlcr", input, SANE_UNSET | REV, INLCR, 0 ) 337 MI_ENTRY("igncr", input, SANE_UNSET | REV, IGNCR, 0 ) 338 MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 ) 339 MI_ENTRY("ixon", input, REV, IXON, 0 ) 340 MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 ) 341 MI_ENTRY("tandem", input, REV | OMIT, IXOFF, 0 ) 342 #if IUCLC 343 MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 ) 344 #endif 345 #if IXANY 346 MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 ) 347 #endif 348 #if IMAXBEL 349 MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 ) 350 #endif 351 MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 ) 352 #if OLCUC 353 MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 ) 354 #endif 355 #if OCRNL 356 MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 ) 357 #endif 358 #if ONLCR 359 MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 ) 360 #endif 361 #if ONOCR 362 MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 ) 363 #endif 364 #if ONLRET 365 MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 ) 366 #endif 367 #if OFILL 368 MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 ) 369 #endif 370 #if OFDEL 371 MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 ) 372 #endif 373 #if NLDLY 374 MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY) 375 MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY) 376 #endif 377 #if CRDLY 378 MI_ENTRY("cr3", output, SANE_UNSET, CR3, CRDLY) 379 MI_ENTRY("cr2", output, SANE_UNSET, CR2, CRDLY) 380 MI_ENTRY("cr1", output, SANE_UNSET, CR1, CRDLY) 381 MI_ENTRY("cr0", output, SANE_SET, CR0, CRDLY) 382 #endif 383 384 #if TABDLY 385 MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY) 386 # if TAB2 387 MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY) 388 # endif 389 # if TAB1 390 MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY) 391 # endif 392 MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY) 393 #else 394 # if OXTABS 395 MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 ) 396 # endif 397 #endif 398 399 #if BSDLY 400 MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY) 401 MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY) 402 #endif 403 #if VTDLY 404 MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY) 405 MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY) 406 #endif 407 #if FFDLY 408 MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY) 409 MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY) 410 #endif 411 MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 ) 412 MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 ) 413 #if IEXTEN 414 MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ) 415 #endif 416 MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) 417 MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ) 418 MI_ENTRY("crterase", local, REV | OMIT, ECHOE, 0 ) 419 MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) 420 MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 ) 421 MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 ) 422 #if XCASE 423 MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 ) 424 #endif 425 #if TOSTOP 426 MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 ) 427 #endif 428 #if ECHOPRT 429 MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 ) 430 MI_ENTRY("prterase", local, REV | OMIT, ECHOPRT, 0 ) 431 #endif 432 #if ECHOCTL 433 MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 ) 434 MI_ENTRY("ctlecho", local, REV | OMIT, ECHOCTL, 0 ) 435 #endif 436 #if ECHOKE 437 MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ) 438 MI_ENTRY("crtkill", local, REV | OMIT, ECHOKE, 0 ) 439 #endif 440 ; 441 442 #undef MI_ENTRY 443 #define MI_ENTRY(N,T,F,B,M) { T, F, M, B }, 174 444 175 445 static const struct mode_info mode_info[] = { 176 MI_ENTRY("parenb", control, REV, PARENB, 0 ), 177 MI_ENTRY("parodd", control, REV, PARODD, 0 ), 178 MI_ENTRY("cs5", control, 0, CS5, CSIZE), 179 MI_ENTRY("cs6", control, 0, CS6, CSIZE), 180 MI_ENTRY("cs7", control, 0, CS7, CSIZE), 181 MI_ENTRY("cs8", control, 0, CS8, CSIZE), 182 MI_ENTRY("hupcl", control, REV, HUPCL, 0 ), 183 MI_ENTRY("hup", control, REV | OMIT, HUPCL, 0 ), 184 MI_ENTRY("cstopb", control, REV, CSTOPB, 0 ), 185 MI_ENTRY("cread", control, SANE_SET | REV, CREAD, 0 ), 186 MI_ENTRY("clocal", control, REV, CLOCAL, 0 ), 187 #ifdef CRTSCTS 188 MI_ENTRY("crtscts", control, REV, CRTSCTS, 0 ), 189 #endif 190 MI_ENTRY("ignbrk", input, SANE_UNSET | REV, IGNBRK, 0 ), 191 MI_ENTRY("brkint", input, SANE_SET | REV, BRKINT, 0 ), 192 MI_ENTRY("ignpar", input, REV, IGNPAR, 0 ), 193 MI_ENTRY("parmrk", input, REV, PARMRK, 0 ), 194 MI_ENTRY("inpck", input, REV, INPCK, 0 ), 195 MI_ENTRY("istrip", input, REV, ISTRIP, 0 ), 196 MI_ENTRY("inlcr", input, SANE_UNSET | REV, INLCR, 0 ), 197 MI_ENTRY("igncr", input, SANE_UNSET | REV, IGNCR, 0 ), 198 MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 ), 199 MI_ENTRY("ixon", input, REV, IXON, 0 ), 200 MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 ), 201 MI_ENTRY("tandem", input, REV | OMIT, IXOFF, 0 ), 202 #ifdef IUCLC 203 MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 ), 204 #endif 205 #ifdef IXANY 206 MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 ), 207 #endif 208 #ifdef IMAXBEL 209 MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 ), 210 #endif 211 MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 ), 212 #ifdef OLCUC 213 MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 ), 214 #endif 215 #ifdef OCRNL 216 MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 ), 217 #endif 218 #ifdef ONLCR 219 MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 ), 220 #endif 221 #ifdef ONOCR 222 MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 ), 223 #endif 224 #ifdef ONLRET 225 MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 ), 226 #endif 227 #ifdef OFILL 228 MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 ), 229 #endif 230 #ifdef OFDEL 231 MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 ), 232 #endif 233 #ifdef NLDLY 234 MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY), 235 MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY), 236 #endif 237 #ifdef CRDLY 238 MI_ENTRY("cr3", output, SANE_UNSET, CR3, CRDLY), 239 MI_ENTRY("cr2", output, SANE_UNSET, CR2, CRDLY), 240 MI_ENTRY("cr1", output, SANE_UNSET, CR1, CRDLY), 241 MI_ENTRY("cr0", output, SANE_SET, CR0, CRDLY), 242 #endif 243 244 #ifdef TABDLY 245 MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY), 246 MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY), 247 MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY), 248 MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY), 446 /* This should be verbatim cut-n-paste copy of the above MI_ENTRYs */ 447 MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) 448 MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) 449 MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 ) 450 MI_ENTRY("nl", combination, REV | OMIT, 0, 0 ) 451 MI_ENTRY("ek", combination, OMIT, 0, 0 ) 452 MI_ENTRY("sane", combination, OMIT, 0, 0 ) 453 MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 ) 454 MI_ENTRY("raw", combination, REV | OMIT, 0, 0 ) 455 MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 ) 456 MI_ENTRY("litout", combination, REV | OMIT, 0, 0 ) 457 MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 ) 458 MI_ENTRY("crt", combination, OMIT, 0, 0 ) 459 MI_ENTRY("dec", combination, OMIT, 0, 0 ) 460 #if IXANY 461 MI_ENTRY("decctlq", combination, REV | OMIT, 0, 0 ) 462 #endif 463 #if TABDLY || OXTABS 464 MI_ENTRY("tabs", combination, REV | OMIT, 0, 0 ) 465 #endif 466 #if XCASE && IUCLC && OLCUC 467 MI_ENTRY("lcase", combination, REV | OMIT, 0, 0 ) 468 MI_ENTRY("LCASE", combination, REV | OMIT, 0, 0 ) 469 #endif 470 MI_ENTRY("parenb", control, REV, PARENB, 0 ) 471 MI_ENTRY("parodd", control, REV, PARODD, 0 ) 472 MI_ENTRY("cs5", control, 0, CS5, CSIZE) 473 MI_ENTRY("cs6", control, 0, CS6, CSIZE) 474 MI_ENTRY("cs7", control, 0, CS7, CSIZE) 475 MI_ENTRY("cs8", control, 0, CS8, CSIZE) 476 MI_ENTRY("hupcl", control, REV, HUPCL, 0 ) 477 MI_ENTRY("hup", control, REV | OMIT, HUPCL, 0 ) 478 MI_ENTRY("cstopb", control, REV, CSTOPB, 0 ) 479 MI_ENTRY("cread", control, SANE_SET | REV, CREAD, 0 ) 480 MI_ENTRY("clocal", control, REV, CLOCAL, 0 ) 481 #if CRTSCTS 482 MI_ENTRY("crtscts", control, REV, CRTSCTS, 0 ) 483 #endif 484 MI_ENTRY("ignbrk", input, SANE_UNSET | REV, IGNBRK, 0 ) 485 MI_ENTRY("brkint", input, SANE_SET | REV, BRKINT, 0 ) 486 MI_ENTRY("ignpar", input, REV, IGNPAR, 0 ) 487 MI_ENTRY("parmrk", input, REV, PARMRK, 0 ) 488 MI_ENTRY("inpck", input, REV, INPCK, 0 ) 489 MI_ENTRY("istrip", input, REV, ISTRIP, 0 ) 490 MI_ENTRY("inlcr", input, SANE_UNSET | REV, INLCR, 0 ) 491 MI_ENTRY("igncr", input, SANE_UNSET | REV, IGNCR, 0 ) 492 MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 ) 493 MI_ENTRY("ixon", input, REV, IXON, 0 ) 494 MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 ) 495 MI_ENTRY("tandem", input, REV | OMIT, IXOFF, 0 ) 496 #if IUCLC 497 MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 ) 498 #endif 499 #if IXANY 500 MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 ) 501 #endif 502 #if IMAXBEL 503 MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 ) 504 #endif 505 MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 ) 506 #if OLCUC 507 MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 ) 508 #endif 509 #if OCRNL 510 MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 ) 511 #endif 512 #if ONLCR 513 MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 ) 514 #endif 515 #if ONOCR 516 MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 ) 517 #endif 518 #if ONLRET 519 MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 ) 520 #endif 521 #if OFILL 522 MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 ) 523 #endif 524 #if OFDEL 525 MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 ) 526 #endif 527 #if NLDLY 528 MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY) 529 MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY) 530 #endif 531 #if CRDLY 532 MI_ENTRY("cr3", output, SANE_UNSET, CR3, CRDLY) 533 MI_ENTRY("cr2", output, SANE_UNSET, CR2, CRDLY) 534 MI_ENTRY("cr1", output, SANE_UNSET, CR1, CRDLY) 535 MI_ENTRY("cr0", output, SANE_SET, CR0, CRDLY) 536 #endif 537 538 #if TABDLY 539 MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY) 540 # if TAB2 541 MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY) 542 # endif 543 # if TAB1 544 MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY) 545 # endif 546 MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY) 249 547 #else 250 # if defOXTABS251 MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 ) ,548 # if OXTABS 549 MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 ) 252 550 # endif 253 551 #endif 254 552 255 #ifdef BSDLY 256 MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY), 257 MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY), 258 #endif 259 #ifdef VTDLY 260 MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY), 261 MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY), 262 #endif 263 #ifdef FFDLY 264 MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY), 265 MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY), 266 #endif 267 MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 ), 268 MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 ), 269 #ifdef IEXTEN 270 MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ), 271 #endif 272 MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ), 273 MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ), 274 MI_ENTRY("crterase", local, REV | OMIT, ECHOE, 0 ), 275 MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ), 276 MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 ), 277 MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 ), 278 #ifdef XCASE 279 MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 ), 280 #endif 281 #ifdef TOSTOP 282 MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 ), 283 #endif 284 #ifdef ECHOPRT 285 MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 ), 286 MI_ENTRY("prterase", local, REV | OMIT, ECHOPRT, 0 ), 287 #endif 288 #ifdef ECHOCTL 289 MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 ), 290 MI_ENTRY("ctlecho", local, REV | OMIT, ECHOCTL, 0 ), 291 #endif 292 #ifdef ECHOKE 293 MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ), 294 MI_ENTRY("crtkill", local, REV | OMIT, ECHOKE, 0 ), 295 #endif 296 MI_ENTRY(evenp, combination, REV | OMIT, 0, 0 ), 297 MI_ENTRY(parity, combination, REV | OMIT, 0, 0 ), 298 MI_ENTRY(stty_oddp, combination, REV | OMIT, 0, 0 ), 299 MI_ENTRY(stty_nl, combination, REV | OMIT, 0, 0 ), 300 MI_ENTRY(stty_ek, combination, OMIT, 0, 0 ), 301 MI_ENTRY(stty_sane, combination, OMIT, 0, 0 ), 302 MI_ENTRY(cooked, combination, REV | OMIT, 0, 0 ), 303 MI_ENTRY(raw, combination, REV | OMIT, 0, 0 ), 304 MI_ENTRY(stty_pass8, combination, REV | OMIT, 0, 0 ), 305 MI_ENTRY(litout, combination, REV | OMIT, 0, 0 ), 306 MI_ENTRY(cbreak, combination, REV | OMIT, 0, 0 ), 307 #ifdef IXANY 308 MI_ENTRY(decctlq, combination, REV | OMIT, 0, 0 ), 309 #endif 310 #if defined(TABDLY) || defined(OXTABS) 311 MI_ENTRY(stty_tabs, combination, REV | OMIT, 0, 0 ), 312 #endif 313 #if defined(XCASE) && defined(IUCLC) && defined(OLCUC) 314 MI_ENTRY(stty_lcase, combination, REV | OMIT, 0, 0 ), 315 MI_ENTRY(stty_LCASE, combination, REV | OMIT, 0, 0 ), 316 #endif 317 MI_ENTRY(stty_crt, combination, OMIT, 0, 0 ), 318 MI_ENTRY(stty_dec, combination, OMIT, 0, 0 ), 553 #if BSDLY 554 MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY) 555 MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY) 556 #endif 557 #if VTDLY 558 MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY) 559 MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY) 560 #endif 561 #if FFDLY 562 MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY) 563 MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY) 564 #endif 565 MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 ) 566 MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 ) 567 #if IEXTEN 568 MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ) 569 #endif 570 MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) 571 MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ) 572 MI_ENTRY("crterase", local, REV | OMIT, ECHOE, 0 ) 573 MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) 574 MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 ) 575 MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 ) 576 #if XCASE 577 MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 ) 578 #endif 579 #if TOSTOP 580 MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 ) 581 #endif 582 #if ECHOPRT 583 MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 ) 584 MI_ENTRY("prterase", local, REV | OMIT, ECHOPRT, 0 ) 585 #endif 586 #if ECHOCTL 587 MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 ) 588 MI_ENTRY("ctlecho", local, REV | OMIT, ECHOCTL, 0 ) 589 #endif 590 #if ECHOKE 591 MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ) 592 MI_ENTRY("crtkill", local, REV | OMIT, ECHOKE, 0 ) 593 #endif 319 594 }; 320 595 … … 323 598 }; 324 599 325 /* Control character settings */ 600 601 /* Control characters */ 326 602 struct control_info { 327 const char *const name; /* Name given on command line */ 328 const unsigned char saneval; /* Value to set for 'stty sane' */ 329 const unsigned char offset; /* Offset in c_cc */ 603 const uint8_t saneval; /* Value to set for 'stty sane' */ 604 const uint8_t offset; /* Offset in c_cc */ 330 605 }; 331 606 332 /* Control characters */ 607 enum { 608 /* Must match control_name[] and control_info[] order! */ 609 CIDX_intr = 0, 610 CIDX_quit, 611 CIDX_erase, 612 CIDX_kill, 613 CIDX_eof, 614 CIDX_eol, 615 #if VEOL2 616 CIDX_eol2, 617 #endif 618 #if VSWTCH 619 CIDX_swtch, 620 #endif 621 CIDX_start, 622 CIDX_stop, 623 CIDX_susp, 624 #if VDSUSP 625 CIDX_dsusp, 626 #endif 627 #if VREPRINT 628 CIDX_rprnt, 629 #endif 630 #if VWERASE 631 CIDX_werase, 632 #endif 633 #if VLNEXT 634 CIDX_lnext, 635 #endif 636 #if VFLUSHO 637 CIDX_flush, 638 #endif 639 #if VSTATUS 640 CIDX_status, 641 #endif 642 CIDX_min, 643 CIDX_time, 644 }; 645 646 #define CI_ENTRY(n,s,o) n "\0" 647 648 /* Name given on command line */ 649 static const char control_name[] = 650 CI_ENTRY("intr", CINTR, VINTR ) 651 CI_ENTRY("quit", CQUIT, VQUIT ) 652 CI_ENTRY("erase", CERASE, VERASE ) 653 CI_ENTRY("kill", CKILL, VKILL ) 654 CI_ENTRY("eof", CEOF, VEOF ) 655 CI_ENTRY("eol", CEOL, VEOL ) 656 #if VEOL2 657 CI_ENTRY("eol2", CEOL2, VEOL2 ) 658 #endif 659 #if VSWTCH 660 CI_ENTRY("swtch", CSWTCH, VSWTCH ) 661 #endif 662 CI_ENTRY("start", CSTART, VSTART ) 663 CI_ENTRY("stop", CSTOP, VSTOP ) 664 CI_ENTRY("susp", CSUSP, VSUSP ) 665 #if VDSUSP 666 CI_ENTRY("dsusp", CDSUSP, VDSUSP ) 667 #endif 668 #if VREPRINT 669 CI_ENTRY("rprnt", CRPRNT, VREPRINT) 670 #endif 671 #if VWERASE 672 CI_ENTRY("werase", CWERASE, VWERASE ) 673 #endif 674 #if VLNEXT 675 CI_ENTRY("lnext", CLNEXT, VLNEXT ) 676 #endif 677 #if VFLUSHO 678 CI_ENTRY("flush", CFLUSHO, VFLUSHO ) 679 #endif 680 #if VSTATUS 681 CI_ENTRY("status", CSTATUS, VSTATUS ) 682 #endif 683 /* These must be last because of the display routines */ 684 CI_ENTRY("min", 1, VMIN ) 685 CI_ENTRY("time", 0, VTIME ) 686 ; 687 688 #undef CI_ENTRY 689 #define CI_ENTRY(n,s,o) { s, o }, 333 690 334 691 static const struct control_info control_info[] = { 335 {"intr", CINTR, VINTR}, 336 {"quit", CQUIT, VQUIT}, 337 {"erase", CERASE, VERASE}, 338 {"kill", CKILL, VKILL}, 339 {stty_eof, CEOF, VEOF}, 340 {stty_eol, CEOL, VEOL}, 341 #ifdef VEOL2 342 {"eol2", CEOL2, VEOL2}, 343 #endif 344 #ifdef VSWTCH 345 {stty_swtch, CSWTCH, VSWTCH}, 346 #endif 347 {"start", CSTART, VSTART}, 348 {"stop", CSTOP, VSTOP}, 349 {"susp", CSUSP, VSUSP}, 350 #ifdef VDSUSP 351 {"dsusp", CDSUSP, VDSUSP}, 352 #endif 353 #ifdef VREPRINT 354 {"rprnt", CRPRNT, VREPRINT}, 355 #endif 356 #ifdef VWERASE 357 {"werase", CWERASE, VWERASE}, 358 #endif 359 #ifdef VLNEXT 360 {"lnext", CLNEXT, VLNEXT}, 361 #endif 362 #ifdef VFLUSHO 363 {"flush", CFLUSHO, VFLUSHO}, 364 #endif 365 #ifdef VSTATUS 366 {"status", CSTATUS, VSTATUS}, 692 /* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */ 693 CI_ENTRY("intr", CINTR, VINTR ) 694 CI_ENTRY("quit", CQUIT, VQUIT ) 695 CI_ENTRY("erase", CERASE, VERASE ) 696 CI_ENTRY("kill", CKILL, VKILL ) 697 CI_ENTRY("eof", CEOF, VEOF ) 698 CI_ENTRY("eol", CEOL, VEOL ) 699 #if VEOL2 700 CI_ENTRY("eol2", CEOL2, VEOL2 ) 701 #endif 702 #if VSWTCH 703 CI_ENTRY("swtch", CSWTCH, VSWTCH ) 704 #endif 705 CI_ENTRY("start", CSTART, VSTART ) 706 CI_ENTRY("stop", CSTOP, VSTOP ) 707 CI_ENTRY("susp", CSUSP, VSUSP ) 708 #if VDSUSP 709 CI_ENTRY("dsusp", CDSUSP, VDSUSP ) 710 #endif 711 #if VREPRINT 712 CI_ENTRY("rprnt", CRPRNT, VREPRINT) 713 #endif 714 #if VWERASE 715 CI_ENTRY("werase", CWERASE, VWERASE ) 716 #endif 717 #if VLNEXT 718 CI_ENTRY("lnext", CLNEXT, VLNEXT ) 719 #endif 720 #if VFLUSHO 721 CI_ENTRY("flush", CFLUSHO, VFLUSHO ) 722 #endif 723 #if VSTATUS 724 CI_ENTRY("status", CSTATUS, VSTATUS ) 367 725 #endif 368 726 /* These must be last because of the display routines */ 369 {stty_min, 1, VMIN},370 {stty_time, 0, VTIME},727 CI_ENTRY("min", 1, VMIN ) 728 CI_ENTRY("time", 0, VTIME ) 371 729 }; 372 730 … … 375 733 }; 376 734 377 /* The width of the screen, for output wrapping */378 unsigned max_col = 80; /* default */379 735 380 736 struct globals { 737 const char *device_name; 738 /* The width of the screen, for output wrapping */ 739 unsigned max_col; 381 740 /* Current position, to know when to wrap */ 382 741 unsigned current_col; 383 742 char buf[10]; 384 } ;743 } FIX_ALIASING; 385 744 #define G (*(struct globals*)&bb_common_bufsiz1) 386 387 static const char *device_name = bb_msg_standard_input; 745 #define INIT_G() do { \ 746 G.device_name = bb_msg_standard_input; \ 747 G.max_col = 80; \ 748 } while (0) 749 388 750 389 751 /* Return a string that is the printable representation of character CH */ … … 418 780 static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode) 419 781 { 420 static const u nsigned chartcflag_offsets[] ALIGN1 = {782 static const uint8_t tcflag_offsets[] ALIGN1 = { 421 783 offsetof(struct termios, c_cflag), /* control */ 422 784 offsetof(struct termios, c_iflag), /* input */ … … 431 793 } 432 794 433 static void set_speed_or_die(enum speed_setting type, const char * constarg,434 struct termios * constmode)795 static void set_speed_or_die(enum speed_setting type, const char *arg, 796 struct termios *mode) 435 797 { 436 798 speed_t baud; … … 446 808 } 447 809 448 static ATTRIBUTE_NORETURN void perror_on_device_and_die(const char *fmt)449 { 450 bb_perror_msg_and_die(fmt, device_name);810 static NORETURN void perror_on_device_and_die(const char *fmt) 811 { 812 bb_perror_msg_and_die(fmt, G.device_name); 451 813 } 452 814 453 815 static void perror_on_device(const char *fmt) 454 816 { 455 bb_perror_msg(fmt, device_name);817 bb_perror_msg(fmt, G.device_name); 456 818 } 457 819 … … 463 825 char buf[128]; 464 826 va_list args; 465 intbuflen;827 unsigned buflen; 466 828 467 829 va_start(args, message); … … 475 837 G.current_col++; 476 838 if (buf[0] != '\n') { 477 if (G.current_col + buflen >= max_col) {478 putchar('\n');839 if (G.current_col + buflen >= G.max_col) { 840 bb_putchar('\n'); 479 841 G.current_col = 0; 480 842 } else 481 putchar(' ');843 bb_putchar(' '); 482 844 } 483 845 } … … 488 850 } 489 851 490 static void set_window_size(const int rows, const int cols) 491 { 492 struct winsize win = { 0, 0, 0, 0}; 852 static void newline(void) 853 { 854 if (G.current_col != 0) 855 wrapf("\n"); 856 } 857 858 #ifdef TIOCGWINSZ 859 static void set_window_size(int rows, int cols) 860 { 861 struct winsize win = { 0, 0, 0, 0 }; 493 862 494 863 if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win)) { … … 508 877 perror_on_device("%s"); 509 878 } 510 511 static void display_window_size(const int fancy) 879 #endif 880 881 static void display_window_size(int fancy) 512 882 { 513 883 const char *fmt_str = "%s\0%s: no size information for this device"; … … 519 889 } 520 890 } else { 521 wrapf(fancy ? "rows % d; columns %d;" : "%d %d\n",891 wrapf(fancy ? "rows %u; columns %u;" : "%u %u\n", 522 892 height, width); 523 893 } … … 528 898 { "k", 1024 }, 529 899 { "B", 1024 }, 530 { }900 { "", 0 } 531 901 }; 532 902 533 903 static const struct mode_info *find_mode(const char *name) 534 904 { 535 int i; 536 for (i = 0; i < NUM_mode_info; ++i) 537 if (!strcmp(name, mode_info[i].name)) 538 return &mode_info[i]; 539 return 0; 905 int i = index_in_strings(mode_name, name); 906 return i >= 0 ? &mode_info[i] : NULL; 540 907 } 541 908 542 909 static const struct control_info *find_control(const char *name) 543 910 { 544 int i; 545 for (i = 0; i < NUM_control_info; ++i) 546 if (!strcmp(name, control_info[i].name)) 547 return &control_info[i]; 548 return 0; 911 int i = index_in_strings(control_name, name); 912 return i >= 0 ? &control_info[i] : NULL; 549 913 } 550 914 … … 561 925 }; 562 926 563 static int find_param(const char * constname)927 static int find_param(const char *name) 564 928 { 565 929 static const char params[] ALIGN1 = … … 611 975 612 976 static void display_recoverable(const struct termios *mode, 613 int ATTRIBUTE_UNUSEDdummy)977 int UNUSED_PARAM dummy) 614 978 { 615 979 int i; … … 619 983 for (i = 0; i < NCCS; ++i) 620 984 printf(":%x", (unsigned int) mode->c_cc[i]); 621 putchar('\n');985 bb_putchar('\n'); 622 986 } 623 987 624 988 static void display_speed(const struct termios *mode, int fancy) 625 989 { 626 //01234567 8 9990 //____________________ 01234567 8 9 627 991 const char *fmt_str = "%lu %lu\n\0ispeed %lu baud; ospeed %lu baud;"; 628 992 unsigned long ispeed, ospeed; … … 631 995 if (ispeed == 0 || ispeed == (ospeed = cfgetospeed(mode))) { 632 996 ispeed = ospeed; /* in case ispeed was 0 */ 633 //0123 4 5 6 7 8 9997 //________ 0123 4 5 6 7 8 9 634 998 fmt_str = "%lu\n\0\0\0\0\0speed %lu baud;"; 635 999 } … … 638 1002 } 639 1003 640 static void do_display(const struct termios *mode, constint all)1004 static void do_display(const struct termios *mode, int all) 641 1005 { 642 1006 int i; … … 649 1013 display_window_size(1); 650 1014 #ifdef HAVE_C_LINE 651 wrapf("line = % d;\n", mode->c_line);1015 wrapf("line = %u;\n", mode->c_line); 652 1016 #else 653 wrapf("\n");654 #endif 655 656 for (i = 0; control_info[i].name != stty_min; ++i) {1017 newline(); 1018 #endif 1019 1020 for (i = 0; i != CIDX_min; ++i) { 657 1021 /* If swtch is the same as susp, don't print both */ 658 1022 #if VSWTCH == VSUSP 659 if ( control_info[i].name == stty_swtch)1023 if (i == CIDX_swtch) 660 1024 continue; 661 1025 #endif 662 1026 /* If eof uses the same slot as min, only print whichever applies */ 663 1027 #if VEOF == VMIN 664 if ((mode->c_lflag & ICANON) == 0 665 && (control_info[i].name == stty_eof 666 || control_info[i].name == stty_eol)) continue; 667 #endif 668 wrapf("%s = %s;", control_info[i].name, 1028 if (!(mode->c_lflag & ICANON) 1029 && (i == CIDX_eof || i == CIDX_eol) 1030 ) { 1031 continue; 1032 } 1033 #endif 1034 wrapf("%s = %s;", nth_string(control_name, i), 669 1035 visible(mode->c_cc[control_info[i].offset])); 670 1036 } … … 672 1038 if ((mode->c_lflag & ICANON) == 0) 673 1039 #endif 674 wrapf("min = % d; time = %d;", mode->c_cc[VMIN], mode->c_cc[VTIME]);675 if (G.current_col) wrapf("\n");1040 wrapf("min = %u; time = %u;", mode->c_cc[VMIN], mode->c_cc[VTIME]); 1041 newline(); 676 1042 677 1043 for (i = 0; i < NUM_mode_info; ++i) { … … 679 1045 continue; 680 1046 if (mode_info[i].type != prev_type) { 681 /* wrapf("\n"); */ 682 if (G.current_col) wrapf("\n"); 1047 newline(); 683 1048 prev_type = mode_info[i].type; 684 1049 } … … 688 1053 if ((*bitsp & mask) == mode_info[i].bits) { 689 1054 if (all || (mode_info[i].flags & SANE_UNSET)) 690 wrapf(" %s", mode_info[i].name);1055 wrapf("-%s"+1, nth_string(mode_name, i)); 691 1056 } else { 692 if ((all && mode_info[i].flags & REV) || 693 (!all && 694 (mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV))) 695 wrapf("-%s", mode_info[i].name); 696 } 697 } 698 if (G.current_col) wrapf("\n"); 1057 if ((all && mode_info[i].flags & REV) 1058 || (!all && (mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)) 1059 ) { 1060 wrapf("-%s", nth_string(mode_name, i)); 1061 } 1062 } 1063 } 1064 newline(); 699 1065 } 700 1066 … … 706 1072 for (i = 0; i < NUM_control_info; ++i) { 707 1073 #if VMIN == VEOF 708 if ( control_info[i].name == stty_min)1074 if (i == CIDX_min) 709 1075 break; 710 1076 #endif … … 725 1091 } 726 1092 727 /* Save set_mode from #ifdef forest plague */728 #ifndef ONLCR729 #define ONLCR 0730 #endif731 #ifndef OCRNL732 #define OCRNL 0733 #endif734 #ifndef ONLRET735 #define ONLRET 0736 #endif737 #ifndef XCASE738 #define XCASE 0739 #endif740 #ifndef IXANY741 #define IXANY 0742 #endif743 #ifndef TABDLY744 #define TABDLY 0745 #endif746 #ifndef OXTABS747 #define OXTABS 0748 #endif749 #ifndef IUCLC750 #define IUCLC 0751 #endif752 #ifndef OLCUC753 #define OLCUC 0754 #endif755 #ifndef ECHOCTL756 #define ECHOCTL 0757 #endif758 #ifndef ECHOKE759 #define ECHOKE 0760 #endif761 762 1093 static void set_mode(const struct mode_info *info, int reversed, 763 1094 struct termios *mode) … … 776 1107 777 1108 /* Combination mode */ 778 if (info ->name == evenp || info->name == parity) {1109 if (info == &mode_info[IDX_evenp] || info == &mode_info[IDX_parity]) { 779 1110 if (reversed) 780 1111 mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8; 781 1112 else 782 mode->c_cflag = 783 } else if (info ->name == stty_oddp) {1113 mode->c_cflag = (mode->c_cflag & ~PARODD & ~CSIZE) | PARENB | CS7; 1114 } else if (info == &mode_info[IDX_oddp]) { 784 1115 if (reversed) 785 1116 mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8; 786 1117 else 787 mode->c_cflag = 788 } else if (info ->name == stty_nl) {1118 mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARODD | PARENB; 1119 } else if (info == &mode_info[IDX_nl]) { 789 1120 if (reversed) { 790 1121 mode->c_iflag = (mode->c_iflag | ICRNL) & ~INLCR & ~IGNCR; 791 mode->c_oflag = (mode->c_oflag | ONLCR) 1122 mode->c_oflag = (mode->c_oflag | ONLCR) & ~OCRNL & ~ONLRET; 792 1123 } else { 793 1124 mode->c_iflag = mode->c_iflag & ~ICRNL; 794 1125 if (ONLCR) mode->c_oflag = mode->c_oflag & ~ONLCR; 795 1126 } 796 } else if (info ->name == stty_ek) {1127 } else if (info == &mode_info[IDX_ek]) { 797 1128 mode->c_cc[VERASE] = CERASE; 798 1129 mode->c_cc[VKILL] = CKILL; 799 } else if (info ->name == stty_sane) {1130 } else if (info == &mode_info[IDX_sane]) { 800 1131 sane_mode(mode); 801 } 802 else if (info->name == cbreak) { 1132 } else if (info == &mode_info[IDX_cbreak]) { 803 1133 if (reversed) 804 1134 mode->c_lflag |= ICANON; 805 1135 else 806 1136 mode->c_lflag &= ~ICANON; 807 } else if (info ->name == stty_pass8) {1137 } else if (info == &mode_info[IDX_pass8]) { 808 1138 if (reversed) { 809 1139 mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARENB; … … 813 1143 mode->c_iflag &= ~ISTRIP; 814 1144 } 815 } else if (info ->name == litout) {1145 } else if (info == &mode_info[IDX_litout]) { 816 1146 if (reversed) { 817 1147 mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARENB; … … 823 1153 mode->c_oflag &= ~OPOST; 824 1154 } 825 } else if (info->name == raw || info->name == cooked) { 826 if ((info->name[0] == 'r' && reversed) 827 || (info->name[0] == 'c' && !reversed)) { 1155 } else if (info == &mode_info[IDX_raw] || info == &mode_info[IDX_cooked]) { 1156 if ((info == &mode_info[IDX_raw] && reversed) 1157 || (info == &mode_info[IDX_cooked] && !reversed) 1158 ) { 828 1159 /* Cooked mode */ 829 1160 mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON; … … 845 1176 } 846 1177 } 847 else if (IXANY && info->name == decctlq) { 1178 #if IXANY 1179 else if (info == &mode_info[IDX_decctlq]) { 848 1180 if (reversed) 849 1181 mode->c_iflag |= IXANY; … … 851 1183 mode->c_iflag &= ~IXANY; 852 1184 } 853 else if (TABDLY && info->name == stty_tabs) { 1185 #endif 1186 #if TABDLY 1187 else if (info == &mode_info[IDX_tabs]) { 854 1188 if (reversed) 855 1189 mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB3; … … 857 1191 mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB0; 858 1192 } 859 else if (OXTABS && info->name == stty_tabs) { 1193 #endif 1194 #if OXTABS 1195 else if (info == &mode_info[IDX_tabs]) { 860 1196 if (reversed) 861 1197 mode->c_oflag |= OXTABS; … … 863 1199 mode->c_oflag &= ~OXTABS; 864 1200 } 865 else if (XCASE && IUCLC && OLCUC 866 && (info->name == stty_lcase || info->name == stty_LCASE)) { 1201 #endif 1202 #if XCASE && IUCLC && OLCUC 1203 else if (info==&mode_info[IDX_lcase] || info==&mode_info[IDX_LCASE]) { 867 1204 if (reversed) { 868 1205 mode->c_lflag &= ~XCASE; … … 875 1212 } 876 1213 } 877 else if (info->name == stty_crt) { 1214 #endif 1215 else if (info == &mode_info[IDX_crt]) { 878 1216 mode->c_lflag |= ECHOE | ECHOCTL | ECHOKE; 879 } 880 else if (info->name == stty_dec) { 1217 } else if (info == &mode_info[IDX_dec]) { 881 1218 mode->c_cc[VINTR] = 3; /* ^C */ 882 1219 mode->c_cc[VERASE] = 127; /* DEL */ … … 892 1229 unsigned char value; 893 1230 894 if (info ->name == stty_min || info->name == stty_time)1231 if (info == &control_info[CIDX_min] || info == &control_info[CIDX_time]) 895 1232 value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes); 896 1233 else if (arg[0] == '\0' || arg[1] == '\0') 897 1234 value = arg[0]; 898 else if ( !strcmp(arg, "^-") || !strcmp(arg, "undef"))1235 else if (strcmp(arg, "^-") == 0 || strcmp(arg, "undef") == 0) 899 1236 value = _POSIX_VDISABLE; 900 1237 else if (arg[0] == '^') { /* Ignore any trailing junk (^Cjunk) */ … … 907 1244 } 908 1245 909 #define STTY_require_set_attr (1<<0) 910 #define STTY_speed_was_set (1<<1) 911 #define STTY_verbose_output (1<<2) 912 #define STTY_recoverable_output (1<<3) 913 #define STTY_noargs (1<<4) 914 int stty_main(int argc, char **argv); 915 int stty_main(int argc, char **argv) 1246 #define STTY_require_set_attr (1 << 0) 1247 #define STTY_speed_was_set (1 << 1) 1248 #define STTY_verbose_output (1 << 2) 1249 #define STTY_recoverable_output (1 << 3) 1250 #define STTY_noargs (1 << 4) 1251 1252 int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1253 int stty_main(int argc UNUSED_PARAM, char **argv) 916 1254 { 917 1255 struct termios mode; 918 void (*output_func)(const struct termios *, constint);1256 void (*output_func)(const struct termios *, int); 919 1257 const char *file_name = NULL; 920 1258 int display_all = 0; 921 1259 int stty_state; 922 1260 int k; 1261 1262 INIT_G(); 923 1263 924 1264 stty_state = STTY_noargs; … … 966 1306 bb_error_msg_and_die(bb_msg_requires_arg, "-F"); 967 1307 /* remove -F param from arg[vc] */ 968 --argc; 969 while (argv[p]) { argv[p] = argv[p+1]; ++p; } 1308 while (argv[p]) { 1309 argv[p] = argv[p+1]; 1310 ++p; 1311 } 970 1312 } 971 1313 goto end_option; … … 1042 1384 bb_error_msg_and_die("verbose and stty-readable output styles are mutually exclusive"); 1043 1385 /* Specifying -a or -g with non-options is an error */ 1044 if (!(stty_state & STTY_noargs) && 1045 (stty_state & (STTY_verbose_output | STTY_recoverable_output))) 1386 if (!(stty_state & STTY_noargs) 1387 && (stty_state & (STTY_verbose_output | STTY_recoverable_output)) 1388 ) { 1046 1389 bb_error_msg_and_die("modes may not be set when specifying an output style"); 1390 } 1047 1391 1048 1392 /* Now it is safe to start doing things */ 1049 1393 if (file_name) { 1050 int fd, fdflags; 1051 device_name = file_name; 1052 fd = xopen(device_name, O_RDONLY | O_NONBLOCK); 1053 if (fd != STDIN_FILENO) { 1054 dup2(fd, STDIN_FILENO); 1055 close(fd); 1056 } 1057 fdflags = fcntl(STDIN_FILENO, F_GETFL); 1058 if (fdflags < 0 || 1059 fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0) 1060 perror_on_device_and_die("%s: cannot reset non-blocking mode"); 1394 G.device_name = file_name; 1395 xmove_fd(xopen_nonblocking(G.device_name), STDIN_FILENO); 1396 ndelay_off(STDIN_FILENO); 1061 1397 } 1062 1398 … … 1068 1404 1069 1405 if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) { 1070 get_terminal_width_height(STDOUT_FILENO, & max_col, NULL);1406 get_terminal_width_height(STDOUT_FILENO, &G.max_col, NULL); 1071 1407 output_func(&mode, display_all); 1072 1408 return EXIT_SUCCESS; … … 1121 1457 #ifdef TIOCGWINSZ 1122 1458 case param_cols: 1459 case param_columns: 1123 1460 set_window_size(-1, xatoul_sfx(argnext, stty_suffixes)); 1124 1461 break; … … 1172 1509 1173 1510 if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) { 1174 #if defCIBAUD1511 #if CIBAUD 1175 1512 /* SunOS 4.1.3 (at least) has the problem that after this sequence, 1176 1513 tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2);
Note:
See TracChangeset
for help on using the changeset viewer.