- int i;
- char opt;
-
- /* default behaviour */
- print = print_normal;
-
- /* parse argv[] */
- for (i = 1; i < argc; i++) {
- if (argv[i][0] == '-') {
- opt = argv[i][1];
- switch (opt) {
- case 's':
- print = print_summary;
- break;
- case 'l':
- count_hardlinks = 1;
- break;
- case 'h':
- case '-':
- usage(du_usage);
- break;
- default:
- fprintf(stderr, "du: invalid option -- %c\n", opt);
- usage(du_usage);
- }
- } else {
- break;
+ long total;
+ int slink_depth_save;
+ int print_final_total;
+ char *smax_print_depth;
+ unsigned opt;
+
+#ifdef CONFIG_FEATURE_DU_DEFUALT_BLOCKSIZE_1K
+ if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
+#ifdef CONFIG_FEATURE_HUMAN_READABLE
+ disp_hr = 512;
+#else
+ disp_k = 0;
+#endif
+ }
+#endif
+
+ /* Note: SUSv3 specifies that -a and -s options cannot be used together
+ * in strictly conforming applications. However, it also says that some
+ * du implementations may produce output when -a and -s are used together.
+ * 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.
+ */
+#ifdef CONFIG_FEATURE_HUMAN_READABLE
+ opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
+ opt = getopt32(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 = 1024*1024;
+ }
+ if((opt & (1 << 2))) {
+ /* -k opt */
+ disp_hr = 1024;
+ }
+#else
+ opt_complementary = "H-L:L-H:s-d:d-s";
+ opt = getopt32(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth);
+#if !defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
+ if((opt & (1 << 2))) {
+ /* -k opt */
+ disp_k = 1;
+ }
+#endif
+#endif
+ 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;
+ }
+ if((opt & (1 << 4))) {
+ /* -s opt */
+ max_print_depth = 0;