diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-04-12 17:17:29 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-04-12 17:17:29 +0200 |
commit | e31ca2e9b206a05263708a3c10fbaec920920ba8 (patch) | |
tree | 060741e2cfcae4bea4fae834423a95fe001e8c67 /coreutils/catv.c | |
parent | d9eb40c18519d10aac3b3d008aa7e338ae830b72 (diff) | |
download | busybox-w32-e31ca2e9b206a05263708a3c10fbaec920920ba8.tar.gz busybox-w32-e31ca2e9b206a05263708a3c10fbaec920920ba8.tar.bz2 busybox-w32-e31ca2e9b206a05263708a3c10fbaec920920ba8.zip |
catv: convert this bbox-specific applet into "cat -v"
function old new delta
cat_main 150 320 +170
packed_usage 31511 31552 +41
applet_install_loc 190 189 -1
applet_main 1516 1512 -4
applet_names 2618 2613 -5
catv_main 227 - -227
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/3 up/down: 211/-237) Total: -26 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/catv.c')
-rw-r--r-- | coreutils/catv.c | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/coreutils/catv.c b/coreutils/catv.c deleted file mode 100644 index 1aeebe1d9..000000000 --- a/coreutils/catv.c +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * cat -v implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2006 Rob Landley <rob@landley.net> | ||
6 | * | ||
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | ||
8 | */ | ||
9 | |||
10 | /* See "Cat -v considered harmful" at | ||
11 | * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */ | ||
12 | |||
13 | //config:config CATV | ||
14 | //config: bool "catv" | ||
15 | //config: default y | ||
16 | //config: help | ||
17 | //config: Display nonprinting characters as escape sequences (like some | ||
18 | //config: implementations' cat -v option). | ||
19 | |||
20 | //applet:IF_CATV(APPLET(catv, BB_DIR_BIN, BB_SUID_DROP)) | ||
21 | |||
22 | //kbuild:lib-$(CONFIG_CATV) += catv.o | ||
23 | |||
24 | //usage:#define catv_trivial_usage | ||
25 | //usage: "[-etv] [FILE]..." | ||
26 | //usage:#define catv_full_usage "\n\n" | ||
27 | //usage: "Display nonprinting characters as ^x or M-x\n" | ||
28 | //usage: "\n -e End each line with $" | ||
29 | //usage: "\n -t Show tabs as ^I" | ||
30 | //usage: "\n -v Don't use ^x or M-x escapes" | ||
31 | |||
32 | #include "libbb.h" | ||
33 | #include "common_bufsiz.h" | ||
34 | |||
35 | #define CATV_OPT_e (1<<0) | ||
36 | #define CATV_OPT_t (1<<1) | ||
37 | #define CATV_OPT_v (1<<2) | ||
38 | struct BUG_const_mismatch { | ||
39 | char BUG_const_mismatch[ | ||
40 | CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS | ||
41 | ? 1 : -1 | ||
42 | ]; | ||
43 | }; | ||
44 | |||
45 | int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
46 | int catv_main(int argc UNUSED_PARAM, char **argv) | ||
47 | { | ||
48 | int retval = EXIT_SUCCESS; | ||
49 | int fd; | ||
50 | unsigned opts; | ||
51 | opts = getopt32(argv, "etv"); | ||
52 | argv += optind; | ||
53 | #if 0 /* These consts match, we can just pass "opts" to visible() */ | ||
54 | if (opts & CATV_OPT_e) | ||
55 | flags |= VISIBLE_ENDLINE; | ||
56 | if (opts & CATV_OPT_t) | ||
57 | flags |= VISIBLE_SHOW_TABS; | ||
58 | #endif | ||
59 | |||
60 | /* Read from stdin if there's nothing else to do. */ | ||
61 | if (!argv[0]) | ||
62 | *--argv = (char*)"-"; | ||
63 | |||
64 | #define read_buf bb_common_bufsiz1 | ||
65 | setup_common_bufsiz(); | ||
66 | do { | ||
67 | fd = open_or_warn_stdin(*argv); | ||
68 | if (fd < 0) { | ||
69 | retval = EXIT_FAILURE; | ||
70 | continue; | ||
71 | } | ||
72 | for (;;) { | ||
73 | int i, res; | ||
74 | |||
75 | res = read(fd, read_buf, COMMON_BUFSIZE); | ||
76 | if (res < 0) | ||
77 | retval = EXIT_FAILURE; | ||
78 | if (res <= 0) | ||
79 | break; | ||
80 | for (i = 0; i < res; i++) { | ||
81 | unsigned char c = read_buf[i]; | ||
82 | if (opts & CATV_OPT_v) { | ||
83 | putchar(c); | ||
84 | } else { | ||
85 | char buf[sizeof("M-^c")]; | ||
86 | visible(c, buf, opts); | ||
87 | fputs(buf, stdout); | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | if (ENABLE_FEATURE_CLEAN_UP && fd) | ||
92 | close(fd); | ||
93 | } while (*++argv); | ||
94 | |||
95 | fflush_stdout_and_exit(retval); | ||
96 | } | ||