about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-07-06 13:10:43 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-07-06 13:10:43 +0000
commitccc2e1bd890ea23c99dda07efdbfe7f3f9a36343 (patch)
treeecc48bc21d27f93e4f51c2addc597dd554f8c321
parente8458f44c4f9377ece69ac60a54e81f8b81ac4e8 (diff)
downloadzsh-ccc2e1bd890ea23c99dda07efdbfe7f3f9a36343.tar.gz
zsh-ccc2e1bd890ea23c99dda07efdbfe7f3f9a36343.tar.xz
zsh-ccc2e1bd890ea23c99dda07efdbfe7f3f9a36343.zip
23660: fix numerical sorting of parameters + tests + documentation
-rw-r--r--ChangeLog4
-rw-r--r--Doc/Zsh/expn.yo11
-rw-r--r--Src/sort.c4
-rw-r--r--Test/D04parameter.ztst7
4 files changed, 18 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 4a212ce7b..92a683deb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2007-07-06  Peter Stephenson  <pws@csr.com>
 
+	* 23660: Doc/Zsh/expn.yo, Src/sort.c, Test/D04parameter.ztst:
+	numerical sorting didn't work in reverse, wasn't tested and wasn't
+	correctly documented.
+
 	* unposted: Functions/Calendar/calendar_lockfiles: configuration
 	appears to reduce collisions between lock attempts in multiple
 	windows.
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index b194febb0..c3c6d5baf 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -764,13 +764,12 @@ item(tt(L))(
 Convert all letters in the result to lower case.
 )
 item(tt(n))(
-Sort decimal numbers numerically; if the first differing
+Sort decimal integers numerically; if the first differing
 characters of two test strings are not digits, sorting
-is lexical.   Numbers with initial zeroes
-are sorted before those without.  Hence the array `tt(foo1 foo02
-foo2 foo3 foo20 foo23)' is sorted into the order shown.  Trailing
-non-digits are not sorted; the order of `tt(2foo)' and `tt(2bar)'
-is not defined.  May be combined with `tt(i)' or `tt(O)'.
+is lexical.   Integers with more initial zeroes
+are sorted before those with fewer or none.  Hence the array `tt(foo1 foo02
+foo2 foo3 foo20 foo23)' is sorted into the order shown.
+May be combined with `tt(i)' or `tt(O)'.
 )
 item(tt(o))(
 Sort the resulting words in ascending order; if this appears on its
diff --git a/Src/sort.c b/Src/sort.c
index 7f539a248..3d00bb576 100644
--- a/Src/sort.c
+++ b/Src/sort.c
@@ -134,9 +134,9 @@ eltpcmp(const void *a, const void *b)
 		    while (idigit(*as) && idigit(*bs))
 			as++, bs++;
 		    if (idigit(*as) && !idigit(*bs))
-			return 1;
+			return sortdir;
 		    if (idigit(*bs) && !idigit(*as))
-			return -1;
+			return -sortdir;
 		}
 	    }
 	}
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 25f4027fe..6df466ed0 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -913,3 +913,10 @@
 >AXB C1D
 >AB C0D
 >AB C0D
+
+  foo=(a6 a117 a17 b6 b117 b17)
+  print ${(n)foo}
+  print ${(On)foo}
+0:Numeric sorting
+>a6 a17 a117 b6 b17 b117
+>b117 b17 b6 a117 a17 a6