From e18c4ff172e0018df5b2d6abffd4f0e37637d00c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 14 Dec 2005 23:59:23 +0000 Subject: [PATCH] (incompatible_options): New function. (check_ordering_compatibility, main): Use it. (main): Check for -c and -o. Don't bother with a usage message for "sort -c a b", for consistency with other error diagnostics. --- src/sort.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/sort.c b/src/sort.c index e887a6dbb..664d1453f 100644 --- a/src/sort.c +++ b/src/sort.c @@ -2034,6 +2034,28 @@ insertkey (struct keyfield *key) key->next = NULL; } +/* Report a bad field specification SPEC, with extra info MSGID. */ + +static void badfieldspec (char const *, char const *) + ATTRIBUTE_NORETURN; +static void +badfieldspec (char const *spec, char const *msgid) +{ + error (SORT_FAILURE, 0, _("%s: invalid field specification %s"), + _(msgid), quote (spec)); + abort (); +} + +/* Report incompatible options. */ + +static void incompatible_options (char const *) ATTRIBUTE_NORETURN; +static void +incompatible_options (char const *opts) +{ + error (SORT_FAILURE, 0, _("options `-%s' are incompatible"), opts); + abort (); +} + /* Check compatibility of ordering options. */ static void @@ -2063,22 +2085,10 @@ check_ordering_compatibility (void) if (key->random) *p++ = 'R'; *p = '\0'; - error (SORT_FAILURE, 0, _("options `-%s' are incompatible"), opts); + incompatible_options (opts); } } -/* Report a bad field specification SPEC, with extra info MSGID. */ - -static void badfieldspec (char const *, char const *) - ATTRIBUTE_NORETURN; -static void -badfieldspec (char const *spec, char const *msgid) -{ - error (SORT_FAILURE, 0, _("%s: invalid field specification %s"), - _(msgid), quote (spec)); - abort (); -} - /* Parse the leading integer in STRING and store the resulting value (which must fit into size_t) into *VAL. Return the address of the suffix after the integer. If MSGID is NULL, return NULL after @@ -2573,11 +2583,11 @@ main (int argc, char **argv) if (checkonly) { if (nfiles > 1) - { - error (0, 0, _("extra operand %s not allowed with -c"), - quote (files[1])); - usage (SORT_FAILURE); - } + error (SORT_FAILURE, 0, _("extra operand %s not allowed with -c"), + quote (files[1])); + + if (outfile) + incompatible_options ("co"); /* POSIX requires that sort return 1 IFF invoked with -c and the input is not properly sorted. */ -- 2.34.1