diff --git a/src/timezone/ialloc.c b/src/timezone/ialloc.c index ec3cbaf29a..0899cb18d8 100644 --- a/src/timezone/ialloc.c +++ b/src/timezone/ialloc.c @@ -1,3 +1,11 @@ +/* + * This file is in the public domain, so clarified as of + * 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/timezone/ialloc.c,v 1.5 2004/05/21 20:59:10 tgl Exp $ + */ + #include "postgres.h" #include "private.h" diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c index c48b1ea206..5ce8664f27 100644 --- a/src/timezone/localtime.c +++ b/src/timezone/localtime.c @@ -1,13 +1,16 @@ /* -** This file is in the public domain, so clarified as of -** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). -*/ + * This file is in the public domain, so clarified as of + * 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/timezone/localtime.c,v 1.6 2004/05/21 20:59:10 tgl Exp $ + */ /* -** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu). -** POSIX-style TZ environment variable handling from Guy Harris -** (guy@auspex.com). -*/ + * Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu). + * POSIX-style TZ environment variable handling from Guy Harris + * (guy@auspex.com). + */ #include "postgres.h" @@ -19,25 +22,26 @@ #ifndef WILDABBR -/* -** Someone might make incorrect use of a time zone abbreviation: -** 1. They might reference tzname[0] before calling tzset (explicitly -** or implicitly). -** 2. They might reference tzname[1] before calling tzset (explicitly -** or implicitly). -** 3. They might reference tzname[1] after setting to a time zone -** in which Daylight Saving Time is never observed. -** 4. They might reference tzname[0] after setting to a time zone -** in which Standard Time is never observed. -** 5. They might reference tm.TM_ZONE after calling offtime. -** What's best to do in the above cases is open to debate; -** for now, we just set things up so that in any of the five cases -** WILDABBR is used. Another possibility: initialize tzname[0] to the -** string "tzname[0] used before set", and similarly for the other cases. -** And another: initialize tzname[0] to "ERA", with an explanation in the -** manual page of what this "time zone abbreviation" means (doing this so -** that tzname[0] has the "normal" length of three characters). -*/ +/*---------- + * Someone might make incorrect use of a time zone abbreviation: + * 1. They might reference tzname[0] before calling tzset (explicitly + * or implicitly). + * 2. They might reference tzname[1] before calling tzset (explicitly + * or implicitly). + * 3. They might reference tzname[1] after setting to a time zone + * in which Daylight Saving Time is never observed. + * 4. They might reference tzname[0] after setting to a time zone + * in which Standard Time is never observed. + * 5. They might reference tm.TM_ZONE after calling offtime. + * What's best to do in the above cases is open to debate; + * for now, we just set things up so that in any of the five cases + * WILDABBR is used. Another possibility: initialize tzname[0] to the + * string "tzname[0] used before set", and similarly for the other cases. + * And another: initialize tzname[0] to "ERA", with an explanation in the + * manual page of what this "time zone abbreviation" means (doing this so + * that tzname[0] has the "normal" length of three characters). + *---------- + */ #define WILDABBR " " #endif /* !defined WILDABBR */ @@ -46,12 +50,12 @@ static char wildabbr[] = "WILDABBR"; static const char gmt[] = "GMT"; /* -** The DST rules to use if TZ has no rules and we can't load TZDEFRULES. -** We default to US rules as of 1999-08-17. -** POSIX 1003.1 section 8.1.1 says that the default DST rules are -** implementation dependent; for historical reasons, US rules are a -** common default. -*/ + * The DST rules to use if TZ has no rules and we can't load TZDEFRULES. + * We default to US rules as of 1999-08-17. + * POSIX 1003.1 section 8.1.1 says that the default DST rules are + * implementation dependent; for historical reasons, US rules are a + * common default. + */ #define TZDEFRULESTRING ",M4.1.0,M10.5.0" struct ttinfo @@ -100,8 +104,8 @@ struct rule * week */ /* -** Prototypes for static functions. -*/ + * Prototypes for static functions. + */ static long detzcode(const char *codep); static const char *getzname(const char *strp); @@ -114,12 +118,20 @@ static void gmtsub(const time_t *timep, long offset, struct pg_tm * tmp); static void localsub(const time_t *timep, long offset, struct pg_tm * tmp); static int increment_overflow(int *number, int delta); static int normalize_overflow(int *tensptr, int *unitsptr, int base); -static time_t time1(struct pg_tm * tmp, void (*funcp) (const time_t *, long, struct pg_tm *), long offset); -static time_t time2(struct pg_tm * tmp, void (*funcp) (const time_t *, long, struct pg_tm *), long offset, int *okayp); -static time_t time2sub(struct pg_tm * tmp, void (*funcp) (const time_t *, long, struct pg_tm *), long offset, int *okayp, int do_norm_secs); -static void timesub(const time_t *timep, long offset, const struct state * sp, struct pg_tm * tmp); +static time_t time1(struct pg_tm * tmp, + void (*funcp) (const time_t *, long, struct pg_tm *), + long offset); +static time_t time2(struct pg_tm * tmp, + void (*funcp) (const time_t *, long, struct pg_tm *), + long offset, int *okayp); +static time_t time2sub(struct pg_tm * tmp, + void (*funcp) (const time_t *, long, struct pg_tm *), + long offset, int *okayp, int do_norm_secs); +static void timesub(const time_t *timep, long offset, + const struct state * sp, struct pg_tm * tmp); static int tmcomp(const struct pg_tm * atmp, const struct pg_tm * btmp); -static time_t transtime(time_t janfirst, int year, const struct rule * rulep, long offset); +static time_t transtime(time_t janfirst, int year, + const struct rule * rulep, long offset); static int tzload(const char *name, struct state * sp); static int tzparse(const char *name, struct state * sp, int lastditch); @@ -134,12 +146,12 @@ static int lcl_is_set = 0; static int gmt_is_set = 0; /* -** Section 4.12.3 of X3.159-1989 requires that -** Except for the strftime function, these functions [asctime, -** ctime, gmtime, localtime] return values in one of two static -** objects: a broken-down time structure and an array of char. -** Thanks to Paul Eggert (eggert@twinsun.com) for noting this. -*/ + * Section 4.12.3 of X3.159-1989 requires that + * Except for the strftime function, these functions [asctime, + * ctime, gmtime, localtime] return values in one of two static + * objects: a broken-down time structure and an array of char. + * Thanks to Paul Eggert (eggert@twinsun.com) for noting this. + */ static struct pg_tm tm; @@ -184,7 +196,7 @@ tzload(register const char *name, register struct state * sp) (void) strcat(fullname, name); /* - * * Set doaccess if '.' (as in "../") shows up in name. + * Set doaccess if '.' (as in "../") shows up in name. */ if (strchr(name, '.') != NULL) doaccess = TRUE; @@ -313,11 +325,10 @@ static const int year_lengths[2] = { }; /* -** Given a pointer into a time zone string, scan until a character that is not -** a valid character in a zone name is found. Return a pointer to that -** character. -*/ - + * Given a pointer into a time zone string, scan until a character that is not + * a valid character in a zone name is found. Return a pointer to that + * character. + */ static const char * getzname(register const char *strp) { @@ -330,12 +341,11 @@ getzname(register const char *strp) } /* -** Given a pointer into a time zone string, extract a number from that string. -** Check that the number is within a specified range; if it is not, return -** NULL. -** Otherwise, return a pointer to the first character not part of the number. -*/ - + * Given a pointer into a time zone string, extract a number from that string. + * Check that the number is within a specified range; if it is not, return + * NULL. + * Otherwise, return a pointer to the first character not part of the number. + */ static const char * getnum(register const char *strp, int *nump, const int min, const int max) { @@ -359,22 +369,21 @@ getnum(register const char *strp, int *nump, const int min, const int max) } /* -** Given a pointer into a time zone string, extract a number of seconds, -** in hh[:mm[:ss]] form, from the string. -** If any error occurs, return NULL. -** Otherwise, return a pointer to the first character not part of the number -** of seconds. -*/ - + * Given a pointer into a time zone string, extract a number of seconds, + * in hh[:mm[:ss]] form, from the string. + * If any error occurs, return NULL. + * Otherwise, return a pointer to the first character not part of the number + * of seconds. + */ static const char * getsecs(register const char *strp, long *secsp) { int num; /* - * * `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like * - * "M10.4.6/26", which does not conform to Posix, * but which - * specifies the equivalent of * ``02:00 on the first Sunday on or + * `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like + * "M10.4.6/26", which does not conform to Posix, but which + * specifies the equivalent of ``02:00 on the first Sunday on or * after 23 Oct''. */ strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1); @@ -402,12 +411,11 @@ getsecs(register const char *strp, long *secsp) } /* -** Given a pointer into a time zone string, extract an offset, in -** [+-]hh[:mm[:ss]] form, from the string. -** If any error occurs, return NULL. -** Otherwise, return a pointer to the first character not part of the time. -*/ - + * Given a pointer into a time zone string, extract an offset, in + * [+-]hh[:mm[:ss]] form, from the string. + * If any error occurs, return NULL. + * Otherwise, return a pointer to the first character not part of the time. + */ static const char * getoffset(register const char *strp, long *offsetp) { @@ -429,19 +437,18 @@ getoffset(register const char *strp, long *offsetp) } /* -** Given a pointer into a time zone string, extract a rule in the form -** date[/time]. See POSIX section 8 for the format of "date" and "time". -** If a valid rule is not found, return NULL. -** Otherwise, return a pointer to the first character not part of the rule. -*/ - + * Given a pointer into a time zone string, extract a rule in the form + * date[/time]. See POSIX section 8 for the format of "date" and "time". + * If a valid rule is not found, return NULL. + * Otherwise, return a pointer to the first character not part of the rule. + */ static const char * getrule(const char *strp, register struct rule * rulep) { if (*strp == 'J') { /* - * * Julian day. + * Julian day. */ rulep->r_type = JULIAN_DAY; ++strp; @@ -450,7 +457,7 @@ getrule(const char *strp, register struct rule * rulep) else if (*strp == 'M') { /* - * * Month, week, day. + * Month, week, day. */ rulep->r_type = MONTH_NTH_DAY_OF_WEEK; ++strp; @@ -469,7 +476,7 @@ getrule(const char *strp, register struct rule * rulep) else if (is_digit(*strp)) { /* - * * Day of year. + * Day of year. */ rulep->r_type = DAY_OF_YEAR; strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1); @@ -481,7 +488,7 @@ getrule(const char *strp, register struct rule * rulep) if (*strp == '/') { /* - * * Time specified. + * Time specified. */ ++strp; strp = getsecs(strp, &rulep->r_time); @@ -492,13 +499,13 @@ getrule(const char *strp, register struct rule * rulep) } /* -** Given the Epoch-relative time of January 1, 00:00:00 UTC, in a year, the -** year, a rule, and the offset from UTC at the time that rule takes effect, -** calculate the Epoch-relative time that rule takes effect. -*/ - + * Given the Epoch-relative time of January 1, 00:00:00 UTC, in a year, the + * year, a rule, and the offset from UTC at the time that rule takes effect, + * calculate the Epoch-relative time that rule takes effect. + */ static time_t -transtime(const time_t janfirst, const int year, register const struct rule * rulep, const long offset) +transtime(const time_t janfirst, const int year, + register const struct rule * rulep, const long offset) { register int leapyear; register time_t value = 0; @@ -517,10 +524,10 @@ transtime(const time_t janfirst, const int year, register const struct rule * ru case JULIAN_DAY: /* - * * Jn - Julian day, 1 == January 1, 60 == March 1 even in - * leap * years. * In non-leap years, or if the day number is - * 59 or less, just * add SECSPERDAY times the day number-1 to - * the time of * January 1, midnight, to get the day. + * Jn - Julian day, 1 == January 1, 60 == March 1 even in + * leap years. In non-leap years, or if the day number is + * 59 or less, just add SECSPERDAY times the day number-1 to + * the time of January 1, midnight, to get the day. */ value = janfirst + (rulep->r_day - 1) * SECSPERDAY; if (leapyear && rulep->r_day >= 60) @@ -530,8 +537,8 @@ transtime(const time_t janfirst, const int year, register const struct rule * ru case DAY_OF_YEAR: /* - * * n - day of year. * Just add SECSPERDAY times the day - * number to the time of * January 1, midnight, to get the + * n - day of year. Just add SECSPERDAY times the day + * number to the time of January 1, midnight, to get the * day. */ value = janfirst + rulep->r_day * SECSPERDAY; @@ -540,15 +547,15 @@ transtime(const time_t janfirst, const int year, register const struct rule * ru case MONTH_NTH_DAY_OF_WEEK: /* - * * Mm.n.d - nth "dth day" of month m. + * Mm.n.d - nth "dth day" of month m. */ value = janfirst; for (i = 0; i < rulep->r_mon - 1; ++i) value += mon_lengths[leapyear][i] * SECSPERDAY; /* - * * Use Zeller's Congruence to get day-of-week of first day - * of * month. + * Use Zeller's Congruence to get day-of-week of first day + * of month. */ m1 = (rulep->r_mon + 9) % 12 + 1; yy0 = (rulep->r_mon <= 2) ? (year - 1) : year; @@ -560,9 +567,9 @@ transtime(const time_t janfirst, const int year, register const struct rule * ru dow += DAYSPERWEEK; /* - * * "dow" is the day-of-week of the first day of the month. - * Get * the day-of-month (zero-origin) of the first "dow" day - * of the * month. + * "dow" is the day-of-week of the first day of the month. + * Get the day-of-month (zero-origin) of the first "dow" day + * of the month. */ d = rulep->r_day - dow; if (d < 0) @@ -576,25 +583,25 @@ transtime(const time_t janfirst, const int year, register const struct rule * ru } /* - * * "d" is the day-of-month (zero-origin) of the day we want. + * "d" is the day-of-month (zero-origin) of the day we want. */ value += d * SECSPERDAY; break; } /* - * * "value" is the Epoch-relative time of 00:00:00 UTC on the day in * - * question. To get the Epoch-relative time of the specified local * - * time on that day, add the transition time and the current offset * + * "value" is the Epoch-relative time of 00:00:00 UTC on the day in + * question. To get the Epoch-relative time of the specified local + * time on that day, add the transition time and the current offset * from UTC. */ return value + rulep->r_time + offset; } /* -** Given a POSIX section 8-style TZ string, fill in the rule tables as -** appropriate. -*/ + * Given a POSIX section 8-style TZ string, fill in the rule tables as + * appropriate. + */ static int tzparse(const char *name, register struct state * sp, const int lastditch) @@ -672,7 +679,7 @@ tzparse(const char *name, register struct state * sp, const int lastditch) sp->typecnt = 2; /* standard time and DST */ /* - * * Two transitions per year, from EPOCH_YEAR to 2037. + * Two transitions per year, from EPOCH_YEAR to 2037. */ sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1); if (sp->timecnt > TZ_MAX_TIMES) @@ -723,7 +730,7 @@ tzparse(const char *name, register struct state * sp, const int lastditch) return -1; /* - * * Initial values of theirstdoffset and theirdstoffset. + * Initial values of theirstdoffset and theirdstoffset. */ theirstdoffset = 0; for (i = 0; i < sp->timecnt; ++i) @@ -749,13 +756,13 @@ tzparse(const char *name, register struct state * sp, const int lastditch) } /* - * * Initially we're assumed to be in standard time. + * Initially we're assumed to be in standard time. */ isdst = FALSE; theiroffset = theirstdoffset; /* - * * Now juggle transition times and types * tracking offsets + * Now juggle transition times and types tracking offsets * as you do. */ for (i = 0; i < sp->timecnt; ++i) @@ -769,16 +776,16 @@ tzparse(const char *name, register struct state * sp, const int lastditch) else { /* - * * If summer time is in effect, and the * transition - * time was not specified as * standard time, add the - * summer time * offset to the transition time; * - * otherwise, add the standard time * offset to the + * If summer time is in effect, and the transition + * time was not specified as standard time, add the + * summer time offset to the transition time; + * otherwise, add the standard time offset to the * transition time. */ /* - * * Transitions from DST to DDST * will effectively - * disappear since * POSIX provides for only one DST * + * Transitions from DST to DDST will effectively + * disappear since POSIX provides for only one DST * offset. */ if (isdst && !sp->ttis[j].tt_ttisstd) @@ -800,7 +807,7 @@ tzparse(const char *name, register struct state * sp, const int lastditch) } /* - * * Finally, fill in ttis. * ttisstd and ttisgmt need not be + * Finally, fill in ttis. ttisstd and ttisgmt need not be * handled. */ sp->ttis[0].tt_gmtoff = -stdoffset; @@ -871,14 +878,13 @@ pg_tzset(const char *name) } /* -** The easy way to behave "as if no library function calls" localtime -** is to not call it--so we drop its guts into "localsub", which can be -** freely called. (And no, the PANS doesn't require the above behavior-- -** but it *is* desirable.) -** -** The unused offset argument is for the benefit of mktime variants. -*/ - + * The easy way to behave "as if no library function calls" localtime + * is to not call it--so we drop its guts into "localsub", which can be + * freely called. (And no, the PANS doesn't require the above behavior-- + * but it *is* desirable.) + * + * The unused offset argument is for the benefit of mktime variants. + */ static void localsub(const time_t *timep, const long offset, struct pg_tm * tmp) { @@ -907,16 +913,12 @@ localsub(const time_t *timep, const long offset, struct pg_tm * tmp) } ttisp = &sp->ttis[i]; - /* - * * To get (wrong) behavior that's compatible with System V Release - * 2.0 * you'd replace the statement below with * t += - * ttisp->tt_gmtoff; * timesub(&t, 0L, sp, tmp); - */ timesub(&t, ttisp->tt_gmtoff, sp, tmp); tmp->tm_isdst = ttisp->tt_isdst; tmp->tm_zone = &sp->chars[ttisp->tt_abbrind]; } + struct pg_tm * pg_localtime(const time_t *timep) { @@ -926,9 +928,8 @@ pg_localtime(const time_t *timep) /* -** gmtsub is to gmtime as localsub is to localtime. -*/ - + * gmtsub is to gmtime as localsub is to localtime. + */ static void gmtsub(const time_t *timep, const long offset, struct pg_tm * tmp) { @@ -940,8 +941,8 @@ gmtsub(const time_t *timep, const long offset, struct pg_tm * tmp) timesub(timep, offset, gmtptr, tmp); /* - * * Could get fancy here and deliver something such as * "UTC+xxxx" - * or "UTC-xxxx" if offset is non-zero, * but this is no time for a + * Could get fancy here and deliver something such as "UTC+xxxx" + * or "UTC-xxxx" if offset is non-zero, but this is no time for a * treasure hunt. */ if (offset != 0) @@ -959,7 +960,8 @@ pg_gmtime(const time_t *timep) static void -timesub(const time_t *timep, const long offset, register const struct state * sp, register struct pg_tm * tmp) +timesub(const time_t *timep, const long offset, + register const struct state * sp, register struct pg_tm * tmp) { register const struct lsinfo *lp; register long days; @@ -1004,7 +1006,7 @@ timesub(const time_t *timep, const long offset, register const struct state * sp if (*timep == 0x80000000) { /* - * * A 3B1 muffs the division on the most negative number. + * A 3B1 muffs the division on the most negative number. */ days = -24855; rem = -11648; @@ -1026,7 +1028,7 @@ timesub(const time_t *timep, const long offset, register const struct state * sp tmp->tm_min = (int) (rem / SECSPERMIN); /* - * * A positive leap second requires a special * representation. This + * A positive leap second requires a special representation. This * uses "... ??:59:60" et seq. */ tmp->tm_sec = (int) (rem % SECSPERMIN) + hit; @@ -1058,20 +1060,20 @@ timesub(const time_t *timep, const long offset, register const struct state * sp } /* -** Adapted from code provided by Robert Elz, who writes: -** The "best" way to do mktime I think is based on an idea of Bob -** Kridle's (so its said...) from a long time ago. -** [kridle@xinet.com as of 1996-01-16.] -** It does a binary search of the time_t space. Since time_t's are -** just 32 bits, its a max of 32 iterations (even at 64 bits it -** would still be very reasonable). -*/ + * Adapted from code provided by Robert Elz, who writes: + * The "best" way to do mktime I think is based on an idea of Bob + * Kridle's (so its said...) from a long time ago. + * [kridle@xinet.com as of 1996-01-16.] + * It does a binary search of the time_t space. Since time_t's are + * just 32 bits, its a max of 32 iterations (even at 64 bits it + * would still be very reasonable). + */ #define WRONG (-1) /* -** Simplified normalize logic courtesy Paul Eggert (eggert@twinsun.com). -*/ + * Simplified normalize logic courtesy Paul Eggert (eggert@twinsun.com). + */ static int increment_overflow(int *number, int delta) @@ -1109,7 +1111,10 @@ tmcomp(register const struct pg_tm * atmp, register const struct pg_tm * btmp) return result; } -static time_t time2sub(struct pg_tm * tmp, void (*funcp) (const time_t *, long, struct pg_tm *), const long offset, int *okayp, const int do_norm_secs) +static time_t +time2sub(struct pg_tm * tmp, + void (*funcp) (const time_t *, long, struct pg_tm *), + const long offset, int *okayp, const int do_norm_secs) { register const struct state *sp; register int dir; @@ -1138,7 +1143,7 @@ static time_t time2sub(struct pg_tm * tmp, void (*funcp) (const time_t *, long, return WRONG; /* - * * Turn yourtm.tm_year into an actual year number for now. * It is + * Turn yourtm.tm_year into an actual year number for now. It is * converted back to an offset from TM_YEAR_BASE later. */ if (increment_overflow(&yourtm.tm_year, TM_YEAR_BASE)) @@ -1177,10 +1182,10 @@ static time_t time2sub(struct pg_tm * tmp, void (*funcp) (const time_t *, long, else if (yourtm.tm_year + TM_YEAR_BASE < EPOCH_YEAR) { /* - * * We can't set tm_sec to 0, because that might push the * time - * below the minimum representable time. * Set tm_sec to 59 - * instead. * This assumes that the minimum representable time is * - * not in the same minute that a leap second was deleted from, * + * We can't set tm_sec to 0, because that might push the time + * below the minimum representable time. Set tm_sec to 59 + * instead. This assumes that the minimum representable time is + * not in the same minute that a leap second was deleted from, * which is a safer assumption than using 58 would be. */ if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN)) @@ -1195,14 +1200,14 @@ static time_t time2sub(struct pg_tm * tmp, void (*funcp) (const time_t *, long, } /* - * * Divide the search space in half * (this works whether time_t is + * Divide the search space in half (this works whether time_t is * signed or unsigned). */ bits = TYPE_BIT(time_t) -1; /* - * * If time_t is signed, then 0 is just above the median, * assuming - * two's complement arithmetic. * If time_t is unsigned, then (1 << + * If time_t is signed, then 0 is just above the median, assuming + * two's complement arithmetic. If time_t is unsigned, then (1 << * bits) is just above the median. */ t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits); @@ -1226,12 +1231,12 @@ static time_t time2sub(struct pg_tm * tmp, void (*funcp) (const time_t *, long, break; /* - * * Right time, wrong type. * Hunt for right time, right type. * - * It's okay to guess wrong since the guess * gets checked. + * Right time, wrong type. Hunt for right time, right type. + * It's okay to guess wrong since the guess gets checked. */ /* - * * The (void *) casts are the benefit of SunOS 3.3 on Sun 2's. + * The (void *) casts are the benefit of SunOS 3.3 on Sun 2's. */ sp = (const struct state *) (((void *) funcp == (void *) localsub) ? @@ -1253,7 +1258,7 @@ static time_t time2sub(struct pg_tm * tmp, void (*funcp) (const time_t *, long, continue; /* - * * We have a match. + * We have a match. */ t = newt; goto label; @@ -1271,20 +1276,26 @@ label: return t; } -static time_t time2(struct pg_tm * tmp, void (*funcp) (const time_t *, long, struct pg_tm *), const long offset, int *okayp) +static time_t +time2(struct pg_tm * tmp, + void (*funcp) (const time_t *, long, struct pg_tm *), + const long offset, int *okayp) { time_t t; /* - * * First try without normalization of seconds * (in case tm_sec - * contains a value associated with a leap second). * If that fails, + * First try without normalization of seconds (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); } -static time_t time1(struct pg_tm * tmp, void (*funcp) (const time_t *, long, struct pg_tm *), const long offset) +static time_t +time1(struct pg_tm * tmp, + void (*funcp) (const time_t *, long, struct pg_tm *), + const long offset) { register time_t t; register const struct state *sp; @@ -1305,14 +1316,14 @@ static time_t time1(struct pg_tm * tmp, void (*funcp) (const time_t *, long, str return t; /* - * * We're supposed to assume that somebody took a time of one type * - * and did some math on it that yielded a "struct pg_tm" that's bad. * - * We try to divine the type they started from and adjust to the * + * We're supposed to assume that somebody took a time of one type + * and did some math on it that yielded a "struct pg_tm" that's bad. + * We try to divine the type they started from and adjust to the * type they need. */ /* - * * The (void *) casts are the benefit of SunOS 3.3 on Sun 2's. + * The (void *) casts are the benefit of SunOS 3.3 on Sun 2's. */ sp = (const struct state *) (((void *) funcp == (void *) localsub) ? lclptr : gmtptr); diff --git a/src/timezone/private.h b/src/timezone/private.h index 75b3072489..7339ef0db5 100644 --- a/src/timezone/private.h +++ b/src/timezone/private.h @@ -2,17 +2,20 @@ #define PRIVATE_H /* -** This file is in the public domain, so clarified as of -** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). -*/ + * This file is in the public domain, so clarified as of + * 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/timezone/private.h,v 1.8 2004/05/21 20:59:10 tgl Exp $ + */ /* -** This header is for use ONLY with the time conversion code. -** There is no guarantee that it will remain unchanged, -** or that it will remain at all. -** Do NOT copy it to any system include directory. -** Thank you! -*/ + * This header is for use ONLY with the time conversion code. + * There is no guarantee that it will remain unchanged, + * or that it will remain at all. + * Do NOT copy it to any system include directory. + * Thank you! + */ #include /* for CHAR_BIT */ #include /* for WIFEXITED and WEXITSTATUS */ @@ -28,32 +31,31 @@ #define WEXITSTATUS(status) (((status) >> 8) & 0xff) #endif /* !defined WEXITSTATUS */ -/* Unlike 's isdigit, this also works if c < 0 | c > UCHAR_MAX. */ +/* Unlike 's isdigit, this also works if c < 0 | c > UCHAR_MAX. */ #define is_digit(c) ((unsigned)(c) - '0' <= 9) /* -** SunOS 4.1.1 headers lack EXIT_SUCCESS. -*/ + * SunOS 4.1.1 headers lack EXIT_SUCCESS. + */ #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif /* !defined EXIT_SUCCESS */ /* -** SunOS 4.1.1 headers lack EXIT_FAILURE. -*/ + * SunOS 4.1.1 headers lack EXIT_FAILURE. + */ #ifndef EXIT_FAILURE #define EXIT_FAILURE 1 #endif /* !defined EXIT_FAILURE */ /* -** SunOS 4.1.1 libraries lack remove. -*/ + * SunOS 4.1.1 libraries lack remove. + */ #ifndef remove extern int unlink(const char *filename); - #define remove unlink #endif /* !defined remove */ @@ -92,11 +94,11 @@ extern char *scheck(const char *string, const char *format); #ifndef INT_STRLEN_MAXIMUM /* -** 302 / 1000 is log10(2.0) rounded up. -** Subtract one for the sign bit if the type is signed; -** add one for integer division truncation; -** add one more for a minus sign if the type is signed. -*/ + * 302 / 1000 is log10(2.0) rounded up. + * Subtract one for the sign bit if the type is signed; + * add one for integer division truncation; + * add one more for a minus sign if the type is signed. + */ #define INT_STRLEN_MAXIMUM(type) \ ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type)) #endif /* !defined INT_STRLEN_MAXIMUM */ @@ -104,7 +106,7 @@ extern char *scheck(const char *string, const char *format); #define _(msgid) (msgid) /* -** UNIX was a registered trademark of The Open Group in 2003. -*/ + * UNIX was a registered trademark of The Open Group in 2003. + */ #endif /* !defined PRIVATE_H */ diff --git a/src/timezone/scheck.c b/src/timezone/scheck.c index 8b72a4dcfa..992739e815 100644 --- a/src/timezone/scheck.c +++ b/src/timezone/scheck.c @@ -1,3 +1,11 @@ +/* + * This file is in the public domain, so clarified as of + * 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/timezone/scheck.c,v 1.5 2004/05/21 20:59:10 tgl Exp $ + */ + #include "postgres.h" #include "private.h" diff --git a/src/timezone/strftime.c b/src/timezone/strftime.c index 9a64df1f1d..3b505364ef 100644 --- a/src/timezone/strftime.c +++ b/src/timezone/strftime.c @@ -1,19 +1,22 @@ /* -** Copyright (c) 1989 The Regents of the University of California. -** All rights reserved. -** -** Redistribution and use in source and binary forms are permitted -** provided that the above copyright notice and this paragraph are -** duplicated in all such forms and that any documentation, -** advertising materials, and other materials related to such -** distribution and use acknowledge that the software was developed -** by the University of California, Berkeley. The name of the -** University may not be used to endorse or promote products derived -** from this software without specific prior written permission. -** THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR -** IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED -** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -*/ + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/timezone/strftime.c,v 1.3 2004/05/21 20:59:10 tgl Exp $ + */ #include "postgres.h" @@ -60,15 +63,19 @@ static const struct lc_time_T C_time_locale = { "%H:%M:%S", /* - * * x_fmt * C99 requires this format. * Using just numbers (as here) - * makes Quakers happier; * it's also compatible with SVR4. + * x_fmt + * + * C99 requires this format. Using just numbers (as here) + * makes Quakers happier; it's also compatible with SVR4. */ "%m/%d/%y", /* - * * c_fmt * C99 requires this format. * Previously this code used "%D - * %X", but we now conform to C99. * Note that * "%a %b %d - * %H:%M:%S %Y" * is used by Solaris 2.3. + * c_fmt + * + * C99 requires this format. Previously this code used "%D %X", but we now + * conform to C99. Note that "%a %b %d %H:%M:%S %Y" is used by Solaris + * 2.3. */ "%a %b %e %T %Y", @@ -84,7 +91,8 @@ static const struct lc_time_T C_time_locale = { static char *_add(const char *, char *, const char *); static char *_conv(int, const char *, char *, const char *); -static char *_fmt(const char *, const struct pg_tm *, char *, const char *, int *); +static char *_fmt(const char *, const struct pg_tm *, char *, + const char *, int *); #define IN_NONE 0 #define IN_SOME 1 @@ -93,7 +101,8 @@ static char *_fmt(const char *, const struct pg_tm *, char *, const char *, int size_t -pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm * t) +pg_strftime(char *s, size_t maxsize, const char *format, + const struct pg_tm *t) { char *p; int warn; @@ -107,7 +116,8 @@ pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm * t) } static char * -_fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, int *warnp) +_fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, + int *warnp) { for (; *format; ++format) { @@ -147,9 +157,9 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, in case 'C': /* - * * %C used to do a... * _fmt("%a %b %e %X %Y", t); * - * ...whereas now POSIX 1003.2 calls for * something - * completely different. * (ado, 1993-05-24) + * %C used to do a... _fmt("%a %b %e %X %Y", t); + * ...whereas now POSIX 1003.2 calls for something + * completely different. (ado, 1993-05-24) */ pt = _conv((t->tm_year + TM_YEAR_BASE) / 100, "%02d", pt, ptlim); @@ -175,10 +185,10 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, in case 'O': /* - * * C99 locale modifiers. * The sequences * %Ec %EC - * %Ex %EX %Ey %EY * %Od %oe %OH %OI %Om %OM * %OS - * %Ou %OU %OV %Ow %OW %Oy * are supposed to provide - * alternate * representations. + * C99 locale modifiers. The sequences %Ec %EC + * %Ex %EX %Ey %EY %Od %oe %OH %OI %Om %OM %OS + * %Ou %OU %OV %Ow %OW %Oy are supposed to provide + * alternate representations. */ goto label; case 'e': @@ -201,12 +211,11 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, in case 'k': /* - * * This used to be... * _conv(t->tm_hour % 12 ? * - * t->tm_hour % 12 : 12, 2, ' '); * ...and has been - * changed to the below to * match SunOS 4.1.1 and - * Arnold Robbins' * strftime version 3.0. That is, - * "%k" and * "%l" have been swapped. * (ado, - * 1993-05-24) + * This used to be... _conv(t->tm_hour % 12 ? t->tm_hour + * % 12 : 12, 2, ' '); ...and has been changed to the + * below to match SunOS 4.1.1 and Arnold Robbins' strftime + * version 3.0. That is, "%k" and "%l" have been + * swapped. (ado, 1993-05-24) */ pt = _conv(t->tm_hour, "%2d", pt, ptlim); continue; @@ -222,10 +231,10 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, in case 'l': /* - * * This used to be... * _conv(t->tm_hour, 2, ' '); * - * ...and has been changed to the below to * match - * SunOS 4.1.1 and Arnold Robbin's * strftime version - * 3.0. That is, "%k" and * "%l" have been swapped. * + * This used to be... _conv(t->tm_hour, 2, ' '); + * ...and has been changed to the below to match + * SunOS 4.1.1 and Arnold Robbin's strftime version + * 3.0. That is, "%k" and "%l" have been swapped. * (ado, 1993-05-24) */ pt = _conv((t->tm_hour % 12) ? @@ -285,9 +294,9 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, in case 'u': /* - * * From Arnold Robbins' strftime version 3.0: * "ISO - * 8601: Weekday as a decimal number * [1 (Monday) - - * 7]" * (ado, 1993-05-24) + * From Arnold Robbins' strftime version 3.0: "ISO 8601: + * Weekday as a decimal number [1 (Monday) - 7]" + * (ado, 1993-05-24) */ pt = _conv((t->tm_wday == 0) ? DAYSPERWEEK : t->tm_wday, @@ -297,23 +306,23 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, in case 'G': /* ISO 8601 year (four digits) */ case 'g': /* ISO 8601 year (two digits) */ /* -** From Arnold Robbins' strftime version 3.0: "the week number of the -** year (the first Monday as the first day of week 1) as a decimal number -** (01-53)." -** (ado, 1993-05-24) -** -** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn: -** "Week 01 of a year is per definition the first week which has the -** Thursday in this year, which is equivalent to the week which contains -** the fourth day of January. In other words, the first week of a new year -** is the week which has the majority of its days in the new year. Week 01 -** might also contain days from the previous year and the week before week -** 01 of a year is the last week (52 or 53) of the previous year even if -** it contains days from the new year. A week starts with Monday (day 1) -** and ends with Sunday (day 7). For example, the first week of the year -** 1997 lasts from 1996-12-30 to 1997-01-05..." -** (ado, 1996-01-02) -*/ + * From Arnold Robbins' strftime version 3.0: "the week number of the + * year (the first Monday as the first day of week 1) as a decimal number + * (01-53)." + * (ado, 1993-05-24) + * + * From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn: + * "Week 01 of a year is per definition the first week which has the + * Thursday in this year, which is equivalent to the week which contains + * the fourth day of January. In other words, the first week of a new year + * is the week which has the majority of its days in the new year. Week 01 + * might also contain days from the previous year and the week before week + * 01 of a year is the last week (52 or 53) of the previous year even if + * it contains days from the new year. A week starts with Monday (day 1) + * and ends with Sunday (day 7). For example, the first week of the year + * 1997 lasts from 1996-12-30 to 1997-01-05..." + * (ado, 1996-01-02) + */ { int year; int yday; @@ -334,14 +343,14 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, in DAYSPERNYEAR; /* - * * What yday (-3 ... 3) does * the ISO year + * What yday (-3 ... 3) does the ISO year * begin on? */ bot = ((yday + 11 - wday) % DAYSPERWEEK) - 3; /* - * * What yday does the NEXT * ISO year begin + * What yday does the NEXT ISO year begin * on? */ top = bot - @@ -383,8 +392,8 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, in case 'v': /* - * * From Arnold Robbins' strftime version 3.0: * - * "date as dd-bbb-YYYY" * (ado, 1993-05-24) + * From Arnold Robbins' strftime version 3.0: + * "date as dd-bbb-YYYY" (ado, 1993-05-24) */ pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp); continue; @@ -426,8 +435,8 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, in pt = _add(t->tm_zone, pt, ptlim); /* - * * C99 says that %Z must be replaced by the * empty - * string if the time zone is not * determinable. + * C99 says that %Z must be replaced by the empty + * string if the time zone is not determinable. */ continue; case 'z': @@ -458,8 +467,8 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, in case '%': /* - * * X311J/88-090 (4.12.3.5): if conversion char is * - * undefined, behavior is undefined. Print out the * + * X311J/88-090 (4.12.3.5): if conversion char is + * undefined, behavior is undefined. Print out the * character itself as printf(3) also does. */ default: diff --git a/src/timezone/tzfile.h b/src/timezone/tzfile.h index cbea51ff3f..29096f7d79 100644 --- a/src/timezone/tzfile.h +++ b/src/timezone/tzfile.h @@ -1,30 +1,32 @@ #ifndef TZFILE_H - #define TZFILE_H /* -** This file is in the public domain, so clarified as of -** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). -*/ + * This file is in the public domain, so clarified as of + * 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/timezone/tzfile.h,v 1.5 2004/05/21 20:59:10 tgl Exp $ + */ /* -** This header is for use ONLY with the time conversion code. -** There is no guarantee that it will remain unchanged, -** or that it will remain at all. -** Do NOT copy it to any system include directory. -** Thank you! -*/ + * This header is for use ONLY with the time conversion code. + * There is no guarantee that it will remain unchanged, + * or that it will remain at all. + * Do NOT copy it to any system include directory. + * Thank you! + */ /* -** Information about time zone files. -*/ + * Information about time zone files. + */ #define TZDEFAULT "localtime" #define TZDEFRULES "posixrules" /* -** Each file begins with. . . -*/ + * Each file begins with. . . + */ #define TZ_MAGIC "TZif" @@ -42,42 +44,43 @@ struct tzhead char tzh_charcnt[4]; /* coded number of abbr. chars */ }; -/* -** . . .followed by. . . -** -** tzh_timecnt (char [4])s coded transition times a la time(2) -** tzh_timecnt (unsigned char)s types of local time starting at above -** tzh_typecnt repetitions of -** one (char [4]) coded UTC offset in seconds -** one (unsigned char) used to set tm_isdst -** one (unsigned char) that's an abbreviation list index -** tzh_charcnt (char)s '\0'-terminated zone abbreviations -** 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, -** 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 UTC, if FALSE, -** transition time is local time -** if absent, transition times are -** assumed to be local time -*/ +/*---------- + * . . .followed by. . . + * + * tzh_timecnt (char [4])s coded transition times a la time(2) + * tzh_timecnt (unsigned char)s types of local time starting at above + * tzh_typecnt repetitions of + * one (char [4]) coded UTC offset in seconds + * one (unsigned char) used to set tm_isdst + * one (unsigned char) that's an abbreviation list index + * tzh_charcnt (char)s '\0'-terminated zone abbreviations + * 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, + * 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 UTC, if FALSE, + * transition time is local time + * if absent, transition times are + * assumed to be local time + *---------- + */ /* -** In the current implementation, "tzset()" refuses to deal with files that -** exceed any of the limits below. -*/ + * In the current implementation, "tzset()" refuses to deal with files that + * exceed any of the limits below. + */ /* -** The TZ_MAX_TIMES value below is enough to handle a bit more than a -** year's worth of solar time (corrected daily to the nearest second) or -** 138 years of Pacific Presidential Election time -** (where there are three time zone transitions every fourth year). -*/ + * The TZ_MAX_TIMES value below is enough to handle a bit more than a + * year's worth of solar time (corrected daily to the nearest second) or + * 138 years of Pacific Presidential Election time + * (where there are three time zone transitions every fourth year). + */ #define TZ_MAX_TIMES 370 #define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can @@ -127,9 +130,9 @@ struct tzhead #define EPOCH_WDAY TM_THURSDAY /* -** Accurate only for the past couple of centuries; -** that will probably do. -*/ + * Accurate only for the past couple of centuries; + * that will probably do. + */ #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) diff --git a/src/timezone/zic.c b/src/timezone/zic.c index 16e44ad6a7..a427e75686 100644 --- a/src/timezone/zic.c +++ b/src/timezone/zic.c @@ -1,3 +1,11 @@ +/* + * This file is in the public domain, so clarified as of + * 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/timezone/zic.c,v 1.7 2004/05/21 20:59:10 tgl Exp $ + */ + #include "postgres.h" #include @@ -26,13 +34,13 @@ static char elsieid[] = "@(#)zic.c 7.115"; /* -** On some ancient hosts, predicates like `isspace(C)' are defined -** only if isascii(C) || C == EOF. Modern hosts obey the C Standard, -** which says they are defined only if C == ((unsigned char) C) || C == EOF. -** Neither the C Standard nor Posix require that `isascii' exist. -** For portability, we check both ancient and modern requirements. -** If isascii is not defined, the isascii check succeeds trivially. -*/ + * On some ancient hosts, predicates like `isspace(C)' are defined + * only if isascii(C) || C == EOF. Modern hosts obey the C Standard, + * which says they are defined only if C == ((unsigned char) C) || C == EOF. + * Neither the C Standard nor Posix require that `isascii' exist. + * For portability, we check both ancient and modern requirements. + * If isascii is not defined, the isascii check succeeds trivially. + */ #include #ifndef isascii #define isascii(x) 1 @@ -67,8 +75,8 @@ struct rule }; /* -** r_dycode r_dayofmonth r_wday -*/ + * r_dycode r_dayofmonth r_wday + */ #define DC_DOM 0 /* 1..31 */ /* unused */ #define DC_DOWGEQ 1 /* 1..31 */ /* 0..6 (Sun..Sat) */ @@ -164,8 +172,8 @@ static int timecnt; static int typecnt; /* -** Line codes. -*/ + * Line codes. + */ #define LC_RULE 0 #define LC_ZONE 1 @@ -173,8 +181,8 @@ static int typecnt; #define LC_LEAP 3 /* -** Which fields are which on a Zone line. -*/ + * Which fields are which on a Zone line. + */ #define ZF_NAME 1 #define ZF_GMTOFF 2 @@ -188,8 +196,8 @@ static int typecnt; #define ZONE_MAXFIELDS 9 /* -** Which fields are which on a Zone continuation line. -*/ + * Which fields are which on a Zone continuation line. + */ #define ZFC_GMTOFF 0 #define ZFC_RULE 1 @@ -202,8 +210,8 @@ static int typecnt; #define ZONEC_MAXFIELDS 7 /* -** Which files are which on a Rule line. -*/ + * Which files are which on a Rule line. + */ #define RF_NAME 1 #define RF_LOYEAR 2 @@ -217,16 +225,16 @@ static int typecnt; #define RULE_FIELDS 10 /* -** Which fields are which on a Link line. -*/ + * Which fields are which on a Link line. + */ #define LF_FROM 1 #define LF_TO 2 #define LINK_FIELDS 3 /* -** Which fields are which on a Leap line. -*/ + * Which fields are which on a Leap line. + */ #define LP_YEAR 1 #define LP_MONTH 2 @@ -237,8 +245,8 @@ static int typecnt; #define LEAP_FIELDS 7 /* -** Year synonyms. -*/ + * Year synonyms. + */ #define YR_MINIMUM 0 #define YR_MAXIMUM 1 @@ -360,8 +368,8 @@ static long corr[TZ_MAX_LEAPS]; static char roll[TZ_MAX_LEAPS]; /* -** Memory allocation. -*/ + * Memory allocation. + */ static char * memcheck(ptr) @@ -384,8 +392,8 @@ char *const ptr; #define ecatalloc(oldp, newp) memcheck(icatalloc((oldp), (newp))) /* -** Error handling. -*/ + * Error handling. + */ #ifndef HAVE_STRERROR static char * @@ -418,8 +426,8 @@ static void error(const char *string) { /* - * * Match the format of "cc" to allow sh users to * zic ... 2>&1 | - * error -t "*" -v * on BSD systems. + * Match the format of "cc" to allow sh users to zic ... 2>&1 | + * error -t "*" -v on BSD systems. */ (void) fprintf(stderr, _("\"%s\", line %d: %s"), filename, linenum, string); @@ -564,7 +572,7 @@ main(int argc, char *argv[]) for (i = 0; i < nzones; i = j) { /* - * * Find the next non-continuation zone entry. + * Find the next non-continuation zone entry. */ for (j = i + 1; j < nzones && zones[j].z_name == NULL; ++j) continue; @@ -572,7 +580,7 @@ main(int argc, char *argv[]) } /* - * * Make links. + * Make links. */ for (i = 0; i < nlinks; ++i) { @@ -616,7 +624,7 @@ dolink(const char *fromfile, const char *tofile) } /* - * * We get to be careful here since * there's a fair chance of root + * We get to be careful here since there's a fair chance of root * running us. */ if (!itsdir(toname)) @@ -670,11 +678,11 @@ dolink(const char *fromfile, const char *tofile) #endif /* !defined INT_MIN */ /* -** The tz file format currently allows at most 32-bit quantities. -** This restriction should be removed before signed 32-bit values -** wrap around in 2038, but unfortunately this will require a -** change to the tz file format. -*/ + * The tz file format currently allows at most 32-bit quantities. + * This restriction should be removed before signed 32-bit values + * wrap around in 2038, but unfortunately this will require a + * change to the tz file format. + */ #define MAX_BITS_IN_FILE 32 #define TIME_T_BITS_IN_FILE ((TYPE_BIT(time_t) < MAX_BITS_IN_FILE) ? TYPE_BIT(time_t) : MAX_BITS_IN_FILE) @@ -717,12 +725,12 @@ itsdir(const char *name) } /* -** Associate sets of rules with zones. -*/ + * Associate sets of rules with zones. + */ /* -** Sort by rule name. -*/ + * Sort by rule name. + */ static int rcomp(const void *cp1, const void *cp2) @@ -800,14 +808,14 @@ associate(void) if (zp->z_nrules == 0) { /* - * * Maybe we have a local standard time offset. + * Maybe we have a local standard time offset. */ eat(zp->z_filename, zp->z_linenum); zp->z_stdoff = gethms(zp->z_rule, _("unruly zone"), TRUE); /* - * * Note, though, that if there's no rule, * a '%s' in the + * Note, though, that if there's no rule, a '%s' in the * format is a bad thing. */ if (strchr(zp->z_format, '%') != 0) @@ -927,14 +935,14 @@ infile(const char *name) error(_("expected continuation line not found")); } -/* -** Convert a string of one of the forms -** h -h hh:mm -hh:mm hh:mm:ss -hh:mm:ss -** into a number of seconds. -** A null string maps to zero. -** Call error with errstring and return zero on errors. -*/ - +/*---------- + * Convert a string of one of the forms + * h -h hh:mm -hh:mm hh:mm:ss -hh:mm:ss + * into a number of seconds. + * A null string maps to zero. + * Call error with errstring and return zero on errors. + *---------- + */ static long gethms(const char *string, const char *errstring, const int signable) { @@ -1144,7 +1152,7 @@ inzsub(register char **fields, const int nfields, const int iscont) zones[nzones++] = z; /* - * * If there was an UNTIL field on this line, * there's more + * If there was an UNTIL field on this line, there's more * information about the zone on the next line. */ return hasuntil; @@ -1302,7 +1310,9 @@ inlink(register char **fields, const int nfields) } static void -rulesub(register struct rule * rp, const char *loyearp, const char *hiyearp, const char *typep, const char *monthp, const char *dayp, const char *timep) +rulesub(register struct rule * rp, const char *loyearp, const char *hiyearp, + const char *typep, const char *monthp, const char *dayp, + const char *timep) { register const struct lookup *lp; register const char *cp; @@ -1346,7 +1356,7 @@ rulesub(register struct rule * rp, const char *loyearp, const char *hiyearp, con ifree(dp); /* - * * Year work. + * Year work. */ cp = loyearp; lp = byword(cp, begin_years); @@ -1428,8 +1438,7 @@ rulesub(register struct rule * rp, const char *loyearp, const char *hiyearp, con min_year = rp->r_loyear; /* - * * Day work. * Accept things such as: * 1 * last-Sunday * Sun<=20 * - * Sun>=7 + * Day work. Accept things such as: 1 last-Sunday Sun<=20 Sun>=7 */ dp = ecpyalloc(dayp); if ((lp = byword(dp, lasts)) != NULL) @@ -1520,14 +1529,14 @@ writezone(const char *name) unsigned char types[TZ_MAX_TIMES]; /* - * * Sort. + * Sort. */ if (timecnt > 1) (void) qsort((void *) attypes, (size_t) timecnt, (size_t) sizeof *attypes, atcomp); /* - * * Optimize. + * Optimize. */ { int fromi; @@ -1560,7 +1569,7 @@ writezone(const char *name) } /* - * * Transfer. + * Transfer. */ for (i = 0; i < timecnt; ++i) { @@ -1572,7 +1581,7 @@ writezone(const char *name) (void) sprintf(fullname, "%s/%s", directory, name); /* - * * Remove old file, if any, to snap links. + * Remove old file, if any, to snap links. */ if (!itsdir(fullname) && remove(fullname) != 0 && errno != ENOENT) { @@ -1714,14 +1723,14 @@ outzone(const struct zone * zpfirst, const int zonecount) char startbuf[BUFSIZ]; /* - * * Now. . .finally. . .generate some useful data! + * Now. . .finally. . .generate some useful data! */ timecnt = 0; typecnt = 0; charcnt = 0; /* - * * Thanks to Earl Chew (earl@dnd.icp.nec.com.au) * for noting the + * Thanks to Earl Chew (earl@dnd.icp.nec.com.au) for noting the * need to unconditionally initialize startttisstd. */ startttisstd = FALSE; @@ -1729,7 +1738,7 @@ outzone(const struct zone * zpfirst, const int zonecount) for (i = 0; i < zonecount; ++i) { /* - * * A guess that may well be corrected later. + * A guess that may well be corrected later. */ stdoff = 0; zp = &zpfirst[i]; @@ -1764,7 +1773,7 @@ outzone(const struct zone * zpfirst, const int zonecount) break; /* - * * Mark which rules to do in the current year. * For + * Mark which rules to do in the current year. For * those to do, calculate rpytime(rp, year); */ for (j = 0; j < zp->z_nrules; ++j) @@ -1789,8 +1798,8 @@ outzone(const struct zone * zpfirst, const int zonecount) if (useuntil) { /* - * * Turn untiltime into UTC * assuming the - * current gmtoff and * stdoff values. + * Turn untiltime into UTC assuming the + * current gmtoff and stdoff values. */ untiltime = zp->z_untiltime; if (!zp->z_untilrule.r_todisgmt) @@ -1802,7 +1811,7 @@ outzone(const struct zone * zpfirst, const int zonecount) } /* - * * Find the rule (of those to do, if any) * that + * Find the rule (of those to do, if any) that * takes effect earliest in the year. */ k = -1; @@ -1885,7 +1894,7 @@ outzone(const struct zone * zpfirst, const int zonecount) } /* - * * Now we may get to set starttime for the next zone line. + * Now we may get to set starttime for the next zone line. */ if (useuntil) { @@ -1930,7 +1939,8 @@ addtt(const time_t starttime, int type) } static int -addtype(const long gmtoff, const char *abbr, const int isdst, const int ttisstd, const int ttisgmt) +addtype(const long gmtoff, const char *abbr, const int isdst, + const int ttisstd, const int ttisgmt) { register int i, j; @@ -1952,7 +1962,7 @@ addtype(const long gmtoff, const char *abbr, const int isdst, const int ttisstd, } /* - * * See if there's already an entry for this zone type. * If so, just + * See if there's already an entry for this zone type. If so, just * return its index. */ for (i = 0; i < typecnt; ++i) @@ -1965,7 +1975,7 @@ addtype(const long gmtoff, const char *abbr, const int isdst, const int ttisstd, } /* - * * There isn't one; add a new one, unless there are already too * + * There isn't one; add a new one, unless there are already too * many. */ if (typecnt >= TZ_MAX_TYPES) @@ -2031,7 +2041,7 @@ adjleap(void) register long last = 0; /* - * * propagate leap seconds forward + * propagate leap seconds forward */ for (i = 0; i < leapcnt; ++i) { @@ -2107,14 +2117,14 @@ byword(register const char *word, register const struct lookup * table) return NULL; /* - * * Look for exact match. + * Look for exact match. */ for (lp = table; lp->l_word != NULL; ++lp) if (ciequal(word, lp->l_word)) return lp; /* - * * Look for inexact match. + * Look for inexact match. */ foundlp = NULL; for (lp = table; lp->l_word != NULL; ++lp) @@ -2200,9 +2210,9 @@ tadd(const time_t t1, const long t2) } /* -** Given a rule, and a year, compute the date - in seconds since January 1, -** 1970, 00:00 LOCAL time - in that year that the rule refers to. -*/ + * Given a rule, and a year, compute the date - in seconds since January 1, + * 1970, 00:00 LOCAL time - in that year that the rule refers to. + */ static time_t rpytime(register const struct rule * rp, register const int wantedy) @@ -2261,7 +2271,7 @@ rpytime(register const struct rule * rp, register const int wantedy) wday = eitol(EPOCH_WDAY); /* - * * Don't trust mod of negative numbers. + * Don't trust mod of negative numbers. */ if (dayoff >= 0) wday = (wday + dayoff) % LDAYSPERWEEK; @@ -2333,7 +2343,7 @@ mkdirs(char *argname) #ifdef WIN32 /* - * * DOS drive specifier? + * DOS drive specifier? */ if (isalpha((unsigned char) name[0]) && name[1] == ':' && name[2] == '\0') @@ -2345,9 +2355,9 @@ mkdirs(char *argname) if (!itsdir(name)) { /* - * * It doesn't seem to exist, so we try to create it. * - * Creation may fail because of the directory being * created - * by some other multiprocessor, so we get * to do extra + * It doesn't seem to exist, so we try to create it. + * Creation may fail because of the directory being created + * by some other multiprocessor, so we get to do extra * checking. */ if (mkdir(name, MKDIR_UMASK) != 0) @@ -2387,8 +2397,8 @@ eitol(const int i) } /* -** UNIX was a registered trademark of The Open Group in 2003. -*/ + * UNIX was a registered trademark of The Open Group in 2003. + */ #ifdef WIN32