diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-06-20 09:01:58 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-06-20 09:01:58 +0000 |
commit | 8876fb2f59a0b515b3121d5894933eef88ce566a (patch) | |
tree | f67de9320202043aca8ded20fb80d668c3b0c2d8 /coreutils/du.c | |
parent | dfce3536ace2bcd38bdd3731841998ce344d786e (diff) | |
download | busybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.tar.gz busybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.tar.bz2 busybox-w32-8876fb2f59a0b515b3121d5894933eef88ce566a.zip |
last_patch89 from vodz:
Manuel,
I rewrite bb_getopt_ulflags() function for more universal usage.
My version support now:
- options with arguments (optional arg as GNU extension also)
- complementaly and/or incomplementaly and/or incongruously and/or list
options
- long_opt (all applets may have long option, add supporting is trivial)
This realisation full compatibile from your version.
Code size grow 480 bytes, but only coreutils/* over compensate this size
after using new function. Last patch reduced over 800 bytes and not full
applied to all. "mkdir" and "mv" applets have long_opt now for demonstrate
trivial addition support long_opt with usage new bb_getopt_ulflags().
Complementaly and/or incomplementaly and/or incongruously and/or list options
logic is not trivial, but new "cut" and "grep" applets using this logic
for examples with full demostrating. New "grep" applet reduced over 300
bytes.
Mark,
Also. I removed bug from "grep" applet.
$ echo a b | busybox grep -e a b
a b
a b
But right is printing one only.
--w
vodz
Diffstat (limited to 'coreutils/du.c')
-rw-r--r-- | coreutils/du.c | 93 |
1 files changed, 48 insertions, 45 deletions
diff --git a/coreutils/du.c b/coreutils/du.c index 1c16cfbd4..a9f6c28ba 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -166,8 +166,9 @@ int du_main(int argc, char **argv) | |||
166 | { | 166 | { |
167 | long total; | 167 | long total; |
168 | int slink_depth_save; | 168 | int slink_depth_save; |
169 | int print_final_total = 0; | 169 | int print_final_total; |
170 | int c; | 170 | char *smax_print_depth; |
171 | unsigned long opt; | ||
171 | 172 | ||
172 | #ifdef CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K | 173 | #ifdef CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K |
173 | if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */ | 174 | if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */ |
@@ -185,57 +186,57 @@ int du_main(int argc, char **argv) | |||
185 | * gnu du exits with an error code in this case. We choose to simply | 186 | * gnu du exits with an error code in this case. We choose to simply |
186 | * ignore -a. This is consistent with -s being equivalent to -d 0. | 187 | * ignore -a. This is consistent with -s being equivalent to -d 0. |
187 | */ | 188 | */ |
188 | |||
189 | while ((c = getopt(argc, argv, "aHkLsx" "d:" "lc" | ||
190 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | ||
191 | "hm" | ||
192 | #endif | ||
193 | )) > 0) { | ||
194 | switch (c) { | ||
195 | case 'a': | ||
196 | print_files = INT_MAX; | ||
197 | break; | ||
198 | case 'H': | ||
199 | slink_depth = 1; | ||
200 | break; | ||
201 | case 'k': | ||
202 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 189 | #ifdef CONFIG_FEATURE_HUMAN_READABLE |
190 | bb_opt_complementaly = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; | ||
191 | opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); | ||
192 | if((opt & (1 << 9))) { | ||
193 | /* -h opt */ | ||
194 | disp_hr = 0; | ||
195 | } | ||
196 | if((opt & (1 << 10))) { | ||
197 | /* -m opt */ | ||
198 | disp_hr = MEGABYTE; | ||
199 | } | ||
200 | if((opt & (1 << 2))) { | ||
201 | /* -k opt */ | ||
203 | disp_hr = KILOBYTE; | 202 | disp_hr = KILOBYTE; |
204 | #elif !defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K | 203 | } |
204 | #else | ||
205 | bb_opt_complementaly = "H-L:L-H:s-d:d-s"; | ||
206 | opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth); | ||
207 | #if !defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K | ||
208 | if((opt & (1 << 2))) { | ||
209 | /* -k opt */ | ||
205 | disp_k = 1; | 210 | disp_k = 1; |
211 | } | ||
212 | #endif | ||
206 | #endif | 213 | #endif |
207 | break; | 214 | if((opt & (1 << 0))) { |
208 | case 'L': | 215 | /* -a opt */ |
216 | print_files = INT_MAX; | ||
217 | } | ||
218 | if((opt & (1 << 1))) { | ||
219 | /* -H opt */ | ||
220 | slink_depth = 1; | ||
221 | } | ||
222 | if((opt & (1 << 3))) { | ||
223 | /* -L opt */ | ||
209 | slink_depth = INT_MAX; | 224 | slink_depth = INT_MAX; |
210 | break; | 225 | } |
211 | case 's': | 226 | if((opt & (1 << 4))) { |
227 | /* -s opt */ | ||
212 | max_print_depth = 0; | 228 | max_print_depth = 0; |
213 | break; | ||
214 | case 'x': | ||
215 | one_file_system = 1; | ||
216 | break; | ||
217 | |||
218 | case 'd': | ||
219 | max_print_depth = bb_xgetularg10_bnd(optarg, 0, INT_MAX); | ||
220 | break; | ||
221 | case 'l': | ||
222 | count_hardlinks = 1; | ||
223 | break; | ||
224 | case 'c': | ||
225 | print_final_total = 1; | ||
226 | break; | ||
227 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | ||
228 | case 'h': | ||
229 | disp_hr = 0; | ||
230 | break; | ||
231 | case 'm': | ||
232 | disp_hr = MEGABYTE; | ||
233 | break; | ||
234 | #endif | ||
235 | default: | ||
236 | bb_show_usage(); | ||
237 | } | 229 | } |
230 | one_file_system = opt & (1 << 5); /* -x opt */ | ||
231 | if((opt & (1 << 6))) { | ||
232 | /* -d opt */ | ||
233 | max_print_depth = bb_xgetularg10_bnd(smax_print_depth, 0, INT_MAX); | ||
238 | } | 234 | } |
235 | if((opt & (1 << 7))) { | ||
236 | /* -l opt */ | ||
237 | count_hardlinks = 1; | ||
238 | } | ||
239 | print_final_total = opt & (1 << 8); /* -c opt */ | ||
239 | 240 | ||
240 | /* go through remaining args (if any) */ | 241 | /* go through remaining args (if any) */ |
241 | argv += optind; | 242 | argv += optind; |
@@ -252,7 +253,9 @@ int du_main(int argc, char **argv) | |||
252 | total += du(*argv); | 253 | total += du(*argv); |
253 | slink_depth = slink_depth_save; | 254 | slink_depth = slink_depth_save; |
254 | } while (*++argv); | 255 | } while (*++argv); |
256 | #ifdef CONFIG_FEATURE_CLEAN_UP | ||
255 | reset_ino_dev_hashtable(); | 257 | reset_ino_dev_hashtable(); |
258 | #endif | ||
256 | 259 | ||
257 | if (print_final_total) { | 260 | if (print_final_total) { |
258 | print(total, "total"); | 261 | print(total, "total"); |