-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.
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
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;
(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
+ 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)
-#!/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
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
_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