diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2006-06-28 23:51:13 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2006-06-28 23:51:13 +0000 |
commit | 4a8016db69e2df36a55c971977102a65ebf2f41e (patch) | |
tree | bb0183ea07600ed1b76e331258489edaa6587c15 | |
parent | 59e82cb26623bfdd7ca04553d31d9832f966a4ec (diff) | |
download | coreutils-4a8016db69e2df36a55c971977102a65ebf2f41e.tar.xz |
* src/sort.c (main): Support obsolete usages like "sort +1 -2" even when
conforming to POSIX 1003.1-2001, since this is a pure extension to
POSIX.
-rw-r--r-- | src/sort.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/sort.c b/src/sort.c index d3a37f3d1..a266bd557 100644 --- a/src/sort.c +++ b/src/sort.c @@ -2320,37 +2320,42 @@ main (int argc, char **argv) { case 1: key = NULL; - if (obsolete_usage && optarg[0] == '+') + if (optarg[0] == '+') { - /* Treat +POS1 [-POS2] as a key if possible; but silently - treat an operand as a file if it is not a valid +POS1. */ - key = new_key (); - s = parse_field_count (optarg + 1, &key->sword, NULL); - if (s && *s == '.') - s = parse_field_count (s + 1, &key->schar, NULL); - if (! (key->sword | key->schar)) - key->sword = SIZE_MAX; - if (! s || *set_ordering (s, key, bl_start)) + bool minus_pos_usage = (optind != argc && argv[optind][0] == '-' + && ISDIGIT (argv[optind][1])); + obsolete_usage |= minus_pos_usage & ~posixly_correct; + if (obsolete_usage) { - free (key); - key = NULL; - } - else - { - if (optind != argc && argv[optind][0] == '-' - && ISDIGIT (argv[optind][1])) + /* Treat +POS1 [-POS2] as a key if possible; but silently + treat an operand as a file if it is not a valid +POS1. */ + key = new_key (); + s = parse_field_count (optarg + 1, &key->sword, NULL); + if (s && *s == '.') + s = parse_field_count (s + 1, &key->schar, NULL); + if (! (key->sword | key->schar)) + key->sword = SIZE_MAX; + if (! s || *set_ordering (s, key, bl_start)) + { + free (key); + key = NULL; + } + else { - char const *optarg1 = argv[optind++]; - s = parse_field_count (optarg1 + 1, &key->eword, + if (minus_pos_usage) + { + char const *optarg1 = argv[optind++]; + s = parse_field_count (optarg1 + 1, &key->eword, N_("invalid number after `-'")); - if (*s == '.') - s = parse_field_count (s + 1, &key->echar, + if (*s == '.') + s = parse_field_count (s + 1, &key->echar, N_("invalid number after `.'")); - if (*set_ordering (s, key, bl_end)) - badfieldspec (optarg1, + if (*set_ordering (s, key, bl_end)) + badfieldspec (optarg1, N_("stray character in field spec")); + } + insertkey (key); } - insertkey (key); } } if (! key) |