diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-04-05 18:17:17 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-04-05 18:17:17 +0200 |
commit | d88f94a5df3a2edb8ba56fab5c13674b452f87ab (patch) | |
tree | abfed9c655cf1c436dac9e4089d7838c36e6e221 /coreutils/cat.c | |
parent | 5d561ef6349b4b6e1d12ad6638acb46abf1eeca6 (diff) | |
download | busybox-w32-d88f94a5df3a2edb8ba56fab5c13674b452f87ab.tar.gz busybox-w32-d88f94a5df3a2edb8ba56fab5c13674b452f87ab.tar.bz2 busybox-w32-d88f94a5df3a2edb8ba56fab5c13674b452f87ab.zip |
nl: new applet; also implement cat -nb (similar functionality to nl)
function old new delta
nl_main - 201 +201
print_numbered_lines - 115 +115
cat_main 36 149 +113
static.nl_longopts - 106 +106
packed_usage 31081 31182 +101
applet_main 1488 1492 +4
applet_names 2575 2578 +3
applet_suid 93 94 +1
applet_install_loc 186 187 +1
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 6/0 up/down: 645/0) Total: 645 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/cat.c')
-rw-r--r-- | coreutils/cat.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c index 65978887e..4169d9516 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
@@ -15,15 +15,31 @@ | |||
15 | 15 | ||
16 | //applet:IF_CAT(APPLET_NOFORK(cat, cat, BB_DIR_BIN, BB_SUID_DROP, cat)) | 16 | //applet:IF_CAT(APPLET_NOFORK(cat, cat, BB_DIR_BIN, BB_SUID_DROP, cat)) |
17 | 17 | ||
18 | //kbuild:lib-$(CONFIG_CAT) += cat.o | 18 | //kbuild:lib-$(CONFIG_CAT) += cat.o |
19 | // For -n: | ||
20 | //kbuild:lib-$(CONFIG_CAT) += nl.o | ||
19 | 21 | ||
20 | /* BB_AUDIT SUSv3 compliant */ | 22 | /* BB_AUDIT SUSv3 compliant */ |
21 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */ | 23 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */ |
22 | 24 | ||
23 | //usage:#define cat_trivial_usage | 25 | //usage:#define cat_trivial_usage |
24 | //usage: "[FILE]..." | 26 | //usage: "[-n] [FILE]..." |
25 | //usage:#define cat_full_usage "\n\n" | 27 | //usage:#define cat_full_usage "\n\n" |
26 | //usage: "Concatenate FILEs and print them to stdout" | 28 | //usage: "Concatenate FILEs and print them to stdout" |
29 | //usage: "\n -n Number output lines" | ||
30 | /* | ||
31 | Longopts not implemented yet: | ||
32 | --number-nonblank number nonempty output lines, overrides -n | ||
33 | --number number all output lines | ||
34 | Not implemented yet: | ||
35 | -A, --show-all equivalent to -vET | ||
36 | -e equivalent to -vE | ||
37 | -E, --show-ends display $ at end of each line | ||
38 | -s, --squeeze-blank suppress repeated empty output lines | ||
39 | -t equivalent to -vT | ||
40 | -T, --show-tabs display TAB characters as ^I | ||
41 | -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB | ||
42 | */ | ||
27 | //usage: | 43 | //usage: |
28 | //usage:#define cat_example_usage | 44 | //usage:#define cat_example_usage |
29 | //usage: "$ cat /proc/uptime\n" | 45 | //usage: "$ cat /proc/uptime\n" |
@@ -61,7 +77,26 @@ int bb_cat(char **argv) | |||
61 | int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 77 | int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
62 | int cat_main(int argc UNUSED_PARAM, char **argv) | 78 | int cat_main(int argc UNUSED_PARAM, char **argv) |
63 | { | 79 | { |
64 | getopt32(argv, "u"); | 80 | struct number_state ns; |
81 | unsigned opt; | ||
82 | |||
83 | /* -u is ignored */ | ||
84 | opt = getopt32(argv, "nbu"); | ||
65 | argv += optind; | 85 | argv += optind; |
66 | return bb_cat(argv); | 86 | if (!(opt & 3)) /* no -n or -b */ |
87 | return bb_cat(argv); | ||
88 | |||
89 | if (!*argv) | ||
90 | *--argv = (char*)"-"; | ||
91 | ns.width = 6; | ||
92 | ns.start = 1; | ||
93 | ns.inc = 1; | ||
94 | ns.sep = "\t"; | ||
95 | ns.empty_str = "\n"; | ||
96 | ns.all = !(opt & 2); /* -n without -b */ | ||
97 | ns.nonempty = (opt & 2); /* -b (with or without -n) */ | ||
98 | do { | ||
99 | print_numbered_lines(&ns, *argv); | ||
100 | } while (*++argv); | ||
101 | fflush_stdout_and_exit(EXIT_SUCCESS); | ||
67 | } | 102 | } |