From: Jim Meyering Date: Tue, 5 Dec 1995 23:50:43 +0000 (+0000) Subject: (main): Diagnose improper form of arguments to -k, then fail. X-Git-Tag: TEXTUTILS-1_13h~31 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e625640bd0870e6c0ba89fe2cfba788956d59065;p=thirdparty%2Fcoreutils.git (main): Diagnose improper form of arguments to -k, then fail. --- diff --git a/src/sort.c b/src/sort.c index 707df9cfb2..95b324f5cb 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1782,15 +1782,34 @@ main (int argc, char **argv) badfieldspec (argv[i]); for (t = 0; digits[UCHAR (*s)]; ++s) t = 10 * t + *s - '0'; - if (t) - t--; + if (t == 0) + { + /* Provoke with `sort -k0' */ + error (0, 0, _("the starting field number argument \ +to the `-k' option must be positive")); + badfieldspec (argv[i]); + } + --t; t2 = 0; if (*s == '.') { + if (!digits[UCHAR (s[1])]) + { + /* Provoke with `sort -k1.' */ + error (0, 0, _("starting field spec has `.' but \ +lacks following character offset")); + badfieldspec (argv[i]); + } for (++s; digits[UCHAR (*s)]; ++s) t2 = 10 * t2 + *s - '0'; - if (t2) - t2--; + if (t2 == 0) + { + /* Provoke with `sort -k1.0' */ + error (0, 0, _("starting field character offset \ +argument to the `-k' option\nmust be positive")); + badfieldspec (argv[i]); + } + --t2; } if (t2 || t) { @@ -1800,20 +1819,45 @@ main (int argc, char **argv) else key->sword = -1; s = set_ordering (s, key, bl_start); - if (*s && *s != ',') + if (*s == 0) + { + key->eword = -1; + key->echar = 0; + } + else if (*s != ',') badfieldspec (argv[i]); - else if (*s++) + else if (*s == ',') { + /* Skip over comma. */ + ++s; + if (*s == 0) + { + /* Provoke with `sort -k1,' */ + error (0, 0, _("field specification has `,' but \ +lacks following field spec")); + badfieldspec (argv[i]); + } /* Get POS2. */ for (t = 0; digits[UCHAR (*s)]; ++s) t = t * 10 + *s - '0'; - if (t) - t--; + if (t == 0) + { + /* Provoke with `sort -k1,0' */ + error (0, 0, _("ending field number argument \ +to the `-k' option must be positive")); + badfieldspec (argv[i]); + } + --t; t2 = 0; - /* FIXME: It's an error to specify `.' without a - following char-spec. */ if (*s == '.') { + if (!digits[UCHAR (s[1])]) + { + /* Provoke with `sort -k1,1.' */ + error (0, 0, _("ending field spec has `.' \ +but lacks following character offset")); + badfieldspec (argv[i]); + } for (++s; digits[UCHAR (*s)]; ++s) t2 = t2 * 10 + *s - '0'; }