diff options
author | Kang-Che Sung <explorer09@gmail.com> | 2017-07-14 09:56:13 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-14 09:56:13 +0200 |
commit | a2bdc5c55485b054088513083ca0c78ce11445a9 (patch) | |
tree | bfc13964ba3f4a407d1de50a4ca2b657345cb2e4 /coreutils | |
parent | 38d966943f5288bb1f2e7219f50a92753c730b14 (diff) | |
download | busybox-w32-a2bdc5c55485b054088513083ca0c78ce11445a9.tar.gz busybox-w32-a2bdc5c55485b054088513083ca0c78ce11445a9.tar.bz2 busybox-w32-a2bdc5c55485b054088513083ca0c78ce11445a9.zip |
cat: allow compiling out -n and -b
When these options were introduced in d88f94a5df3a2edb8ba56fab5c13674b452f87ab
it provides no config options to compile them out. Now provide one.
Introduce config FEATURE_CATN.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/cat.c | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c index 4d9147f8a..178f96b09 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
@@ -13,6 +13,13 @@ | |||
13 | //config: cat is used to concatenate files and print them to the standard | 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. | 14 | //config: output. Enable this option if you wish to enable the 'cat' utility. |
15 | //config: | 15 | //config: |
16 | //config:config FEATURE_CATN | ||
17 | //config: bool "Enable -n and -b options" | ||
18 | //config: default y | ||
19 | //config: depends on CAT | ||
20 | //config: help | ||
21 | //config: -n numbers all output lines while -b numbers nonempty output lines. | ||
22 | //config: | ||
16 | //config:config FEATURE_CATV | 23 | //config:config FEATURE_CATV |
17 | //config: bool "cat -v[etA]" | 24 | //config: bool "cat -v[etA]" |
18 | //config: default y | 25 | //config: default y |
@@ -27,12 +34,19 @@ | |||
27 | /* BB_AUDIT SUSv3 compliant */ | 34 | /* BB_AUDIT SUSv3 compliant */ |
28 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */ | 35 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */ |
29 | 36 | ||
37 | //usage:#if ENABLE_FEATURE_CATN || ENABLE_FEATURE_CATV | ||
38 | //usage:#define cat_trivial_usage | ||
39 | //usage: "[-" IF_FEATURE_CATN("nb") IF_FEATURE_CATV("vteA") "] [FILE]..." | ||
40 | //usage:#else | ||
30 | //usage:#define cat_trivial_usage | 41 | //usage:#define cat_trivial_usage |
31 | //usage: "[-nb"IF_FEATURE_CATV("vteA")"] [FILE]..." | 42 | //usage: "[FILE]..." |
43 | //usage:#endif | ||
32 | //usage:#define cat_full_usage "\n\n" | 44 | //usage:#define cat_full_usage "\n\n" |
33 | //usage: "Print FILEs to stdout\n" | 45 | //usage: "Print FILEs to stdout\n" |
46 | //usage: IF_FEATURE_CATN( | ||
34 | //usage: "\n -n Number output lines" | 47 | //usage: "\n -n Number output lines" |
35 | //usage: "\n -b Number nonempty lines" | 48 | //usage: "\n -b Number nonempty lines" |
49 | //usage: ) | ||
36 | //usage: IF_FEATURE_CATV( | 50 | //usage: IF_FEATURE_CATV( |
37 | //usage: "\n -v Show nonprinting characters as ^x or M-x" | 51 | //usage: "\n -v Show nonprinting characters as ^x or M-x" |
38 | //usage: "\n -t ...and tabs as ^I" | 52 | //usage: "\n -t ...and tabs as ^I" |
@@ -84,7 +98,7 @@ | |||
84 | * I agree with the argument. Unfortunately, this ship has sailed (1983...). | 98 | * I agree with the argument. Unfortunately, this ship has sailed (1983...). |
85 | * There are dozens of Linux distros and each of them has "cat" which supports -v. | 99 | * There are dozens of Linux distros and each of them has "cat" which supports -v. |
86 | * It's unrealistic for us to "reeducate" them to use our, incompatible way | 100 | * It's unrealistic for us to "reeducate" them to use our, incompatible way |
87 | * to achieve "cat -v" effect. The actuall effect would be "users pissed off | 101 | * to achieve "cat -v" effect. The actual effect would be "users pissed off |
88 | * by gratuitous incompatibility". | 102 | * by gratuitous incompatibility". |
89 | */ | 103 | */ |
90 | #define CATV_OPT_e (1<<0) | 104 | #define CATV_OPT_e (1<<0) |
@@ -147,7 +161,7 @@ int cat_main(int argc UNUSED_PARAM, char **argv) | |||
147 | 161 | ||
148 | IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */) | 162 | IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */) |
149 | /* -u is ignored ("unbuffered") */ | 163 | /* -u is ignored ("unbuffered") */ |
150 | opts = getopt32(argv, IF_FEATURE_CATV("etvA")"nbu"); | 164 | opts = getopt32(argv, IF_FEATURE_CATV("etvA") IF_FEATURE_CATN("nb") "u"); |
151 | argv += optind; | 165 | argv += optind; |
152 | 166 | ||
153 | #if ENABLE_FEATURE_CATV | 167 | #if ENABLE_FEATURE_CATV |
@@ -157,23 +171,26 @@ int cat_main(int argc UNUSED_PARAM, char **argv) | |||
157 | opts >>= 4; | 171 | opts >>= 4; |
158 | #endif | 172 | #endif |
159 | 173 | ||
160 | #define CAT_OPT_n (1<<0) | 174 | #if ENABLE_FEATURE_CATN |
161 | #define CAT_OPT_b (1<<1) | 175 | # define CAT_OPT_n (1<<0) |
162 | #define CAT_OPT_u (1<<2) | 176 | # define CAT_OPT_b (1<<1) |
163 | if (!(opts & (CAT_OPT_n|CAT_OPT_b))) /* no -n or -b */ | 177 | if (opts & (CAT_OPT_n|CAT_OPT_b)) { /* -n or -b */ |
164 | return bb_cat(argv); | 178 | if (!*argv) |
179 | *--argv = (char*)"-"; | ||
180 | ns.width = 6; | ||
181 | ns.start = 1; | ||
182 | ns.inc = 1; | ||
183 | ns.sep = "\t"; | ||
184 | ns.empty_str = "\n"; | ||
185 | ns.all = !(opts & CAT_OPT_b); /* -n without -b */ | ||
186 | ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */ | ||
187 | do { | ||
188 | print_numbered_lines(&ns, *argv); | ||
189 | } while (*++argv); | ||
190 | fflush_stdout_and_exit(EXIT_SUCCESS); | ||
191 | } | ||
192 | /*opts >>= 2;*/ | ||
193 | #endif | ||
165 | 194 | ||
166 | if (!*argv) | 195 | return bb_cat(argv); |
167 | *--argv = (char*)"-"; | ||
168 | ns.width = 6; | ||
169 | ns.start = 1; | ||
170 | ns.inc = 1; | ||
171 | ns.sep = "\t"; | ||
172 | ns.empty_str = "\n"; | ||
173 | ns.all = !(opts & CAT_OPT_b); /* -n without -b */ | ||
174 | ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */ | ||
175 | do { | ||
176 | print_numbered_lines(&ns, *argv); | ||
177 | } while (*++argv); | ||
178 | fflush_stdout_and_exit(EXIT_SUCCESS); | ||
179 | } | 196 | } |