[PROPOSED 1/2] Refactor duplicate duplicate-option code
* zic.c (duplicate_options): New function. (main): Use it. --- zic.c | 73 +++++++++++++++++++---------------------------------------- 1 file changed, 23 insertions(+), 50 deletions(-) diff --git a/zic.c b/zic.c index 67bcaa43..34e7d91c 100644 --- a/zic.c +++ b/zic.c @@ -708,6 +708,13 @@ close_file(FILE *stream, char const *dir, char const *name, } } +ATTRIBUTE_NORETURN static void +duplicate_options(char const *opt) +{ + fprintf(stderr, _("%s: More than one %s option specified\n"), progname, opt); + exit(EXIT_FAILURE); +} + ATTRIBUTE_NORETURN static void usage(FILE *stream, int status) { @@ -1063,73 +1070,39 @@ main(int argc, char **argv) error(_("invalid option: -b '%s'"), optarg); break; case 'd': - if (directory == NULL) - directory = optarg; - else { - fprintf(stderr, - _("%s: More than one -d option" - " specified\n"), - progname); - return EXIT_FAILURE; - } + if (directory) + duplicate_options("-d"); + directory = optarg; break; case 'l': - if (lcltime == NULL) - lcltime = optarg; - else { - fprintf(stderr, - _("%s: More than one -l option" - " specified\n"), - progname); - return EXIT_FAILURE; - } + if (lcltime) + duplicate_options("-l"); + lcltime = optarg; break; case 'p': - if (psxrules == NULL) - psxrules = optarg; - else { - fprintf(stderr, - _("%s: More than one -p option" - " specified\n"), - progname); - return EXIT_FAILURE; - } + if (psxrules) + duplicate_options("-p"); + psxrules = optarg; break; case 't': - if (tzdefault != NULL) { - fprintf(stderr, - _("%s: More than one -t option" - " specified\n"), - progname); - return EXIT_FAILURE; - } + if (tzdefault) + duplicate_options("-t"); tzdefault = optarg; break; case 'y': warning(_("-y ignored")); break; case 'L': - if (leapsec == NULL) - leapsec = optarg; - else { - fprintf(stderr, - _("%s: More than one -L option" - " specified\n"), - progname); - return EXIT_FAILURE; - } + if (leapsec) + duplicate_options("-L"); + leapsec = optarg; break; case 'v': noise = true; break; case 'r': - if (timerange_given) { - fprintf(stderr, - _("%s: More than one -r option" - " specified\n"), - progname); - return EXIT_FAILURE; - } + if (timerange_given) + duplicate_options("-r"); if (! timerange_option(optarg)) { fprintf(stderr, _("%s: invalid time range: %s\n"), -- 2.48.1
* private.h (_) [!HAVE_GETTEXT]: Parenthesize result, for compatibility with the HAVE_GETTEXT case. (N_): New macro, useful in later patches. --- private.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/private.h b/private.h index 2008660d..2563ed7c 100644 --- a/private.h +++ b/private.h @@ -1068,8 +1068,9 @@ time_t timeoff(struct tm *, long); #if HAVE_GETTEXT # define _(msgid) gettext(msgid) #else /* !HAVE_GETTEXT */ -# define _(msgid) msgid +# define _(msgid) (msgid) #endif /* !HAVE_GETTEXT */ +#define N_(msgid) (msgid) #if !defined TZ_DOMAIN && defined HAVE_GETTEXT # define TZ_DOMAIN "tz" -- 2.48.1
účastníci (1)
-
Paul Eggert