diff options
author | Rob Landley <rob@landley.net> | 2006-05-31 19:36:04 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-05-31 19:36:04 +0000 |
commit | 8abbee474c4eff45bdc2cacb59047f466e1d6ae1 (patch) | |
tree | 35f25489cf48f7a80e3545472a84d534ef9915a3 /coreutils | |
parent | 9a5686b605a4dfe2f24660940e309bb444fe5f3f (diff) | |
download | busybox-w32-8abbee474c4eff45bdc2cacb59047f466e1d6ae1.tar.gz busybox-w32-8abbee474c4eff45bdc2cacb59047f466e1d6ae1.tar.bz2 busybox-w32-8abbee474c4eff45bdc2cacb59047f466e1d6ae1.zip |
Add catv (separate applet instead of cat -v). Also cleanup cat.c comments,
the following of which (from cat.c) belongs in svn history instead of the
source code:
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* This is a new implementation of 'cat' which aims to be SUSv3 compliant.
*
* Changes from the previous implementation include:
* 1) Multiple '-' args are accepted as required by SUSv3. The previous
* implementation would close stdin and segfault on a subsequent '-'.
* 2) The '-u' options is required by SUSv3. Note that the specified
* behavior for '-u' is done by default, so all we need do is accept
* the option.
*/
Diffstat (limited to 'coreutils')
-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 |
4 files changed, 74 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 | } | ||