diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2013-07-30 11:41:58 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-07-30 11:41:58 +0200 |
commit | bfa6ed1bf43ea607e33a6e89a0ef03f84a5b5d38 (patch) | |
tree | 7d83bd734ff714fd4c940685d82aa3015ccc4135 | |
parent | 79c618c41193eaaa092cb977f06fc112155ba92b (diff) | |
download | busybox-w32-bfa6ed1bf43ea607e33a6e89a0ef03f84a5b5d38.tar.gz busybox-w32-bfa6ed1bf43ea607e33a6e89a0ef03f84a5b5d38.tar.bz2 busybox-w32-bfa6ed1bf43ea607e33a6e89a0ef03f84a5b5d38.zip |
catv: code shrink
catv_main 250 227 -23
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/catv.c | 15 | ||||
-rw-r--r-- | include/libbb.h | 5 |
2 files changed, 13 insertions, 7 deletions
diff --git a/coreutils/catv.c b/coreutils/catv.c index 18b18104e..0139b397f 100644 --- a/coreutils/catv.c +++ b/coreutils/catv.c | |||
@@ -26,19 +26,22 @@ int catv_main(int argc UNUSED_PARAM, char **argv) | |||
26 | int retval = EXIT_SUCCESS; | 26 | int retval = EXIT_SUCCESS; |
27 | int fd; | 27 | int fd; |
28 | unsigned opts; | 28 | unsigned opts; |
29 | int flags = 0; | ||
30 | |||
31 | opts = getopt32(argv, "etv"); | ||
32 | #define CATV_OPT_e (1<<0) | 29 | #define CATV_OPT_e (1<<0) |
33 | #define CATV_OPT_t (1<<1) | 30 | #define CATV_OPT_t (1<<1) |
34 | #define CATV_OPT_v (1<<2) | 31 | #define CATV_OPT_v (1<<2) |
32 | typedef char BUG_const_mismatch[ | ||
33 | CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS | ||
34 | ? 1 : -1 | ||
35 | ]; | ||
36 | |||
37 | opts = getopt32(argv, "etv"); | ||
35 | argv += optind; | 38 | argv += optind; |
36 | if (opts & (CATV_OPT_e | CATV_OPT_t)) | 39 | #if 0 /* These consts match, we can just pass "opts" to visible() */ |
37 | opts &= ~CATV_OPT_v; | ||
38 | if (opts & CATV_OPT_e) | 40 | if (opts & CATV_OPT_e) |
39 | flags |= VISIBLE_ENDLINE; | 41 | flags |= VISIBLE_ENDLINE; |
40 | if (opts & CATV_OPT_t) | 42 | if (opts & CATV_OPT_t) |
41 | flags |= VISIBLE_SHOW_TABS; | 43 | flags |= VISIBLE_SHOW_TABS; |
44 | #endif | ||
42 | 45 | ||
43 | /* Read from stdin if there's nothing else to do. */ | 46 | /* Read from stdin if there's nothing else to do. */ |
44 | if (!argv[0]) | 47 | if (!argv[0]) |
@@ -64,7 +67,7 @@ int catv_main(int argc UNUSED_PARAM, char **argv) | |||
64 | putchar(c); | 67 | putchar(c); |
65 | } else { | 68 | } else { |
66 | char buf[sizeof("M-^c")]; | 69 | char buf[sizeof("M-^c")]; |
67 | visible(c, buf, flags); | 70 | visible(c, buf, opts); |
68 | fputs(buf, stdout); | 71 | fputs(buf, stdout); |
69 | } | 72 | } |
70 | } | 73 | } |
diff --git a/include/libbb.h b/include/libbb.h index 0c3734cdb..171214586 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -680,7 +680,10 @@ enum { PRINTABLE_META = 0x100 }; | |||
680 | void fputc_printable(int ch, FILE *file) FAST_FUNC; | 680 | void fputc_printable(int ch, FILE *file) FAST_FUNC; |
681 | /* Return a string that is the printable representation of character ch. | 681 | /* Return a string that is the printable representation of character ch. |
682 | * Buffer must hold at least four characters. */ | 682 | * Buffer must hold at least four characters. */ |
683 | enum { VISIBLE_SHOW_TABS = 1, VISIBLE_ENDLINE = 2 }; | 683 | enum { |
684 | VISIBLE_ENDLINE = 1 << 0, | ||
685 | VISIBLE_SHOW_TABS = 1 << 1, | ||
686 | }; | ||
684 | void visible(unsigned ch, char *buf, int flags) FAST_FUNC; | 687 | void visible(unsigned ch, char *buf, int flags) FAST_FUNC; |
685 | 688 | ||
686 | /* dmalloc will redefine these to it's own implementation. It is safe | 689 | /* dmalloc will redefine these to it's own implementation. It is safe |