aboutsummaryrefslogtreecommitdiff
path: root/coreutils/cat.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/cat.c')
-rw-r--r--coreutils/cat.c43
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)
61int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 77int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
62int cat_main(int argc UNUSED_PARAM, char **argv) 78int 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}