>From 3069d50b766a2db8b86406904b7327e5de5e315f Mon Sep 17 00:00:00 2001 From: =?utf-8?q?P=C3=A1draig=20Brady?= Date: Thu, 17 Dec 2009 10:48:54 +0000 Subject: [PATCH] doc: enhance and reference info about version comparison * doc/coreutils.texi (sort invocation): Reference the additional info about filevercmp rather than the unused strverscmp. (Details about version sort): Add some examples that are not handled well by fileversmp. * src/ls.c: Change a comment referencing the now unused strverscmp. --- doc/coreutils.texi | 33 ++++++++++++++++++++++++--------- src/ls.c | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 3721bee..ab1c20a 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -3862,10 +3862,9 @@ To compare such strings numerically, use the @opindex -V @opindex --version-sort @cindex version number sort address@hidden LC_NUMERIC -Sort per @code{strverscmp(3)}. This is a normal string comparison, except -that embedded decimal numbers are sorted by numeric value -(see @option{--numeric-sort} above). +Sort by version name and number. It behaves like a standard sort, +except that each sequence of decimal digits is treated numerically +as an index/version number. (@xref{Details about version sort}.) @item -r @itemx --reverse @@ -6720,11 +6719,27 @@ abc-1.012b.tgz abc-1.007.tgz abc-1.01a.tgz abc-1.012b.tgz @end example -This functionality is implemented using gnulib's @code{filevercmp} function. -One result of that implementation decision is that @samp{ls -v} -and @samp{sort -V} do not use the locale category, @env{LC_COLLATE}, -which means non-numeric prefixes are sorted as if @env{LC_COLLATE} were set -to @samp{C}. +This functionality is implemented using gnulib's @code{filevercmp} function, +which has some caveats worth noting. + address@hidden @bullet address@hidden @env{LC_COLLATE} is ignored, which means @samp{ls -v} and @samp{sort -V} +will sort non-numeric prefixes as if the @env{LC_COLLATE} locale category +was set to @samp{C}. address@hidden Some suffixes will not be matched by the regular +expression mentioned above. Consequently these examples may +not sort as you expect: + address@hidden +abc-1.2.3.4.7z +abc-1.2.3.7z address@hidden example + address@hidden +abc-1.2.3.4.x86_64.rpm +abc-1.2.3.x86_64.rpm address@hidden example address@hidden itemize @node General output formatting @subsection General output formatting diff --git a/src/ls.c b/src/ls.c index aeaa584..5c7f6aa 100644 --- a/src/ls.c +++ b/src/ls.c @@ -3272,7 +3272,7 @@ DEFINE_SORT_FUNCTIONS (extension, cmp_extension) All the other sort options, in fact, need xstrcoll and strcmp variants, because they all use a string comparison (either as the primary or secondary sort key), and xstrcoll has the ability to do a longjmp if strcoll fails for - locale reasons. Last, strverscmp is ALWAYS available in coreutils, + locale reasons. Last, filevercmp is ALWAYS available in coreutils, thanks to the gnulib library. */ static inline int cmp_version (struct fileinfo const *a, struct fileinfo const *b) -- 1.6.2.5