summaryrefslogtreecommitdiff
path: root/coreutils/du.c
diff options
context:
space:
mode:
authorEric Andersen2003-06-20 09:01:58 +0000
committerEric Andersen2003-06-20 09:01:58 +0000
commit8876fb2f59a0b515b3121d5894933eef88ce566a (patch)
treef67de9320202043aca8ded20fb80d668c3b0c2d8 /coreutils/du.c
parentdfce3536ace2bcd38bdd3731841998ce344d786e (diff)
downloadbusybox-8876fb2f59a0b515b3121d5894933eef88ce566a.zip
busybox-8876fb2f59a0b515b3121d5894933eef88ce566a.tar.gz
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.c93
1 files changed, 48 insertions, 45 deletions
diff --git a/coreutils/du.c b/coreutils/du.c
index 1c16cfb..a9f6c28 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -166,8 +166,9 @@ int du_main(int argc, char **argv)
{
long total;
int slink_depth_save;
- int print_final_total = 0;
- int c;
+ int print_final_total;
+ char *smax_print_depth;
+ unsigned long opt;
#ifdef CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K
if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
@@ -185,57 +186,57 @@ int du_main(int argc, char **argv)
* gnu du exits with an error code in this case. We choose to simply
* ignore -a. This is consistent with -s being equivalent to -d 0.
*/
-
- while ((c = getopt(argc, argv, "aHkLsx" "d:" "lc"
-#ifdef CONFIG_FEATURE_HUMAN_READABLE
- "hm"
-#endif
- )) > 0) {
- switch (c) {
- case 'a':
- print_files = INT_MAX;
- break;
- case 'H':
- slink_depth = 1;
- break;
- case 'k':
#ifdef CONFIG_FEATURE_HUMAN_READABLE
+ bb_opt_complementaly = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
+ opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
+ if((opt & (1 << 9))) {
+ /* -h opt */
+ disp_hr = 0;
+ }
+ if((opt & (1 << 10))) {
+ /* -m opt */
+ disp_hr = MEGABYTE;
+ }
+ if((opt & (1 << 2))) {
+ /* -k opt */
disp_hr = KILOBYTE;
-#elif !defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K
+ }
+#else
+ bb_opt_complementaly = "H-L:L-H:s-d:d-s";
+ opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth);
+#if !defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K
+ if((opt & (1 << 2))) {
+ /* -k opt */
disp_k = 1;
+ }
+#endif
#endif
- break;
- case 'L':
+ if((opt & (1 << 0))) {
+ /* -a opt */
+ print_files = INT_MAX;
+ }
+ if((opt & (1 << 1))) {
+ /* -H opt */
+ slink_depth = 1;
+ }
+ if((opt & (1 << 3))) {
+ /* -L opt */
slink_depth = INT_MAX;
- break;
- case 's':
+ }
+ if((opt & (1 << 4))) {
+ /* -s opt */
max_print_depth = 0;
- break;
- case 'x':
- one_file_system = 1;
- break;
-
- case 'd':
- max_print_depth = bb_xgetularg10_bnd(optarg, 0, INT_MAX);
- break;
- case 'l':
- count_hardlinks = 1;
- break;
- case 'c':
- print_final_total = 1;
- break;
-#ifdef CONFIG_FEATURE_HUMAN_READABLE
- case 'h':
- disp_hr = 0;
- break;
- case 'm':
- disp_hr = MEGABYTE;
- break;
-#endif
- default:
- bb_show_usage();
}
+ one_file_system = opt & (1 << 5); /* -x opt */
+ if((opt & (1 << 6))) {
+ /* -d opt */
+ max_print_depth = bb_xgetularg10_bnd(smax_print_depth, 0, INT_MAX);
}
+ if((opt & (1 << 7))) {
+ /* -l opt */
+ count_hardlinks = 1;
+ }
+ print_final_total = opt & (1 << 8); /* -c opt */
/* go through remaining args (if any) */
argv += optind;
@@ -252,7 +253,9 @@ int du_main(int argc, char **argv)
total += du(*argv);
slink_depth = slink_depth_save;
} while (*++argv);
+#ifdef CONFIG_FEATURE_CLEAN_UP
reset_ino_dev_hashtable();
+#endif
if (print_final_total) {
print(total, "total");