1 /* vi: set sw=4 ts=4: */
3 * cat implementation for busybox
5 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
7 * Licensed under GPLv2, see file LICENSE in this source tree.
13 //config: cat is used to concatenate files and print them to the standard
14 //config: output. Enable this option if you wish to enable the 'cat' utility.
16 //applet:IF_CAT(APPLET_NOFORK(cat, cat, BB_DIR_BIN, BB_SUID_DROP, cat))
18 //kbuild:lib-$(CONFIG_CAT) += cat.o
20 /* BB_AUDIT SUSv3 compliant */
21 /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
23 //usage:#define cat_trivial_usage
24 //usage: "[-n] [FILE]..."
25 //usage:#define cat_full_usage "\n\n"
26 //usage: "Concatenate FILEs and print them to stdout"
27 //usage: "\n -n Number output lines"
29 Longopts not implemented yet:
30 --number-nonblank number nonempty output lines, overrides -n
31 --number number all output lines
33 -A, --show-all equivalent to -vET
35 -E, --show-ends display $ at end of each line
36 -s, --squeeze-blank suppress repeated empty output lines
38 -T, --show-tabs display TAB characters as ^I
39 -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
42 //usage:#define cat_example_usage
43 //usage: "$ cat /proc/uptime\n"
44 //usage: "110716.72 17.67"
48 /* This is a NOFORK applet. Be very careful! */
50 int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
51 int cat_main(int argc UNUSED_PARAM, char **argv)
53 struct number_state ns;
57 opt = getopt32(argv, "nbu");
59 if (!(opt & 3)) /* no -n or -b */
69 ns.all = !(opt & 2); /* -n without -b */
70 ns.nonempty = (opt & 2); /* -b (with or without -n) */
72 print_numbered_lines(&ns, *argv);
74 fflush_stdout_and_exit(EXIT_SUCCESS);