|
|
|
@ -3,7 +3,7 @@ |
|
|
|
|
* 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). |
|
|
|
|
* |
|
|
|
|
* IDENTIFICATION |
|
|
|
|
* $PostgreSQL: pgsql/src/timezone/zic.c,v 1.14 2005/04/19 03:13:59 momjian Exp $ |
|
|
|
|
* $PostgreSQL: pgsql/src/timezone/zic.c,v 1.15 2005/06/20 08:00:51 neilc Exp $ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include "postgres.h" |
|
|
|
@ -134,11 +134,11 @@ static char *memcheck(char *tocheck); |
|
|
|
|
static int mkdirs(char *filename); |
|
|
|
|
static void newabbr(const char *abbr); |
|
|
|
|
static long oadd(long t1, long t2); |
|
|
|
|
static void outzone(const struct zone * zp, int ntzones); |
|
|
|
|
static void outzone(const struct zone *zp, int ntzones); |
|
|
|
|
static void puttzcode(long code, FILE *fp); |
|
|
|
|
static int rcomp(const void *leftp, const void *rightp); |
|
|
|
|
static pg_time_t rpytime(const struct rule * rp, int wantedy); |
|
|
|
|
static void rulesub(struct rule * rp, |
|
|
|
|
static pg_time_t rpytime(const struct rule *rp, int wantedy); |
|
|
|
|
static void rulesub(struct rule *rp, |
|
|
|
|
const char *loyearp, const char *hiyearp, |
|
|
|
|
const char *typep, const char *monthp, |
|
|
|
|
const char *dayp, const char *timep); |
|
|
|
@ -390,7 +390,7 @@ memcheck(char *ptr) |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
eats(const char *name, const int num, const char *rname, const int rnum) |
|
|
|
|
eats(const char *name, int num, const char *rname, int rnum) |
|
|
|
|
{ |
|
|
|
|
filename = name; |
|
|
|
|
linenum = num; |
|
|
|
@ -399,7 +399,7 @@ eats(const char *name, const int num, const char *rname, const int rnum) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
eat(const char *name, const int num) |
|
|
|
|
eat(const char *name, int num) |
|
|
|
|
{ |
|
|
|
|
eats(name, num, (char *) NULL, -1); |
|
|
|
|
} |
|
|
|
@ -450,9 +450,9 @@ static int sflag = FALSE; |
|
|
|
|
int |
|
|
|
|
main(int argc, char *argv[]) |
|
|
|
|
{ |
|
|
|
|
register int i; |
|
|
|
|
register int j; |
|
|
|
|
register int c; |
|
|
|
|
int i; |
|
|
|
|
int j; |
|
|
|
|
int c; |
|
|
|
|
|
|
|
|
|
#ifndef WIN32 |
|
|
|
|
(void) umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH)); |
|
|
|
@ -585,8 +585,8 @@ main(int argc, char *argv[]) |
|
|
|
|
static void |
|
|
|
|
dolink(const char *fromfile, const char *tofile) |
|
|
|
|
{ |
|
|
|
|
register char *fromname; |
|
|
|
|
register char *toname; |
|
|
|
|
char *fromname; |
|
|
|
|
char *toname; |
|
|
|
|
|
|
|
|
|
if (fromfile[0] == '/') |
|
|
|
|
fromname = ecpyalloc(fromfile); |
|
|
|
@ -625,7 +625,7 @@ dolink(const char *fromfile, const char *tofile) |
|
|
|
|
!itsdir(fromname)) |
|
|
|
|
{ |
|
|
|
|
const char *s = tofile; |
|
|
|
|
register char *symlinkcontents = NULL; |
|
|
|
|
char *symlinkcontents = NULL; |
|
|
|
|
|
|
|
|
|
while ((s = strchr(s + 1, '/')) != NULL) |
|
|
|
|
symlinkcontents = ecatalloc(symlinkcontents, "../"); |
|
|
|
@ -695,8 +695,8 @@ setboundaries(void) |
|
|
|
|
static int |
|
|
|
|
itsdir(const char *name) |
|
|
|
|
{ |
|
|
|
|
register char *myname; |
|
|
|
|
register int accres; |
|
|
|
|
char *myname; |
|
|
|
|
int accres; |
|
|
|
|
|
|
|
|
|
myname = ecpyalloc(name); |
|
|
|
|
myname = ecatalloc(myname, "/."); |
|
|
|
@ -723,12 +723,12 @@ rcomp(const void *cp1, const void *cp2) |
|
|
|
|
static void |
|
|
|
|
associate(void) |
|
|
|
|
{ |
|
|
|
|
register struct zone *zp; |
|
|
|
|
register struct rule *rp; |
|
|
|
|
register int base, |
|
|
|
|
out; |
|
|
|
|
register int i, |
|
|
|
|
j; |
|
|
|
|
struct zone *zp; |
|
|
|
|
struct rule *rp; |
|
|
|
|
int base, |
|
|
|
|
out; |
|
|
|
|
int i, |
|
|
|
|
j; |
|
|
|
|
|
|
|
|
|
if (nrules != 0) |
|
|
|
|
{ |
|
|
|
@ -810,13 +810,13 @@ associate(void) |
|
|
|
|
static void |
|
|
|
|
infile(const char *name) |
|
|
|
|
{ |
|
|
|
|
register FILE *fp; |
|
|
|
|
register char **fields; |
|
|
|
|
register char *cp; |
|
|
|
|
register const struct lookup *lp; |
|
|
|
|
register int nfields; |
|
|
|
|
register int wantcont; |
|
|
|
|
register int num; |
|
|
|
|
FILE *fp; |
|
|
|
|
char **fields; |
|
|
|
|
char *cp; |
|
|
|
|
const struct lookup *lp; |
|
|
|
|
int nfields; |
|
|
|
|
int wantcont; |
|
|
|
|
int num; |
|
|
|
|
char buf[BUFSIZ]; |
|
|
|
|
|
|
|
|
|
if (strcmp(name, "-") == 0) |
|
|
|
@ -925,7 +925,7 @@ infile(const char *name) |
|
|
|
|
*---------- |
|
|
|
|
*/ |
|
|
|
|
static long |
|
|
|
|
gethms(const char *string, const char *errstring, const int signable) |
|
|
|
|
gethms(const char *string, const char *errstring, int signable) |
|
|
|
|
{ |
|
|
|
|
int hh, |
|
|
|
|
mm, |
|
|
|
@ -969,7 +969,7 @@ gethms(const char *string, const char *errstring, const int signable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
inrule(register char **fields, const int nfields) |
|
|
|
|
inrule(char **fields, int nfields) |
|
|
|
|
{ |
|
|
|
|
static struct rule r; |
|
|
|
|
|
|
|
|
@ -996,9 +996,9 @@ inrule(register char **fields, const int nfields) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
inzone(register char **fields, const int nfields) |
|
|
|
|
inzone(char **fields, int nfields) |
|
|
|
|
{ |
|
|
|
|
register int i; |
|
|
|
|
int i; |
|
|
|
|
static char *buf; |
|
|
|
|
|
|
|
|
|
if (nfields < ZONE_MINFIELDS || nfields > ZONE_MAXFIELDS) |
|
|
|
@ -1043,7 +1043,7 @@ inzone(register char **fields, const int nfields) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
inzcont(register char **fields, const int nfields) |
|
|
|
|
inzcont(char **fields, int nfields) |
|
|
|
|
{ |
|
|
|
|
if (nfields < ZONEC_MINFIELDS || nfields > ZONEC_MAXFIELDS) |
|
|
|
|
{ |
|
|
|
@ -1054,18 +1054,18 @@ inzcont(register char **fields, const int nfields) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
inzsub(register char **fields, const int nfields, const int iscont) |
|
|
|
|
inzsub(char **fields, int nfields, int iscont) |
|
|
|
|
{ |
|
|
|
|
register char *cp; |
|
|
|
|
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; |
|
|
|
|
int i_gmtoff, |
|
|
|
|
i_rule, |
|
|
|
|
i_format; |
|
|
|
|
int i_untilyear, |
|
|
|
|
i_untilmonth; |
|
|
|
|
int i_untilday, |
|
|
|
|
i_untiltime; |
|
|
|
|
int hasuntil; |
|
|
|
|
|
|
|
|
|
if (iscont) |
|
|
|
|
{ |
|
|
|
@ -1140,11 +1140,11 @@ inzsub(register char **fields, const int nfields, const int iscont) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
inleap(register char **fields, const int nfields) |
|
|
|
|
inleap(char **fields, int nfields) |
|
|
|
|
{ |
|
|
|
|
register const char *cp; |
|
|
|
|
register const struct lookup *lp; |
|
|
|
|
register int i, |
|
|
|
|
const char *cp; |
|
|
|
|
const struct lookup *lp; |
|
|
|
|
int i, |
|
|
|
|
j; |
|
|
|
|
int year, |
|
|
|
|
month, |
|
|
|
@ -1219,7 +1219,7 @@ inleap(register char **fields, const int nfields) |
|
|
|
|
tod = gethms(fields[LP_TIME], _("invalid time of day"), FALSE); |
|
|
|
|
cp = fields[LP_CORR]; |
|
|
|
|
{ |
|
|
|
|
register int positive; |
|
|
|
|
int positive; |
|
|
|
|
int count; |
|
|
|
|
|
|
|
|
|
if (strcmp(cp, "") == 0) |
|
|
|
@ -1257,7 +1257,7 @@ inleap(register char **fields, const int nfields) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
inlink(register char **fields, const int nfields) |
|
|
|
|
inlink(char **fields, int nfields) |
|
|
|
|
{ |
|
|
|
|
struct link l; |
|
|
|
|
|
|
|
|
@ -1286,14 +1286,14 @@ inlink(register char **fields, const int nfields) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
rulesub(register struct rule * rp, const char *loyearp, const char *hiyearp, |
|
|
|
|
rulesub(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; |
|
|
|
|
register char *dp; |
|
|
|
|
register char *ep; |
|
|
|
|
const struct lookup *lp; |
|
|
|
|
const char *cp; |
|
|
|
|
char *dp; |
|
|
|
|
char *ep; |
|
|
|
|
|
|
|
|
|
if ((lp = byword(monthp, mon_names)) == NULL) |
|
|
|
|
{ |
|
|
|
@ -1464,17 +1464,17 @@ rulesub(register struct rule * rp, const char *loyearp, const char *hiyearp, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
convert(const long val, char *buf) |
|
|
|
|
convert(long val, char *buf) |
|
|
|
|
{ |
|
|
|
|
register int i; |
|
|
|
|
register long shift; |
|
|
|
|
int i; |
|
|
|
|
long shift; |
|
|
|
|
|
|
|
|
|
for (i = 0, shift = 24; i < 4; ++i, shift -= 8) |
|
|
|
|
buf[i] = val >> shift; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
puttzcode(const long val, FILE *fp) |
|
|
|
|
puttzcode(long val, FILE *fp) |
|
|
|
|
{ |
|
|
|
|
char buf[4]; |
|
|
|
|
|
|
|
|
@ -1496,9 +1496,9 @@ atcomp(const void *avp, const void *bvp) |
|
|
|
|
static void |
|
|
|
|
writezone(const char *name) |
|
|
|
|
{ |
|
|
|
|
register FILE *fp; |
|
|
|
|
register int i, |
|
|
|
|
j; |
|
|
|
|
FILE *fp; |
|
|
|
|
int i, |
|
|
|
|
j; |
|
|
|
|
static char *fullname; |
|
|
|
|
static struct tzhead tzh; |
|
|
|
|
pg_time_t ats[TZ_MAX_TIMES]; |
|
|
|
@ -1660,7 +1660,7 @@ writezone(const char *name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
doabbr(char *abbr, const char *format, const char *letters, const int isdst) |
|
|
|
|
doabbr(char *abbr, const char *format, const char *letters, int isdst) |
|
|
|
|
{ |
|
|
|
|
if (strchr(format, '/') == NULL) |
|
|
|
|
{ |
|
|
|
@ -1679,23 +1679,23 @@ doabbr(char *abbr, const char *format, const char *letters, const int isdst) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
outzone(const struct zone * zpfirst, const int zonecount) |
|
|
|
|
outzone(const struct zone *zpfirst, int zonecount) |
|
|
|
|
{ |
|
|
|
|
register const struct zone *zp; |
|
|
|
|
register struct rule *rp; |
|
|
|
|
register int i, |
|
|
|
|
j; |
|
|
|
|
register int usestart, |
|
|
|
|
useuntil; |
|
|
|
|
register pg_time_t starttime = 0; |
|
|
|
|
register pg_time_t untiltime = 0; |
|
|
|
|
register long gmtoff; |
|
|
|
|
register long stdoff; |
|
|
|
|
register int year; |
|
|
|
|
register long startoff; |
|
|
|
|
register int startttisstd; |
|
|
|
|
register int startttisgmt; |
|
|
|
|
register int type; |
|
|
|
|
const struct zone *zp; |
|
|
|
|
struct rule *rp; |
|
|
|
|
int i, |
|
|
|
|
j; |
|
|
|
|
int usestart, |
|
|
|
|
useuntil; |
|
|
|
|
pg_time_t starttime = 0; |
|
|
|
|
pg_time_t untiltime = 0; |
|
|
|
|
long gmtoff; |
|
|
|
|
long stdoff; |
|
|
|
|
int year; |
|
|
|
|
long startoff; |
|
|
|
|
int startttisstd; |
|
|
|
|
int startttisgmt; |
|
|
|
|
int type; |
|
|
|
|
char startbuf[BUFSIZ]; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -1765,10 +1765,9 @@ outzone(const struct zone * zpfirst, const int zonecount) |
|
|
|
|
} |
|
|
|
|
for (;;) |
|
|
|
|
{ |
|
|
|
|
register int k; |
|
|
|
|
register pg_time_t jtime, |
|
|
|
|
ktime = 0; |
|
|
|
|
register long offset; |
|
|
|
|
int k; |
|
|
|
|
pg_time_t jtime, ktime = 0; |
|
|
|
|
long offset; |
|
|
|
|
char buf[BUFSIZ]; |
|
|
|
|
|
|
|
|
|
if (useuntil) |
|
|
|
@ -1915,11 +1914,11 @@ addtt(const pg_time_t starttime, int type) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
addtype(const long gmtoff, const char *abbr, const int isdst, |
|
|
|
|
const int ttisstd, const int ttisgmt) |
|
|
|
|
addtype(long gmtoff, const char *abbr, int isdst, |
|
|
|
|
int ttisstd, int ttisgmt) |
|
|
|
|
{ |
|
|
|
|
register int i, |
|
|
|
|
j; |
|
|
|
|
int i; |
|
|
|
|
int j; |
|
|
|
|
|
|
|
|
|
if (isdst != TRUE && isdst != FALSE) |
|
|
|
|
{ |
|
|
|
@ -1974,10 +1973,10 @@ addtype(const long gmtoff, const char *abbr, const int isdst, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
leapadd(const pg_time_t t, const int positive, const int rolling, int count) |
|
|
|
|
leapadd(const pg_time_t t, int positive, int rolling, int count) |
|
|
|
|
{ |
|
|
|
|
register int i, |
|
|
|
|
j; |
|
|
|
|
int i; |
|
|
|
|
int j; |
|
|
|
|
|
|
|
|
|
if (leapcnt + (positive ? count : 1) > TZ_MAX_LEAPS) |
|
|
|
|
{ |
|
|
|
@ -2012,8 +2011,8 @@ leapadd(const pg_time_t t, const int positive, const int rolling, int count) |
|
|
|
|
static void |
|
|
|
|
adjleap(void) |
|
|
|
|
{ |
|
|
|
|
register int i; |
|
|
|
|
register long last = 0; |
|
|
|
|
int i; |
|
|
|
|
long last = 0; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* propagate leap seconds forward |
|
|
|
@ -2026,7 +2025,7 @@ adjleap(void) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
yearistype(const int year, const char *type) |
|
|
|
|
yearistype(int year, const char *type) |
|
|
|
|
{ |
|
|
|
|
static char *buf; |
|
|
|
|
int result; |
|
|
|
@ -2059,7 +2058,7 @@ lowerit(int a) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
ciequal(register const char *ap, register const char *bp) |
|
|
|
|
ciequal(const char *ap, const char *bp) |
|
|
|
|
{ |
|
|
|
|
while (lowerit(*ap) == lowerit(*bp++)) |
|
|
|
|
if (*ap++ == '\0') |
|
|
|
@ -2068,7 +2067,7 @@ ciequal(register const char *ap, register const char *bp) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
itsabbr(register const char *abbr, register const char *word) |
|
|
|
|
itsabbr(const char *abbr, const char *word) |
|
|
|
|
{ |
|
|
|
|
if (lowerit(*abbr) != lowerit(*word)) |
|
|
|
|
return FALSE; |
|
|
|
@ -2083,10 +2082,10 @@ itsabbr(register const char *abbr, register const char *word) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static const struct lookup * |
|
|
|
|
byword(register const char *word, register const struct lookup * table) |
|
|
|
|
byword(const char *word, const struct lookup *table) |
|
|
|
|
{ |
|
|
|
|
register const struct lookup *foundlp; |
|
|
|
|
register const struct lookup *lp; |
|
|
|
|
const struct lookup *foundlp; |
|
|
|
|
const struct lookup *lp; |
|
|
|
|
|
|
|
|
|
if (word == NULL || table == NULL) |
|
|
|
|
return NULL; |
|
|
|
@ -2114,11 +2113,11 @@ byword(register const char *word, register const struct lookup * table) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static char ** |
|
|
|
|
getfields(register char *cp) |
|
|
|
|
getfields(char *cp) |
|
|
|
|
{ |
|
|
|
|
register char *dp; |
|
|
|
|
register char **array; |
|
|
|
|
register int nsubs; |
|
|
|
|
char *dp; |
|
|
|
|
char **array; |
|
|
|
|
int nsubs; |
|
|
|
|
|
|
|
|
|
if (cp == NULL) |
|
|
|
|
return NULL; |
|
|
|
@ -2153,9 +2152,9 @@ getfields(register char *cp) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static long |
|
|
|
|
oadd(const long t1, const long t2) |
|
|
|
|
oadd(long t1, long t2) |
|
|
|
|
{ |
|
|
|
|
register long t; |
|
|
|
|
long t; |
|
|
|
|
|
|
|
|
|
t = t1 + t2; |
|
|
|
|
if ((t2 > 0 && t <= t1) || (t2 < 0 && t >= t1)) |
|
|
|
@ -2167,9 +2166,9 @@ oadd(const long t1, const long t2) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static pg_time_t |
|
|
|
|
tadd(const pg_time_t t1, const long t2) |
|
|
|
|
tadd(const pg_time_t t1, long t2) |
|
|
|
|
{ |
|
|
|
|
register pg_time_t t; |
|
|
|
|
pg_time_t t; |
|
|
|
|
|
|
|
|
|
if (t1 == max_time && t2 > 0) |
|
|
|
|
return max_time; |
|
|
|
@ -2190,13 +2189,13 @@ tadd(const pg_time_t t1, const long t2) |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
static pg_time_t |
|
|
|
|
rpytime(register const struct rule * rp, register const int wantedy) |
|
|
|
|
rpytime(const struct rule *rp, int wantedy) |
|
|
|
|
{ |
|
|
|
|
register int y, |
|
|
|
|
m, |
|
|
|
|
i; |
|
|
|
|
register long dayoff; /* with a nod to Margaret O. */ |
|
|
|
|
register pg_time_t t; |
|
|
|
|
int y, |
|
|
|
|
m, |
|
|
|
|
i; |
|
|
|
|
long dayoff; /* with a nod to Margaret O. */ |
|
|
|
|
pg_time_t t; |
|
|
|
|
|
|
|
|
|
if (wantedy == INT_MIN) |
|
|
|
|
return min_time; |
|
|
|
@ -2240,7 +2239,7 @@ rpytime(register const struct rule * rp, register const int wantedy) |
|
|
|
|
dayoff = oadd(dayoff, eitol(i)); |
|
|
|
|
if (rp->r_dycode == DC_DOWGEQ || rp->r_dycode == DC_DOWLEQ) |
|
|
|
|
{ |
|
|
|
|
register long wday; |
|
|
|
|
long wday; |
|
|
|
|
|
|
|
|
|
#define LDAYSPERWEEK ((long) DAYSPERWEEK) |
|
|
|
|
wday = eitol(EPOCH_WDAY); |
|
|
|
@ -2289,7 +2288,7 @@ rpytime(register const struct rule * rp, register const int wantedy) |
|
|
|
|
static void |
|
|
|
|
newabbr(const char *string) |
|
|
|
|
{ |
|
|
|
|
register int i; |
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
i = strlen(string) + 1; |
|
|
|
|
if (charcnt + i > TZ_MAX_CHARS) |
|
|
|
@ -2304,8 +2303,8 @@ newabbr(const char *string) |
|
|
|
|
static int |
|
|
|
|
mkdirs(char *argname) |
|
|
|
|
{ |
|
|
|
|
register char *name; |
|
|
|
|
register char *cp; |
|
|
|
|
char *name; |
|
|
|
|
char *cp; |
|
|
|
|
|
|
|
|
|
if (argname == NULL || *argname == '\0') |
|
|
|
|
return 0; |
|
|
|
@ -2353,7 +2352,7 @@ mkdirs(char *argname) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static long |
|
|
|
|
eitol(const int i) |
|
|
|
|
eitol(int i) |
|
|
|
|
{ |
|
|
|
|
long l; |
|
|
|
|
|
|
|
|
|