diff options
-rw-r--r-- | coreutils/Config.in | 6 | ||||
-rw-r--r-- | coreutils/Makefile.in | 1 | ||||
-rw-r--r-- | coreutils/cat.c | 31 | ||||
-rw-r--r-- | coreutils/catv.c | 65 | ||||
-rw-r--r-- | include/applets.h | 1 | ||||
-rw-r--r-- | include/usage.h | 7 |
6 files changed, 82 insertions, 29 deletions
diff --git a/coreutils/Config.in b/coreutils/Config.in index 818854cb1..96f4d7a6e 100644 --- a/coreutils/Config.in +++ b/coreutils/Config.in | |||
@@ -25,6 +25,12 @@ config CONFIG_CAT | |||
25 | help | 25 | help |
26 | cat is used to concatenate files and print them to the standard | 26 | cat is used to concatenate files and print them to the standard |
27 | output. Enable this option if you wish to enable the 'cat' utility. | 27 | output. Enable this option if you wish to enable the 'cat' utility. |
28 | config CONFIG_CATV | ||
29 | bool "catv" | ||
30 | default n | ||
31 | help | ||
32 | Display nonprinting characters as escape sequences (like some | ||
33 | implementations' cat -v option). | ||
28 | 34 | ||
29 | config CONFIG_FEATURE_CAT_ESCAPE | 35 | config CONFIG_FEATURE_CAT_ESCAPE |
30 | bool "support -vetET" | 36 | bool "support -vetET" |
diff --git a/coreutils/Makefile.in b/coreutils/Makefile.in index 24eee0b91..50c090f8d 100644 --- a/coreutils/Makefile.in +++ b/coreutils/Makefile.in | |||
@@ -14,6 +14,7 @@ COREUTILS-y:= | |||
14 | COREUTILS-$(CONFIG_BASENAME) += basename.o | 14 | COREUTILS-$(CONFIG_BASENAME) += basename.o |
15 | COREUTILS-$(CONFIG_CAL) += cal.o | 15 | COREUTILS-$(CONFIG_CAL) += cal.o |
16 | COREUTILS-$(CONFIG_CAT) += cat.o | 16 | COREUTILS-$(CONFIG_CAT) += cat.o |
17 | COREUTILS-$(CONFIG_CATV) += catv.o | ||
17 | COREUTILS-$(CONFIG_CHGRP) += chgrp.o | 18 | COREUTILS-$(CONFIG_CHGRP) += chgrp.o |
18 | COREUTILS-$(CONFIG_CHMOD) += chmod.o | 19 | COREUTILS-$(CONFIG_CHMOD) += chmod.o |
19 | COREUTILS-$(CONFIG_CHOWN) += chown.o | 20 | COREUTILS-$(CONFIG_CHOWN) += chown.o |
diff --git a/coreutils/cat.c b/coreutils/cat.c index 9645f6143..37237ec1d 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
@@ -4,41 +4,14 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * Licensed under GPLv2 or later, see file License in this tarball for details. |
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | 8 | */ |
22 | 9 | ||
23 | /* BB_AUDIT SUSv3 compliant */ | 10 | /* BB_AUDIT SUSv3 compliant */ |
24 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */ | 11 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */ |
25 | 12 | ||
26 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) | ||
27 | * | ||
28 | * This is a new implementation of 'cat' which aims to be SUSv3 compliant. | ||
29 | * | ||
30 | * Changes from the previous implementation include: | ||
31 | * 1) Multiple '-' args are accepted as required by SUSv3. The previous | ||
32 | * implementation would close stdin and segfault on a subsequent '-'. | ||
33 | * 2) The '-u' options is required by SUSv3. Note that the specified | ||
34 | * behavior for '-u' is done by default, so all we need do is accept | ||
35 | * the option. | ||
36 | */ | ||
37 | |||
38 | #include <stdlib.h> | ||
39 | #include <stdio.h> | ||
40 | #include <unistd.h> | ||
41 | #include "busybox.h" | 13 | #include "busybox.h" |
14 | #include <unistd.h> | ||
42 | 15 | ||
43 | int cat_main(int argc, char **argv) | 16 | int cat_main(int argc, char **argv) |
44 | { | 17 | { |
diff --git a/coreutils/catv.c b/coreutils/catv.c new file mode 100644 index 000000000..dd4aa44e3 --- /dev/null +++ b/coreutils/catv.c | |||
@@ -0,0 +1,65 @@ | |||
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 tarball for details. | ||
8 | */ | ||
9 | |||
10 | /* See "Cat -v considered harmful" at | ||
11 | * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */ | ||
12 | |||
13 | #include "busybox.h" | ||
14 | #include <unistd.h> | ||
15 | #include <fcntl.h> | ||
16 | |||
17 | int catv_main(int argc, char **argv) | ||
18 | { | ||
19 | int retval = EXIT_SUCCESS, fd, flags; | ||
20 | |||
21 | flags = bb_getopt_ulflags(argc, argv, "etv"); | ||
22 | flags ^= 4; | ||
23 | |||
24 | // Loop through files. | ||
25 | |||
26 | argv += optind; | ||
27 | do { | ||
28 | // Read from stdin if there's nothing else to do. | ||
29 | |||
30 | fd = 0; | ||
31 | if (*argv && 0>(fd = bb_xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE; | ||
32 | else for(;;) { | ||
33 | int i, res; | ||
34 | |||
35 | res = read(fd, bb_common_bufsiz1, sizeof(bb_common_bufsiz1)); | ||
36 | if (res < 0) retval = EXIT_FAILURE; | ||
37 | if (res <1) break; | ||
38 | for (i=0; i<res; i++) { | ||
39 | char c=bb_common_bufsiz1[i]; | ||
40 | |||
41 | if (c > 126 && (flags & 4)) { | ||
42 | if (c == 127) { | ||
43 | printf("^?"); | ||
44 | continue; | ||
45 | } else { | ||
46 | printf("M-"); | ||
47 | c -= 128; | ||
48 | } | ||
49 | } | ||
50 | if (c < 32) { | ||
51 | if (c == 10) { | ||
52 | if (flags & 1) putchar('$'); | ||
53 | } else if (flags & (c==9 ? 2 : 4)) { | ||
54 | printf("^%c", c+'@'); | ||
55 | continue; | ||
56 | } | ||
57 | } | ||
58 | putchar(c); | ||
59 | } | ||
60 | } | ||
61 | if (ENABLE_FEATURE_CLEAN_UP && fd) close(fd); | ||
62 | } while (*++argv); | ||
63 | |||
64 | return retval; | ||
65 | } | ||
diff --git a/include/applets.h b/include/applets.h index bbff772f0..ab2a6c5bf 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -63,6 +63,7 @@ APPLET_NOUSAGE(busybox, busybox, _BB_DIR_BIN, _BB_SUID_MAYBE) | |||
63 | USE_BUNZIP2(APPLET(bzcat, bunzip2, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 63 | USE_BUNZIP2(APPLET(bzcat, bunzip2, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
64 | USE_CAL(APPLET(cal, cal, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 64 | USE_CAL(APPLET(cal, cal, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
65 | USE_CAT(APPLET(cat, cat, _BB_DIR_BIN, _BB_SUID_NEVER)) | 65 | USE_CAT(APPLET(cat, cat, _BB_DIR_BIN, _BB_SUID_NEVER)) |
66 | USE_CATV(APPLET(catv, catv, _BB_DIR_BIN, _BB_SUID_NEVER)) | ||
66 | USE_CHATTR(APPLET(chattr, chattr, _BB_DIR_BIN, _BB_SUID_NEVER)) | 67 | USE_CHATTR(APPLET(chattr, chattr, _BB_DIR_BIN, _BB_SUID_NEVER)) |
67 | USE_CHGRP(APPLET(chgrp, chgrp, _BB_DIR_BIN, _BB_SUID_NEVER)) | 68 | USE_CHGRP(APPLET(chgrp, chgrp, _BB_DIR_BIN, _BB_SUID_NEVER)) |
68 | USE_CHMOD(APPLET(chmod, chmod, _BB_DIR_BIN, _BB_SUID_NEVER)) | 69 | USE_CHMOD(APPLET(chmod, chmod, _BB_DIR_BIN, _BB_SUID_NEVER)) |
diff --git a/include/usage.h b/include/usage.h index 3f894c5b7..1d143e61e 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -136,6 +136,13 @@ | |||
136 | "$ cat /proc/uptime\n" \ | 136 | "$ cat /proc/uptime\n" \ |
137 | "110716.72 17.67" | 137 | "110716.72 17.67" |
138 | 138 | ||
139 | #define catv_trivial_usage \ | ||
140 | "[-etv] [FILE]..." | ||
141 | #define catv_full_usage \ | ||
142 | "Display nonprinting characters as ^x or M-x.\n\n"\ | ||
143 | "\t-e\tEnd each line with $\n" \ | ||
144 | "\t-t\tShow tabs as ^I\n" \ | ||
145 | "\t-v\tDon't use ^x or M-x escapes." | ||
139 | #define chattr_trivial_usage \ | 146 | #define chattr_trivial_usage \ |
140 | "[-R] [-+=AacDdijsStTu] [-v version] files..." | 147 | "[-R] [-+=AacDdijsStTu] [-v version] files..." |
141 | #define chattr_full_usage \ | 148 | #define chattr_full_usage \ |