summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@suse.de>2008-02-20 08:36:56 +0100
committerJim Meyering <meyering@redhat.com>2008-02-20 08:41:29 +0100
commitcb3147d29860195780f745faf42e2b8a02bdcbf5 (patch)
tree4fe7240b19d7d861907ae2f5713361c3aea8034a /src
parentc78039b87de6c636a167d3206081cced54af08e2 (diff)
downloadcoreutils-cb3147d29860195780f745faf42e2b8a02bdcbf5.tar.xz
sort: 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. * NEWS: Mention this.
Diffstat (limited to 'src')
-rw-r--r--src/sort.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/sort.c b/src/sort.c
index 1183fc5cc..8b2eec542 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1,5 +1,5 @@
/* sort - sort lines of text (with all kinds of options).
- Copyright (C) 1988, 1991-2007 Free Software Foundation, Inc.
+ Copyright (C) 1988, 1991-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
@@ -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':