summaryrefslogtreecommitdiff
path: root/coreutils/stty.c
diff options
context:
space:
mode:
authorBartosz Golaszewski2013-07-30 06:29:42 +0200
committerDenys Vlasenko2013-07-30 06:29:42 +0200
commit79c618c41193eaaa092cb977f06fc112155ba92b (patch)
tree369938db46d4691ebbcc476386c7dafdac827887 /coreutils/stty.c
parentd0bc708cb52693b9ed1dab495e5f99fb8e1122f7 (diff)
downloadbusybox-79c618c41193eaaa092cb977f06fc112155ba92b.zip
busybox-79c618c41193eaaa092cb977f06fc112155ba92b.tar.gz
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.c39
1 files changed, 7 insertions, 32 deletions
diff --git a/coreutils/stty.c b/coreutils/stty.c
index d1e74f4..378a848 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -781,36 +781,6 @@ struct globals {
G.max_col = 80; \
} while (0)
-
-/* Return a string that is the printable representation of character CH */
-/* Adapted from 'cat' by Torbjorn Granlund */
-static const char *visible(unsigned ch)
-{
- char *bpout = G.buf;
-
- if (ch == _POSIX_VDISABLE)
- return "<undef>";
-
- if (ch >= 128) {
- ch -= 128;
- *bpout++ = 'M';
- *bpout++ = '-';
- }
-
- if (ch < 32) {
- *bpout++ = '^';
- *bpout++ = ch + 64;
- } else if (ch < 127) {
- *bpout++ = ch;
- } else {
- *bpout++ = '^';
- *bpout++ = '?';
- }
-
- *bpout = '\0';
- return G.buf;
-}
-
static void set_speed_or_die(enum speed_setting type, const char *arg,
struct termios *mode)
{
@@ -1038,6 +1008,7 @@ static void do_display(const struct termios *mode, int all)
#endif
for (i = 0; i != CIDX_min; ++i) {
+ char ch;
/* If swtch is the same as susp, don't print both */
#if VSWTCH == VSUSP
if (i == CIDX_swtch)
@@ -1051,8 +1022,12 @@ static void do_display(const struct termios *mode, int all)
continue;
}
#endif
- wrapf("%s = %s;", nth_string(control_name, i),
- visible(mode->c_cc[control_info[i].offset]));
+ ch = mode->c_cc[control_info[i].offset];
+ if (ch == _POSIX_VDISABLE)
+ strcpy(G.buf, "<undef>");
+ else
+ visible(ch, G.buf, 0);
+ wrapf("%s = %s;", nth_string(control_name, i), G.buf);
}
#if VEOF == VMIN
if ((mode->c_lflag & ICANON) == 0)