From 7eb7c7349c80e28c531b65d7d196a1bac279aa1c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 20 Aug 2014 08:13:31 -0700 Subject: [PATCH] Use bool for boolean. The tz source code predates C99 and so used int, 0 and 1 for boolean, but nowadays bool is available and makes the code clearer. Include backwards-compatibility definitions for pre-C99 platforms, and don't go beyond what the backwards-compatibility defintions support. * date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime): * localtime.c (struct ttinfo, struct state, gmt_is_set) (differ_by_repeat, tzload, typesequiv, getoffset, transtime) (tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck) (localtime_tzset, timesub, increment_overflow) (increment_overflow32, increment_overflow_time) (normalize_overflow, normalize_overflow32, time2sub, time2) (time1): * strftime.c (_fmt, _yconv, _loc): * zdump.c (warned, errout, is_alpha, my_localtime, abbrok) (main, hunt, show): * zic.c (struct rule, errors, warnings, leapseen, noise) (leap_types, ttisstds, ttisgmts, error, warning, main, dolink) (associate, infile, gethms, inzone, inzcont, inzsub, inleap) (rulesub, is32, writezone, doabbr, stringoffset, stringrule) (stringzone, outzone, addtype, leapadd, yearistype, is_space) (is_alpha, ciequal, itsabbr, mkdirs): Use bool for boolean. * localtime.c (tzload, tzparse): * zic.c (stringoffset, mkdirs): Return true for success and false for failure instead of 0 and -1. All callers changed. * private.h, zdump.c (TRUE, FALSE): Remove, replacing by ... (true, false, bool): Define by if C99 or later, by macros otherwise. * tzfile.h: Remove mention of TRUE and FALSE from commentary. * zic.c (addtype): Remove now-unnecessary checks that a bool is a boolean. --- date.c | 63 ++++++------- localtime.c | 193 +++++++++++++++++++------------------- private.h | 14 +-- strftime.c | 26 +++--- tzfile.h | 8 +- zdump.c | 58 ++++++------ zic.c | 262 +++++++++++++++++++++++++--------------------------- 7 files changed, 304 insertions(+), 320 deletions(-) diff --git a/date.c b/date.c index c2a39f2..c8fab75 100644 --- a/date.c +++ b/date.c @@ -54,7 +54,7 @@ extern char * tzname[2]; static int retval = EXIT_SUCCESS; -static void checkfinal(const char *, int, time_t, time_t); +static void checkfinal(char const *, bool, time_t, time_t); static time_t convert(const char *, int, time_t); static void display(const char *, time_t); static void dogmt(void); @@ -75,12 +75,12 @@ main(const int argc, char *argv[]) register const char * value; register const char * cp; register int ch; - register int dousg; - register int aflag = 0; - register int dflag = 0; - register int nflag = 0; - register int tflag = 0; - register int rflag = 0; + register bool dousg; + register bool aflag = false; + register bool dflag = false; + register bool nflag = false; + register bool tflag = false; + register bool rflag = false; register int minuteswest; register int dsttime; register double adjust; @@ -115,7 +115,7 @@ main(const int argc, char *argv[]) _("date: error: multiple -r's used")); usage(); } - rflag = 1; + rflag = true; errno = 0; secs = strtoimax (optarg, &endarg, 0); if (*endarg || optarg == endarg) @@ -130,7 +130,7 @@ main(const int argc, char *argv[]) t = secs; break; case 'n': /* don't set network */ - nflag = 1; + nflag = true; break; case 'd': /* daylight saving time */ if (dflag) { @@ -138,7 +138,7 @@ main(const int argc, char *argv[]) _("date: error: multiple -d's used")); usage(); } - dflag = 1; + dflag = true; cp = optarg; dsttime = atoi(cp); if (*cp == '\0' || *nondigit(cp) != '\0') @@ -151,7 +151,7 @@ main(const int argc, char *argv[]) _("date: error: multiple -t's used")); usage(); } - tflag = 1; + tflag = true; cp = optarg; minuteswest = atoi(cp); if (*cp == '+' || *cp == '-') @@ -166,7 +166,7 @@ main(const int argc, char *argv[]) _("date: error: multiple -a's used")); usage(); } - aflag = 1; + aflag = true; cp = optarg; adjust = atof(cp); if (*cp == '+' || *cp == '-') @@ -208,9 +208,9 @@ _("date: error: multiple values in command line\n")); ** even if time_t's range all the way back to the thirteenth ** century. Do not change the order. */ - t = convert(value, (dousg = TRUE), now); + t = convert(value, (dousg = true), now); if (t == -1) - t = convert(value, (dousg = FALSE), now); + t = convert(value, (dousg = false), now); if (t == -1) { /* ** Out of range values, @@ -231,9 +231,9 @@ _("date: error: multiple values in command line\n")); _("out of range seconds given")); } dogmt(); - t = convert(value, FALSE, now); + t = convert(value, false, now); if (t == -1) - t = convert(value, TRUE, now); + t = convert(value, true, now); wildinput(_("time"), value, (t == -1) ? _("out of range value given") : @@ -334,7 +334,7 @@ dogmt(void) /*ARGSUSED*/ static void -reset(const time_t newt, const int nflag) +reset(time_t newt, bool nflag) { register int fid; time_t oldt; @@ -433,14 +433,14 @@ extern int logwtmp(); #endif /* HAVE_SETTIMEOFDAY == 1 */ #ifdef TSP_SETDATE -static int netsettime(struct timeval); +static bool netsettime(struct timeval); #endif #ifndef TSP_SETDATE /*ARGSUSED*/ #endif /* !defined TSP_SETDATE */ static void -reset(const time_t newt, const int nflag) +reset(time_t newt, bool nflag) { register const char * username; static struct timeval tv; /* static so tv_usec is 0 */ @@ -578,7 +578,7 @@ timeout(FILE *const fp, const char *const format, const struct tm *tmp) free(cp); } -static int +static bool sametm(register const struct tm *const atmp, register const struct tm *const btmp) { @@ -598,7 +598,7 @@ sametm(register const struct tm *const atmp, #define ATOI2(ar) (ar[0] - '0') * 10 + (ar[1] - '0'); ar += 2; static time_t -convert(register const char * const value, const int dousg, const time_t t) +convert(char const *value, bool dousg, time_t t) { register const char * cp; register const char * dotp; @@ -705,10 +705,7 @@ convert(register const char * const value, const int dousg, const time_t t) */ static void -checkfinal(const char * const value, - const int didusg, - const time_t t, - const time_t oldnow) +checkfinal(char const *value, bool didusg, time_t t, time_t oldnow) { time_t othert; struct tm tm, *tmp; @@ -776,7 +773,7 @@ iffy(const time_t thist, const time_t thatt, const char * const value, const char * const reason) { struct tm *tmp; - int dst; + bool dst; fprintf(stderr, _("date: warning: ambiguous time \"%s\", %s.\n"), value, reason); @@ -788,7 +785,7 @@ iffy(const time_t thist, const time_t thatt, %M\ %Y.%S\n"), tmp); tmp = localtime(&thist); - dst = tmp ? tmp->tm_isdst : 0; + dst = tmp && tmp->tm_isdst; timeout(stderr, _("to get %c"), tmp); fprintf(stderr, _(" (%s). Use\n"), dst ? _("summer time") : _("standard time")); @@ -797,7 +794,7 @@ iffy(const time_t thist, const time_t thatt, %M\ %Y.%S\n"), tmp); tmp = localtime(&thatt); - dst = tmp ? tmp->tm_isdst : 0; + dst = tmp && tmp->tm_isdst; timeout(stderr, _("to get %c"), tmp); fprintf(stderr, _(" (%s).\n"), dst ? _("summer time") : _("standard time")); @@ -815,9 +812,9 @@ iffy(const time_t thist, const time_t thatt, * If the timedaemon is in the master state, it performs the * correction on all slaves. If it is in the slave state, it * notifies the master that a correction is needed. - * Returns 1 on success, 0 on failure. + * Return true on success. */ -static int +static bool netsettime(struct timeval ntv) { int s, length, port, timed_ack, found, err, waittime; @@ -832,7 +829,7 @@ netsettime(struct timeval ntv) if (! sp) { fputs(_("udp/timed: unknown service\n"), stderr); retval = 2; - return (0); + return false; } dest.sin_port = sp->s_port; dest.sin_family = AF_INET; @@ -915,7 +912,7 @@ loop: case TSP_DATEACK: lose(s); - return (1); + return true; default: fprintf(stderr, @@ -931,6 +928,6 @@ loop: bad: lose(s); retval = 2; - return (0); + return false; } #endif /* defined TSP_SETDATE */ diff --git a/localtime.c b/localtime.c index 0a16f49..e88e335 100644 --- a/localtime.c +++ b/localtime.c @@ -92,10 +92,10 @@ static const char gmt[] = "GMT"; struct ttinfo { /* time type information */ int_fast32_t tt_gmtoff; /* UT offset in seconds */ - int tt_isdst; /* used to set tm_isdst */ + bool tt_isdst; /* used to set tm_isdst */ int tt_abbrind; /* abbreviation list index */ - int tt_ttisstd; /* TRUE if transition is std time */ - int tt_ttisgmt; /* TRUE if transition is UT */ + bool tt_ttisstd; /* transition is std time */ + bool tt_ttisgmt; /* transition is UT */ }; struct lsinfo { /* leap second information */ @@ -117,8 +117,8 @@ struct state { int timecnt; int typecnt; int charcnt; - int goback; - int goahead; + bool goback; + bool goahead; time_t ats[TZ_MAX_TIMES]; unsigned char types[TZ_MAX_TIMES]; struct ttinfo ttis[TZ_MAX_TYPES]; @@ -141,13 +141,13 @@ struct rule { #define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d = month, week, day of week */ static struct tm *gmtsub(time_t const *, int_fast32_t, struct tm *); -static int increment_overflow(int *, int); -static int increment_overflow_time(time_t *, int_fast32_t); -static int normalize_overflow32(int_fast32_t *, int *, int); +static bool increment_overflow(int *, int); +static bool increment_overflow_time(time_t *, int_fast32_t); +static bool normalize_overflow32(int_fast32_t *, int *, int); static struct tm *timesub(time_t const *, int_fast32_t, struct state const *, struct tm *); -static int typesequiv(struct state const *, int, int); -static int tzparse(char const *, struct state *, int); +static bool typesequiv(struct state const *, int, int); +static bool tzparse(char const *, struct state *, bool); #ifdef ALL_STATE static struct state * lclptr; @@ -167,7 +167,7 @@ static struct state gmtmem; static char lcl_TZname[TZ_STRLEN_MAX + 1]; static int VOLATILE lcl_is_set; -static int VOLATILE gmt_is_set; +static bool VOLATILE gmt_is_set; char * tzname[2] = { (char *) wildabbr, @@ -281,7 +281,7 @@ settzname(void) } } -static int +static bool differ_by_repeat(const time_t t1, const time_t t0) { if (TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS) @@ -289,9 +289,9 @@ differ_by_repeat(const time_t t1, const time_t t0) return t1 - t0 == SECSPERREPEAT; } -static int +static bool tzload(register const char *name, register struct state *const sp, - register const int doextend) + bool doextend) { register const char * p; register int i; @@ -322,12 +322,12 @@ tzload(register const char *name, register struct state *const sp, }; register char *fullname; register u_t *up; - register int doaccess; + register bool doaccess; register union local_storage *lsp; #ifdef ALL_STATE lsp = malloc(sizeof *lsp); if (!lsp) - return -1; + return false; #else /* !defined ALL_STATE */ union local_storage ls; lsp = &ls; @@ -335,7 +335,7 @@ tzload(register const char *name, register struct state *const sp, fullname = lsp->fullname; up = &lsp->u.u; - sp->goback = sp->goahead = FALSE; + sp->goback = sp->goahead = false; if (! name) { name = TZDEFAULT; @@ -355,7 +355,7 @@ tzload(register const char *name, register struct state *const sp, strcat(fullname, name); /* Set doaccess if '.' (as in "../") shows up in name. */ if (strchr(name, '.')) - doaccess = TRUE; + doaccess = true; name = fullname; } if (doaccess && access(name, R_OK) != 0) @@ -475,12 +475,11 @@ tzload(register const char *name, register struct state *const sp, ttisp = &sp->ttis[i]; if (ttisstdcnt == 0) - ttisp->tt_ttisstd = FALSE; + ttisp->tt_ttisstd = false; else { - ttisp->tt_ttisstd = *p++; - if (ttisp->tt_ttisstd != TRUE && - ttisp->tt_ttisstd != FALSE) + if (*p != true && *p != false) goto oops; + ttisp->tt_ttisstd = *p++; } } for (i = 0; i < sp->typecnt; ++i) { @@ -488,12 +487,11 @@ tzload(register const char *name, register struct state *const sp, ttisp = &sp->ttis[i]; if (ttisgmtcnt == 0) - ttisp->tt_ttisgmt = FALSE; + ttisp->tt_ttisgmt = false; else { - ttisp->tt_ttisgmt = *p++; - if (ttisp->tt_ttisgmt != TRUE && - ttisp->tt_ttisgmt != FALSE) + if (*p != true && *p != false) goto oops; + ttisp->tt_ttisgmt = *p++; } } /* @@ -514,12 +512,11 @@ tzload(register const char *name, register struct state *const sp, up->buf[0] == '\n' && up->buf[nread - 1] == '\n' && sp->typecnt + 2 <= TZ_MAX_TYPES) { struct state *ts = &lsp->u.st; - register int result; up->buf[nread - 1] = '\0'; - result = tzparse(&up->buf[1], ts, FALSE); - if (result == 0 && ts->typecnt == 2 && - sp->charcnt + ts->charcnt <= TZ_MAX_CHARS) { + if (tzparse(&up->buf[1], ts, false) + && ts->typecnt == 2 + && sp->charcnt + ts->charcnt <= TZ_MAX_CHARS) { for (i = 0; i < 2; ++i) ts->ttis[i].tt_abbrind += sp->charcnt; @@ -549,7 +546,7 @@ tzload(register const char *name, register struct state *const sp, for (i = 1; i < sp->timecnt; ++i) if (typesequiv(sp, sp->types[i], sp->types[0]) && differ_by_repeat(sp->ats[i], sp->ats[0])) { - sp->goback = TRUE; + sp->goback = true; break; } for (i = sp->timecnt - 2; i >= 0; --i) @@ -557,7 +554,7 @@ tzload(register const char *name, register struct state *const sp, sp->types[i]) && differ_by_repeat(sp->ats[sp->timecnt - 1], sp->ats[i])) { - sp->goahead = TRUE; + sp->goahead = true; break; } } @@ -598,23 +595,23 @@ tzload(register const char *name, register struct state *const sp, #ifdef ALL_STATE free(up); #endif /* defined ALL_STATE */ - return 0; + return true; oops: #ifdef ALL_STATE free(up); #endif /* defined ALL_STATE */ - return -1; + return false; } -static int +static bool typesequiv(const struct state *const sp, const int a, const int b) { - register int result; + register bool result; if (sp == NULL || a < 0 || a >= sp->typecnt || b < 0 || b >= sp->typecnt) - result = FALSE; + result = false; else { register const struct ttinfo * ap = &sp->ttis[a]; register const struct ttinfo * bp = &sp->ttis[b]; @@ -752,10 +749,10 @@ getsecs(register const char *strp, int_fast32_t *const secsp) static const char * getoffset(register const char *strp, int_fast32_t *const offsetp) { - register int neg = 0; + register bool neg = false; if (*strp == '-') { - neg = 1; + neg = true; ++strp; } else if (*strp == '+') ++strp; @@ -829,7 +826,7 @@ static int_fast32_t ATTRIBUTE_PURE transtime(const int year, register const struct rule *const rulep, const int_fast32_t offset) { - register int leapyear; + register bool leapyear; register int_fast32_t value; register int i; int d, m1, yy0, yy1, yy2, dow; @@ -916,9 +913,9 @@ transtime(const int year, register const struct rule *const rulep, ** appropriate. */ -static int +static bool tzparse(const char *name, register struct state *const sp, - const int lastditch) + bool lastditch) { const char * stdname; const char * dstname; @@ -927,7 +924,7 @@ tzparse(const char *name, register struct state *const sp, int_fast32_t stdoffset; int_fast32_t dstoffset; register char * cp; - register int load_result; + register bool load_ok; static struct ttinfo zttinfo; stdname = name; @@ -943,7 +940,7 @@ tzparse(const char *name, register struct state *const sp, stdname = name; name = getqzname(name, '>'); if (*name != '>') - return (-1); + return false; stdlen = name - stdname; name++; } else { @@ -951,20 +948,20 @@ tzparse(const char *name, register struct state *const sp, stdlen = name - stdname; } if (*name == '\0') - return -1; + return false; name = getoffset(name, &stdoffset); if (name == NULL) - return -1; + return false; } - load_result = tzload(TZDEFRULES, sp, FALSE); - if (load_result != 0) + load_ok = tzload(TZDEFRULES, sp, false); + if (!load_ok) sp->leapcnt = 0; /* so, we're off a little */ if (*name != '\0') { if (*name == '<') { dstname = ++name; name = getqzname(name, '>'); if (*name != '>') - return -1; + return false; dstlen = name - dstname; name++; } else { @@ -975,9 +972,9 @@ tzparse(const char *name, register struct state *const sp, if (*name != '\0' && *name != ',' && *name != ';') { name = getoffset(name, &dstoffset); if (name == NULL) - return -1; + return false; } else dstoffset = stdoffset - SECSPERHOUR; - if (*name == '\0' && load_result != 0) + if (*name == '\0' && !load_ok) name = TZDEFRULESTRING; if (*name == ',' || *name == ';') { struct rule start; @@ -989,23 +986,23 @@ tzparse(const char *name, register struct state *const sp, ++name; if ((name = getrule(name, &start)) == NULL) - return -1; + return false; if (*name++ != ',') - return -1; + return false; if ((name = getrule(name, &end)) == NULL) - return -1; + return false; if (*name != '\0') - return -1; + return false; sp->typecnt = 2; /* standard time and DST */ /* ** Two transitions per year, from EPOCH_YEAR forward. */ sp->ttis[0] = sp->ttis[1] = zttinfo; sp->ttis[0].tt_gmtoff = -dstoffset; - sp->ttis[0].tt_isdst = 1; + sp->ttis[0].tt_isdst = true; sp->ttis[0].tt_abbrind = stdlen + 1; sp->ttis[1].tt_gmtoff = -stdoffset; - sp->ttis[1].tt_isdst = 0; + sp->ttis[1].tt_isdst = false; sp->ttis[1].tt_abbrind = 0; sp->defaulttype = 0; timecnt = 0; @@ -1018,7 +1015,7 @@ tzparse(const char *name, register struct state *const sp, int_fast32_t yearsecs = (year_lengths[isleap(year)] * SECSPERDAY); - int reversed = endtime < starttime; + bool reversed = endtime < starttime; if (reversed) { int_fast32_t swap = starttime; starttime = endtime; @@ -1053,12 +1050,12 @@ tzparse(const char *name, register struct state *const sp, register int_fast32_t theirstdoffset; register int_fast32_t theirdstoffset; register int_fast32_t theiroffset; - register int isdst; + register bool isdst; register int i; register int j; if (*name != '\0') - return -1; + return false; /* ** Initial values of theirstdoffset and theirdstoffset. */ @@ -1083,7 +1080,7 @@ tzparse(const char *name, register struct state *const sp, /* ** Initially we're assumed to be in standard time. */ - isdst = FALSE; + isdst = false; theiroffset = theirstdoffset; /* ** Now juggle transition times and types @@ -1127,10 +1124,10 @@ tzparse(const char *name, register struct state *const sp, */ sp->ttis[0] = sp->ttis[1] = zttinfo; sp->ttis[0].tt_gmtoff = -stdoffset; - sp->ttis[0].tt_isdst = FALSE; + sp->ttis[0].tt_isdst = false; sp->ttis[0].tt_abbrind = 0; sp->ttis[1].tt_gmtoff = -dstoffset; - sp->ttis[1].tt_isdst = TRUE; + sp->ttis[1].tt_isdst = true; sp->ttis[1].tt_abbrind = stdlen + 1; sp->typecnt = 2; sp->defaulttype = 0; @@ -1141,7 +1138,7 @@ tzparse(const char *name, register struct state *const sp, sp->timecnt = 0; sp->ttis[0] = zttinfo; sp->ttis[0].tt_gmtoff = -stdoffset; - sp->ttis[0].tt_isdst = 0; + sp->ttis[0].tt_isdst = false; sp->ttis[0].tt_abbrind = 0; sp->defaulttype = 0; } @@ -1149,7 +1146,7 @@ tzparse(const char *name, register struct state *const sp, if (dstlen != 0) sp->charcnt += dstlen + 1; if ((size_t) sp->charcnt > sizeof sp->chars) - return -1; + return false; cp = sp->chars; strncpy(cp, stdname, stdlen); cp += stdlen; @@ -1158,14 +1155,14 @@ tzparse(const char *name, register struct state *const sp, strncpy(cp, dstname, dstlen); *(cp + dstlen) = '\0'; } - return 0; + return true; } static void gmtload(struct state *const sp) { - if (tzload(gmt, sp, TRUE) != 0) - tzparse(gmt, sp, TRUE); + if (! tzload(gmt, sp, true)) + tzparse(gmt, sp, true); } static void @@ -1177,7 +1174,7 @@ tzsetwall_unlocked(void) if (! lclptr) lclptr = malloc(sizeof *lclptr); #endif - if (lclptr && tzload(NULL, lclptr, TRUE) != 0) + if (lclptr && ! tzload(NULL, lclptr, true)) gmtload(lclptr); settzname(); lcl_is_set = -1; @@ -1197,7 +1194,7 @@ tzsetwall(void) static void tzset_unlocked(void) { - int shortname; + bool shortname; register char const *name = getenv("TZ"); if (!name) { @@ -1221,12 +1218,12 @@ tzset_unlocked(void) lclptr->leapcnt = 0; /* so, we're off a little */ lclptr->timecnt = 0; lclptr->typecnt = 0; - lclptr->ttis[0].tt_isdst = 0; + lclptr->ttis[0].tt_isdst = false; lclptr->ttis[0].tt_gmtoff = 0; lclptr->ttis[0].tt_abbrind = 0; strcpy(lclptr->chars, gmt); - } else if (tzload(name, lclptr, TRUE) != 0) - if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0) + } else if (! tzload(name, lclptr, true)) + if (name[0] == ':' || ! tzparse(name, lclptr, false)) gmtload(lclptr); } settzname(); @@ -1252,7 +1249,7 @@ gmtcheck(void) #endif if (gmtptr) gmtload(gmtptr); - gmt_is_set = TRUE; + gmt_is_set = true; } /* @@ -1341,7 +1338,7 @@ localsub(const time_t *const timep, const int_fast32_t offset, } static struct tm * -localtime_tzset(time_t const *timep, struct tm *tmp, int skip_tzset) +localtime_tzset(time_t const *timep, struct tm *tmp, bool skip_tzset) { int err = lock(); if (err) { @@ -1460,11 +1457,11 @@ timesub(const time_t *const timep, const int_fast32_t offset, int y; register const int * ip; register int_fast64_t corr; - register int hit; + register bool hit; register int i; corr = 0; - hit = 0; + hit = false; i = (sp == NULL) ? 0 : sp->leapcnt; while (--i >= 0) { lp = &sp->lsis[i]; @@ -1613,7 +1610,7 @@ ctime_r(const time_t *const timep, char *buf) ** Normalize logic courtesy Paul Eggert. */ -static int +static bool increment_overflow(int *const ip, int j) { register int const i = *ip; @@ -1625,23 +1622,23 @@ increment_overflow(int *const ip, int j) ** or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow. */ if ((i >= 0) ? (j > INT_MAX - i) : (j < INT_MIN - i)) - return TRUE; + return true; *ip += j; - return FALSE; + return false; } -static int +static bool increment_overflow32(int_fast32_t *const lp, int const m) { register int_fast32_t const l = *lp; if ((l >= 0) ? (m > INT_FAST32_MAX - l) : (m < INT_FAST32_MIN - l)) - return TRUE; + return true; *lp += m; - return FALSE; + return false; } -static int +static bool increment_overflow_time(time_t *tp, int_fast32_t j) { /* @@ -1652,12 +1649,12 @@ increment_overflow_time(time_t *tp, int_fast32_t j) if (! (j < 0 ? (TYPE_SIGNED(time_t) ? time_t_min - j <= *tp : -1 - j < *tp) : *tp <= time_t_max - j)) - return TRUE; + return true; *tp += j; - return FALSE; + return false; } -static int +static bool normalize_overflow(int *const tensptr, int *const unitsptr, const int base) { register int tensdelta; @@ -1669,7 +1666,7 @@ normalize_overflow(int *const tensptr, int *const unitsptr, const int base) return increment_overflow(tensptr, tensdelta); } -static int +static bool normalize_overflow32(int_fast32_t *const tensptr, int *const unitsptr, const int base) { @@ -1702,8 +1699,8 @@ static time_t time2sub(struct tm *const tmp, struct tm *(*const funcp)(const time_t *, int_fast32_t, struct tm *), const int_fast32_t offset, - int *const okayp, - const int do_norm_secs) + bool *okayp, + bool do_norm_secs) { register const struct state * sp; register int dir; @@ -1717,7 +1714,7 @@ time2sub(struct tm *const tmp, time_t t; struct tm yourtm, mytm; - *okayp = FALSE; + *okayp = false; yourtm = *tmp; if (do_norm_secs) { if (normalize_overflow(&yourtm.tm_min, &yourtm.tm_sec, @@ -1870,7 +1867,7 @@ label: return WRONG; t = newt; if ((*funcp)(&t, offset, tmp)) - *okayp = TRUE; + *okayp = true; return t; } @@ -1878,7 +1875,7 @@ static time_t time2(struct tm * const tmp, struct tm * (*const funcp)(const time_t *, int_fast32_t, struct tm *), const int_fast32_t offset, - int *const okayp) + bool *okayp) { time_t t; @@ -1887,8 +1884,8 @@ time2(struct tm * const tmp, ** (in case tm_sec contains a value associated with a leap second). ** If that fails, try with normalization of seconds. */ - t = time2sub(tmp, funcp, offset, okayp, FALSE); - return *okayp ? t : time2sub(tmp, funcp, offset, okayp, TRUE); + t = time2sub(tmp, funcp, offset, okayp, false); + return *okayp ? t : time2sub(tmp, funcp, offset, okayp, true); } static time_t @@ -1904,7 +1901,7 @@ time1(struct tm *const tmp, register int nseen; char seen[TZ_MAX_TYPES]; unsigned char types[TZ_MAX_TYPES]; - int okay; + bool okay; if (tmp == NULL) { errno = EINVAL; @@ -1934,11 +1931,11 @@ time1(struct tm *const tmp, if (sp == NULL) return WRONG; for (i = 0; i < sp->typecnt; ++i) - seen[i] = FALSE; + seen[i] = false; nseen = 0; for (i = sp->timecnt - 1; i >= 0; --i) if (!seen[sp->types[i]]) { - seen[sp->types[i]] = TRUE; + seen[sp->types[i]] = true; types[nseen++] = sp->types[i]; } for (sameind = 0; sameind < nseen; ++sameind) { diff --git a/private.h b/private.h index 2389e37..529b1dc 100644 --- a/private.h +++ b/private.h @@ -365,13 +365,13 @@ const char * scheck(const char * string, const char * format); ** Finally, some convenience items. */ -#ifndef TRUE -#define TRUE 1 -#endif /* !defined TRUE */ - -#ifndef FALSE -#define FALSE 0 -#endif /* !defined FALSE */ +#if __STDC_VERSION__ < 199901 +# define true 1 +# define false 0 +# define bool int +#else +# include +#endif #ifndef TYPE_BIT #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) diff --git a/strftime.c b/strftime.c index 259c90a..8f75499 100644 --- a/strftime.c +++ b/strftime.c @@ -101,7 +101,7 @@ static char * _add(const char *, char *, const char *); static char * _conv(int, const char *, char *, const char *); static char * _fmt(const char *, const struct tm *, char *, const char *, int *); -static char * _yconv(int, int, int, int, char *, const char *); +static char * _yconv(int, int, bool, bool, char *, char const *); extern char * tzname[]; @@ -193,8 +193,8 @@ label: ** something completely different. ** (ado, 1993-05-24) */ - pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0, - pt, ptlim); + pt = _yconv(t->tm_year, TM_YEAR_BASE, + true, false, pt, ptlim); continue; case 'c': { @@ -422,9 +422,11 @@ label: pt, ptlim); else if (*format == 'g') { *warnp = IN_ALL; - pt = _yconv(year, base, 0, 1, + pt = _yconv(year, base, + false, true, pt, ptlim); - } else pt = _yconv(year, base, 1, 1, + } else pt = _yconv(year, base, + true, true, pt, ptlim); } continue; @@ -462,11 +464,13 @@ label: continue; case 'y': *warnp = IN_ALL; - pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1, + pt = _yconv(t->tm_year, TM_YEAR_BASE, + false, true, pt, ptlim); continue; case 'Y': - pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1, + pt = _yconv(t->tm_year, TM_YEAR_BASE, + true, true, pt, ptlim); continue; case 'Z': @@ -585,7 +589,7 @@ _add(const char *str, char *pt, const char *const ptlim) */ static char * -_yconv(const int a, const int b, const int convert_top, const int convert_yy, +_yconv(int a, int b, bool convert_top, bool convert_yy, char *pt, const char *const ptlim) { register int lead; @@ -621,7 +625,7 @@ _loc(void) static char * locale_buf; int fd; - int oldsun; /* "...ain't got nothin' to do..." */ + bool oldsun; /* "...ain't got nothin' to do..." */ char * lbuf; char * name; char * p; @@ -659,14 +663,14 @@ _loc(void) if (sizeof filename < ((sizeof locale_home) + namesize + (sizeof lc_time))) goto no_locale; - oldsun = 0; + oldsun = false; sprintf(filename, "%s/%s/%s", locale_home, name, lc_time); fd = open(filename, O_RDONLY); if (fd < 0) { /* ** Old Sun systems have a different naming and data convention. */ - oldsun = 1; + oldsun = true; sprintf(filename, "%s/%s/%s", locale_home, lc_time, name); fd = open(filename, O_RDONLY); diff --git a/tzfile.h b/tzfile.h index 150f956..ebecd68 100644 --- a/tzfile.h +++ b/tzfile.h @@ -62,13 +62,13 @@ struct tzhead { ** tzh_leapcnt repetitions of ** one (char [4]) coded leap second transition times ** one (char [4]) total correction after above -** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition -** time is standard time, if FALSE, +** tzh_ttisstdcnt (char)s indexed by type; if 1, transition +** time is standard time, if 0, ** transition time is wall clock time ** if absent, transition times are ** assumed to be wall clock time -** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition -** time is UT, if FALSE, +** tzh_ttisgmtcnt (char)s indexed by type; if 1, transition +** time is UT, if 0, ** transition time is local time ** if absent, transition times are ** assumed to be local time diff --git a/zdump.c b/zdump.c index 79286bf..8753d94 100644 --- a/zdump.c +++ b/zdump.c @@ -102,13 +102,13 @@ typedef long intmax_t; #define MAX_STRING_LENGTH 1024 #endif /* !defined MAX_STRING_LENGTH */ -#ifndef TRUE -#define TRUE 1 -#endif /* !defined TRUE */ - -#ifndef FALSE -#define FALSE 0 -#endif /* !defined FALSE */ +#if __STDC_VERSION__ < 199901 +# define true 1 +# define false 0 +# define bool int +#else +# include +#endif #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 @@ -222,24 +222,24 @@ static time_t const absolute_max_time = : -1); static size_t longest; static char * progname; -static int warned; -static int errout; +static bool warned; +static bool errout; static char *abbr(struct tm *); static intmax_t delta(struct tm *, struct tm *) ATTRIBUTE_PURE; static void dumptime(struct tm const *); static time_t hunt(char *, time_t, time_t); -static void show(char *, time_t, int); +static void show(char *, time_t, bool); static const char *tformat(void); static time_t yeartot(intmax_t) ATTRIBUTE_PURE; /* Is A an alphabetic character in the C locale? */ -static int +static bool is_alpha(char a) { switch (a) { default: - return 0; + return false; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': @@ -248,7 +248,7 @@ is_alpha(char a) case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': - return 1; + return true; } } @@ -282,7 +282,7 @@ my_localtime(time_t *tp) fprintf(stderr, " -> "); fprintf(stderr, tformat(), t); fprintf(stderr, "\n"); - errout = TRUE; + errout = true; } } return tmp; @@ -321,7 +321,7 @@ abbrok(const char *const abbrp, const char *const zone) fprintf(stderr, _("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"), progname, zone, abbrp, wp); - warned = errout = TRUE; + warned = errout = true; } static void @@ -352,8 +352,8 @@ int main(int argc, char *argv[]) { register int i; - register int vflag; - register int Vflag; + register bool vflag; + register bool Vflag; register char * cutarg; register char * cuttimes; register time_t cutlotime; @@ -384,14 +384,14 @@ main(int argc, char *argv[]) } else if (strcmp(argv[i], "--help") == 0) { usage(stdout, EXIT_SUCCESS); } - vflag = Vflag = 0; + vflag = Vflag = false; cutarg = cuttimes = NULL; for (;;) switch (getopt(argc, argv, "c:t:vV")) { case 'c': cutarg = optarg; break; case 't': cuttimes = optarg; break; - case 'v': vflag = 1; break; - case 'V': Vflag = 1; break; + case 'v': vflag = true; break; + case 'V': Vflag = true; break; case -1: if (! (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) goto arg_processing_done; @@ -487,15 +487,15 @@ main(int argc, char *argv[]) strcpy(&fakeenv[0][3], argv[i]); if (! (vflag | Vflag)) { - show(argv[i], now, FALSE); + show(argv[i], now, false); continue; } - warned = FALSE; + warned = false; t = absolute_min_time; if (!Vflag) { - show(argv[i], t, TRUE); + show(argv[i], t, true); t += SECSPERDAY; - show(argv[i], t, TRUE); + show(argv[i], t, true); } if (t < cutlotime) t = cutlotime; @@ -533,9 +533,9 @@ main(int argc, char *argv[]) if (!Vflag) { t = absolute_max_time; t -= SECSPERDAY; - show(argv[i], t, TRUE); + show(argv[i], t, true); t += SECSPERDAY; - show(argv[i], t, TRUE); + show(argv[i], t, true); } } close_file(stdout); @@ -624,8 +624,8 @@ hunt(char *name, time_t lot, time_t hit) lotmp = tmp; } else hit = t; } - show(name, lot, TRUE); - show(name, hit, TRUE); + show(name, lot, true); + show(name, hit, true); return hit; } @@ -655,7 +655,7 @@ delta(struct tm * newp, struct tm *oldp) } static void -show(char *zone, time_t t, int v) +show(char *zone, time_t t, bool v) { register struct tm * tmp; diff --git a/zic.c b/zic.c index d230663..73ae17d 100644 --- a/zic.c +++ b/zic.c @@ -41,8 +41,8 @@ struct rule { zic_t r_loyear; /* for example, 1986 */ zic_t r_hiyear; /* for example, 1986 */ const char * r_yrtype; - int r_lowasnum; - int r_hiwasnum; + bool r_lowasnum; + bool r_hiwasnum; int r_month; /* 0..11 */ @@ -51,10 +51,10 @@ struct rule { int r_wday; zic_t r_tod; /* time from midnight */ - int r_todisstd; /* above is standard time if TRUE */ - /* or wall clock time if FALSE */ - int r_todisgmt; /* above is GMT if TRUE */ - /* or local time if FALSE */ + bool r_todisstd; /* above is standard time if 1 */ + /* or wall clock time if 0 */ + bool r_todisgmt; /* above is GMT if 1 */ + /* or local time if 0 */ zic_t r_stdoff; /* offset from standard time */ const char * r_abbrvar; /* variable part of abbreviation */ @@ -102,26 +102,25 @@ extern int optind; #endif static void addtt(zic_t starttime, int type); -static int addtype(zic_t gmtoff, const char * abbr, int isdst, - int ttisstd, int ttisgmt); -static void leapadd(zic_t t, int positive, int rolling, int count); +static int addtype(zic_t, char const *, bool, bool, bool); +static void leapadd(zic_t, bool, int, int); static void adjleap(void); static void associate(void); static void dolink(const char * fromfield, const char * tofield); static char ** getfields(char * buf); static zic_t gethms(const char * string, const char * errstring, - int signable); + bool); static void infile(const char * filename); static void inleap(char ** fields, int nfields); static void inlink(char ** fields, int nfields); static void inrule(char ** fields, int nfields); static int inzcont(char ** fields, int nfields); static int inzone(char ** fields, int nfields); -static int inzsub(char ** fields, int nfields, int iscont); +static bool inzsub(char **, int, bool); static int itsdir(const char * name); static int is_alpha(char a); static char lowerit(char); -static int mkdirs(char * filename); +static bool mkdirs(char *); static void newabbr(const char * abbr); static zic_t oadd(zic_t t1, zic_t t2); static void outzone(const struct zone * zp, int ntzones); @@ -134,11 +133,11 @@ static zic_t tadd(zic_t t1, zic_t t2); static int yearistype(int year, const char * type); static int charcnt; -static int errors; -static int warnings; +static bool errors; +static bool warnings; static const char * filename; static int leapcnt; -static int leapseen; +static bool leapseen; static zic_t leapminyear; static zic_t leapmaxyear; static int linenum; @@ -146,7 +145,7 @@ static int max_abbrvar_len; static int max_format_len; static zic_t max_year; static zic_t min_year; -static int noise; +static bool noise; static const char * rfilename; static int rlinenum; static const char * progname; @@ -322,8 +321,8 @@ static struct lookup const end_years[] = { }; static struct lookup const leap_types[] = { - { "Rolling", TRUE }, - { "Stationary", FALSE }, + { "Rolling", true }, + { "Stationary", false }, { NULL, 0 } }; @@ -343,8 +342,8 @@ static struct attype { static zic_t gmtoffs[TZ_MAX_TYPES]; static char isdsts[TZ_MAX_TYPES]; static unsigned char abbrinds[TZ_MAX_TYPES]; -static char ttisstds[TZ_MAX_TYPES]; -static char ttisgmts[TZ_MAX_TYPES]; +static bool ttisstds[TZ_MAX_TYPES]; +static bool ttisgmts[TZ_MAX_TYPES]; static char chars[TZ_MAX_CHARS]; static zic_t trans[TZ_MAX_LEAPS]; static zic_t corr[TZ_MAX_LEAPS]; @@ -439,7 +438,7 @@ error(const char *const string, ...) va_start(args, string); verror(string, args); va_end(args); - errors = 1; + errors = true; } static void ATTRIBUTE_FORMAT((printf, 1, 2)) @@ -450,7 +449,7 @@ warning(const char *const string, ...) va_start(args, string); verror(string, args); va_end(args); - warnings = 1; + warnings = true; } static void @@ -573,7 +572,7 @@ _("%s: More than one -L option specified\n"), } break; case 'v': - noise = TRUE; + noise = true; break; case 's': warning(_("-s ignored\n")); @@ -725,7 +724,7 @@ dolink(const char *const fromfield, const char *const tofield) if (link(fromname, toname) != 0) { int result; - if (mkdirs(toname) != 0) + if (! mkdirs(toname)) exit(EXIT_FAILURE); result = link(fromname, toname); @@ -914,7 +913,7 @@ associate(void) */ eat(zp->z_filename, zp->z_linenum); zp->z_stdoff = gethms(zp->z_rule, _("unruly zone"), - TRUE); + true); /* ** Note, though, that if there's no rule, ** a '%s' in the format is a bad thing. @@ -935,7 +934,7 @@ infile(const char *name) register char * cp; register const struct lookup * lp; register int nfields; - register int wantcont; + register bool wantcont; register int num; char buf[BUFSIZ]; @@ -949,7 +948,7 @@ infile(const char *name) progname, name, e); exit(EXIT_FAILURE); } - wantcont = FALSE; + wantcont = false; for (num = 1; ; ++num) { eat(name, num); if (fgets(buf, sizeof buf, fp) != buf) @@ -980,14 +979,14 @@ infile(const char *name) else switch ((int) (lp->l_value)) { case LC_RULE: inrule(fields, nfields); - wantcont = FALSE; + wantcont = false; break; case LC_ZONE: wantcont = inzone(fields, nfields); break; case LC_LINK: inlink(fields, nfields); - wantcont = FALSE; + wantcont = false; break; case LC_LEAP: if (name != leapsec) @@ -995,7 +994,7 @@ infile(const char *name) _("%s: Leap line in non leap seconds file %s\n"), progname, name); else inleap(fields, nfields); - wantcont = FALSE; + wantcont = false; break; default: /* "cannot happen" */ fprintf(stderr, @@ -1020,7 +1019,7 @@ _("%s: panic: Invalid l_value %d\n"), */ static zic_t -gethms(const char *string, const char *const errstring, const int signable) +gethms(char const *string, char const *errstring, bool signable) { zic_t hh; int mm, ss, sign; @@ -1074,7 +1073,7 @@ inrule(register char **const fields, const int nfields) } r.r_filename = filename; r.r_linenum = linenum; - r.r_stdoff = gethms(fields[RF_STDOFF], _("invalid saved time"), TRUE); + r.r_stdoff = gethms(fields[RF_STDOFF], _("invalid saved time"), true); rulesub(&r, fields[RF_LOYEAR], fields[RF_HIYEAR], fields[RF_COMMAND], fields[RF_MONTH], fields[RF_DAY], fields[RF_TOD]); r.r_name = ecpyalloc(fields[RF_NAME]); @@ -1085,26 +1084,26 @@ inrule(register char **const fields, const int nfields) rules[nrules++] = r; } -static int +static bool inzone(register char **const fields, const int nfields) { register int i; if (nfields < ZONE_MINFIELDS || nfields > ZONE_MAXFIELDS) { error(_("wrong number of fields on Zone line")); - return FALSE; + return false; } if (strcmp(fields[ZF_NAME], TZDEFAULT) == 0 && lcltime != NULL) { error( _("\"Zone %s\" line and -l option are mutually exclusive"), TZDEFAULT); - return FALSE; + return false; } if (strcmp(fields[ZF_NAME], TZDEFRULES) == 0 && psxrules != NULL) { error( _("\"Zone %s\" line and -p option are mutually exclusive"), TZDEFRULES); - return FALSE; + return false; } for (i = 0; i < nzones; ++i) if (zones[i].z_name != NULL && @@ -1114,30 +1113,30 @@ _("duplicate zone name %s (file \"%s\", line %d)"), fields[ZF_NAME], zones[i].z_filename, zones[i].z_linenum); - return FALSE; + return false; } - return inzsub(fields, nfields, FALSE); + return inzsub(fields, nfields, false); } -static int +static bool inzcont(register char **const fields, const int nfields) { if (nfields < ZONEC_MINFIELDS || nfields > ZONEC_MAXFIELDS) { error(_("wrong number of fields on Zone continuation line")); - return FALSE; + return false; } - return inzsub(fields, nfields, TRUE); + return inzsub(fields, nfields, true); } -static int -inzsub(register char **const fields, const int nfields, const int iscont) +static bool +inzsub(char **fields, int nfields, bool iscont) { register char * cp; static struct zone z; register int i_gmtoff, i_rule, i_format; register int i_untilyear, i_untilmonth; register int i_untilday, i_untiltime; - register int hasuntil; + register bool hasuntil; if (iscont) { i_gmtoff = ZFC_GMTOFF; @@ -1160,11 +1159,11 @@ inzsub(register char **const fields, const int nfields, const int iscont) } z.z_filename = filename; z.z_linenum = linenum; - z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid UT offset"), TRUE); + z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid UT offset"), true); if ((cp = strchr(fields[i_format], '%')) != 0) { if (*++cp != 's' || strchr(cp, '%') != 0) { error(_("invalid abbreviation format")); - return FALSE; + return false; } } z.z_rule = ecpyalloc(fields[i_rule]); @@ -1194,7 +1193,7 @@ inzsub(register char **const fields, const int nfields, const int iscont) error(_( "Zone continuation line end time is not after end time of previous line" )); - return FALSE; + return false; } } zones = growalloc(zones, sizeof *zones, nzones, &nzones_alloc); @@ -1234,7 +1233,7 @@ inleap(register char ** const fields, const int nfields) leapmaxyear = year; if (!leapseen || leapminyear > year) leapminyear = year; - leapseen = TRUE; + leapseen = true; j = EPOCH_YEAR; while (j != year) { if (year > j) { @@ -1273,23 +1272,23 @@ inleap(register char ** const fields, const int nfields) return; } t = dayoff * SECSPERDAY; - tod = gethms(fields[LP_TIME], _("invalid time of day"), FALSE); + tod = gethms(fields[LP_TIME], _("invalid time of day"), false); cp = fields[LP_CORR]; { - register int positive; + register bool positive; int count; if (strcmp(cp, "") == 0) { /* infile() turns "-" into "" */ - positive = FALSE; + positive = false; count = 1; } else if (strcmp(cp, "--") == 0) { - positive = FALSE; + positive = false; count = 2; } else if (strcmp(cp, "+") == 0) { - positive = TRUE; + positive = true; count = 1; } else if (strcmp(cp, "++") == 0) { - positive = TRUE; + positive = true; count = 2; } else { error(_("illegal CORRECTION field on Leap line")); @@ -1354,32 +1353,32 @@ rulesub(register struct rule *const rp, return; } rp->r_month = lp->l_value; - rp->r_todisstd = FALSE; - rp->r_todisgmt = FALSE; + rp->r_todisstd = false; + rp->r_todisgmt = false; dp = ecpyalloc(timep); if (*dp != '\0') { ep = dp + strlen(dp) - 1; switch (lowerit(*ep)) { case 's': /* Standard */ - rp->r_todisstd = TRUE; - rp->r_todisgmt = FALSE; + rp->r_todisstd = true; + rp->r_todisgmt = false; *ep = '\0'; break; case 'w': /* Wall */ - rp->r_todisstd = FALSE; - rp->r_todisgmt = FALSE; + rp->r_todisstd = false; + rp->r_todisgmt = false; *ep = '\0'; break; case 'g': /* Greenwich */ case 'u': /* Universal */ case 'z': /* Zulu */ - rp->r_todisstd = TRUE; - rp->r_todisgmt = TRUE; + rp->r_todisstd = true; + rp->r_todisgmt = true; *ep = '\0'; break; } } - rp->r_tod = gethms(dp, _("invalid time of day"), FALSE); + rp->r_tod = gethms(dp, _("invalid time of day"), false); free(dp); /* ** Year work. @@ -1534,7 +1533,7 @@ atcomp(const void *avp, const void *bvp) return (a < b) ? -1 : (a > b); } -static int +static bool is32(const zic_t x) { return INT32_MIN <= x && x <= INT32_MAX; @@ -1648,7 +1647,7 @@ writezone(const char *const name, const char *const string, char version) exit(EXIT_FAILURE); } if ((fp = fopen(fullname, "wb")) == NULL) { - if (mkdirs(fullname) != 0) + if (! mkdirs(fullname)) exit(EXIT_FAILURE); if ((fp = fopen(fullname, "wb")) == NULL) { const char *e = strerror(errno); @@ -1690,16 +1689,16 @@ writezone(const char *const name, const char *const string, char version) ** (32- or 64-bit) window. */ if (typecnt != 0) - writetype[typecnt - 1] = TRUE; + writetype[typecnt - 1] = true; } else { for (i = thistimei - 1; i < thistimelim; ++i) if (i >= 0) - writetype[types[i]] = TRUE; + writetype[types[i]] = true; /* ** For America/Godthab and Antarctica/Palmer */ if (thistimei == 0) - writetype[0] = TRUE; + writetype[0] = true; } #ifndef LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH /* @@ -1729,22 +1728,22 @@ writezone(const char *const name, const char *const string, char version) isdsts[mrudst] = -1; type = addtype(gmtoffs[mrudst], &chars[abbrinds[mrudst]], - TRUE, + true, ttisstds[mrudst], ttisgmts[mrudst]); - isdsts[mrudst] = TRUE; - writetype[type] = TRUE; + isdsts[mrudst] = 1; + writetype[type] = true; } if (histd >= 0 && mrustd >= 0 && histd != mrustd && gmtoffs[histd] != gmtoffs[mrustd]) { isdsts[mrustd] = -1; type = addtype(gmtoffs[mrustd], &chars[abbrinds[mrustd]], - FALSE, + false, ttisstds[mrustd], ttisgmts[mrustd]); - isdsts[mrustd] = FALSE; - writetype[type] = TRUE; + isdsts[mrustd] = 0; + writetype[type] = true; } } #endif /* !defined LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH */ @@ -1855,7 +1854,7 @@ writezone(const char *const name, const char *const string, char version) static void doabbr(char *const abbr, const char *const format, const char *const letters, - const int isdst, const int doquotes) + bool isdst, bool doquotes) { register char * cp; register char * slashp; @@ -1896,7 +1895,7 @@ updateminmax(const zic_t x) max_year = x; } -static int +static bool stringoffset(char *result, zic_t offset) { register int hours; @@ -1915,7 +1914,7 @@ stringoffset(char *result, zic_t offset) hours = offset; if (hours >= HOURSPERDAY * DAYSPERWEEK) { result[0] = '\0'; - return -1; + return false; } sprintf(end(result), "%d", hours); if (minutes != 0 || seconds != 0) { @@ -1923,7 +1922,7 @@ stringoffset(char *result, zic_t offset) if (seconds != 0) sprintf(end(result), ":%02d", seconds); } - return 0; + return true; } static int @@ -1982,7 +1981,7 @@ stringrule(char *result, const struct rule *const rp, const zic_t dstoff, tod += dstoff; if (tod != 2 * SECSPERMIN * MINSPERHOUR) { strcat(result, "/"); - if (stringoffset(end(result), tod) != 0) + if (! stringoffset(end(result), tod)) return -1; if (tod < 0) { if (compat < 2013) @@ -2071,14 +2070,14 @@ stringzone(char *result, const struct zone *const zpfirst, const int zonecount) dstr.r_dycode = DC_DOM; dstr.r_dayofmonth = 1; dstr.r_tod = 0; - dstr.r_todisstd = dstr.r_todisgmt = FALSE; + dstr.r_todisstd = dstr.r_todisgmt = false; dstr.r_stdoff = stdrp->r_stdoff; dstr.r_abbrvar = stdrp->r_abbrvar; stdr.r_month = TM_DECEMBER; stdr.r_dycode = DC_DOM; stdr.r_dayofmonth = 31; stdr.r_tod = SECSPERDAY + stdrp->r_stdoff; - stdr.r_todisstd = stdr.r_todisgmt = FALSE; + stdr.r_todisstd = stdr.r_todisgmt = false; stdr.r_stdoff = 0; stdr.r_abbrvar = (stdabbrrp ? stdabbrrp->r_abbrvar : ""); @@ -2089,17 +2088,17 @@ stringzone(char *result, const struct zone *const zpfirst, const int zonecount) if (stdrp == NULL && (zp->z_nrules != 0 || zp->z_stdoff != 0)) return -1; abbrvar = (stdrp == NULL) ? "" : stdrp->r_abbrvar; - doabbr(result, zp->z_format, abbrvar, FALSE, TRUE); - if (stringoffset(end(result), -zp->z_gmtoff) != 0) { + doabbr(result, zp->z_format, abbrvar, false, true); + if (! stringoffset(end(result), -zp->z_gmtoff)) { result[0] = '\0'; return -1; } if (dstrp == NULL) return compat; - doabbr(end(result), zp->z_format, dstrp->r_abbrvar, TRUE, TRUE); + doabbr(end(result), zp->z_format, dstrp->r_abbrvar, true, true); if (dstrp->r_stdoff != SECSPERMIN * MINSPERHOUR) - if (stringoffset(end(result), - -(zp->z_gmtoff + dstrp->r_stdoff)) != 0) { + if (! stringoffset(end(result), + -(zp->z_gmtoff + dstrp->r_stdoff))) { result[0] = '\0'; return -1; } @@ -2128,23 +2127,23 @@ outzone(const struct zone * const zpfirst, const int zonecount) register const struct zone * zp; register struct rule * rp; register int i, j; - register int usestart, useuntil; + register bool usestart, useuntil; register zic_t starttime, untiltime; register zic_t gmtoff; register zic_t stdoff; register zic_t year; register zic_t startoff; - register int startttisstd; - register int startttisgmt; + register bool startttisstd; + register bool startttisgmt; register int type; register char * startbuf; register char * ab; register char * envvar; register int max_abbr_len; register int max_envvar_len; - register int prodstic; /* all rules are min to max */ + register bool prodstic; /* all rules are min to max */ register int compat; - register int do_extend; + register bool do_extend; register char version; max_abbr_len = 2 + max_format_len + max_abbrvar_len; @@ -2165,8 +2164,8 @@ outzone(const struct zone * const zpfirst, const int zonecount) ** Thanks to Earl Chew ** for noting the need to unconditionally initialize startttisstd. */ - startttisstd = FALSE; - startttisgmt = FALSE; + startttisstd = false; + startttisgmt = false; min_year = max_year = EPOCH_YEAR; if (leapseen) { updateminmax(leapminyear); @@ -2183,7 +2182,7 @@ outzone(const struct zone * const zpfirst, const int zonecount) if (rp->r_hiwasnum) updateminmax(rp->r_hiyear); if (rp->r_lowasnum || rp->r_hiwasnum) - prodstic = FALSE; + prodstic = false; } } /* @@ -2264,13 +2263,13 @@ outzone(const struct zone * const zpfirst, const int zonecount) if (zp->z_nrules == 0) { stdoff = zp->z_stdoff; doabbr(startbuf, zp->z_format, - NULL, stdoff != 0, FALSE); + NULL, stdoff != 0, false); type = addtype(oadd(zp->z_gmtoff, stdoff), startbuf, stdoff != 0, startttisstd, startttisgmt); if (usestart) { addtt(starttime, type); - usestart = FALSE; + usestart = false; } else addtt(big_bang_time, type); } else for (year = min_year; year <= max_year; ++year) { if (useuntil && year > zp->z_untilrule.r_hiyear) @@ -2336,12 +2335,12 @@ outzone(const struct zone * const zpfirst, const int zonecount) if (k < 0) break; /* go on to next year */ rp = &zp->z_rules[k]; - rp->r_todo = FALSE; + rp->r_todo = false; if (useuntil && ktime >= untiltime) break; stdoff = rp->r_stdoff; if (usestart && ktime == starttime) - usestart = FALSE; + usestart = false; if (usestart) { if (ktime < starttime) { startoff = oadd(zp->z_gmtoff, @@ -2349,7 +2348,7 @@ outzone(const struct zone * const zpfirst, const int zonecount) doabbr(startbuf, zp->z_format, rp->r_abbrvar, rp->r_stdoff != 0, - FALSE); + false); continue; } if (*startbuf == '\0' && @@ -2359,14 +2358,14 @@ outzone(const struct zone * const zpfirst, const int zonecount) zp->z_format, rp->r_abbrvar, rp->r_stdoff != - 0, - FALSE); + false, + false); } } eats(zp->z_filename, zp->z_linenum, rp->r_filename, rp->r_linenum); doabbr(ab, zp->z_format, rp->r_abbrvar, - rp->r_stdoff != 0, FALSE); + rp->r_stdoff != 0, false); offset = oadd(zp->z_gmtoff, rp->r_stdoff); type = addtype(offset, ab, rp->r_stdoff != 0, rp->r_todisstd, rp->r_todisgmt); @@ -2469,23 +2468,10 @@ addtt(const zic_t starttime, int type) } static int -addtype(const zic_t gmtoff, const char *const abbr, const int isdst, - const int ttisstd, const int ttisgmt) +addtype(zic_t gmtoff, char const *abbr, bool isdst, bool ttisstd, bool ttisgmt) { register int i, j; - if (isdst != TRUE && isdst != FALSE) { - error(_("internal error: addtype called with bad isdst")); - exit(EXIT_FAILURE); - } - if (ttisstd != TRUE && ttisstd != FALSE) { - error(_("internal error: addtype called with bad ttisstd")); - exit(EXIT_FAILURE); - } - if (ttisgmt != TRUE && ttisgmt != FALSE) { - error(_("internal error: addtype called with bad ttisgmt")); - exit(EXIT_FAILURE); - } /* ** See if there's already an entry for this zone type. ** If so, just return its index. @@ -2525,7 +2511,7 @@ addtype(const zic_t gmtoff, const char *const abbr, const int isdst, } static void -leapadd(const zic_t t, const int positive, const int rolling, int count) +leapadd(zic_t t, bool positive, int rolling, int count) { register int i, j; @@ -2569,22 +2555,22 @@ adjleap(void) } } -static int +static bool yearistype(const int year, const char *const type) { static char * buf; int result; if (type == NULL || *type == '\0') - return TRUE; + return true; buf = erealloc(buf, 132 + strlen(yitcommand) + strlen(type)); sprintf(buf, "%s %d %s", yitcommand, year, type); result = system(buf); if (WIFEXITED(result)) switch (WEXITSTATUS(result)) { case 0: - return TRUE; + return true; case 1: - return FALSE; + return false; } error(_("Wild result from command execution")); fprintf(stderr, _("%s: command was '%s', result was %d\n"), @@ -2594,24 +2580,24 @@ yearistype(const int year, const char *const type) } /* Is A a space character in the C locale? */ -static int +static bool is_space(char a) { switch (a) { default: - return 0; + return false; case ' ': case '\f': case '\n': case '\r': case '\t': case '\v': - return 1; + return true; } } /* Is A an alphabetic character in the C locale? */ -static int +static bool is_alpha(char a) { switch (a) { default: - return 0; + return false; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': @@ -2620,7 +2606,7 @@ is_alpha(char a) case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': - return 1; + return true; } } @@ -2644,27 +2630,27 @@ lowerit(char a) } /* case-insensitive equality */ -static ATTRIBUTE_PURE int +static ATTRIBUTE_PURE bool ciequal(register const char *ap, register const char *bp) { while (lowerit(*ap) == lowerit(*bp++)) if (*ap++ == '\0') - return TRUE; - return FALSE; + return true; + return false; } -static ATTRIBUTE_PURE int +static ATTRIBUTE_PURE bool itsabbr(register const char *abbr, register const char *word) { if (lowerit(*abbr) != lowerit(*word)) - return FALSE; + return false; ++word; while (*++abbr != '\0') do { if (*word == '\0') - return FALSE; + return false; } while (lowerit(*word++) != lowerit(*abbr)); - return TRUE; + return true; } static ATTRIBUTE_PURE const struct lookup * @@ -2887,14 +2873,14 @@ mp = _("time zone abbreviation differs from POSIX standard"); charcnt += i; } -static int +static bool mkdirs(char *argname) { register char * name; register char * cp; if (argname == NULL || *argname == '\0') - return 0; + return true; cp = name = ecpyalloc(argname); while ((cp = strchr(cp + 1, '/')) != 0) { *cp = '\0'; @@ -2920,11 +2906,11 @@ mkdirs(char *argname) " %s: %s\n"), progname, name, e); free(name); - return -1; + return false; } } *cp = '/'; } free(name); - return 0; + return true; }