whitespace fixes. no code changes
[oweals/busybox.git] / coreutils / df.c
index 83794ad8824be9a52b60772ef9b136a72d6058d5..5e9a8670f340f27e6965c980334270f32fbc15e1 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  * based on original code by (I think) Bruce Perens <bruce@pixar.com>.
  *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
 /* BB_AUDIT SUSv3 _NOT_ compliant -- option -t missing. */
  * Implement -P and -B; better coreutils compat; cleanup
  */
 
+//usage:#define df_trivial_usage
+//usage:       "[-Pk"
+//usage:       IF_FEATURE_HUMAN_READABLE("mh")
+//usage:       IF_FEATURE_DF_FANCY("ai] [-B SIZE")
+//usage:       "] [FILESYSTEM]..."
+//usage:#define df_full_usage "\n\n"
+//usage:       "Print filesystem usage statistics\n"
+//usage:     "\n       -P      POSIX output format"
+//usage:     "\n       -k      1024-byte blocks (default)"
+//usage:       IF_FEATURE_HUMAN_READABLE(
+//usage:     "\n       -m      1M-byte blocks"
+//usage:     "\n       -h      Human readable (e.g. 1K 243M 2G)"
+//usage:       )
+//usage:       IF_FEATURE_DF_FANCY(
+//usage:     "\n       -a      Show all filesystems"
+//usage:     "\n       -i      Inodes"
+//usage:     "\n       -B SIZE Blocksize"
+//usage:       )
+//usage:
+//usage:#define df_example_usage
+//usage:       "$ df\n"
+//usage:       "Filesystem           1K-blocks      Used Available Use% Mounted on\n"
+//usage:       "/dev/sda3              8690864   8553540    137324  98% /\n"
+//usage:       "/dev/sda1                64216     36364     27852  57% /boot\n"
+//usage:       "$ df /dev/sda3\n"
+//usage:       "Filesystem           1K-blocks      Used Available Use% Mounted on\n"
+//usage:       "/dev/sda3              8690864   8553540    137324  98% /\n"
+//usage:       "$ POSIXLY_CORRECT=sure df /dev/sda3\n"
+//usage:       "Filesystem         512B-blocks      Used Available Use% Mounted on\n"
+//usage:       "/dev/sda3             17381728  17107080    274648  98% /\n"
+//usage:       "$ POSIXLY_CORRECT=yep df -P /dev/sda3\n"
+//usage:       "Filesystem          512-blocks      Used Available Capacity Mounted on\n"
+//usage:       "/dev/sda3             17381728  17107080    274648      98% /\n"
+
 #include <mntent.h>
 #include <sys/vfs.h>
 #include "libbb.h"
@@ -58,7 +92,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
        const char *disp_units_hdr = NULL;
        char *chp;
 
-       check_unicode_in_env();
+       init_unicode();
 
 #if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY
        opt_complementary = "k-mB:m-Bk:B-km";
@@ -76,9 +110,9 @@ int df_main(int argc UNUSED_PARAM, char **argv)
                df_disp_hr = xatoul_range(chp, 1, ULONG_MAX); /* disallow 0 */
 
        /* From the manpage of df from coreutils-6.10:
-          Disk space is shown in 1K blocks by default, unless the environment
-          variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
-       */
+        * Disk space is shown in 1K blocks by default, unless the environment
+        * variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
+        */
        if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */
                df_disp_hr = 512;
 
@@ -114,9 +148,6 @@ int df_main(int argc UNUSED_PARAM, char **argv)
        while (1) {
                const char *device;
                const char *mount_point;
-#if ENABLE_FEATURE_ASSUME_UNICODE
-               size_t dev_len;
-#endif
 
                if (mount_table) {
                        mount_entry = getmntent(mount_table);
@@ -163,7 +194,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
                        }
 
                        /* GNU coreutils 6.10 skips certain mounts, try to be compatible.  */
-                       if (strcmp(device, "rootfs") == 0)
+                       if (ENABLE_FEATURE_SKIP_ROOTFS && strcmp(device, "rootfs") == 0)
                                continue;
 
 #ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
@@ -177,16 +208,20 @@ int df_main(int argc UNUSED_PARAM, char **argv)
                        }
 #endif
 
-#if ENABLE_FEATURE_ASSUME_UNICODE
-                       dev_len = bb_mbstrlen(device);
-                       if (dev_len > 20) {
-                               printf("%s\n%20s", device, "");
-                       } else {
-                               printf("%s%*s", device, 20 - (int)dev_len, "");
+#if ENABLE_UNICODE_SUPPORT
+                       {
+                               uni_stat_t uni_stat;
+                               char *uni_dev = unicode_conv_to_printable(&uni_stat, device);
+                               if (uni_stat.unicode_width > 20 && !(opt & OPT_POSIX)) {
+                                       printf("%s\n%20s", uni_dev, "");
+                               } else {
+                                       printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, "");
+                               }
+                               free(uni_dev);
                        }
 #else
-                       if (printf("\n%-20s" + 1, device) > 20)
-                                   printf("\n%-20s", "");
+                       if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX))
+                               printf("\n%-20s", "");
 #endif
 
 #if ENABLE_FEATURE_HUMAN_READABLE