From 6b599c2ad6bd41187ba440a517065f57013abc21 Mon Sep 17 00:00:00 2001 From: Garrett Wollman Date: Fri, 4 Feb 1994 00:22:30 +0000 Subject: [PATCH] Timezone compiler to mach new data files from ADO --- share/zoneinfo/Theory | 2 +- share/zoneinfo/ialloc.c | 8 +- share/zoneinfo/private.h | 17 +++-- share/zoneinfo/zic.8 | 2 +- share/zoneinfo/zic.c | 161 ++++++++++++++++++++------------------- 5 files changed, 100 insertions(+), 90 deletions(-) diff --git a/share/zoneinfo/Theory b/share/zoneinfo/Theory index 610a4de767..93a07c0f7d 100644 --- a/share/zoneinfo/Theory +++ b/share/zoneinfo/Theory @@ -1,4 +1,4 @@ -@(#)Theory 7.1 +@(#)Theory 7.2 These time and date functions are much like the System V Release 2.0 (SVR2) time and date functions; there are a few additions and changes to extend diff --git a/share/zoneinfo/ialloc.c b/share/zoneinfo/ialloc.c index 4c49ac87b2..7dc2f2b494 100644 --- a/share/zoneinfo/ialloc.c +++ b/share/zoneinfo/ialloc.c @@ -1,6 +1,6 @@ #ifndef lint #ifndef NOID -static char elsieid[] = "@(#)ialloc.c 8.20"; +static char elsieid[] = "@(#)ialloc.c 8.21"; #endif /* !defined NOID */ #endif /* !defined lint */ @@ -10,7 +10,8 @@ static char elsieid[] = "@(#)ialloc.c 8.20"; #ifdef MAL #define NULLMAL(x) ((x) == NULL || (x) == MAL) -#else /* !defined MAL */ +#endif /* defined MAL */ +#ifndef MAL #define NULLMAL(x) ((x) == NULL) #endif /* !defined MAL */ @@ -32,7 +33,8 @@ const int n; result = malloc((alloc_size_t) nonzero(n)); return NULLMAL(result) ? NULL : result; -#else /* !defined MAL */ +#endif /* defined MAL */ +#ifndef MAL return malloc((alloc_size_t) nonzero(n)); #endif /* !defined MAL */ } diff --git a/share/zoneinfo/private.h b/share/zoneinfo/private.h index 8f03eef005..5af259c626 100644 --- a/share/zoneinfo/private.h +++ b/share/zoneinfo/private.h @@ -16,7 +16,7 @@ #ifndef lint #ifndef NOID -static char privatehid[] = "@(#)private.h 7.4"; +static char privatehid[] = "@(#)private.h 7.5"; #endif /* !defined NOID */ #endif /* !defined lint */ @@ -51,7 +51,8 @@ static char privatehid[] = "@(#)private.h 7.4"; #ifndef P #ifdef __STDC__ #define P(x) x -#else /* !defined __STDC__ */ +#endif /* defined __STDC__ */ +#ifndef __STDC__ #define ASTERISK * #define P(x) ( /ASTERISK x ASTERISK/ ) #endif /* !defined __STDC__ */ @@ -63,7 +64,8 @@ static char privatehid[] = "@(#)private.h 7.4"; #ifdef __STDC__ typedef void * genericptr_t; -#else /* !defined __STDC__ */ +#endif /* defined __STDC__ */ +#ifndef __STDC__ typedef char * genericptr_t; #endif /* !defined __STDC__ */ @@ -92,7 +94,8 @@ extern int unlink P((const char * filename)); #ifdef MAXPATHLEN #define FILENAME_MAX MAXPATHLEN -#else /* !defined MAXPATHLEN */ +#endif /* defined MAXPATHLEN */ +#ifndef MAXPATHLEN #define FILENAME_MAX 1024 /* Pure guesswork */ #endif /* !defined MAXPATHLEN */ @@ -112,7 +115,8 @@ extern int unlink P((const char * filename)); #define qsort_size_t size_t #define fwrite_size_t size_t -#else /* !defined __STDC__ */ +#endif /* defined __STDC__ */ +#ifndef __STDC__ #ifndef alloc_size_t #define alloc_size_t unsigned @@ -121,7 +125,8 @@ extern int unlink P((const char * filename)); #ifndef qsort_size_t #ifdef USG #define qsort_size_t unsigned -#else /* !defined USG */ +#endif /* defined USG */ +#ifndef USG #define qsort_size_t int #endif /* !defined USG */ #endif /* !defined qsort_size_t */ diff --git a/share/zoneinfo/zic.8 b/share/zoneinfo/zic.8 index f32df73395..820a48e00d 100644 --- a/share/zoneinfo/zic.8 +++ b/share/zoneinfo/zic.8 @@ -400,4 +400,4 @@ the earliest transition time recorded in the compiled file is correct. /usr/local/etc/zoneinfo standard directory used for created files .SH "SEE ALSO" newctime(3), tzfile(5), zdump(8) -.\" @(#)zic.8 7.5 +.\" @(#)zic.8 7.6 diff --git a/share/zoneinfo/zic.c b/share/zoneinfo/zic.c index f44af0bf2e..eb19a5c3e3 100644 --- a/share/zoneinfo/zic.c +++ b/share/zoneinfo/zic.c @@ -1,6 +1,6 @@ #ifndef lint #ifndef NOID -static char elsieid[] = "@(#)zic.c 7.9"; +static char elsieid[] = "@(#)zic.c 7.19"; #endif /* !defined NOID */ #endif /* !defined lint */ @@ -72,7 +72,7 @@ extern char * scheck P((const char * string, const char * format)); static void addtt P((time_t starttime, int type)); static int addtype P((long gmtoff, const char * abbr, int isdst, - int ttisstd)); + int ttisstd)); static void leapadd P((time_t t, int positive, int rolling, int count)); static void adjleap P((void)); static void associate P((void)); @@ -546,10 +546,14 @@ const char * const tofile; if (!itsdir(toname)) (void) remove(toname); if (link(fromname, toname) != 0) { - (void) fprintf(stderr, "%s: Can't link from %s to ", - progname, fromname); - (void) perror(toname); - (void) exit(EXIT_FAILURE); + if (mkdirs(toname) != 0) + (void) exit(EXIT_FAILURE); + if (link(fromname, toname) != 0) { + (void) fprintf(stderr, "%s: Can't link from %s to ", + progname, fromname); + (void) perror(toname); + (void) exit(EXIT_FAILURE); + } } if (fromname != fromfile) ifree(fromname); @@ -842,7 +846,7 @@ const int nfields; if (strcmp(fields[ZF_NAME], TZDEFAULT) == 0 && lcltime != NULL) { buf = erealloc(buf, 132 + strlen(TZDEFAULT)); (void) sprintf(buf, - "\"Zone %s\" line and -l option are mutually exclusive", +"\"Zone %s\" line and -l option are mutually exclusive", TZDEFAULT); error(buf); return FALSE; @@ -850,7 +854,7 @@ const int nfields; if (strcmp(fields[ZF_NAME], TZDEFRULES) == 0 && psxrules != NULL) { buf = erealloc(buf, 132 + strlen(TZDEFRULES)); (void) sprintf(buf, - "\"Zone %s\" line and -p option are mutually exclusive", +"\"Zone %s\" line and -p option are mutually exclusive", TZDEFRULES); error(buf); return FALSE; @@ -935,15 +939,20 @@ const int iscont; fields[i_untilyear], "only", "", - (nfields > i_untilmonth) ? fields[i_untilmonth] : "Jan", + (nfields > i_untilmonth) ? + fields[i_untilmonth] : "Jan", (nfields > i_untilday) ? fields[i_untilday] : "1", (nfields > i_untiltime) ? fields[i_untiltime] : "0"); - z.z_untiltime = rpytime(&z.z_untilrule, z.z_untilrule.r_loyear); - if (iscont && nzones > 0 && z.z_untiltime < max_time && + z.z_untiltime = rpytime(&z.z_untilrule, + z.z_untilrule.r_loyear); + if (iscont && nzones > 0 && z.z_untiltime > min_time && + z.z_untiltime < max_time && + zones[nzones - 1].z_untiltime > min_time && + zones[nzones - 1].z_untiltime < max_time && zones[nzones - 1].z_untiltime >= z.z_untiltime) { error("Zone continuation line end time is not after end time of previous line"); - return FALSE; + return FALSE; } } zones = (struct zone *) erealloc((char *) zones, @@ -974,8 +983,7 @@ const int nfields; } dayoff = 0; cp = fields[LP_YEAR]; - if (sscanf(cp, scheck(cp, "%d"), &year) != 1 || - year < min_year || year > max_year) { + if (sscanf(cp, scheck(cp, "%d"), &year) != 1) { /* * Leapin' Lizards! */ @@ -1131,12 +1139,9 @@ char * const timep; "%s: panic: Invalid l_value %d\n", progname, lp->l_value); (void) exit(EXIT_FAILURE); - } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_loyear) != 1 || - rp->r_loyear < min_year || rp->r_loyear > max_year) { - if (noise) - error("invalid starting year"); - if (rp->r_loyear > max_year) - return; + } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_loyear) != 1) { + error("invalid starting year"); + return; } cp = hiyearp; if ((lp = byword(cp, end_years)) != NULL) switch ((int) lp->l_value) { @@ -1154,19 +1159,10 @@ char * const timep; "%s: panic: Invalid l_value %d\n", progname, lp->l_value); (void) exit(EXIT_FAILURE); - } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_hiyear) != 1 || - rp->r_hiyear < min_year || rp->r_hiyear > max_year) { - if (noise) - error("invalid ending year"); - if (rp->r_hiyear < min_year) - return; + } else if (sscanf(cp, scheck(cp, "%d"), &rp->r_hiyear) != 1) { + error("invalid ending year"); + return; } - if (rp->r_hiyear < min_year) - return; - if (rp->r_loyear < min_year) - rp->r_loyear = min_year; - if (rp->r_hiyear > max_year) - rp->r_hiyear = max_year; if (rp->r_loyear > rp->r_hiyear) { error("starting year greater than ending year"); return; @@ -1352,9 +1348,8 @@ const int zonecount; typecnt = 0; charcnt = 0; /* - ** Two guesses. . .the second may well be corrected later. + ** A guess that may well be corrected later. */ - gmtoff = zpfirst->z_gmtoff; stdoff = 0; /* ** Thanks to Earl Chew (earl@dnd.icp.nec.com.au) @@ -1365,19 +1360,23 @@ const int zonecount; starttime = 0; #endif /* defined lint */ for (i = 0; i < zonecount; ++i) { - usestart = i > 0; - useuntil = i < (zonecount - 1); zp = &zpfirst[i]; + usestart = i > 0 && (zp - 1)->z_untiltime > min_time; + useuntil = i < (zonecount - 1); + if (useuntil && zp->z_untiltime <= min_time) + continue; + gmtoff = zp->z_gmtoff; eat(zp->z_filename, zp->z_linenum); startisdst = -1; if (zp->z_nrules == 0) { - type = addtype(oadd(zp->z_gmtoff, zp->z_stdoff), - zp->z_format, zp->z_stdoff != 0, - startttisstd); + stdoff = zp->z_stdoff; + (void) strcpy(startbuf, zp->z_format); + type = addtype(oadd(zp->z_gmtoff, stdoff), + startbuf, stdoff != 0, startttisstd); if (usestart) addtt(starttime, type); - gmtoff = zp->z_gmtoff; - stdoff = zp->z_stdoff; + else if (stdoff != 0) + addtt(min_time, type); } else for (year = min_year; year <= max_year; ++year) { if (useuntil && year > zp->z_untilrule.r_hiyear) break; @@ -1407,11 +1406,11 @@ const int zonecount; ** assuming the current gmtoff and ** stdoff values. */ - offset = gmtoff; - if (!zp->z_untilrule.r_todisstd) - offset = oadd(offset, stdoff); untiltime = tadd(zp->z_untiltime, - -offset); + -gmtoff); + if (!zp->z_untilrule.r_todisstd) + untiltime = tadd(untiltime, + -stdoff); } /* ** Find the rule (of those to do, if any) @@ -1447,21 +1446,33 @@ const int zonecount; if (useuntil && ktime >= untiltime) break; if (usestart) { - if (ktime < starttime) { - stdoff = rp->r_stdoff; - startoff = oadd(zp->z_gmtoff, - rp->r_stdoff); - (void) sprintf(startbuf, - zp->z_format, - rp->r_abbrvar); - startisdst = - rp->r_stdoff != 0; - continue; + if (ktime < starttime) { + stdoff = rp->r_stdoff; + startoff = oadd(zp->z_gmtoff, + rp->r_stdoff); + (void) sprintf(startbuf, zp->z_format, + rp->r_abbrvar); + startisdst = rp->r_stdoff != 0; + continue; + } + usestart = FALSE; + if (ktime != starttime) { + if (startisdst < 0 && + zp->z_gmtoff != + (zp - 1)->z_gmtoff) { + type = (timecnt == 0) ? 0 : + types[timecnt - 1]; + startoff = oadd(gmtoffs[type], + -(zp - 1)->z_gmtoff); + startisdst = startoff != 0; + startoff = oadd(startoff, + zp->z_gmtoff); + (void) strcpy(startbuf, + &chars[abbrinds[type]]); } - if (ktime != starttime && - startisdst >= 0) + if (startisdst >= 0) addtt(starttime, addtype(startoff, startbuf, startisdst, startttisstd)); - usestart = FALSE; + } } eats(zp->z_filename, zp->z_linenum, rp->r_filename, rp->r_linenum); @@ -1470,9 +1481,7 @@ addtt(starttime, addtype(startoff, startbuf, startisdst, startttisstd)); offset = oadd(zp->z_gmtoff, rp->r_stdoff); type = addtype(offset, buf, rp->r_stdoff != 0, rp->r_todisstd); - if (timecnt != 0 || rp->r_stdoff != 0) - addtt(ktime, type); - gmtoff = zp->z_gmtoff; + addtt(ktime, type); stdoff = rp->r_stdoff; } } @@ -1480,9 +1489,10 @@ addtt(starttime, addtype(startoff, startbuf, startisdst, startttisstd)); ** Now we may get to set starttime for the next zone line. */ if (useuntil) { - starttime = tadd(zp->z_untiltime, - -gmtoffs[types[timecnt - 1]]); + starttime = tadd(zp->z_untiltime, -gmtoff); startttisstd = zp->z_untilrule.r_todisstd; + if (!startttisstd) + starttime = tadd(starttime, -stdoff); } } writezone(zpfirst->z_name); @@ -1495,6 +1505,8 @@ const int type; { if (timecnt != 0 && type == types[timecnt - 1]) return; /* easy enough! */ + if (timecnt == 0 && type == 0 && isdsts[0] == 0) + return; /* handled by default rule */ if (timecnt >= TZ_MAX_TIMES) { error("too many transitions?!"); (void) exit(EXIT_FAILURE); @@ -1827,24 +1839,14 @@ register const int wantedy; (void) exit(EXIT_FAILURE); } } - if (dayoff < 0 && !tt_signed) { - if (wantedy == rp->r_loyear) - return min_time; - error("time before zero"); - (void) exit(EXIT_FAILURE); - } + if (dayoff < 0 && !tt_signed) + return min_time; t = (time_t) dayoff * SECSPERDAY; /* ** Cheap overflow check. */ - if (t / SECSPERDAY != dayoff) { - if (wantedy == rp->r_hiyear) - return max_time; - if (wantedy == rp->r_loyear) - return min_time; - error("time overflow"); - (void) exit(EXIT_FAILURE); - } + if (t / SECSPERDAY != dayoff) + return (dayoff > 0) ? max_time : min_time; return tadd(t, rp->r_tod); } @@ -1855,7 +1857,7 @@ const char * const string; register int i; i = strlen(string) + 1; - if (charcnt + i >= TZ_MAX_CHARS) { + if (charcnt + i > TZ_MAX_CHARS) { error("too many, or too long, time zone abbreviations"); (void) exit(EXIT_FAILURE); } @@ -1908,7 +1910,8 @@ const int i; l = i; if ((i < 0 && l >= 0) || (i == 0 && l != 0) || (i > 0 && l <= 0)) { - (void) fprintf(stderr, "%s: %d did not sign extend correctly\n", + (void) fprintf(stderr, + "%s: %d did not sign extend correctly\n", progname, i); (void) exit(EXIT_FAILURE); } -- 2.20.1