>From 033b2dfb9eb12cd1d4d02953d5ed33d4a449521e Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Sun, 24 Jan 2016 23:01:32 +0100 Subject: [PATCH] xargs: emit a short hint to --help rather than full usage * xargs/xargs.c (usage): Change argument from FILE* to int, now taking the exit code. Unless called with EXIT_SUCCESS, just emit a short hint to try again with the --help option rather than emitting the full usage. Afterward, exit the program with the given status. (parse_num, main): Update all callers, removing the now-obsolete return or exit(). --- xargs/xargs.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/xargs/xargs.c b/xargs/xargs.c index fd9b313..ed7d5bc 100644 --- a/xargs/xargs.c +++ b/xargs/xargs.c @@ -223,7 +223,7 @@ static void wait_for_proc_all (void); static void increment_proc_max (int); static void decrement_proc_max (int); static long parse_num (char *str, int option, long min, long max, int fatal); -static void usage (FILE * stream); +static void usage (int status); static char @@ -531,8 +531,7 @@ main (int argc, char **argv) break; case 'h': - usage (stdout); - return 0; + usage (EXIT_SUCCESS); case 'I': /* POSIX */ case 'i': /* deprecated */ @@ -651,8 +650,7 @@ main (int argc, char **argv) break; default: - usage (stderr); - return 1; + usage (EXIT_FAILURE); } } @@ -1612,7 +1610,7 @@ parse_num (char *str, int option, long int min, long int max, int fatal) { fprintf (stderr, _("%s: invalid number \"%s\" for -%c option\n"), program_name, str, option); - usage (stderr); + usage (EXIT_FAILURE); exit (EXIT_FAILURE); } else if (val < min) @@ -1620,40 +1618,36 @@ parse_num (char *str, int option, long int min, long int max, int fatal) fprintf (stderr, _("%s: value %s for -%c option should be >= %ld\n"), program_name, str, option, min); if (fatal) - { - usage (stderr); - exit (EXIT_FAILURE); - } - else - { - val = min; - } + usage (EXIT_FAILURE); + + val = min; } else if (max >= 0 && val > max) { fprintf (stderr, _("%s: value %s for -%c option should be <= %ld\n"), program_name, str, option, max); if (fatal) - { - usage (stderr); - exit (EXIT_FAILURE); - } - else - { - val = max; - } + usage (EXIT_FAILURE); + + val = max; } return val; } static void -usage (FILE *stream) +usage (int status) { - fprintf (stream, + if (status != EXIT_SUCCESS) + { + fprintf (stderr, _("Try '%s --help' for more information.\n"), program_name); + exit (status); + } + + fprintf (stdout, _("Usage: %s [OPTION]... COMMAND [INITIAL-ARGS]...\n"), program_name); -#define HTL(t) fputs (t, stream); +#define HTL(t) fputs (t, stdout); HTL (_("Run COMMAND with arguments INITIAL-ARGS and more arguments read from input.\n" "\n")); @@ -1695,4 +1689,5 @@ usage (FILE *stream) HTL (_(" --version output version information and exit\n")); HTL (_("\n" "Report bugs to .\n")); + exit (status); } -- 2.1.4