[PROPOSED 1/3] zic now uses is_digit
Refactor zic.c to use is_digit like others use. * zic.c (is_digit): New static function, copied from localtime.c and from zdump.c. It’s too bad we can’t avoid duplication by putting this into private.h, because gcc -Wunused-function would then complain about it. Perhaps ‘inline’ would pacify gcc but then we’d have to port ‘inline’ to ancient compilers and anyway ‘inline’ is supposed to be just a performance hint which is not needed here. --- zic.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/zic.c b/zic.c index 39e1e2bc..30426621 100644 --- a/zic.c +++ b/zic.c @@ -229,6 +229,13 @@ static bool rulesub(struct rule * rp, const char * dayp, const char * timep); static zic_t tadd(zic_t t1, zic_t t2); +/* Is C an ASCII digit? */ +static bool +is_digit(char c) +{ + return '0' <= c && c <= '9'; +} + /* Bound on length of what %z can expand to. */ enum { PERCENT_Z_LEN_BOUND = sizeof "+995959" - 1 }; @@ -1852,7 +1859,7 @@ gethms(char const *string, char const *errstring) &hh, &hhx, &mm, &mmx, &ss, &ssx, &tenths, &xr, &xs)) { default: ok = false; break; case 8: - ok = '0' <= xr && xr <= '9'; + ok = is_digit(xr); ATTRIBUTE_FALLTHROUGH; case 7: ok &= ssx == '.'; @@ -3952,7 +3959,7 @@ newabbr(const char *string) cp = string; mp = NULL; - while (is_alpha(*cp) || ('0' <= *cp && *cp <= '9') + while (is_alpha(*cp) || is_digit(*cp) || *cp == '-' || *cp == '+') ++cp; if (noise && cp - string < 3) -- 2.51.0
* date.c, zic.c (main): Do not worry about getopt returning EOF as opposed to returning -1. The standards have long said that it returns -1 not EOF, and EOF == -1 on all known platforms anyway. The business with EOF is merely long-obsolete confusion about getopt return values. --- date.c | 2 +- zic.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/date.c b/date.c index b62f04d7..ba62c0b5 100644 --- a/date.c +++ b/date.c @@ -64,7 +64,7 @@ main(const int argc, char *argv[]) textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT */ t = time(NULL); - while ((ch = getopt(argc, argv, "ucr:")) != EOF && ch != -1) { + while ((ch = getopt(argc, argv, "ucr:")) != -1) { switch (ch) { default: usage(); diff --git a/zic.c b/zic.c index 30426621..eca7820f 100644 --- a/zic.c +++ b/zic.c @@ -1040,8 +1040,7 @@ main(int argc, char **argv) } else if (strcmp(argv[k], "--help") == 0) { usage(stdout, EXIT_SUCCESS); } - while ((c = getopt(argc, argv, "b:d:l:L:p:r:R:st:vy:")) != EOF - && c != -1) + while ((c = getopt(argc, argv, "b:d:l:L:p:r:R:st:vy:")) != -1) switch (c) { default: usage(stderr, EXIT_FAILURE); -- 2.51.0
* zic.c (usage): Omit unnecessary “'”s from help output. Unlike -r, the -R option-arg cannot be empty, so there is no need to quote it. --- zic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zic.c b/zic.c index eca7820f..b1923438 100644 --- a/zic.c +++ b/zic.c @@ -705,7 +705,7 @@ usage(FILE *stream, int status) _("%s: usage is %s [ --version ] [ --help ] [ -v ] \\\n" "\t[ -b {slim|fat} ] [ -d directory ] [ -l localtime ]" " [ -L leapseconds ] \\\n" - "\t[ -p posixrules ] [ -r '[@lo][/@hi]' ] [ -R '@hi' ] \\\n" + "\t[ -p posixrules ] [ -r '[@lo][/@hi]' ] [ -R @hi ] \\\n" "\t[ -t localtime-link ] \\\n" "\t[ filename ... ]\n\n" "Report bugs to %s.\n"), -- 2.51.0
účastníci (1)
-
Paul Eggert