[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
df patch: add -w option
From: |
Kasper Dupont |
Subject: |
df patch: add -w option |
Date: |
Mon, 8 Aug 2005 15:36:43 +0200 |
User-agent: |
Mutt/1.4.1i |
This patch adds a -w option to df that will change the width
of the device column similar to the IRIX version of df. It
was tested on Fedora Core 1 and Fedora Core 3.
diff -Nur coreutils-5.2.1.df-width/src/df.c coreutils-5.2.1/src/df.c
--- coreutils-5.2.1.df-width/src/df.c 2004-01-27 16:55:38.000000000 +0100
+++ coreutils-5.2.1/src/df.c 2005-08-07 10:57:20.000000000 +0200
@@ -17,7 +17,8 @@
/* Written by David MacKenzie <address@hidden>.
--human-readable and --megabyte options added by address@hidden
- --si and large file support added by address@hidden */
+ --si and large file support added by address@hidden
+ --width option added by Kasper Dupont <address@hidden> */
#include <config.h>
#include <stdio.h>
@@ -111,6 +112,9 @@
/* If nonzero, print filesystem type as well. */
static int print_type;
+/* Width to use for device name */
+static int device_width = 20;
+
/* For long options that have no equivalent short option, use a
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
enum
@@ -134,6 +138,7 @@
{"sync", no_argument, NULL, SYNC_OPTION},
{"no-sync", no_argument, NULL, NO_SYNC_OPTION},
{"type", required_argument, NULL, 't'},
+ {"width", required_argument, NULL, 'w'},
{"exclude-type", required_argument, NULL, 'x'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
@@ -146,9 +151,9 @@
char buf[MAX (LONGEST_HUMAN_READABLE + 1, INT_BUFSIZE_BOUND (uintmax_t))];
if (print_type)
- fputs (_("Filesystem Type"), stdout);
+ printf("%*s%s",-(device_width-6),"Filesystem","Type");
else
- fputs (_("Filesystem "), stdout);
+ printf("%*s",-(device_width-2),"Filesystem");
if (inode_format)
printf (_(" Inodes IUsed IFree IUse%%"));
@@ -316,19 +321,19 @@
{
int disk_name_len = (int) strlen (disk);
int fstype_len = (int) strlen (fstype);
- if (disk_name_len + fstype_len + 2 < 20)
- printf ("%s%*s ", disk, 18 - disk_name_len, fstype);
+ if (disk_name_len + fstype_len + 2 < device_width)
+ printf ("%s%*s ", disk, (device_width - 2) - disk_name_len, fstype);
else if (!posix_format)
- printf ("%s\n%18s ", disk, fstype);
+ printf ("%s\n%*s ", disk, device_width - 2, fstype);
else
printf ("%s %s", disk, fstype);
}
else
{
- if ((int) strlen (disk) > 20 && !posix_format)
- printf ("%s\n%20s", disk, "");
+ if ((int) strlen (disk) > device_width && !posix_format)
+ printf ("%s\n%*s", disk, device_width, "");
else
- printf ("%-20s", disk);
+ printf ("%*s", -device_width , disk);
}
if (inode_format)
@@ -753,6 +758,9 @@
-x, --exclude-type=TYPE limit listing to filesystems not of type TYPE\n\
-v (ignored)\n\
"), stdout);
+ fputs (_("\
+ -w, --width=NUMBER Change display width of device field\n\
+"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
fputs (_("\n\
@@ -792,7 +800,7 @@
posix_format = 0;
exit_status = 0;
- while ((c = getopt_long (argc, argv, "aB:iF:hHklmPTt:vx:", long_options,
NULL))
+ while ((c = getopt_long (argc, argv, "aB:iF:hHklmPTt:vw:x:", long_options,
NULL))
!= -1)
{
switch (c)
@@ -849,6 +857,9 @@
case 'v': /* For SysV compatibility. */
/* ignore */
break;
+ case 'w':
+ device_width=atoi(optarg);
+ break;
case 'x':
add_excluded_fs_type (optarg);
break;
--
Kasper Dupont
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- df patch: add -w option,
Kasper Dupont <=