bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PATCH: df alignment with -mP


From: Gustavo G. Rondina
Subject: PATCH: df alignment with -mP
Date: Sun, 20 Aug 2006 02:08:05 -0300

The usage of some options (e.g., -mP) causes a bad column alignment.  I
have written this patch to solve this.  I hope it is OK.

Cheers,
Gustavo



diff -u -r coreutils.orig/NEWS coreutils/NEWS
--- coreutils.orig/NEWS 2006-08-20 01:53:08.000000000 -0300
+++ coreutils/NEWS      2006-08-20 01:56:17.000000000 -0300
@@ -8,6 +8,8 @@
 
 ** Bug fixes
 
+  df now aligns correctly with e.g., -mP 
+
   cp --sparse preserves sparseness at the end of a file, even when
   the file's apparent size is not a multiple of its block size.
   [introduced with the original design, in fileutils-4.0r, 2000-04-29]
diff -u -r coreutils.orig/TODO coreutils/TODO
--- coreutils.orig/TODO 2006-08-20 01:53:08.000000000 -0300
+++ coreutils/TODO      2006-08-20 01:55:00.000000000 -0300
@@ -50,9 +50,6 @@
 
 add mktemp?  Suggested by Nelson Beebe
 
-df: alignment problem of `Used' heading with e.g., -mP
-  reported by Karl Berry
-
 tr: support nontrivial equivalence classes, e.g. [=e=] with
LC_COLLATE=fr_FR 
 lib/strftime.c: Since %N is the only format that we need but that
diff -u -r coreutils.orig/src/df.c coreutils/src/df.c
--- coreutils.orig/src/df.c     2006-08-20 01:53:08.000000000 -0300
+++ coreutils/src/df.c  2006-08-20 01:53:55.000000000 -0300
@@ -276,6 +276,7 @@
   char buf[3][LONGEST_HUMAN_READABLE + 2];
   int width;
   int use_width;
+  int blocks_width;            /* Width of -blocks' column.  */
   uintmax_t input_units;
   uintmax_t output_units;
   uintmax_t total;
@@ -346,7 +347,7 @@
 
   if (inode_format)
     {
-      width = 7;
+      blocks_width = width = 7;
       use_width = 5;
       input_units = output_units = 1;
       total = fsu.fsu_files;
@@ -362,6 +363,31 @@
       use_width = ((posix_format
                    && ! (human_output_opts & human_autoscale))
                   ? 8 : 4);
+      
+      if (human_output_opts & human_autoscale)
+       blocks_width = 5 + ! (human_output_opts & human_base_1024);
+      else
+       {
+         blocks_width = width;
+         if (posix_format)
+           /* This will not align correctly if block size is 1 digit
+              only, otherwise alignment is fine.  Maybe it would be
+              better to get rid of all these magic numbers.  */
+           {
+             char *bp;
+             char header_buf[ MAX (LONGEST_HUMAN_READABLE + 1,
+                                   INT_BUFSIZE_BOUND (uintmax_t)) + 8];
+             bp = umaxtostr (output_block_size, header_buf);
+             if (bp)
+               {
+                 blocks_width = strlen (strcat (bp, "-blocks"));
+                 blocks_width = ((blocks_width >= 11)
+                                 ? blocks_width - 2
+                                 : 9);
+               }
+           }
+       }
+
       input_units = fsu.fsu_blocksize;
       output_units = output_block_size;
       total = fsu.fsu_blocks;
@@ -380,7 +406,7 @@
     }
 
   printf (" %*s %*s %*s ",
-         width, df_readable (false, total,
+         blocks_width, df_readable (false, total,
                              buf[0], input_units, output_units),
          width, df_readable (negate_used, used,
                              buf[1], input_units, output_units),




reply via email to

[Prev in Thread] Current Thread [Next in Thread]