adjust
authorJim Meyering <meyering@redhat.com>
Fri, 15 Aug 2008 07:48:43 +0000 (09:48 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 15 Aug 2008 08:18:51 +0000 (10:18 +0200)
ChangeLog-2008
NEWS
src/sort.c
tests/misc/sort-version [changed mode: 0644->0755]

index da33f93..aac9feb 100644 (file)
@@ -1,10 +1,3 @@
-2008-07-05  Bruce Korb  <bkorb@gnu.org>
-
-       * src/sort.c: implement version number sort
-       (compare_version): new procedure to do it.
-       * tests/misc/sort-version: new test file
-       * tests/Makefile.am: add it to the list
-
 2008-02-07  Jim Meyering  <meyering@redhat.com>
 
        We *do* need two different version files.
diff --git a/NEWS b/NEWS
index 72c885c..4979dd5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -39,8 +39,8 @@ GNU coreutils NEWS                                    -*- outline -*-
   represents the maximum number of inputs that will be merged at once.
   When processing more than NMERGE inputs, sort uses temporary files.
 
-  sort accepts still another new option --version-sort, specifying that
-  ordering is to be based on strverscmp(3).
+  sort accepts a new option --version-sort (-V, --sort=version),
+  specifying that ordering is to be based on strverscmp(3).
 
 ** Bug fixes
 
index 4e5fc84..a617517 100644 (file)
@@ -1822,19 +1822,19 @@ compare_random (char *restrict texta, size_t lena,
 
 static int
 compare_version (char *restrict texta, size_t lena,
-                char *restrict textb, size_t lenb)
+                char *restrict textb, size_t lenb)
 {
   int diff;
 
-  /*
-   *  It is necessary to save the character after the end of the field.
-   *  "strverscmp" works with NUL terminated strings.  Our blocks of
-   *  text are not necessarily terminated with a NUL byte.
-   */
+  /* It is necessary to save the character after the end of the field.
+     "strverscmp" works with NUL terminated strings.  Our blocks of
+     text are not necessarily terminated with a NUL byte. */
   char sv_a = texta[lena];
   char sv_b = textb[lenb];
 
-  texta[lena] = textb[lenb] = '\0';
+  texta[lena] = '\0';
+  textb[lenb] = '\0';
+
   diff = strverscmp (texta, textb);
 
   texta[lena] = sv_a;
@@ -1882,10 +1882,8 @@ keycompare (const struct line *a, const struct line *b)
                  (texta, textb));
          *lima = savea, *limb = saveb;
        }
-
       else if (key->version)
-        diff = compare_version (texta, lena, textb, lenb);
-
+       diff = compare_version (texta, lena, textb, lenb);
       else if (key->month)
        diff = getmonth (texta, lena) - getmonth (textb, lenb);
       /* Sorting like this may become slow, so in a simple locale the user
@@ -2745,7 +2743,7 @@ check_ordering_compatibility (void)
              + key->version + !!key->ignore))
        || (key->random && key->translate))
       {
-        /* The following is too big, but guaranteed to be "big enough". */
+       /* The following is too big, but guaranteed to be "big enough". */
        char opts[sizeof short_options];
        char *p = opts;
        if (key->ignore == nondictionary)
old mode 100644 (file)
new mode 100755 (executable)
index a4ebd40..3208f2e
@@ -1,18 +1,29 @@
-#!/usr/bin/echo do-not-run-this-directly.-Use-a-shell
-# -*- Mode: shell-script -*-
+#!/bin/sh
+# exercise sort's --sort=version option
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 if test "$VERBOSE" = yes; then
   set -x
   sort --version
 fi
 
-. $top_srcdir/tests/test-lib.sh
-
-s_file=sort-ver-src
-g_file=sort-ver-good
-r_file=sort-ver-res
+. $srcdir/test-lib.sh
 
-cat > $s_file <<- _EOF_
+cat > in <<- _EOF_
        string start 5.0.0 end of str
        string start 5.00.0 end of str
        string start 5.1.0 end of str
@@ -35,8 +46,7 @@ cat > $s_file <<- _EOF_
        string start 5.90.0 end of str
        _EOF_
 
-
-cat > $g_file <<- _EOF_
+cat > exp <<- _EOF_
        string start 5.00.0 end of str
        string start 5.0.0 end of str
        string start 5.1.0 end of str
@@ -60,6 +70,6 @@ cat > $g_file <<- _EOF_
        _EOF_
 
 fail=0
-sort --sort=version -o $r_file $s_file
-compare $g_file $r_file >/dev/null 2>&1 || fail=1
-(exit $fail) ; exit $fail
+sort --sort=version -o out in || fail=1
+compare exp out || fail=1
+(exit $fail); exit $fail