aboutsummaryrefslogtreecommitdiff
path: root/coreutils/stty.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2007-01-17 19:46:12 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2007-01-17 19:46:12 +0000
commit94feb1c8076742c83f569a4e42405a70902066a0 (patch)
treebbaf21c2226d7f436aa46c7890ba1096479f7515 /coreutils/stty.c
parentd4a745c3d4936690660a4813b0c5e2ca9990838f (diff)
downloadbusybox-w32-94feb1c8076742c83f569a4e42405a70902066a0.tar.gz
busybox-w32-94feb1c8076742c83f569a4e42405a70902066a0.tar.bz2
busybox-w32-94feb1c8076742c83f569a4e42405a70902066a0.zip
- merge display_changed() and display_all()
This one is a bit risky but did work for me in cursory testing..
Diffstat (limited to 'coreutils/stty.c')
-rw-r--r--coreutils/stty.c91
1 files changed, 22 insertions, 69 deletions
diff --git a/coreutils/stty.c b/coreutils/stty.c
index 05d91d8c1..2682e969d 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -623,7 +623,8 @@ static int recover_mode(const char *arg, struct termios *mode)
623 return 1; 623 return 1;
624} 624}
625 625
626static void display_recoverable(const struct termios *mode) 626static void display_recoverable(const struct termios *mode,
627 const int ATTRIBUTE_UNUSED dummy)
627{ 628{
628 int i; 629 int i;
629 printf("%lx:%lx:%lx:%lx", 630 printf("%lx:%lx:%lx:%lx",
@@ -650,7 +651,7 @@ static void display_speed(const struct termios *mode, int fancy)
650 wrapf(fmt_str, tty_baud_to_value(ispeed), tty_baud_to_value(ospeed)); 651 wrapf(fmt_str, tty_baud_to_value(ispeed), tty_baud_to_value(ospeed));
651} 652}
652 653
653static void display_all(const struct termios *mode) 654static void do_display(const struct termios *mode, const int all)
654{ 655{
655 int i; 656 int i;
656 tcflag_t *bitsp; 657 tcflag_t *bitsp;
@@ -658,7 +659,8 @@ static void display_all(const struct termios *mode)
658 int prev_type = control; 659 int prev_type = control;
659 660
660 display_speed(mode, 1); 661 display_speed(mode, 1);
661 display_window_size(1); 662 if (all)
663 display_window_size(1);
662#ifdef HAVE_C_LINE 664#ifdef HAVE_C_LINE
663 wrapf("line = %d;\n", mode->c_line); 665 wrapf("line = %d;\n", mode->c_line);
664#else 666#else
@@ -690,16 +692,22 @@ static void display_all(const struct termios *mode)
690 if (mode_info[i].flags & OMIT) 692 if (mode_info[i].flags & OMIT)
691 continue; 693 continue;
692 if (mode_info[i].type != prev_type) { 694 if (mode_info[i].type != prev_type) {
693 wrapf("\n"); 695 /* wrapf("\n"); */
696 if (current_col) wrapf("\n");
694 prev_type = mode_info[i].type; 697 prev_type = mode_info[i].type;
695 } 698 }
696 699
697 bitsp = mode_type_flag(mode_info[i].type, mode); 700 bitsp = mode_type_flag(mode_info[i].type, mode);
698 mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; 701 mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;
699 if ((*bitsp & mask) == mode_info[i].bits) 702 if ((*bitsp & mask) == mode_info[i].bits) {
700 wrapf("%s", mode_info[i].name); 703 if (all || (mode_info[i].flags & SANE_UNSET))
701 else if (mode_info[i].flags & REV) 704 wrapf("%s", mode_info[i].name);
702 wrapf("-%s", mode_info[i].name); 705 } else {
706 if ((all && mode_info[i].flags & REV) ||
707 (!all &&
708 (mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)))
709 wrapf("-%s", mode_info[i].name);
710 }
703 } 711 }
704 if (current_col) wrapf("\n"); 712 if (current_col) wrapf("\n");
705} 713}
@@ -892,63 +900,6 @@ static void set_mode(const struct mode_info *info, int reversed,
892 } 900 }
893} 901}
894 902
895static void display_changed(const struct termios *mode)
896{
897 int i;
898 tcflag_t *bitsp;
899 unsigned long mask;
900 int prev_type = control;
901
902 display_speed(mode, 1);
903#ifdef HAVE_C_LINE
904 wrapf("line = %d;\n", mode->c_line);
905#else
906 wrapf("\n");
907#endif
908
909 for (i = 0; control_info[i].name != stty_min; ++i) {
910 if (mode->c_cc[control_info[i].offset] == control_info[i].saneval)
911 continue;
912 /* If swtch is the same as susp, don't print both */
913#if VSWTCH == VSUSP
914 if (control_info[i].name == stty_swtch)
915 continue;
916#endif
917 /* If eof uses the same slot as min, only print whichever applies */
918#if VEOF == VMIN
919 if ((mode->c_lflag & ICANON) == 0
920 && (control_info[i].name == stty_eof
921 || control_info[i].name == stty_eol)) continue;
922#endif
923 wrapf("%s = %s;", control_info[i].name,
924 visible(mode->c_cc[control_info[i].offset]));
925 }
926 if ((mode->c_lflag & ICANON) == 0)
927 wrapf("min = %d; time = %d;", mode->c_cc[VMIN], mode->c_cc[VTIME]);
928
929 if (current_col) wrapf("\n");
930
931 for (i = 0; i < NUM_mode_info; ++i) {
932 if (mode_info[i].flags & OMIT)
933 continue;
934 if (mode_info[i].type != prev_type) {
935 if (current_col) wrapf("\n");
936 prev_type = mode_info[i].type;
937 }
938
939 bitsp = mode_type_flag(mode_info[i].type, mode);
940 mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;
941 if ((*bitsp & mask) == mode_info[i].bits) {
942 if (mode_info[i].flags & SANE_UNSET) {
943 wrapf("%s", mode_info[i].name);
944 }
945 } else if ((mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)) {
946 wrapf("-%s", mode_info[i].name);
947 }
948 }
949 if (current_col) wrapf("\n");
950}
951
952static void set_control_char_or_die(const struct control_info *info, 903static void set_control_char_or_die(const struct control_info *info,
953 const char *arg, struct termios *mode) 904 const char *arg, struct termios *mode)
954{ 905{
@@ -977,11 +928,12 @@ static void set_control_char_or_die(const struct control_info *info,
977int stty_main(int argc, char **argv) 928int stty_main(int argc, char **argv)
978{ 929{
979 struct termios mode; 930 struct termios mode;
980 void (*output_func)(const struct termios *); 931 void (*output_func)(const struct termios *, const int);
981 const char *file_name = NULL; 932 const char *file_name = NULL;
982 int k; 933 int k;
934 int display_all = 0;
983 option_mask32 = STTY_noargs; 935 option_mask32 = STTY_noargs;
984 output_func = display_changed; 936 output_func = do_display;
985 937
986 /* First pass: only parse/verify command line params */ 938 /* First pass: only parse/verify command line params */
987 k = 0; 939 k = 0;
@@ -1007,7 +959,8 @@ int stty_main(int argc, char **argv)
1007 switch (arg[i]) { 959 switch (arg[i]) {
1008 case 'a': 960 case 'a':
1009 option_mask32 |= STTY_verbose_output; 961 option_mask32 |= STTY_verbose_output;
1010 output_func = display_all; 962 output_func = do_display;
963 display_all = 1;
1011 break; 964 break;
1012 case 'g': 965 case 'g':
1013 option_mask32 |= STTY_recoverable_output; 966 option_mask32 |= STTY_recoverable_output;
@@ -1125,7 +1078,7 @@ invalid_argument:
1125 1078
1126 if (option_mask32 & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) { 1079 if (option_mask32 & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) {
1127 get_terminal_width_height(STDOUT_FILENO, &max_col, NULL); 1080 get_terminal_width_height(STDOUT_FILENO, &max_col, NULL);
1128 output_func(&mode); 1081 output_func(&mode, display_all);
1129 return EXIT_SUCCESS; 1082 return EXIT_SUCCESS;
1130 } 1083 }
1131 1084