diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-11 15:00:17 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-11 15:00:17 +0100 |
commit | 800ff7cc75b05f475461869daf80f71cab62aba4 (patch) | |
tree | 642748f6fcfda792a1a873ff6a2ba0eb4aefcf37 /coreutils | |
parent | 9f5a577a3241597cb5e7ba9f6df33c2e3c440e44 (diff) | |
download | busybox-w32-800ff7cc75b05f475461869daf80f71cab62aba4.tar.gz busybox-w32-800ff7cc75b05f475461869daf80f71cab62aba4.tar.bz2 busybox-w32-800ff7cc75b05f475461869daf80f71cab62aba4.zip |
stty: code shrink -44 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/stty.c | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/coreutils/stty.c b/coreutils/stty.c index 776a16a76..4952d53d3 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c | |||
@@ -619,9 +619,9 @@ enum { | |||
619 | 619 | ||
620 | 620 | ||
621 | struct globals { | 621 | struct globals { |
622 | const char *device_name; // = bb_msg_standard_input; | 622 | const char *device_name; |
623 | /* The width of the screen, for output wrapping */ | 623 | /* The width of the screen, for output wrapping */ |
624 | unsigned max_col; // = 80; | 624 | unsigned max_col; |
625 | /* Current position, to know when to wrap */ | 625 | /* Current position, to know when to wrap */ |
626 | unsigned current_col; | 626 | unsigned current_col; |
627 | char buf[10]; | 627 | char buf[10]; |
@@ -734,7 +734,13 @@ static void wrapf(const char *message, ...) | |||
734 | G.current_col = 0; | 734 | G.current_col = 0; |
735 | } | 735 | } |
736 | 736 | ||
737 | static void set_window_size(const int rows, const int cols) | 737 | static void newline(void) |
738 | { | ||
739 | if (G.current_col != 0) | ||
740 | wrapf("\n"); | ||
741 | } | ||
742 | |||
743 | static void set_window_size(int rows, int cols) | ||
738 | { | 744 | { |
739 | struct winsize win = { 0, 0, 0, 0 }; | 745 | struct winsize win = { 0, 0, 0, 0 }; |
740 | 746 | ||
@@ -755,7 +761,7 @@ bail: | |||
755 | perror_on_device("%s"); | 761 | perror_on_device("%s"); |
756 | } | 762 | } |
757 | 763 | ||
758 | static void display_window_size(const int fancy) | 764 | static void display_window_size(int fancy) |
759 | { | 765 | { |
760 | const char *fmt_str = "%s\0%s: no size information for this device"; | 766 | const char *fmt_str = "%s\0%s: no size information for this device"; |
761 | unsigned width, height; | 767 | unsigned width, height; |
@@ -765,7 +771,7 @@ static void display_window_size(const int fancy) | |||
765 | perror_on_device(fmt_str); | 771 | perror_on_device(fmt_str); |
766 | } | 772 | } |
767 | } else { | 773 | } else { |
768 | wrapf(fancy ? "rows %d; columns %d;" : "%d %d\n", | 774 | wrapf(fancy ? "rows %u; columns %u;" : "%u %u\n", |
769 | height, width); | 775 | height, width); |
770 | } | 776 | } |
771 | } | 777 | } |
@@ -864,21 +870,21 @@ static void display_recoverable(const struct termios *mode, | |||
864 | 870 | ||
865 | static void display_speed(const struct termios *mode, int fancy) | 871 | static void display_speed(const struct termios *mode, int fancy) |
866 | { | 872 | { |
867 | //01234567 8 9 | 873 | //____________________ 01234567 8 9 |
868 | const char *fmt_str = "%lu %lu\n\0ispeed %lu baud; ospeed %lu baud;"; | 874 | const char *fmt_str = "%lu %lu\n\0ispeed %lu baud; ospeed %lu baud;"; |
869 | unsigned long ispeed, ospeed; | 875 | unsigned long ispeed, ospeed; |
870 | 876 | ||
871 | ospeed = ispeed = cfgetispeed(mode); | 877 | ospeed = ispeed = cfgetispeed(mode); |
872 | if (ispeed == 0 || ispeed == (ospeed = cfgetospeed(mode))) { | 878 | if (ispeed == 0 || ispeed == (ospeed = cfgetospeed(mode))) { |
873 | ispeed = ospeed; /* in case ispeed was 0 */ | 879 | ispeed = ospeed; /* in case ispeed was 0 */ |
874 | //0123 4 5 6 7 8 9 | 880 | //________ 0123 4 5 6 7 8 9 |
875 | fmt_str = "%lu\n\0\0\0\0\0speed %lu baud;"; | 881 | fmt_str = "%lu\n\0\0\0\0\0speed %lu baud;"; |
876 | } | 882 | } |
877 | if (fancy) fmt_str += 9; | 883 | if (fancy) fmt_str += 9; |
878 | wrapf(fmt_str, tty_baud_to_value(ispeed), tty_baud_to_value(ospeed)); | 884 | wrapf(fmt_str, tty_baud_to_value(ispeed), tty_baud_to_value(ospeed)); |
879 | } | 885 | } |
880 | 886 | ||
881 | static void do_display(const struct termios *mode, const int all) | 887 | static void do_display(const struct termios *mode, int all) |
882 | { | 888 | { |
883 | int i; | 889 | int i; |
884 | tcflag_t *bitsp; | 890 | tcflag_t *bitsp; |
@@ -889,9 +895,9 @@ static void do_display(const struct termios *mode, const int all) | |||
889 | if (all) | 895 | if (all) |
890 | display_window_size(1); | 896 | display_window_size(1); |
891 | #ifdef HAVE_C_LINE | 897 | #ifdef HAVE_C_LINE |
892 | wrapf("line = %d;\n", mode->c_line); | 898 | wrapf("line = %u;\n", mode->c_line); |
893 | #else | 899 | #else |
894 | wrapf("\n"); | 900 | newline(); |
895 | #endif | 901 | #endif |
896 | 902 | ||
897 | for (i = 0; i != CIDX_min; ++i) { | 903 | for (i = 0; i != CIDX_min; ++i) { |
@@ -902,7 +908,7 @@ static void do_display(const struct termios *mode, const int all) | |||
902 | #endif | 908 | #endif |
903 | /* If eof uses the same slot as min, only print whichever applies */ | 909 | /* If eof uses the same slot as min, only print whichever applies */ |
904 | #if VEOF == VMIN | 910 | #if VEOF == VMIN |
905 | if ((mode->c_lflag & ICANON) == 0 | 911 | if (!(mode->c_lflag & ICANON) |
906 | && (i == CIDX_eof || i == CIDX_eol) | 912 | && (i == CIDX_eof || i == CIDX_eol) |
907 | ) { | 913 | ) { |
908 | continue; | 914 | continue; |
@@ -914,15 +920,14 @@ static void do_display(const struct termios *mode, const int all) | |||
914 | #if VEOF == VMIN | 920 | #if VEOF == VMIN |
915 | if ((mode->c_lflag & ICANON) == 0) | 921 | if ((mode->c_lflag & ICANON) == 0) |
916 | #endif | 922 | #endif |
917 | wrapf("min = %d; time = %d;", mode->c_cc[VMIN], mode->c_cc[VTIME]); | 923 | wrapf("min = %u; time = %u;", mode->c_cc[VMIN], mode->c_cc[VTIME]); |
918 | if (G.current_col) wrapf("\n"); | 924 | newline(); |
919 | 925 | ||
920 | for (i = 0; i < NUM_mode_info; ++i) { | 926 | for (i = 0; i < NUM_mode_info; ++i) { |
921 | if (mode_info[i].flags & OMIT) | 927 | if (mode_info[i].flags & OMIT) |
922 | continue; | 928 | continue; |
923 | if (mode_info[i].type != prev_type) { | 929 | if (mode_info[i].type != prev_type) { |
924 | /* wrapf("\n"); */ | 930 | newline(); |
925 | if (G.current_col) wrapf("\n"); | ||
926 | prev_type = mode_info[i].type; | 931 | prev_type = mode_info[i].type; |
927 | } | 932 | } |
928 | 933 | ||
@@ -939,7 +944,7 @@ static void do_display(const struct termios *mode, const int all) | |||
939 | } | 944 | } |
940 | } | 945 | } |
941 | } | 946 | } |
942 | if (G.current_col) wrapf("\n"); | 947 | newline(); |
943 | } | 948 | } |
944 | 949 | ||
945 | static void sane_mode(struct termios *mode) | 950 | static void sane_mode(struct termios *mode) |
@@ -1138,7 +1143,7 @@ static void set_control_char_or_die(const struct control_info *info, | |||
1138 | value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes); | 1143 | value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes); |
1139 | else if (arg[0] == '\0' || arg[1] == '\0') | 1144 | else if (arg[0] == '\0' || arg[1] == '\0') |
1140 | value = arg[0]; | 1145 | value = arg[0]; |
1141 | else if (!strcmp(arg, "^-") || !strcmp(arg, "undef")) | 1146 | else if (strcmp(arg, "^-") == 0 || strcmp(arg, "undef") == 0) |
1142 | value = _POSIX_VDISABLE; | 1147 | value = _POSIX_VDISABLE; |
1143 | else if (arg[0] == '^') { /* Ignore any trailing junk (^Cjunk) */ | 1148 | else if (arg[0] == '^') { /* Ignore any trailing junk (^Cjunk) */ |
1144 | value = arg[1] & 0x1f; /* Non-letters get weird results */ | 1149 | value = arg[1] & 0x1f; /* Non-letters get weird results */ |
@@ -1159,7 +1164,7 @@ int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
1159 | int stty_main(int argc UNUSED_PARAM, char **argv) | 1164 | int stty_main(int argc UNUSED_PARAM, char **argv) |
1160 | { | 1165 | { |
1161 | struct termios mode; | 1166 | struct termios mode; |
1162 | void (*output_func)(const struct termios *, const int); | 1167 | void (*output_func)(const struct termios *, int); |
1163 | const char *file_name = NULL; | 1168 | const char *file_name = NULL; |
1164 | int display_all = 0; | 1169 | int display_all = 0; |
1165 | int stty_state; | 1170 | int stty_state; |
@@ -1289,9 +1294,11 @@ int stty_main(int argc UNUSED_PARAM, char **argv) | |||
1289 | (STTY_verbose_output | STTY_recoverable_output)) | 1294 | (STTY_verbose_output | STTY_recoverable_output)) |
1290 | bb_error_msg_and_die("verbose and stty-readable output styles are mutually exclusive"); | 1295 | bb_error_msg_and_die("verbose and stty-readable output styles are mutually exclusive"); |
1291 | /* Specifying -a or -g with non-options is an error */ | 1296 | /* Specifying -a or -g with non-options is an error */ |
1292 | if (!(stty_state & STTY_noargs) && | 1297 | if (!(stty_state & STTY_noargs) |
1293 | (stty_state & (STTY_verbose_output | STTY_recoverable_output))) | 1298 | && (stty_state & (STTY_verbose_output | STTY_recoverable_output)) |
1299 | ) { | ||
1294 | bb_error_msg_and_die("modes may not be set when specifying an output style"); | 1300 | bb_error_msg_and_die("modes may not be set when specifying an output style"); |
1301 | } | ||
1295 | 1302 | ||
1296 | /* Now it is safe to start doing things */ | 1303 | /* Now it is safe to start doing things */ |
1297 | if (file_name) { | 1304 | if (file_name) { |