bug-fileutils
[Top][All Lists]
Advanced

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

About version sorting of `ls'.


From: ISONO Tomoatsu
Subject: About version sorting of `ls'.
Date: Mon, 05 Mar 2001 09:26:03 +0900

Dear Maintainers,

  In fileutils-4.0.41, there is a conflict between the description of
version sorting and a result of it.  The conflict concerns fractional
cases.

# SunOS smaux 5.7 Generic_106541-05 sun4u sparc

    A result of `ls -1v'.  The description in fileutils.texi.
     abc-1.007.tgz          abc-1.007.tgz
     abc-1.012b.tgz         abc-1.01a.tgz
     abc-1.01a.tgz          abc-1.012b.tgz

  A resolution is given below, which makes `ls' output in the
described way.  I hope you will adopt this kind of change.

                                       Yours sincerely,
                                         ISONO Tomoatsu
-------------------------------------------------------------------
 ISONO Tomoatsu <address@hidden>
-------------------------------------------------------------------


diff -rc fileutils-4.0.41/lib/strverscmp.c 
fileutils-4.0.41+modified-20010305/lib/strverscmp.c
*** fileutils-4.0.41/lib/strverscmp.c   Thu Nov 16 18:08:53 2000
--- fileutils-4.0.41+modified-20010305/lib/strverscmp.c Mon Mar  5 08:15:11 2001
***************
*** 36,41 ****
--- 36,43 ----
  #define CMP    2
  #define LEN    3
  
+ /* Use DUM to fill spaces. */
+ #define DUM    0
  
  /* ISDIGIT differs from isdigit, as follows:
     - Its arg may be any int or unsigned int; it need not be an unsigned char.
***************
*** 59,64 ****
--- 61,119 ----
     equal to or greater than S2 (for more info, see the texinfo doc).
  */
  
+ /* MODIFIED VERSION:
+    The following is the ordering of the original version.
+ 
+    a.x
+    a00.x
+    a01.x
+    a012.x
+    a01a.x
+    a0a.x
+    aa.x
+    abc-1.007.tgz
+    abc-1.012b.tgz
+    abc-1.01a.tgz
+ 
+    But I think this is not so good, and suggest a new clear definition of
+    order.  And, please note that the last three filenames are examples in
+    `doc/fileutils.texi' and that the order of them is different from the
+    description there.
+ 
+    1. Treat each maximal successive sequence of digits /[0-9]+/ as a
+       `character' (we refer it as DIGSEQ).
+ 
+    2. The numerical value of a DIGSEQ is considered as a fractional one if
+       it begins with `0'. But in fractional cases, there exists ambiguity
+       due to last successive `0's in DIGSEQ. So, when the numerical values
+       of them are equal, we regard the longer one as the larger one.
+ 
+       (This is equivalent to consider as following: we define numerical
+       values of `0' (resp. `1',... ,`9') as 1 (resp. 2,... , 10). Consider
+       a DIGSEQ is an undecimal, or eleven-adic expression (both in integer
+       case and in fractional case).
+ 
+    3. The order between a DIGSEQ and a non-digit character CHAR is defined
+       to be the same order between '0' and CHAR.
+    
+    4. The order between two DIGSEQs is defined to be the same order as
+       numerical values of two DIGSEQs.
+ 
+    5. Compare strings according to the order of `character's.
+ 
+    Original        Modified
+     a.x             a.x
+     a00.x           a0a.x
+     a01.x           a00.x
+     a012.x          a01.x
+     a01a.x          a01a.x
+     a0a.x           a012.x
+     aa.x            aa.x
+     abc-1.007.tgz   abc-1.007.tgz
+     abc-1.012b.tgz  abc-1.01a.tgz
+     abc-1.01a.tgz   abc-1.012b.tgz
+ */
+ 
  int
  __strverscmp (const char *s1, const char *s2)
  {
***************
*** 73,89 ****
--- 128,164 ----
    static const unsigned int next_state[] =
    {
        /* state    x    d    0    - */
+     /* the first zero digit means fractional state,
+        the first non-zero digit means integral state. */
+       /* S_N */  S_N, S_I, S_F, DUM, 
+     /* the successive digit means integral in integral state. */
+       /* S_I */  S_N, S_I, S_I, DUM,
+     /* the successive digit means fractional in fractional state. */
+       /* S_F */  S_N, S_F, S_F/*,DUM,*/
+     /* No need to use S_Z state */
+ #if 0
        /* S_N */  S_N, S_I, S_Z, S_N,
        /* S_I */  S_N, S_I, S_I, S_I,
        /* S_F */  S_N, S_F, S_F, S_F,
        /* S_Z */  S_N, S_F, S_Z, S_Z
+ #endif
    };
  
    static const int result_type[] =
    {
+     /* Note we never refer to 0/0 */
        /* state   x/x  x/d  x/0  x/-  d/x  d/d  d/0  d/-
                   0/x  0/d  0/0  0/-  -/x  -/d  -/0  -/- */
  
+       /* S_N */  CMP, CMP, CMP, DUM, CMP, LEN, CMP, DUM, /* int > frac */
+                  CMP, CMP, DUM, DUM, DUM, DUM, DUM, DUM, 
+       /* S_I */  CMP, -1,  -1,  DUM,  1,  LEN, LEN, DUM, 
+                   1,  LEN, DUM, DUM, DUM, DUM, DUM, DUM, 
+       /* S_F */  CMP, -1,  -1,  DUM,  1,  CMP, CMP, DUM, /* no need LEN cmp */
+                   1,  CMP/*,DUM,DUM, DUM, DUM, DUM, DUM, */
+       /* S_Z *//*CMP, -1,  -1,  DUM,  1,  CMP, CMP, DUM, 
+                   1,  CMP, CMP, DUM */
+ #if 0
        /* S_N */  CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
                   CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
        /* S_I */  CMP, -1,  -1,  CMP,  1,  LEN, LEN, CMP,
***************
*** 92,97 ****
--- 167,173 ----
                   CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
        /* S_Z */  CMP,  1,   1,  CMP, -1,  CMP, CMP, CMP,
                   -1,  CMP, CMP, CMP
+ #endif
    };
  
    if (p1 == p2)



reply via email to

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