Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: numericglobsort



Here's something else I broke (in 23118).  There's already a test for
numericglobsort, but it turns out it works in the C locale.  I've
duplicated the test in the multibyte code, although the problem is not
strictly dependent on multibyte support.  For some reason in the UTF-8
locales zero sorts ahead of dot instead of vice versa; goodness knows
why but ls confirms this isn't just zsh.

Index: Src/sort.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/sort.c,v
retrieving revision 1.3
diff -u -r1.3 sort.c
--- Src/sort.c	22 Jan 2007 17:28:16 -0000	1.3
+++ Src/sort.c	15 Apr 2007 21:20:35 -0000
@@ -42,8 +42,8 @@
 {
     const SortElt ae = *(const SortElt *)a;
     const SortElt be = *(const SortElt *)b;
-    const char *as = ae->cmp;
-    const char *bs = be->cmp;
+    const char *as = ae->cmp, *bs = be->cmp;
+    const char *ao = as;
     int cmp;
 
     if (ae->len != -1 || be->len != -1) {
@@ -122,7 +122,7 @@
 	cmp = (int)STOUC(*as) - (int)STOUC(*bs);
 #endif
 	if (idigit(*as) || idigit(*bs)) {
-	    for (; as > *(char **)a && idigit(as[-1]); as--, bs--);
+	    for (; as > ao && idigit(as[-1]); as--, bs--);
 	    if (idigit(*as) && idigit(*bs)) {
 		while (*as == '0')
 		    as++;
Index: Test/D07multibyte.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D07multibyte.ztst,v
retrieving revision 1.15
diff -u -r1.15 D07multibyte.ztst
--- Test/D07multibyte.ztst	10 Feb 2007 22:12:59 -0000	1.15
+++ Test/D07multibyte.ztst	15 Apr 2007 21:20:35 -0000
@@ -358,3 +358,22 @@
 >1 148
 >1 149
 >1 150
+
+  touch ngs1.txt ngs2.txt ngs10.txt ngs20.txt ngs100.txt ngs200.txt
+  setopt numericglobsort
+  print -l ngs*
+  unsetopt numericglobsort
+  print -l ngs*
+0:NUMERIC_GLOB_SORT option in UTF-8 locale
+>ngs1.txt
+>ngs2.txt
+>ngs10.txt
+>ngs20.txt
+>ngs100.txt
+>ngs200.txt
+>ngs100.txt
+>ngs10.txt
+>ngs1.txt
+>ngs200.txt
+>ngs20.txt
+>ngs2.txt

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author