From 4a8016db69e2df36a55c971977102a65ebf2f41e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 28 Jun 2006 23:51:13 +0000 Subject: [PATCH] * 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. --- src/sort.c | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/sort.c b/src/sort.c index d3a37f3..a266bd5 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) -- 2.7.4