[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sort --compare-version
From: |
Andreas Schwab |
Subject: |
Re: sort --compare-version |
Date: |
Mon, 18 Feb 2008 23:27:40 +0100 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/22.1 (gnu/linux) |
Jim Meyering <address@hidden> writes:
> Do you feel like adding a few tests (tests/sort/Test.pm) to exercise
> the new feature, and adding to coreutils.texi and NEWS?
Here is an updated patch.
Andreas.
2008-02-18 Andreas Schwab <address@hidden>
Add --sort option.
* src/sort.c (SORT_OPTION): New enum.
(sort_args, sort_types): Define.
(usage, long_options, main): New option --sort.
* tests/sort/Test.pm: Test it.
doc/:
* coreutils.texi (sort invocation): Document --sort option.
diff --git a/NEWS b/NEWS
index bc1b47d..fb46361 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,13 @@ GNU coreutils NEWS -*-
outline -*-
* Noteworthy changes in release 6.?? (2008-??-??) [stable]
+** New features
+
+ sort accepts the new option --sort=WORD, where WORD can be one of
+ general-numeric, month, numeric or random. These are equivalent to the
+ options --general-numeric-sort/-g, --month-sort/-M, --numeric-sort/-n
+ and --random-sort/-R, resp.
+
** Bug fixes
configure --enable-no-install-program=groups now works.
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 016673a..7d9cbcb 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -3536,8 +3536,10 @@ The @env{LC_CTYPE} locale determines character types.
@item -g
@itemx --general-numeric-sort
address@hidden --sort=general-numeric
@opindex -g
@opindex --general-numeric-sort
address@hidden --sort
@cindex general numeric sort
@vindex LC_NUMERIC
Sort numerically, using the standard C function @code{strtod} to convert
@@ -3580,8 +3582,10 @@ This option has no effect if the stronger
@option{--dictionary-order}
@item -M
@itemx --month-sort
address@hidden --sort=month
@opindex -M
@opindex --month-sort
address@hidden --sort
@cindex months, sorting by
@vindex LC_TIME
An initial string, consisting of any amount of blanks, followed
@@ -3594,8 +3598,10 @@ can change this.
@item -n
@itemx --numeric-sort
address@hidden --sort=numeric
@opindex -n
@opindex --numeric-sort
address@hidden --sort
@cindex numeric sort
@vindex LC_NUMERIC
Sort numerically. The number begins each line and consists
@@ -3623,8 +3629,10 @@ appear earlier in the output instead of later.
@item -R
@itemx --random-sort
address@hidden --sort=random
@opindex -R
@opindex --random-sort
address@hidden --sort
@cindex random sort
Sort by hashing the input keys and then sorting the hash values.
Choose the hash function at random, ensuring that it is free of
diff --git a/src/sort.c b/src/sort.c
index 1183fc5..79cca18 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -329,6 +329,9 @@ Ordering options:\n\
-n, --numeric-sort compare according to string numerical value\n\
-R, --random-sort sort by random hash of keys\n\
--random-source=FILE get random bytes from FILE (default
/dev/urandom)\n\
+ --sort=WORD sort according to WORD:\n\
+ general-numeric -g, month -M, numeric -n,\n\
+ random -R\n\
-r, --reverse reverse the result of comparisons\n\
\n\
"), stdout);
@@ -391,7 +394,8 @@ enum
{
CHECK_OPTION = CHAR_MAX + 1,
COMPRESS_PROGRAM_OPTION,
- RANDOM_SOURCE_OPTION
+ RANDOM_SOURCE_OPTION,
+ SORT_OPTION
};
static char const short_options[] = "-bcCdfgik:mMno:rRsS:t:T:uy:z";
@@ -411,6 +415,7 @@ static struct option const long_options[] =
{"numeric-sort", no_argument, NULL, 'n'},
{"random-sort", no_argument, NULL, 'R'},
{"random-source", required_argument, NULL, RANDOM_SOURCE_OPTION},
+ {"sort", required_argument, NULL, SORT_OPTION},
{"output", required_argument, NULL, 'o'},
{"reverse", no_argument, NULL, 'r'},
{"stable", no_argument, NULL, 's'},
@@ -434,6 +439,16 @@ static char const check_types[] =
};
ARGMATCH_VERIFY (check_args, check_types);
+static char const *const sort_args[] =
+{
+ "general-numeric", "month", "numeric", "random", NULL
+};
+static char const sort_types[] =
+{
+ 'g', 'M', 'n', 'R'
+};
+ARGMATCH_VERIFY (sort_args, sort_types);
+
/* The set of signals that are caught. */
static sigset_t caught_signals;
@@ -2902,6 +2917,9 @@ main (int argc, char **argv)
files[nfiles++] = optarg;
break;
+ case SORT_OPTION:
+ c = XARGMATCH ("--sort", optarg, sort_args, sort_types);
+ /* Fall through. */
case 'b':
case 'd':
case 'f':
diff --git a/tests/sort/Test.pm b/tests/sort/Test.pm
index e4d98be..0462973 100644
--- a/tests/sort/Test.pm
+++ b/tests/sort/Test.pm
@@ -274,6 +274,7 @@ my @tv = (
["incompat4", '-c -o /dev/null', '', '', 2],
["incompat5", '-C -o /dev/null', '', '', 2],
["incompat6", '-cC', '', '', 2],
+["incompat7", '--sort=random -n', '', '', 2],
# -t '\0' is accepted, as of coreutils-5.0.91
['nul-tab', "-k2,2 -t '\\0'", "a\0z\01\nb\0y\02\n", "b\0y\02\na\0z\01\n", 0],
@@ -289,6 +290,9 @@ my @tv = (
# Exercise the code that enlarges the line buffer. See the thread here:
# http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/11006
['realloc-buf', '-S1', 'a'x4000 ."\n", 'a'x4000 ."\n", 0],
+
+["sort-numeric", '--sort=numeric', ".01\n0\n", "0\n.01\n", 0],
+["sort-gennum", '--sort=general-numeric', "1e2\n2e1\n", "2e1\n1e2\n", 0],
);
sub test_vector
--
Andreas Schwab, SuSE Labs, address@hidden
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
- Re: sort --compare-version, Bob Proulx, 2008/02/04
- Re: sort --compare-version, James Youngman, 2008/02/05
- Re: sort --compare-version, Bruce Korb, 2008/02/06
- Re: sort --compare-version, Andreas Schwab, 2008/02/06
- Re: sort --compare-version, Bruce Korb, 2008/02/06
- Re: sort --compare-version, Jim Meyering, 2008/02/06
- Re: sort --compare-version, Bob Proulx, 2008/02/06
- Re: sort --compare-version, Andreas Schwab, 2008/02/08
- Re: sort --compare-version, Jim Meyering, 2008/02/10
- Re: sort --compare-version,
Andreas Schwab <=
- Re: sort --compare-version, Jim Meyering, 2008/02/20
- Re: sort --compare-version, Bauke Jan Douma, 2008/02/06
Re: sort --compare-version, Bob Proulx, 2008/02/06