Patch to support --help
The tools zdump and zic support the GNU-standard --version option (output version information to stdout and exit successfully), but not the associated --help option (output usage and bug reporting information to stdout and exit successfully). This patch adds such support. tzselect supports neither option, so this patch adds support for both options to it. diff -ru tzcode.orig/tzselect.ksh tzcode/tzselect.ksh --- tzcode.orig/tzselect.ksh 2008-09-10 02:33:17.000000000 +0000 +++ tzcode/tzselect.ksh 2009-01-02 16:55:45.000000000 +0000 @@ -1,6 +1,6 @@ #! /bin/ksh -# '@(#)tzselect.ksh 8.1' +VERSION='@(#)tzselect.ksh 8.1' # Ask the user about the time zone, and output the resulting TZ value to stdout. # Interact with the user via stderr and stdin. @@ -45,6 +45,21 @@ exit 1 } +if [ "$1" = "--help" ]; then + cat <<EOF +Usage: tzselect +Select a time zone interactively. + +Report bugs to tz@elsie.nci.nih.gov. +EOF + exit 0 +elif [ "$1" = "--version" ]; then + cat <<EOF +tzselect $VERSION +EOF + exit 0 +fi + # Make sure the tables are readable. TZ_COUNTRY_TABLE=$TZDIR/iso3166.tab TZ_ZONE_TABLE=$TZDIR/zone.tab diff -ru tzcode.orig/zdump.c tzcode/zdump.c --- tzcode.orig/zdump.c 2008-09-10 02:33:24.000000000 +0000 +++ tzcode/zdump.c 2009-01-02 16:56:59.000000000 +0000 @@ -230,6 +230,17 @@ warned = TRUE; } +static void +usage(const char *progname, FILE *stream, int status) +{ + (void) fprintf(stream, +_("%s: usage is %s [ --version ] [ --help ] [ -v ] [ -c [loyear,]hiyear ] zonename ...\n\ +\n\ +Report bugs to tz@elsie.nci.nih.gov.\n"), + progname, progname); + exit(status); +} + int main(argc, argv) int argc; @@ -266,6 +277,8 @@ if (strcmp(argv[i], "--version") == 0) { (void) printf("%s\n", elsieid); exit(EXIT_SUCCESS); + } else if (strcmp(argv[i], "--help") == 0) { + usage(progname, stdout, EXIT_SUCCESS); } vflag = 0; cutarg = NULL; @@ -275,10 +288,7 @@ else cutarg = optarg; if ((c != EOF && c != -1) || (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) { - (void) fprintf(stderr, -_("%s: usage is %s [ --version ] [ -v ] [ -c [loyear,]hiyear ] zonename ...\n"), - progname, progname); - exit(EXIT_FAILURE); + usage(progname, stderr, EXIT_FAILURE); } if (vflag) { if (cutarg != NULL) { diff -ru tzcode.orig/zic.c tzcode/zic.c --- tzcode.orig/zic.c 2008-09-10 02:33:18.000000000 +0000 +++ tzcode/zic.c 2009-01-02 16:57:40.000000000 +0000 @@ -156,7 +156,7 @@ const struct zone * zp, int ntzones); static void setboundaries(void); static zic_t tadd(zic_t t1, long t2); -static void usage(void); +static void usage(FILE *stream, int status); static void writezone(const char * name, const char * string); static int yearistype(int year, const char * type); @@ -454,13 +454,15 @@ } static void -usage(void) +usage(FILE *stream, int status) { - (void) fprintf(stderr, _("%s: usage is %s \ -[ --version ] [ -v ] [ -l localtime ] [ -p posixrules ] \\\n\ -\t[ -d directory ] [ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n"), - progname, progname); - exit(EXIT_FAILURE); + (void) fprintf(stream, _("%s: usage is %s \ +[ --version ] [ --help ] [ -v ] [ -l localtime ] [ -p posixrules ] \\\n\ +\t[ -d directory ] [ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n\ +\n\ +Report bugs to tz@elsie.nci.nih.gov.\n"), + progname, progname); + exit(status); } static const char * psxrules; @@ -498,11 +500,13 @@ if (strcmp(argv[i], "--version") == 0) { (void) printf("%s\n", elsieid); exit(EXIT_SUCCESS); + } else if (strcmp(argv[i], "--help") == 0) { + usage(stdout, EXIT_SUCCESS); } while ((c = getopt(argc, argv, "d:l:p:L:vsy:")) != EOF && c != -1) switch (c) { default: - usage(); + usage(stderr, EXIT_FAILURE); case 'd': if (directory == NULL) directory = optarg; @@ -561,7 +565,7 @@ break; } if (optind == argc - 1 && strcmp(argv[optind], "=") == 0) - usage(); /* usage message by request */ + usage(stderr, EXIT_FAILURE); /* usage message by request */ if (directory == NULL) directory = TZDIR; if (yitcommand == NULL) -- Joseph S. Myers jsm@polyomino.org.uk
Joseph S. Myers schrieb:
The tools zdump and zic support the GNU-standard --version option (output version information to stdout and exit successfully), but not the associated --help option (output usage and bug reporting information to stdout and exit successfully). This patch adds such support. tzselect supports neither option, so this patch adds support for both options to it.
I've never understood the reasoning of the "GNU standard" (?!) behind this. Will not '--help' without this patch show the usage as well? Is it just the successful exit that is so important here? Sascha -- http://yoyodyne.ath.cx
On Fri, 2 Jan 2009, Sascha Wildner wrote:
Joseph S. Myers schrieb:
The tools zdump and zic support the GNU-standard --version option (output version information to stdout and exit successfully), but not the associated --help option (output usage and bug reporting information to stdout and exit successfully). This patch adds such support. tzselect supports neither option, so this patch adds support for both options to it.
I've never understood the reasoning of the "GNU standard" (?!) behind this. Will not '--help' without this patch show the usage as well? Is it just the successful exit that is so important here?
It will show the usage with a previous "invalid option -- '-'" error, on stderr which is less user-friendly if the output is piped through a pager (which is a natural enough habit given that many commands have rather long --help output). If you support one of the options I think you may as well support both of them properly, and I think doing so is strictly better than the present handling of --help. -- Joseph S. Myers jsm@polyomino.org.uk
participants (2)
-
Joseph S. Myers -
Sascha Wildner