From d7c526e66d7c4d3d11ca80c141b9fae18f0a9668 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 26 Oct 1993 00:11:14 +0000 Subject: [PATCH] merge with 1.8.1i --- old/sh-utils/ChangeLog | 8 +++++++ src/basename.c | 12 ++++------- src/date.c | 12 ++++------- src/dirname.c | 12 ++++------- src/echo.c | 12 ++++------- src/env.c | 15 ++++++------- src/expr.c | 14 ++++++------- src/id.c | 12 ++++------- src/logname.c | 12 ++++------- src/nice.c | 14 +++++-------- src/pathchk.c | 12 ++++------- src/printf.c | 19 ++++++++--------- src/sleep.c | 12 ++++------- src/stty.c | 57 ++++++++++++++++++++++++++++++++++++-------------- src/su.c | 16 ++++++-------- src/tee.c | 12 ++++------- src/test.c | 16 +++++++------- src/tty.c | 12 ++++------- src/uname.c | 12 ++++------- src/who.c | 12 ++++------- 20 files changed, 136 insertions(+), 167 deletions(-) diff --git a/old/sh-utils/ChangeLog b/old/sh-utils/ChangeLog index 4ba2951..3fcd6be 100644 --- a/old/sh-utils/ChangeLog +++ b/old/sh-utils/ChangeLog @@ -1,5 +1,13 @@ +Mon Oct 25 19:22:58 EDT 1993 + + * stty.c (main, integer_arg): Don't just call error(1,... about + improper usage. Call `error (0,...' them usage (1). + Sun Oct 24 14:10:23 1993 Jim Meyering (meyering@comco.com) + * test.c [member]: Don't try to cast index return value to an int. + That can lose on systems with 64-bit pointers. + * long-options.c: Save and restore optind, too. * long-options.h: New file. * long-options.c, echo.c, expr.c, printf.c, test.c, yes.c: diff --git a/src/basename.c b/src/basename.c index 6c8e7fe..9b7ccae 100644 --- a/src/basename.c +++ b/src/basename.c @@ -68,22 +68,18 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... PATH [SUFFIX]\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]... PATH [SUFFIX]\n", program_name); + printf ("\ \n\ --help display this help and exit\n\ --version output version information and exit\n\ "); - + } exit (status); } diff --git a/src/date.c b/src/date.c index 9e5605c..08998b2 100644 --- a/src/date.c +++ b/src/date.c @@ -224,20 +224,17 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... [+FORMAT] [MMDDhhmm[[CC]YY][.ss]]\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else { + printf ("Usage: %s [OPTION]... [+FORMAT] [MMDDhhmm[[CC]YY][.ss]]\n", + program_name); printf ("\ \n\ - -d, --date STRING display time described by STRING, not `now'\n\ - -s, --set STRING set time described by STRING\n\ + -d, --date=STRING display time described by STRING, not `now'\n\ + -s, --set=STRING set time described by STRING\n\ -u, --uct, --universal print or set Universal Coordinated Time\n\ --help display this help and exit\n\ --version output version information and exit\n\ @@ -278,6 +275,5 @@ FORMAT controls the output. Interpreted sequences are:\n\ %%y last two digits of year (00..99)\n\ "); } - exit (status); } diff --git a/src/dirname.c b/src/dirname.c index a40c826..8027135 100644 --- a/src/dirname.c +++ b/src/dirname.c @@ -57,22 +57,18 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... PATH\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]... PATH\n", program_name); + printf ("\ \n\ --help display this help and exit\n\ --version output version information and exit\n\ "); - + } exit (status); } diff --git a/src/echo.c b/src/echo.c index 4a2f673..65864ec 100644 --- a/src/echo.c +++ b/src/echo.c @@ -76,17 +76,13 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... [STRING]...\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]... [STRING]...\n", program_name); + printf ("\ \n\ -n do not output the trailing newline\n\ -e (unused)\n\ @@ -107,7 +103,7 @@ Without -E, the following sequences are recognized and interpolated:\n\ \\t horizontal tab\n\ \\v vertical tab\n\ "); - + } exit (status); } diff --git a/src/env.c b/src/env.c index 2fb0d7e..743cf5d 100644 --- a/src/env.c +++ b/src/env.c @@ -195,25 +195,22 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]\n", + program_name); + printf ("\ \n\ - -u, --unset NAME remove variable from the environment\n\ + -u, --unset=NAME remove variable from the environment\n\ -i, --ignore-environment start with an empty environment\n\ --help display this help and exit\n\ --version output version information and exit\n\ \n\ A mere - implies -i. If no COMMAND, print the resulting environment.\n\ "); - + } exit (status); } diff --git a/src/expr.c b/src/expr.c index 22e7e83..26c4ffa 100644 --- a/src/expr.c +++ b/src/expr.c @@ -46,7 +46,7 @@ #include "system.h" #include "version.h" -#include "long-option.h" +#include "long-options.h" #if !defined (isascii) || defined (STDC_HEADERS) #undef isascii @@ -110,18 +110,17 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s EXPRESSION\n\ - or: %s OPTION\n\ -", - program_name, program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else { printf ("\ +Usage: %s EXPRESSION\n\ + or: %s OPTION\n\ +", + program_name, program_name); + printf ("\ \n\ --help display this help and exit\n\ --version output version information and exit\n\ @@ -166,7 +165,6 @@ Pattern matches return the string matched between \\( and \\) or null; if\n\ \\( and \\) are not used, they return the number of characters matched or 0.\n\ "); } - exit (status); } diff --git a/src/id.c b/src/id.c index 3f2b32c..a43921b 100644 --- a/src/id.c +++ b/src/id.c @@ -363,17 +363,13 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... [USERNAME]\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]... [USERNAME]\n", program_name); + printf ("\ \n\ -g, --group print only the group ID\n\ -n, --name print a name instead of a number, for -ugG\n\ @@ -385,6 +381,6 @@ Usage: %s [OPTION]... [USERNAME]\n\ \n\ Without any OPTION, print some useful set of identified information.\n\ "); - + } exit (status); } diff --git a/src/logname.c b/src/logname.c index f8fcf38..86f648c 100644 --- a/src/logname.c +++ b/src/logname.c @@ -53,22 +53,18 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]...\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]...\n", program_name); + printf ("\ \n\ --help display this help and exit\n\ --version output version information and exit\n\ "); - + } exit (status); } diff --git a/src/nice.c b/src/nice.c index 616a8f3..94f750e 100644 --- a/src/nice.c +++ b/src/nice.c @@ -174,26 +174,22 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... [COMMAND [ARG]...]\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]... [COMMAND [ARG]...]\n", program_name); + printf ("\ \n\ -ADJUST increment priority by ADJUST first\n\ - -n, --adjustment ADJUST same as -ADJUST\n\ + -n, --adjustment=ADJUST same as -ADJUST\n\ --help display this help and exit\n\ --version output version information and exit\n\ \n\ With no COMMAND, print the current scheduling priority. ADJUST is 10\n\ by default. Range goes from -20 (highest priority) to 19 (lowest).\n\ "); - + } exit (status); } diff --git a/src/pathchk.c b/src/pathchk.c index afb663a..e98b75e 100644 --- a/src/pathchk.c +++ b/src/pathchk.c @@ -361,22 +361,18 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... PATH...\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]... PATH...\n", program_name); + printf ("\ \n\ -p, --portability check for all POSIX systems, not only this one\n\ --help display this help and exit\n\ --version output version information and exit\n\ "); - + } exit (status); } diff --git a/src/printf.c b/src/printf.c index c6d476b..43cc0de 100644 --- a/src/printf.c +++ b/src/printf.c @@ -61,7 +61,7 @@ #include "system.h" #include "version.h" -#include "long-option.h" +#include "long-options.h" #if !defined (isascii) || defined (STDC_HEADERS) #undef isascii @@ -104,18 +104,17 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s FORMAT [ARGUMENT]...\n\ - or: %s OPTION\n\ -", - program_name, program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("\ +Usage: %s FORMAT [ARGUMENT]...\n\ + or: %s OPTION\n\ +", + program_name, program_name); + printf ("\ \n\ --help display this help and exit\n\ --version output version information and exit\n\ @@ -141,7 +140,7 @@ FORMAT controls the output as in C printf. Interpreted sequences are:\n\ and all C format specifications ending with one of diouxXfeEgGcs, with\n\ ARGUMENTs converted to proper type first. Variable widths are handled.\n\ "); - + } exit (status); } diff --git a/src/sleep.c b/src/sleep.c index a98ce9d..bf15f81 100644 --- a/src/sleep.c +++ b/src/sleep.c @@ -57,24 +57,20 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... NUMBER[SUFFIX]\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]... NUMBER[SUFFIX]\n", program_name); + printf ("\ \n\ --help display this help and exit\n\ --version output version information and exit\n\ \n\ SUFFIX may be s for seconds, m for minutes, h for hours or d for days.\n\ "); - + } exit (status); } diff --git a/src/stty.c b/src/stty.c index c4d0946..07307ff 100644 --- a/src/stty.c +++ b/src/stty.c @@ -446,16 +446,12 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... [SETTING]...\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else { + printf ("Usage: %s [OPTION]... [SETTING]...\n", program_name); printf ("\ \n\ -a, --all print all current settings in human-readable form\n\ @@ -619,7 +615,6 @@ settings, CHAR is taken literally, or coded as in ^c, 0x37, 0177 or\n\ 127; special values ^- or undef used to disable special characters.\n\ "); } - exit (status); } @@ -675,7 +670,10 @@ done:; if (optind == argc) { if (optc == '?') - error (1, 0, "invalid argument `%s'", argv[--optind]); + { + error (0, 0, "invalid argument `%s'", argv[--optind]); + usage (1); + } display_settings (output_type, &mode); exit (0); } @@ -700,7 +698,10 @@ done:; } } if (match_found == 0 && reversed) - error (1, 0, "invalid argument `%s'", --argv[optind]); + { + error (0, 0, "invalid argument `%s'", --argv[optind]); + usage (1); + } if (match_found == 0) { for (i = 0; control_info[i].name != NULL; ++i) @@ -708,7 +709,10 @@ done:; if (!strcmp (argv[optind], control_info[i].name)) { if (optind == argc - 1) - error (1, 0, "missing argument to `%s'", argv[optind]); + { + error (0, 0, "missing argument to `%s'", argv[optind]); + usage (1); + } match_found = 1; ++optind; set_control_char (&control_info[i], argv[optind], &mode); @@ -721,14 +725,20 @@ done:; if (!strcmp (argv[optind], "ispeed")) { if (optind == argc - 1) - error (1, 0, "missing argument to `%s'", argv[optind]); + { + error (0, 0, "missing argument to `%s'", argv[optind]); + usage (1); + } ++optind; set_speed (input_speed, argv[optind], &mode); } else if (!strcmp (argv[optind], "ospeed")) { if (optind == argc - 1) - error (1, 0, "missing argument to `%s'", argv[optind]); + { + error (0, 0, "missing argument to `%s'", argv[optind]); + usage (1); + } ++optind; set_speed (output_speed, argv[optind], &mode); } @@ -736,7 +746,10 @@ done:; else if (!strcmp (argv[optind], "rows")) { if (optind == argc - 1) - error (1, 0, "missing argument to `%s'", argv[optind]); + { + error (0, 0, "missing argument to `%s'", argv[optind]); + usage (1); + } ++optind; set_window_size ((int) integer_arg (argv[optind]), -1); } @@ -744,7 +757,10 @@ done:; || !strcmp (argv[optind], "columns")) { if (optind == argc - 1) - error (1, 0, "missing argument to `%s'", argv[optind]); + { + error (0, 0, "missing argument to `%s'", argv[optind]); + usage (1); + } ++optind; set_window_size (-1, (int) integer_arg (argv[optind])); } @@ -755,7 +771,10 @@ done:; else if (!strcmp (argv[optind], "line")) { if (optind == argc - 1) - error (1, 0, "missing argument to `%s'", argv[optind]); + { + error (0, 0, "missing argument to `%s'", argv[optind]); + usage (1); + } ++optind; mode.c_line = integer_arg (argv[optind]); } @@ -765,7 +784,10 @@ done:; else if (string_to_baud (argv[optind]) != (speed_t) -1) set_speed (both_speeds, argv[optind], &mode); else if (recover_mode (argv[optind], &mode) == 0) - error (1, 0, "invalid argument `%s'", argv[optind]); + { + error (0, 0, "invalid argument `%s'", argv[optind]); + usage (1); + } } optind++; } @@ -1479,6 +1501,9 @@ integer_arg (s) p--; if (*p) - error (1, 0, "invalid integer argument `%s'", s); + { + error (0, 0, "invalid integer argument `%s'", s); + usage (1); + } return value; } diff --git a/src/su.c b/src/su.c index 7db31c1..7669aef 100644 --- a/src/su.c +++ b/src/su.c @@ -551,29 +551,25 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... [-] [USER [ARG]...]\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]... [-] [USER [ARG]...]\n", program_name); + printf ("\ \n\ -l, --login make the shell a login shell\n\ - -c, --commmand COMMAND pass a single COMMAND to the shell with -c\n\ + -c, --commmand=COMMAND pass a single COMMAND to the shell with -c\n\ -f, --fast pass -f to the shell (for csh or tcsh)\n\ -m, --preserve-environment do not reset environment variables\n\ -p same as -m\n\ - -s, --shell SHELL run SHELL if /etc/shells allows it\n\ + -s, --shell=SHELL run SHELL if /etc/shells allows it\n\ --help display this help and exit\n\ --version output version information and exit\n\ \n\ A mere - implies -l. If USER not given, assume root.\n\ "); - + } exit (status); } diff --git a/src/tee.c b/src/tee.c index 66fccd9..4cfa93c 100644 --- a/src/tee.c +++ b/src/tee.c @@ -70,24 +70,20 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... [FILE]...\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]... [FILE]...\n", program_name); + printf ("\ \n\ -a, --append append to the given FILEs, do not overwrite\n\ -i, --ignore-interrupts ignore interrupt signals\n\ --help display this help and exit\n\ --version output version information and exit\n\ "); - + } exit (status); } diff --git a/src/test.c b/src/test.c index c3d5c54..a4fd543 100644 --- a/src/test.c +++ b/src/test.c @@ -1008,25 +1008,24 @@ posixtest () } #if defined (TEST_STANDALONE) -#include "long-option.h" +#include "long-options.h" static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s EXPRESSION\n\ - or: [ EXPRESSION ]\n\ - or: %s OPTION\n\ -", - program_name, program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else { printf ("\ +Usage: %s EXPRESSION\n\ + or: [ EXPRESSION ]\n\ + or: %s OPTION\n\ +", + program_name, program_name); + printf ("\ \n\ --help display this help and exit\n\ --version output version information and exit\n\ @@ -1087,7 +1086,6 @@ Beware that parentheses need to be escaped by backslashes for shells.\n\ INTEGER may also be -l STRING, which evaluates to the length of STRING.\n\ "); } - exit (status); } #endif /* TEST_STANDALONE */ diff --git a/src/tty.c b/src/tty.c index 83e3512..4b7aaa0 100644 --- a/src/tty.c +++ b/src/tty.c @@ -123,22 +123,18 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]...\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]...\n", program_name); + printf ("\ \n\ -s, --silent, --quiet print nothing, only return an exit status\n\ --help display this help and exit\n\ --version output version information and exit\n\ "); - + } exit (status); } diff --git a/src/uname.c b/src/uname.c index 01b5f02..65fad1c 100644 --- a/src/uname.c +++ b/src/uname.c @@ -188,17 +188,13 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]...\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]...\n", program_name); + printf ("\ \n\ -a, --all print all information\n\ -m, --machine print the machine (hardware) type\n\ @@ -211,6 +207,6 @@ Usage: %s [OPTION]...\n\ \n\ Without any OPTION, assume -s.\n\ "); - + } exit (status); } diff --git a/src/who.c b/src/who.c index 8b122c8..f01da1b 100644 --- a/src/who.c +++ b/src/who.c @@ -462,17 +462,13 @@ static void usage (status) int status; { - fprintf (status == 0 ? stdout : stderr, "\ -Usage: %s [OPTION]... [ FILE | ARG1 ARG2 ]\n\ -", - program_name); - if (status != 0) fprintf (stderr, "Try `%s --help' for more information.\n", program_name); else - - printf ("\ + { + printf ("Usage: %s [OPTION]... [ FILE | ARG1 ARG2 ]\n", program_name); + printf ("\ \n\ -H, --heading print line of column headings\n\ -T, -w, --mesg add user's message status as +, - or ?\n\ @@ -488,6 +484,6 @@ Usage: %s [OPTION]... [ FILE | ARG1 ARG2 ]\n\ If FILE not given, uses /etc/utmp. /etc/wtmp as FILE is common.\n\ If ARG1 ARG2 given, -m presumed: `am i' or `mom likes' are usual.\n\ "); - + } exit (status); } -- 2.7.4