bug-fileutils
[Top][All Lists]
Advanced

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

Re: New option submission for ls -- thousands separator in file size


From: John Saalwaechter
Subject: Re: New option submission for ls -- thousands separator in file size
Date: Mon, 05 Nov 2001 00:20:58 -0500

Well, the best way I see to keep hotmail from corrupting the patch is to attach it as a gzipped patch file (ls.c.patch.gz).

--
John W. Saalwaechter <address@hidden>

From: "John Saalwaechter" <address@hidden>
To: address@hidden
Subject: New option submission for ls -- thousands separator in file size
Date: Fri, 02 Nov 2001 02:35:48 -0500

I have modified ls to include a --thousands-separator option that
puts thousands' separators in the file size field.  It does this with
printf's apostrophe format specifier (%'), which automatically makes it
locale aware.  My patch also widens the default file size field from 8
to 10 chars so that sizes up to 9999999999 (9,999,999,999) print aligned.
Please consider adding this change into ls.

I know ls has the -h option, but I find that I prefer file sizes shown
as thousands-separated numbers in ls output instead of numbers with
scale-factor suffixes.  For example,

$ ./ls -lh /boot/vmlinu*
-rwxr-xr-x    1 root     root           2.2M Apr  8  2001
/boot/vmlinux-2.4.2-2
lrwxrwxrwx    1 root     root             15 May 26 11:06 /boot/vmlinuz ->
vmlinuz-2.4.2-2
-rw-r--r--    1 root     root           763k Apr  8  2001
/boot/vmlinuz-2.4.2-2
$ ./ls -l --thousands-separator /boot/vmlinu*
-rwxr-xr-x    1 root     root         2,280,836 Apr  8  2001
/boot/vmlinux-2.4.2-2
lrwxrwxrwx    1 root     root                15 May 26 11:06 /boot/vmlinuz
-> vmlinuz-2.4.2-2
-rw-r--r--    1 root     root           781,806 Apr  8  2001
/boot/vmlinuz-2.4.2-2

Below is sample output and the patch.  (Note that --thousands-separator
can be shortened on the command line to just --th)

$ echo $LANG
en_US

$ /bin/ls -l /tmp/foo    (using ls version 4.0.36)
total 178716
-rw-r--r--    1 user1    user1    104857600 Nov  2 00:03 file.100m
-rw-r--r--    1 user1    user1    10485760 Nov  2 00:02 file.10m
-rw-r--r--    1 user1    user1    1073741824 Nov  2 00:05 file.1g
-rw-r--r--    1 user1    user1        1024 Nov  2 00:02 file.1k
-rw-r--r--    1 user1    user1     1048576 Nov  2 00:02 file.1m

$ ./ls -l /tmp/foo       (my patch widens standard file size field to 10)
total 178716
-rw-r--r--    1 user1    user1     104857600 Nov  2 00:03 file.100m
-rw-r--r--    1 user1    user1      10485760 Nov  2 00:02 file.10m
-rw-r--r--    1 user1    user1    1073741824 Nov  2 00:05 file.1g
-rw-r--r--    1 user1    user1          1024 Nov  2 00:02 file.1k
-rw-r--r--    1 user1    user1       1048576 Nov  2 00:02 file.1m

$ ./ls -l --thousands-separator /tmp/foo    (with new option)
total 178716
-rw-r--r--    1 user1    user1      104,857,600 Nov  2 00:03 file.100m
-rw-r--r--    1 user1    user1       10,485,760 Nov  2 00:02 file.10m
-rw-r--r--    1 user1    user1    1,073,741,824 Nov  2 00:05 file.1g
-rw-r--r--    1 user1    user1            1,024 Nov  2 00:02 file.1k
-rw-r--r--    1 user1    user1        1,048,576 Nov  2 00:02 file.1m

$ ./ls -l --th /tmp/foo    (only really need to type '--th')
total 178716
-rw-r--r--    1 user1    user1      104,857,600 Nov  2 00:03 file.100m
-rw-r--r--    1 user1    user1       10,485,760 Nov  2 00:02 file.10m
-rw-r--r--    1 user1    user1    1,073,741,824 Nov  2 00:05 file.1g
-rw-r--r--    1 user1    user1            1,024 Nov  2 00:02 file.1k
-rw-r--r--    1 user1    user1        1,048,576 Nov  2 00:02 file.1m

