Your message dated Sat, 26 Jan 2008 15:56:50 -0500
with message-id <[EMAIL PROTECTED]>
and subject line ls: sort by width of filename option
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--- Begin Message ---
Package: fileutils
Version: 4.1-10
Severity: wishlist
Tags: patch

 The following patch adds a -W option (and --sort width) which sorts
by the width of the filename, then by name order.  This has the
advantage that it helps to minimise the number of lines displayed by
ls.

(e.g.:
: pts/7[2] bash[6563] ; ~/hackery/ls/fileutils-4.1/builddir/src/ls /bin/
ae     date           fuser     lspci    ping       stty        zcmp
afio   dd             grep      mbchk    ps         su          zdiff
arch   df             gunzip    mkdir    pwd        sync        zegrep
ash    dir            gzexe     mknod    rbash      tar         zfgrep
bash   dmesg          gzip      mktemp   readlink   tempfile    zforce
cat    dnsdomainname  hostname  more     rm         touch       zgrep
chgrp  echo           ip        mount    rmdir      true        zless
chmod  ed             kill      mt       run-parts  umount      zmore
chown  egrep          ln        mt-gnu   sed        uname       znew
cp     false          loadkeys  mv       setserial  uncompress  zsh
cpio   fdflush        login     netstat  sh         vdir        zsh-4.0.4
csh    fgrep          ls        pidof    sleep      zcat        zsh4

: pts/7[2] bash[6564] ; ~/hackery/ls/fileutils-4.1/builddir/src/ls -W /bin/
ae  mv   pwd   echo  vdir   egrep  mknod  zgrep   zforce     zsh-4.0.4
cp  ps   sed   grep  zcat   false  mount  zless   fdflush    uncompress
dd  rm   tar   gzip  zcmp   fgrep  pidof  zmore   netstat    dnsdomainname
df  sh   zsh   kill  znew   fuser  rbash  gunzip  hostname
ed  su   afio  more  zsh4   gzexe  rmdir  mktemp  loadkeys
ip  ash  arch  ping  chgrp  login  sleep  mt-gnu  readlink
ln  cat  bash  stty  chmod  lspci  touch  umount  tempfile
ls  csh  cpio  sync  chown  mbchk  uname  zegrep  run-parts
mt  dir  date  true  dmesg  mkdir  zdiff  zfgrep  setserial


--- fileutils-4.1.orig/src/ls.c Fri Oct 25 02:34:40 2002
+++ fileutils-4.1/src/ls.c      Fri Oct 25 02:33:22 2002
@@ -289,6 +289,10 @@
                                 const struct fileinfo *file2));
 static int rev_cmp_name PARAMS ((const struct fileinfo *file2,
                                 const struct fileinfo *file1));
+static int compare_width PARAMS ((const struct fileinfo *file1,
+                                 const struct fileinfo *file2));
+static int rev_cmp_width PARAMS ((const struct fileinfo *file2,
+                                 const struct fileinfo *file1));
 static int compare_extension PARAMS ((const struct fileinfo *file1,
                                      const struct fileinfo *file2));
 static int rev_cmp_extension PARAMS ((const struct fileinfo *file2,
@@ -422,7 +426,7 @@
 
 static int full_time;
 
-/* The file characteristic to sort by.  Controlled by -t, -S, -U, -X, -v. */
+/* The file characteristic to sort by. Controlled by -t, -S, -U, -X, -v, -W. */
 
 enum sort_type
   {
@@ -431,7 +435,8 @@
     sort_extension,            /* -X */
     sort_time,                 /* -t */
     sort_size,                 /* -S */
-    sort_version               /* -v */
+    sort_version,              /* -v */
+    sort_width                 /* -W */
   };
 
 static enum sort_type sort_type;
@@ -720,12 +725,12 @@
 
 static char const *const sort_args[] =
 {
-  "none", "time", "size", "extension", "version", 0
+  "none", "time", "size", "extension", "version", "width", 0
 };
 
 static enum sort_type const sort_types[] =
 {
-  sort_none, sort_time, sort_size, sort_extension, sort_version
+  sort_none, sort_time, sort_size, sort_extension, sort_version, sort_width
 };
 
 static char const *const time_args[] =
@@ -1076,7 +1081,7 @@
     }
 
   while ((c = getopt_long (argc, argv,
-                          "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UX1",
+                          "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UWX1",
                           long_options, NULL)) != -1)
     {
       switch (c)
@@ -1263,6 +1268,11 @@
          sort_type_specified = 1;
          break;
 
+       case 'W':
+         sort_type = sort_width;
+         sort_type_specified = 1;
+         break;
+
        case 'X':
          sort_type = sort_extension;
          sort_type_specified = 1;
@@ -2169,6 +2179,9 @@
     case sort_version:
       func = sort_reverse ? rev_cmp_version : compare_version;
       break;
+    case sort_width:
+      func = sort_reverse ? rev_cmp_width : compare_width;
+      break;
     default:
       abort ();
     }
@@ -2274,6 +2287,24 @@
   return strcoll (file1->name, file2->name);
 }
 
+/* Compare the width of the filename first, then by filenames */
+
+static int
+compare_width (const struct fileinfo *file1, const struct fileinfo *file2)
+{
+  int i;
+  i = strlen(file1->name) - strlen(file2->name);
+  return i ? i : strcoll (file1->name, file2->name);
+}
+
+static int
+rev_cmp_width (const struct fileinfo *file2, const struct fileinfo *file1)
+{
+  int i;
+  i = strlen(file1->name) - strlen(file2->name);
+  return i ? i : strcoll (file1->name, file2->name);
+}
+
 /* Compare file extensions.  Files with no extension are `smallest'.
    If extensions are the same, compare by filenames instead. */
 
@@ -3307,7 +3338,7 @@
       printf (_("\
   -S                         sort by file size\n\
       --sort=WORD            extension -X, none -U, size -S, time -t,\n\
-                               version -v\n\
+                              version -v, width -W\n\
                              status -c, time -t, atime -u, access -u, use -u\n\
       --time=WORD            show time as WORD instead of modification time:\n\
                                atime, access, use, ctime or status; use\n\
@@ -3320,6 +3351,9 @@
   -U                         do not sort; list entries in directory order\n\
   -v                         sort by version\n\
   -w, --width=COLS           assume screen width instead of current value\n\
+  -W                         sort by file name width, then by name\n\
+                               this will often cause multi-column outputs\n\
+                               to use less vertical lines\n\
   -x                         list entries by lines instead of by columns\n\
   -X                         sort alphabetically by entry extension\n\
   -1                         list one file per line\n\


-- System Information
Debian Release: 3.0
Architecture: i386
Kernel: Linux dorothee 2.4.17 #2 Tue Jan 22 01:06:37 GMT 2002 i686
Locale: LANG=C, LC_CTYPE=C

Versions of packages fileutils depends on:
ii  libc6                         2.2.5-11.2 GNU C Library: Shared libraries an



--- End Message ---
--- Begin Message --- Closing, to make bug listing more readable. Will still be availabled in the archived bugs section.

Mike Stone


--- End Message ---

Reply via email to