diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-19 14:17:10 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-19 14:17:10 +0000 |
commit | 9efb070dcb8c1bf92c3a44b182e13c8da708bd6f (patch) | |
tree | b7933ecb84e725b1bbd97b43ff4fc7dd13e43b96 /coreutils/stty.c | |
parent | 7eab79acc58a14078a8cf14fb9be7aa5103a5d41 (diff) | |
download | busybox-w32-9efb070dcb8c1bf92c3a44b182e13c8da708bd6f.tar.gz busybox-w32-9efb070dcb8c1bf92c3a44b182e13c8da708bd6f.tar.bz2 busybox-w32-9efb070dcb8c1bf92c3a44b182e13c8da708bd6f.zip |
stty: style fixes
Diffstat (limited to 'coreutils/stty.c')
-rw-r--r-- | coreutils/stty.c | 195 |
1 files changed, 93 insertions, 102 deletions
diff --git a/coreutils/stty.c b/coreutils/stty.c index a63c1d1fa..6f14efe63 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c | |||
@@ -23,17 +23,14 @@ | |||
23 | 23 | ||
24 | #include "busybox.h" | 24 | #include "busybox.h" |
25 | 25 | ||
26 | #define STREQ(a, b) (strcmp ((a), (b)) == 0) | ||
27 | |||
28 | |||
29 | #ifndef _POSIX_VDISABLE | 26 | #ifndef _POSIX_VDISABLE |
30 | # define _POSIX_VDISABLE ((unsigned char) 0) | 27 | # define _POSIX_VDISABLE ((unsigned char) 0) |
31 | #endif | 28 | #endif |
32 | 29 | ||
33 | #define Control(c) ((c) & 0x1f) | 30 | #define Control(c) ((c) & 0x1f) |
34 | /* Canonical values for control characters. */ | 31 | /* Canonical values for control characters */ |
35 | #ifndef CINTR | 32 | #ifndef CINTR |
36 | # define CINTR Control ('c') | 33 | # define CINTR Control('c') |
37 | #endif | 34 | #endif |
38 | #ifndef CQUIT | 35 | #ifndef CQUIT |
39 | # define CQUIT 28 | 36 | # define CQUIT 28 |
@@ -42,27 +39,27 @@ | |||
42 | # define CERASE 127 | 39 | # define CERASE 127 |
43 | #endif | 40 | #endif |
44 | #ifndef CKILL | 41 | #ifndef CKILL |
45 | # define CKILL Control ('u') | 42 | # define CKILL Control('u') |
46 | #endif | 43 | #endif |
47 | #ifndef CEOF | 44 | #ifndef CEOF |
48 | # define CEOF Control ('d') | 45 | # define CEOF Control('d') |
49 | #endif | 46 | #endif |
50 | #ifndef CEOL | 47 | #ifndef CEOL |
51 | # define CEOL _POSIX_VDISABLE | 48 | # define CEOL _POSIX_VDISABLE |
52 | #endif | 49 | #endif |
53 | #ifndef CSTART | 50 | #ifndef CSTART |
54 | # define CSTART Control ('q') | 51 | # define CSTART Control('q') |
55 | #endif | 52 | #endif |
56 | #ifndef CSTOP | 53 | #ifndef CSTOP |
57 | # define CSTOP Control ('s') | 54 | # define CSTOP Control('s') |
58 | #endif | 55 | #endif |
59 | #ifndef CSUSP | 56 | #ifndef CSUSP |
60 | # define CSUSP Control ('z') | 57 | # define CSUSP Control('z') |
61 | #endif | 58 | #endif |
62 | #if defined(VEOL2) && !defined(CEOL2) | 59 | #if defined(VEOL2) && !defined(CEOL2) |
63 | # define CEOL2 _POSIX_VDISABLE | 60 | # define CEOL2 _POSIX_VDISABLE |
64 | #endif | 61 | #endif |
65 | /* ISC renamed swtch to susp for termios, but we'll accept either name. */ | 62 | /* ISC renamed swtch to susp for termios, but we'll accept either name */ |
66 | #if defined(VSUSP) && !defined(VSWTCH) | 63 | #if defined(VSUSP) && !defined(VSWTCH) |
67 | # define VSWTCH VSUSP | 64 | # define VSWTCH VSUSP |
68 | # define CSWTCH CSUSP | 65 | # define CSWTCH CSUSP |
@@ -82,19 +79,19 @@ | |||
82 | # define VWERASE VWERSE | 79 | # define VWERASE VWERSE |
83 | #endif | 80 | #endif |
84 | #if defined(VDSUSP) && !defined (CDSUSP) | 81 | #if defined(VDSUSP) && !defined (CDSUSP) |
85 | # define CDSUSP Control ('y') | 82 | # define CDSUSP Control('y') |
86 | #endif | 83 | #endif |
87 | #if !defined(VREPRINT) && defined(VRPRNT) /* Irix 4.0.5 */ | 84 | #if !defined(VREPRINT) && defined(VRPRNT) /* Irix 4.0.5 */ |
88 | # define VREPRINT VRPRNT | 85 | # define VREPRINT VRPRNT |
89 | #endif | 86 | #endif |
90 | #if defined(VREPRINT) && !defined(CRPRNT) | 87 | #if defined(VREPRINT) && !defined(CRPRNT) |
91 | # define CRPRNT Control ('r') | 88 | # define CRPRNT Control('r') |
92 | #endif | 89 | #endif |
93 | #if defined(VWERASE) && !defined(CWERASE) | 90 | #if defined(VWERASE) && !defined(CWERASE) |
94 | # define CWERASE Control ('w') | 91 | # define CWERASE Control('w') |
95 | #endif | 92 | #endif |
96 | #if defined(VLNEXT) && !defined(CLNEXT) | 93 | #if defined(VLNEXT) && !defined(CLNEXT) |
97 | # define CLNEXT Control ('v') | 94 | # define CLNEXT Control('v') |
98 | #endif | 95 | #endif |
99 | #if defined(VDISCARD) && !defined(VFLUSHO) | 96 | #if defined(VDISCARD) && !defined(VFLUSHO) |
100 | # define VFLUSHO VDISCARD | 97 | # define VFLUSHO VDISCARD |
@@ -112,25 +109,24 @@ | |||
112 | # define ECHOKE CRTKIL | 109 | # define ECHOKE CRTKIL |
113 | #endif | 110 | #endif |
114 | #if defined(VFLUSHO) && !defined(CFLUSHO) | 111 | #if defined(VFLUSHO) && !defined(CFLUSHO) |
115 | # define CFLUSHO Control ('o') | 112 | # define CFLUSHO Control('o') |
116 | #endif | 113 | #endif |
117 | #if defined(VSTATUS) && !defined(CSTATUS) | 114 | #if defined(VSTATUS) && !defined(CSTATUS) |
118 | # define CSTATUS Control ('t') | 115 | # define CSTATUS Control('t') |
119 | #endif | 116 | #endif |
120 | 117 | ||
121 | /* Which speeds to set. */ | 118 | /* Which speeds to set */ |
122 | enum speed_setting { | 119 | enum speed_setting { |
123 | input_speed, output_speed, both_speeds | 120 | input_speed, output_speed, both_speeds |
124 | }; | 121 | }; |
125 | 122 | ||
126 | /* Which member(s) of `struct termios' a mode uses. */ | 123 | /* Which member(s) of `struct termios' a mode uses */ |
127 | enum mode_type { | 124 | enum mode_type { |
128 | /* Do NOT change the order or values, as mode_type_flag() | 125 | /* Do NOT change the order or values, as mode_type_flag() |
129 | * depends on them. */ | 126 | * depends on them */ |
130 | control, input, output, local, combination | 127 | control, input, output, local, combination |
131 | }; | 128 | }; |
132 | 129 | ||
133 | |||
134 | static const char evenp [] = "evenp"; | 130 | static const char evenp [] = "evenp"; |
135 | static const char raw [] = "raw"; | 131 | static const char raw [] = "raw"; |
136 | static const char stty_min [] = "min"; | 132 | static const char stty_min [] = "min"; |
@@ -154,22 +150,22 @@ static const char stty_LCASE[] = "LCASE"; | |||
154 | static const char stty_crt [] = "crt"; | 150 | static const char stty_crt [] = "crt"; |
155 | static const char stty_dec [] = "dec"; | 151 | static const char stty_dec [] = "dec"; |
156 | 152 | ||
153 | /* Flags for `struct mode_info' */ | ||
154 | #define SANE_SET 1 /* Set in `sane' mode */ | ||
155 | #define SANE_UNSET 2 /* Unset in `sane' mode */ | ||
156 | #define REV 4 /* Can be turned off by prepending `-' */ | ||
157 | #define OMIT 8 /* Don't display value */ | ||
157 | 158 | ||
158 | /* Flags for `struct mode_info'. */ | 159 | /* Each mode */ |
159 | #define SANE_SET 1 /* Set in `sane' mode. */ | ||
160 | #define SANE_UNSET 2 /* Unset in `sane' mode. */ | ||
161 | #define REV 4 /* Can be turned off by prepending `-'. */ | ||
162 | #define OMIT 8 /* Don't display value. */ | ||
163 | |||
164 | /* Each mode. */ | ||
165 | struct mode_info { | 160 | struct mode_info { |
166 | const char *name; /* Name given on command line. */ | 161 | const char *name; /* Name given on command line */ |
167 | /* enum mode_type type; */ | 162 | /* enum mode_type type; */ |
168 | char type; /* Which structure element to change. */ | 163 | char type; /* Which structure element to change */ |
169 | char flags; /* Setting and display options. */ | 164 | char flags; /* Setting and display options */ |
170 | unsigned short mask; /* Other bits to turn off for this mode. */ | 165 | unsigned short mask; /* Other bits to turn off for this mode */ |
171 | unsigned long bits; /* Bits to set for this mode. */ | 166 | unsigned long bits; /* Bits to set for this mode */ |
172 | }; | 167 | }; |
168 | #define EMT(t) ((enum mode_type)(t)) | ||
173 | 169 | ||
174 | #define MI_ENTRY(N,T,F,B,M) { N, T, F, M, B } | 170 | #define MI_ENTRY(N,T,F,B,M) { N, T, F, M, B } |
175 | 171 | ||
@@ -308,7 +304,7 @@ static const struct mode_info mode_info[] = { | |||
308 | #ifdef IXANY | 304 | #ifdef IXANY |
309 | MI_ENTRY(decctlq, combination, REV | OMIT, 0, 0 ), | 305 | MI_ENTRY(decctlq, combination, REV | OMIT, 0, 0 ), |
310 | #endif | 306 | #endif |
311 | #if defined (TABDLY) || defined (OXTABS) | 307 | #if defined(TABDLY) || defined(OXTABS) |
312 | MI_ENTRY(stty_tabs, combination, REV | OMIT, 0, 0 ), | 308 | MI_ENTRY(stty_tabs, combination, REV | OMIT, 0, 0 ), |
313 | #endif | 309 | #endif |
314 | #if defined(XCASE) && defined(IUCLC) && defined(OLCUC) | 310 | #if defined(XCASE) && defined(IUCLC) && defined(OLCUC) |
@@ -320,18 +316,17 @@ static const struct mode_info mode_info[] = { | |||
320 | }; | 316 | }; |
321 | 317 | ||
322 | enum { | 318 | enum { |
323 | NUM_mode_info = | 319 | NUM_mode_info = (sizeof(mode_info) / sizeof(mode_info[0])) |
324 | (sizeof(mode_info) / sizeof(struct mode_info)) | ||
325 | }; | 320 | }; |
326 | 321 | ||
327 | /* Control character settings. */ | 322 | /* Control character settings */ |
328 | struct control_info { | 323 | struct control_info { |
329 | const char *name; /* Name given on command line. */ | 324 | const char *name; /* Name given on command line */ |
330 | unsigned char saneval; /* Value to set for `stty sane'. */ | 325 | unsigned char saneval; /* Value to set for `stty sane' */ |
331 | unsigned char offset; /* Offset in c_cc. */ | 326 | unsigned char offset; /* Offset in c_cc */ |
332 | }; | 327 | }; |
333 | 328 | ||
334 | /* Control characters. */ | 329 | /* Control characters */ |
335 | 330 | ||
336 | static const struct control_info control_info[] = { | 331 | static const struct control_info control_info[] = { |
337 | {"intr", CINTR, VINTR}, | 332 | {"intr", CINTR, VINTR}, |
@@ -367,17 +362,20 @@ static const struct control_info control_info[] = { | |||
367 | #ifdef VSTATUS | 362 | #ifdef VSTATUS |
368 | {"status", CSTATUS, VSTATUS}, | 363 | {"status", CSTATUS, VSTATUS}, |
369 | #endif | 364 | #endif |
370 | /* These must be last because of the display routines. */ | 365 | /* These must be last because of the display routines */ |
371 | {stty_min, 1, VMIN}, | 366 | {stty_min, 1, VMIN}, |
372 | {stty_time, 0, VTIME}, | 367 | {stty_time, 0, VTIME}, |
373 | }; | 368 | }; |
374 | 369 | ||
375 | enum { | 370 | enum { |
376 | NUM_control_info = | 371 | NUM_control_info = (sizeof(control_info) / sizeof(control_info[0])) |
377 | (sizeof(control_info) / sizeof(struct control_info)) | ||
378 | }; | 372 | }; |
379 | 373 | ||
380 | #define EMT(t) ((enum mode_type)(t)) | 374 | /* The width of the screen, for output wrapping */ |
375 | static int max_col; | ||
376 | |||
377 | /* Current position, to know when to wrap */ | ||
378 | static int current_col; | ||
381 | 379 | ||
382 | static const char * visible(unsigned int ch); | 380 | static const char * visible(unsigned int ch); |
383 | static int recover_mode(const char *arg, struct termios *mode); | 381 | static int recover_mode(const char *arg, struct termios *mode); |
@@ -385,11 +383,11 @@ static int screen_columns(void); | |||
385 | static void set_mode(const struct mode_info *info, | 383 | static void set_mode(const struct mode_info *info, |
386 | int reversed, struct termios *mode); | 384 | int reversed, struct termios *mode); |
387 | static speed_t string_to_baud(const char *arg); | 385 | static speed_t string_to_baud(const char *arg); |
388 | static tcflag_t* mode_type_flag(enum mode_type type, struct termios *mode); | 386 | static tcflag_t* mode_type_flag(enum mode_type type, const struct termios *mode); |
389 | static void display_all(struct termios *mode); | 387 | static void display_all(const struct termios *mode); |
390 | static void display_changed(struct termios *mode); | 388 | static void display_changed(const struct termios *mode); |
391 | static void display_recoverable(struct termios *mode); | 389 | static void display_recoverable(const struct termios *mode); |
392 | static void display_speed(struct termios *mode, int fancy); | 390 | static void display_speed(const struct termios *mode, int fancy); |
393 | static void display_window_size(int fancy); | 391 | static void display_window_size(int fancy); |
394 | static void sane_mode(struct termios *mode); | 392 | static void sane_mode(struct termios *mode); |
395 | static void set_control_char(const struct control_info *info, | 393 | static void set_control_char(const struct control_info *info, |
@@ -405,21 +403,19 @@ static ATTRIBUTE_NORETURN void perror_on_device(const char *fmt) | |||
405 | bb_perror_msg_and_die(fmt, device_name); | 403 | bb_perror_msg_and_die(fmt, device_name); |
406 | } | 404 | } |
407 | 405 | ||
408 | 406 | static ATTRIBUTE_ALWAYS_INLINE int streq(const char *a, const char *b) | |
409 | /* The width of the screen, for output wrapping. */ | 407 | { |
410 | static int max_col; | 408 | return strcmp(a, b) == 0; |
411 | 409 | } | |
412 | /* Current position, to know when to wrap. */ | ||
413 | static int current_col; | ||
414 | 410 | ||
415 | /* Print format string MESSAGE and optional args. | 411 | /* Print format string MESSAGE and optional args. |
416 | Wrap to next line first if it won't fit. | 412 | Wrap to next line first if it won't fit. |
417 | Print a space first unless MESSAGE will start a new line. */ | 413 | Print a space first unless MESSAGE will start a new line */ |
418 | 414 | ||
419 | static void wrapf(const char *message, ...) | 415 | static void wrapf(const char *message, ...) |
420 | { | 416 | { |
421 | va_list args; | 417 | va_list args; |
422 | char buf[1024]; /* Plenty long for our needs. */ | 418 | char buf[1024]; /* Plenty long for our needs */ |
423 | int buflen; | 419 | int buflen; |
424 | 420 | ||
425 | va_start(args, message); | 421 | va_start(args, message); |
@@ -449,7 +445,7 @@ static const struct mode_info *find_mode(const char *name) | |||
449 | { | 445 | { |
450 | int i; | 446 | int i; |
451 | for (i = 0; i < NUM_mode_info; ++i) | 447 | for (i = 0; i < NUM_mode_info; ++i) |
452 | if (STREQ(name, mode_info[i].name)) | 448 | if (streq(name, mode_info[i].name)) |
453 | return &mode_info[i]; | 449 | return &mode_info[i]; |
454 | return 0; | 450 | return 0; |
455 | } | 451 | } |
@@ -458,7 +454,7 @@ static const struct control_info *find_control(const char *name) | |||
458 | { | 454 | { |
459 | int i; | 455 | int i; |
460 | for (i = 0; i < NUM_control_info; ++i) | 456 | for (i = 0; i < NUM_control_info; ++i) |
461 | if (STREQ(name, control_info[i].name)) | 457 | if (streq(name, control_info[i].name)) |
462 | return &control_info[i]; | 458 | return &control_info[i]; |
463 | return 0; | 459 | return 0; |
464 | } | 460 | } |
@@ -477,17 +473,17 @@ enum { | |||
477 | static int find_param(const char *name) | 473 | static int find_param(const char *name) |
478 | { | 474 | { |
479 | #ifdef HAVE_C_LINE | 475 | #ifdef HAVE_C_LINE |
480 | if (STREQ(name, "line")) return param_line; | 476 | if (streq(name, "line")) return param_line; |
481 | #endif | 477 | #endif |
482 | #ifdef TIOCGWINSZ | 478 | #ifdef TIOCGWINSZ |
483 | if (STREQ(name, "rows")) return param_rows; | 479 | if (streq(name, "rows")) return param_rows; |
484 | if (STREQ(name, "cols")) return param_cols; | 480 | if (streq(name, "cols")) return param_cols; |
485 | if (STREQ(name, "columns")) return param_cols; | 481 | if (streq(name, "columns")) return param_cols; |
486 | if (STREQ(name, "size")) return param_size; | 482 | if (streq(name, "size")) return param_size; |
487 | #endif | 483 | #endif |
488 | if (STREQ(name, "ispeed")) return param_ispeed; | 484 | if (streq(name, "ispeed")) return param_ispeed; |
489 | if (STREQ(name, "ospeed")) return param_ospeed; | 485 | if (streq(name, "ospeed")) return param_ospeed; |
490 | if (STREQ(name, "speed")) return param_speed; | 486 | if (streq(name, "speed")) return param_speed; |
491 | return 0; | 487 | return 0; |
492 | } | 488 | } |
493 | 489 | ||
@@ -495,7 +491,7 @@ static int find_param(const char *name) | |||
495 | int stty_main(int argc, char **argv) | 491 | int stty_main(int argc, char **argv) |
496 | { | 492 | { |
497 | struct termios mode; | 493 | struct termios mode; |
498 | void (*output_func)(struct termios *); | 494 | void (*output_func)(const struct termios *); |
499 | const char *file_name = NULL; | 495 | const char *file_name = NULL; |
500 | int require_set_attr; | 496 | int require_set_attr; |
501 | int speed_was_set; | 497 | int speed_was_set; |
@@ -634,7 +630,7 @@ end_option: | |||
634 | } | 630 | } |
635 | 631 | ||
636 | /* Initialize to all zeroes so there is no risk memcmp will report a | 632 | /* Initialize to all zeroes so there is no risk memcmp will report a |
637 | spurious difference in an uninitialized portion of the structure. */ | 633 | spurious difference in an uninitialized portion of the structure */ |
638 | memset(&mode, 0, sizeof(mode)); | 634 | memset(&mode, 0, sizeof(mode)); |
639 | if (tcgetattr(STDIN_FILENO, &mode)) | 635 | if (tcgetattr(STDIN_FILENO, &mode)) |
640 | perror_on_device("%s"); | 636 | perror_on_device("%s"); |
@@ -739,10 +735,10 @@ end_option: | |||
739 | can report `success' when it has actually failed to perform | 735 | can report `success' when it has actually failed to perform |
740 | some proper subset of the requested operations. To detect | 736 | some proper subset of the requested operations. To detect |
741 | this partial failure, get the current terminal attributes and | 737 | this partial failure, get the current terminal attributes and |
742 | compare them to the requested ones. */ | 738 | compare them to the requested ones */ |
743 | 739 | ||
744 | /* Initialize to all zeroes so there is no risk memcmp will report a | 740 | /* Initialize to all zeroes so there is no risk memcmp will report a |
745 | spurious difference in an uninitialized portion of the structure. */ | 741 | spurious difference in an uninitialized portion of the structure */ |
746 | memset(&new_mode, 0, sizeof(new_mode)); | 742 | memset(&new_mode, 0, sizeof(new_mode)); |
747 | if (tcgetattr(STDIN_FILENO, &new_mode)) | 743 | if (tcgetattr(STDIN_FILENO, &new_mode)) |
748 | perror_on_device("%s"); | 744 | perror_on_device("%s"); |
@@ -756,7 +752,7 @@ end_option: | |||
756 | Sun users a little confusion, don't report an error if this | 752 | Sun users a little confusion, don't report an error if this |
757 | happens. But suppress the error only if we haven't tried to | 753 | happens. But suppress the error only if we haven't tried to |
758 | set the baud rate explicitly -- otherwise we'd never give an | 754 | set the baud rate explicitly -- otherwise we'd never give an |
759 | error for a true failure to set the baud rate. */ | 755 | error for a true failure to set the baud rate */ |
760 | 756 | ||
761 | new_mode.c_cflag &= (~CIBAUD); | 757 | new_mode.c_cflag &= (~CIBAUD); |
762 | if (speed_was_set || memcmp(&mode, &new_mode, sizeof(mode)) != 0) | 758 | if (speed_was_set || memcmp(&mode, &new_mode, sizeof(mode)) != 0) |
@@ -768,7 +764,6 @@ end_option: | |||
768 | return EXIT_SUCCESS; | 764 | return EXIT_SUCCESS; |
769 | } | 765 | } |
770 | 766 | ||
771 | /* Return 0 if not applied because not reversible; otherwise return 1. */ | ||
772 | 767 | ||
773 | static void | 768 | static void |
774 | set_mode(const struct mode_info *info, int reversed, struct termios *mode) | 769 | set_mode(const struct mode_info *info, int reversed, struct termios *mode) |
@@ -778,7 +773,7 @@ set_mode(const struct mode_info *info, int reversed, struct termios *mode) | |||
778 | bitsp = mode_type_flag(EMT(info->type), mode); | 773 | bitsp = mode_type_flag(EMT(info->type), mode); |
779 | 774 | ||
780 | if (bitsp == NULL) { | 775 | if (bitsp == NULL) { |
781 | /* Combination mode. */ | 776 | /* Combination mode */ |
782 | if (info->name == evenp || info->name == parity) { | 777 | if (info->name == evenp || info->name == parity) { |
783 | if (reversed) | 778 | if (reversed) |
784 | mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8; | 779 | mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8; |
@@ -843,7 +838,7 @@ set_mode(const struct mode_info *info, int reversed, struct termios *mode) | |||
843 | } else if (info->name == raw || info->name == cooked) { | 838 | } else if (info->name == raw || info->name == cooked) { |
844 | if ((info->name[0] == 'r' && reversed) | 839 | if ((info->name[0] == 'r' && reversed) |
845 | || (info->name[0] == 'c' && !reversed)) { | 840 | || (info->name[0] == 'c' && !reversed)) { |
846 | /* Cooked mode. */ | 841 | /* Cooked mode */ |
847 | mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON; | 842 | mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON; |
848 | mode->c_oflag |= OPOST; | 843 | mode->c_oflag |= OPOST; |
849 | mode->c_lflag |= ISIG | ICANON; | 844 | mode->c_lflag |= ISIG | ICANON; |
@@ -854,7 +849,7 @@ set_mode(const struct mode_info *info, int reversed, struct termios *mode) | |||
854 | mode->c_cc[VEOL] = CEOL; | 849 | mode->c_cc[VEOL] = CEOL; |
855 | #endif | 850 | #endif |
856 | } else { | 851 | } else { |
857 | /* Raw mode. */ | 852 | /* Raw mode */ |
858 | mode->c_iflag = 0; | 853 | mode->c_iflag = 0; |
859 | mode->c_oflag &= ~OPOST; | 854 | mode->c_oflag &= ~OPOST; |
860 | mode->c_lflag &= ~(ISIG | ICANON | 855 | mode->c_lflag &= ~(ISIG | ICANON |
@@ -945,13 +940,13 @@ set_control_char(const struct control_info *info, const char *arg, | |||
945 | value = bb_xparse_number(arg, stty_suffixes); | 940 | value = bb_xparse_number(arg, stty_suffixes); |
946 | else if (arg[0] == '\0' || arg[1] == '\0') | 941 | else if (arg[0] == '\0' || arg[1] == '\0') |
947 | value = arg[0]; | 942 | value = arg[0]; |
948 | else if (STREQ(arg, "^-") || STREQ(arg, "undef")) | 943 | else if (streq(arg, "^-") || streq(arg, "undef")) |
949 | value = _POSIX_VDISABLE; | 944 | value = _POSIX_VDISABLE; |
950 | else if (arg[0] == '^' && arg[1] != '\0') { /* Ignore any trailing junk. */ | 945 | else if (arg[0] == '^' && arg[1] != '\0') { /* Ignore any trailing junk */ |
951 | if (arg[1] == '?') | 946 | if (arg[1] == '?') |
952 | value = 127; | 947 | value = 127; |
953 | else | 948 | else |
954 | value = arg[1] & ~0140; /* Non-letters get weird results. */ | 949 | value = arg[1] & ~0140; /* Non-letters get weird results */ |
955 | } else | 950 | } else |
956 | value = bb_xparse_number(arg, stty_suffixes); | 951 | value = bb_xparse_number(arg, stty_suffixes); |
957 | mode->c_cc[info->offset] = value; | 952 | mode->c_cc[info->offset] = value; |
@@ -976,9 +971,7 @@ set_speed(enum speed_setting type, const char *arg, struct termios *mode) | |||
976 | 971 | ||
977 | static int get_win_size(int fd, struct winsize *win) | 972 | static int get_win_size(int fd, struct winsize *win) |
978 | { | 973 | { |
979 | int err = ioctl(fd, TIOCGWINSZ, (char *) win); | 974 | return ioctl(fd, TIOCGWINSZ, (char *) win); |
980 | |||
981 | return err; | ||
982 | } | 975 | } |
983 | 976 | ||
984 | static void | 977 | static void |
@@ -1002,7 +995,7 @@ set_window_size(int rows, int cols) | |||
1002 | The following code deals with a bug in the SunOS 4.x (and 3.x?) kernel. | 995 | The following code deals with a bug in the SunOS 4.x (and 3.x?) kernel. |
1003 | This comment from sys/ttold.h describes Sun's twisted logic - a better | 996 | This comment from sys/ttold.h describes Sun's twisted logic - a better |
1004 | test would have been (ts_lines > 64k || ts_cols > 64k || ts_cols == 0). | 997 | test would have been (ts_lines > 64k || ts_cols > 64k || ts_cols == 0). |
1005 | At any rate, the problem is gone in Solaris 2.x. */ | 998 | At any rate, the problem is gone in Solaris 2.x */ |
1006 | 999 | ||
1007 | if (win.ws_row == 0 || win.ws_col == 0) { | 1000 | if (win.ws_row == 0 || win.ws_col == 0) { |
1008 | struct ttysize ttysz; | 1001 | struct ttysize ttysz; |
@@ -1055,7 +1048,7 @@ static int screen_columns(void) | |||
1055 | On ISC 3.0, it fails for the console and the serial port | 1048 | On ISC 3.0, it fails for the console and the serial port |
1056 | (but it works for ptys). | 1049 | (but it works for ptys). |
1057 | It can also fail on any system when stdout isn't a tty. | 1050 | It can also fail on any system when stdout isn't a tty. |
1058 | In case of any failure, just use the default. */ | 1051 | In case of any failure, just use the default */ |
1059 | if (get_win_size(STDOUT_FILENO, &win) == 0 && win.ws_col > 0) | 1052 | if (get_win_size(STDOUT_FILENO, &win) == 0 && win.ws_col > 0) |
1060 | return win.ws_col; | 1053 | return win.ws_col; |
1061 | #endif | 1054 | #endif |
@@ -1067,7 +1060,7 @@ static int screen_columns(void) | |||
1067 | return columns; | 1060 | return columns; |
1068 | } | 1061 | } |
1069 | 1062 | ||
1070 | static tcflag_t *mode_type_flag(enum mode_type type, struct termios *mode) | 1063 | static tcflag_t *mode_type_flag(enum mode_type type, const struct termios *mode) |
1071 | { | 1064 | { |
1072 | static const unsigned char tcflag_offsets[] = { | 1065 | static const unsigned char tcflag_offsets[] = { |
1073 | offsetof(struct termios, c_cflag), /* control */ | 1066 | offsetof(struct termios, c_cflag), /* control */ |
@@ -1082,7 +1075,7 @@ static tcflag_t *mode_type_flag(enum mode_type type, struct termios *mode) | |||
1082 | return NULL; | 1075 | return NULL; |
1083 | } | 1076 | } |
1084 | 1077 | ||
1085 | static void display_changed(struct termios *mode) | 1078 | static void display_changed(const struct termios *mode) |
1086 | { | 1079 | { |
1087 | int i; | 1080 | int i; |
1088 | int empty_line; | 1081 | int empty_line; |
@@ -1101,12 +1094,12 @@ static void display_changed(struct termios *mode) | |||
1101 | for (i = 0; control_info[i].name != stty_min; ++i) { | 1094 | for (i = 0; control_info[i].name != stty_min; ++i) { |
1102 | if (mode->c_cc[control_info[i].offset] == control_info[i].saneval) | 1095 | if (mode->c_cc[control_info[i].offset] == control_info[i].saneval) |
1103 | continue; | 1096 | continue; |
1104 | /* If swtch is the same as susp, don't print both. */ | 1097 | /* If swtch is the same as susp, don't print both */ |
1105 | #if VSWTCH == VSUSP | 1098 | #if VSWTCH == VSUSP |
1106 | if (control_info[i].name == stty_swtch) | 1099 | if (control_info[i].name == stty_swtch) |
1107 | continue; | 1100 | continue; |
1108 | #endif | 1101 | #endif |
1109 | /* If eof uses the same slot as min, only print whichever applies. */ | 1102 | /* If eof uses the same slot as min, only print whichever applies */ |
1110 | #if VEOF == VMIN | 1103 | #if VEOF == VMIN |
1111 | if ((mode->c_lflag & ICANON) == 0 | 1104 | if ((mode->c_lflag & ICANON) == 0 |
1112 | && (control_info[i].name == stty_eof | 1105 | && (control_info[i].name == stty_eof |
@@ -1144,9 +1137,7 @@ static void display_changed(struct termios *mode) | |||
1144 | wrapf("%s", mode_info[i].name); | 1137 | wrapf("%s", mode_info[i].name); |
1145 | empty_line = 0; | 1138 | empty_line = 0; |
1146 | } | 1139 | } |
1147 | } | 1140 | } else if ((mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)) { |
1148 | else if ((mode_info[i].flags & (SANE_SET | REV)) == | ||
1149 | (SANE_SET | REV)) { | ||
1150 | wrapf("-%s", mode_info[i].name); | 1141 | wrapf("-%s", mode_info[i].name); |
1151 | empty_line = 0; | 1142 | empty_line = 0; |
1152 | } | 1143 | } |
@@ -1157,7 +1148,7 @@ static void display_changed(struct termios *mode) | |||
1157 | } | 1148 | } |
1158 | 1149 | ||
1159 | static void | 1150 | static void |
1160 | display_all(struct termios *mode) | 1151 | display_all(const struct termios *mode) |
1161 | { | 1152 | { |
1162 | int i; | 1153 | int i; |
1163 | tcflag_t *bitsp; | 1154 | tcflag_t *bitsp; |
@@ -1175,12 +1166,12 @@ display_all(struct termios *mode) | |||
1175 | current_col = 0; | 1166 | current_col = 0; |
1176 | 1167 | ||
1177 | for (i = 0; control_info[i].name != stty_min; ++i) { | 1168 | for (i = 0; control_info[i].name != stty_min; ++i) { |
1178 | /* If swtch is the same as susp, don't print both. */ | 1169 | /* If swtch is the same as susp, don't print both */ |
1179 | #if VSWTCH == VSUSP | 1170 | #if VSWTCH == VSUSP |
1180 | if (control_info[i].name == stty_swtch) | 1171 | if (control_info[i].name == stty_swtch) |
1181 | continue; | 1172 | continue; |
1182 | #endif | 1173 | #endif |
1183 | /* If eof uses the same slot as min, only print whichever applies. */ | 1174 | /* If eof uses the same slot as min, only print whichever applies */ |
1184 | #if VEOF == VMIN | 1175 | #if VEOF == VMIN |
1185 | if ((mode->c_lflag & ICANON) == 0 | 1176 | if ((mode->c_lflag & ICANON) == 0 |
1186 | && (control_info[i].name == stty_eof | 1177 | && (control_info[i].name == stty_eof |
@@ -1217,7 +1208,7 @@ display_all(struct termios *mode) | |||
1217 | current_col = 0; | 1208 | current_col = 0; |
1218 | } | 1209 | } |
1219 | 1210 | ||
1220 | static void display_speed(struct termios *mode, int fancy) | 1211 | static void display_speed(const struct termios *mode, int fancy) |
1221 | { | 1212 | { |
1222 | unsigned long ispeed, ospeed; | 1213 | unsigned long ispeed, ospeed; |
1223 | const char *fmt_str = | 1214 | const char *fmt_str = |
@@ -1237,7 +1228,7 @@ static void display_speed(struct termios *mode, int fancy) | |||
1237 | current_col = 0; | 1228 | current_col = 0; |
1238 | } | 1229 | } |
1239 | 1230 | ||
1240 | static void display_recoverable(struct termios *mode) | 1231 | static void display_recoverable(const struct termios *mode) |
1241 | { | 1232 | { |
1242 | int i; | 1233 | int i; |
1243 | 1234 | ||
@@ -1256,7 +1247,7 @@ static int recover_mode(const char *arg, struct termios *mode) | |||
1256 | unsigned long iflag, oflag, cflag, lflag; | 1247 | unsigned long iflag, oflag, cflag, lflag; |
1257 | 1248 | ||
1258 | /* Scan into temporaries since it is too much trouble to figure out | 1249 | /* Scan into temporaries since it is too much trouble to figure out |
1259 | the right format for `tcflag_t'. */ | 1250 | the right format for `tcflag_t' */ |
1260 | if (sscanf(arg, "%lx:%lx:%lx:%lx%n", | 1251 | if (sscanf(arg, "%lx:%lx:%lx:%lx%n", |
1261 | &iflag, &oflag, &cflag, &lflag, &n) != 4) | 1252 | &iflag, &oflag, &cflag, &lflag, &n) != 4) |
1262 | return 0; | 1253 | return 0; |
@@ -1272,7 +1263,7 @@ static int recover_mode(const char *arg, struct termios *mode) | |||
1272 | arg += n; | 1263 | arg += n; |
1273 | } | 1264 | } |
1274 | 1265 | ||
1275 | /* Fail if there are too many fields. */ | 1266 | /* Fail if there are too many fields */ |
1276 | if (*arg != '\0') | 1267 | if (*arg != '\0') |
1277 | return 0; | 1268 | return 0; |
1278 | 1269 | ||
@@ -1310,8 +1301,8 @@ static void sane_mode(struct termios *mode) | |||
1310 | } | 1301 | } |
1311 | } | 1302 | } |
1312 | 1303 | ||
1313 | /* Return a string that is the printable representation of character CH. */ | 1304 | /* Return a string that is the printable representation of character CH */ |
1314 | /* Adapted from `cat' by Torbjorn Granlund. */ | 1305 | /* Adapted from `cat' by Torbjorn Granlund */ |
1315 | 1306 | ||
1316 | static const char *visible(unsigned int ch) | 1307 | static const char *visible(unsigned int ch) |
1317 | { | 1308 | { |