diff options
author | Bartosz Golaszewski <bartekgola@gmail.com> | 2013-07-30 06:29:42 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-07-30 06:29:42 +0200 |
commit | 79c618c41193eaaa092cb977f06fc112155ba92b (patch) | |
tree | 369938db46d4691ebbcc476386c7dafdac827887 /coreutils/stty.c | |
parent | d0bc708cb52693b9ed1dab495e5f99fb8e1122f7 (diff) | |
download | busybox-w32-79c618c41193eaaa092cb977f06fc112155ba92b.tar.gz busybox-w32-79c618c41193eaaa092cb977f06fc112155ba92b.tar.bz2 busybox-w32-79c618c41193eaaa092cb977f06fc112155ba92b.zip |
Refactor catv. Move visible() from stty to libbb.
Fixes the following TODO:
stty's visible() function and catv's guts are identical. Merge them into
an appropriate libbb function.
Also makes catv behave exactly like coreutils' cat -v e.g. it'll print 'M-^I'
instead of 'M- '.
function old new delta
visible - 70 +70
do_display 431 379 -52
catv_main 306 250 -56
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 70/-108) Total: -38 bytes
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/stty.c')
-rw-r--r-- | coreutils/stty.c | 39 |
1 files changed, 7 insertions, 32 deletions
diff --git a/coreutils/stty.c b/coreutils/stty.c index d1e74f437..378a848e7 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c | |||
@@ -781,36 +781,6 @@ struct globals { | |||
781 | G.max_col = 80; \ | 781 | G.max_col = 80; \ |
782 | } while (0) | 782 | } while (0) |
783 | 783 | ||
784 | |||
785 | /* Return a string that is the printable representation of character CH */ | ||
786 | /* Adapted from 'cat' by Torbjorn Granlund */ | ||
787 | static const char *visible(unsigned ch) | ||
788 | { | ||
789 | char *bpout = G.buf; | ||
790 | |||
791 | if (ch == _POSIX_VDISABLE) | ||
792 | return "<undef>"; | ||
793 | |||
794 | if (ch >= 128) { | ||
795 | ch -= 128; | ||
796 | *bpout++ = 'M'; | ||
797 | *bpout++ = '-'; | ||
798 | } | ||
799 | |||
800 | if (ch < 32) { | ||
801 | *bpout++ = '^'; | ||
802 | *bpout++ = ch + 64; | ||
803 | } else if (ch < 127) { | ||
804 | *bpout++ = ch; | ||
805 | } else { | ||
806 | *bpout++ = '^'; | ||
807 | *bpout++ = '?'; | ||
808 | } | ||
809 | |||
810 | *bpout = '\0'; | ||
811 | return G.buf; | ||
812 | } | ||
813 | |||
814 | static void set_speed_or_die(enum speed_setting type, const char *arg, | 784 | static void set_speed_or_die(enum speed_setting type, const char *arg, |
815 | struct termios *mode) | 785 | struct termios *mode) |
816 | { | 786 | { |
@@ -1038,6 +1008,7 @@ static void do_display(const struct termios *mode, int all) | |||
1038 | #endif | 1008 | #endif |
1039 | 1009 | ||
1040 | for (i = 0; i != CIDX_min; ++i) { | 1010 | for (i = 0; i != CIDX_min; ++i) { |
1011 | char ch; | ||
1041 | /* If swtch is the same as susp, don't print both */ | 1012 | /* If swtch is the same as susp, don't print both */ |
1042 | #if VSWTCH == VSUSP | 1013 | #if VSWTCH == VSUSP |
1043 | if (i == CIDX_swtch) | 1014 | if (i == CIDX_swtch) |
@@ -1051,8 +1022,12 @@ static void do_display(const struct termios *mode, int all) | |||
1051 | continue; | 1022 | continue; |
1052 | } | 1023 | } |
1053 | #endif | 1024 | #endif |
1054 | wrapf("%s = %s;", nth_string(control_name, i), | 1025 | ch = mode->c_cc[control_info[i].offset]; |
1055 | visible(mode->c_cc[control_info[i].offset])); | 1026 | if (ch == _POSIX_VDISABLE) |
1027 | strcpy(G.buf, "<undef>"); | ||
1028 | else | ||
1029 | visible(ch, G.buf, 0); | ||
1030 | wrapf("%s = %s;", nth_string(control_name, i), G.buf); | ||
1056 | } | 1031 | } |
1057 | #if VEOF == VMIN | 1032 | #if VEOF == VMIN |
1058 | if ((mode->c_lflag & ICANON) == 0) | 1033 | if ((mode->c_lflag & ICANON) == 0) |