$ env LANG=deutsch ./ls -l --th /tmp/foo    (locale aware)
total 178716
-rw-r--r--    1 user1    user1      104.857.600 Nov  2 00:03 file.100m
-rw-r--r--    1 user1    user1       10.485.760 Nov  2 00:02 file.10m
-rw-r--r--    1 user1    user1    1.073.741.824 Nov  2 00:05 file.1g
-rw-r--r--    1 user1    user1            1.024 Nov  2 00:02 file.1k
-rw-r--r--    1 user1    user1        1.048.576 Nov  2 00:02 file.1m

===========START PATCH======================================
--- ls.c        Fri Nov  2 02:00:42 2001
+++ ls.c.orig   Thu Nov  1 22:58:01 2001
@@ -608,10 +608,6 @@
   quoting methods pass through control chars as-is.  */
static int qmark_funny_chars;

-/* Nonzero means print file size numbers with the locale's thousands
-   separator.  For example, "12,345,678". */
-static int print_with_thousands_sep;
-
/* Quoting options for file and dir name output.  */

static struct quoting_options *filename_quoting_options;
@@ -667,7 +663,6 @@
  SHOW_CONTROL_CHARS_OPTION,
  SI_OPTION,
  SORT_OPTION,
-  THOUSANDS_SEPARATOR_OPTION,
  TIME_OPTION
};

@@ -706,7 +701,6 @@
  {"time", required_argument, 0, TIME_OPTION},
  {"color", optional_argument, 0, COLOR_OPTION},
  {"block-size", required_argument, 0, BLOCK_SIZE_OPTION},
-  {"thousands-separator", no_argument, 0, THOUSANDS_SEPARATOR_OPTION},
  {GETOPT_HELP_OPTION_DECL},
  {GETOPT_VERSION_OPTION_DECL},
  {NULL, 0, NULL, 0}
@@ -980,7 +974,6 @@
  int sort_type_specified = 0;

  qmark_funny_chars = 0;
-  print_with_thousands_sep = 0;

  /* initialize all switches to default settings */

@@ -1127,7 +1120,6 @@

        case 'h':
          output_block_size = -1024;
-         print_with_thousands_sep = 0;
          break;

        case 'H':
@@ -1138,7 +1130,6 @@
          /* Fall through.  */
        case SI_OPTION:
          output_block_size = -1000;
-         print_with_thousands_sep = 0;
          break;

        case 'i':
@@ -1343,10 +1334,6 @@
          human_block_size (optarg, 1, &output_block_size);
          break;

-       case THOUSANDS_SEPARATOR_OPTION:
-         print_with_thousands_sep = 1;
-         break;
-
        case_GETOPT_HELP_CHAR;

        case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -2542,10 +2529,7 @@
  else
    {
      char hbuf[LONGEST_HUMAN_READABLE + 1];
-      if (print_with_thousands_sep)
-        sprintf (p, "%'13lu ", f->stat.st_size);
-         else
-        sprintf (p, "%10s ",
+      sprintf (p, "%8s ",
               human_readable ((uintmax_t) f->stat.st_size, hbuf, 1,
                               output_block_size < 0 ? output_block_size : 1));
    }
@@ -3330,7 +3314,6 @@
specified time as sort key if --sort=time\n\
  -t                         sort by modification time\n\
  -T, --tabsize=COLS         assume tab stops at each COLS instead of 8\n\
-      --thousands-separator  print file sizes with locale's thousands
separator\n\
  -u                         with -lt: sort by, and show, access time\n\
                               with -l: show access time and sort by
name\n\
                               otherwise: sort by access time\n\
===========END PATCH========================================

--
John W. Saalwaechter <address@hidden>



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


_______________________________________________
Bug-fileutils mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/bug-fileutils


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

Attachment: ls.c.patch.gz
Description: application/gzip-compressed


reply via email to

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