1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list

provided by Andrew.
This commit is contained in:
Bruce Momjian
2009-06-11 14:49:15 +00:00
parent 4e86efb4e5
commit d747140279
654 changed files with 11900 additions and 11387 deletions

View File

@ -3,7 +3,7 @@
* 1996-06-05 by Arthur David Olson.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/localtime.c,v 1.20 2008/02/16 21:16:04 tgl Exp $
* $PostgreSQL: pgsql/src/timezone/localtime.c,v 1.21 2009/06/11 14:49:15 momjian Exp $
*/
/*
@ -77,7 +77,7 @@ struct rule
static long detzcode(const char *codep);
static pg_time_t detzcode64(const char *codep);
static int differ_by_repeat(pg_time_t t1, pg_time_t t0);
static int differ_by_repeat(pg_time_t t1, pg_time_t t0);
static const char *getzname(const char *strp);
static const char *getqzname(const char *strp, int delim);
static const char *getnum(const char *strp, int *nump, int min, int max);
@ -85,16 +85,16 @@ static const char *getsecs(const char *strp, long *secsp);
static const char *getoffset(const char *strp, long *offsetp);
static const char *getrule(const char *strp, struct rule * rulep);
static void gmtload(struct state * sp);
static struct pg_tm *gmtsub(const pg_time_t *timep, long offset,
struct pg_tm *tmp);
static struct pg_tm *localsub(const pg_time_t *timep, long offset,
struct pg_tm *tmp, const pg_tz *tz);
static int increment_overflow(int *number, int delta);
static struct pg_tm *gmtsub(const pg_time_t *timep, long offset,
struct pg_tm * tmp);
static struct pg_tm *localsub(const pg_time_t *timep, long offset,
struct pg_tm * tmp, const pg_tz *tz);
static int increment_overflow(int *number, int delta);
static pg_time_t transtime(pg_time_t janfirst, int year,
const struct rule *rulep, long offset);
static int typesequiv(const struct state *sp, int a, int b);
const struct rule * rulep, long offset);
static int typesequiv(const struct state * sp, int a, int b);
static struct pg_tm *timesub(const pg_time_t *timep, long offset,
const struct state *sp, struct pg_tm *tmp);
const struct state * sp, struct pg_tm * tmp);
/* GMT timezone */
static struct state gmtmem;
@ -130,10 +130,10 @@ detzcode(const char *codep)
static pg_time_t
detzcode64(const char *codep)
{
pg_time_t result;
int i;
pg_time_t result;
int i;
result = (codep[0] & 0x80) ? (~(int64) 0) : 0;
result = (codep[0] & 0x80) ? (~(int64) 0) : 0;
for (i = 0; i < 8; ++i)
result = result * 256 + (codep[i] & 0xff);
return result;
@ -143,7 +143,7 @@ static int
differ_by_repeat(pg_time_t t1, pg_time_t t0)
{
if (TYPE_INTEGRAL(pg_time_t) &&
TYPE_BIT(pg_time_t) - TYPE_SIGNED(pg_time_t) < SECSPERREPEAT_BITS)
TYPE_BIT(pg_time_t) -TYPE_SIGNED(pg_time_t) <SECSPERREPEAT_BITS)
return 0;
return t1 - t0 == SECSPERREPEAT;
}
@ -160,9 +160,9 @@ tzload(const char *name, char *canonname, struct state * sp, int doextend)
{
struct tzhead tzhead;
char buf[2 * sizeof(struct tzhead) +
2 * sizeof *sp +
4 * TZ_MAX_TIMES];
} u;
2 * sizeof *sp +
4 * TZ_MAX_TIMES];
} u;
if (name == NULL && (name = TZDEFAULT) == NULL)
return -1;
@ -194,9 +194,9 @@ tzload(const char *name, char *canonname, struct state * sp, int doextend)
(ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))
return -1;
if (nread - (p - u.buf) <
sp->timecnt * stored + /* ats */
sp->timecnt * stored + /* ats */
sp->timecnt + /* types */
sp->typecnt * 6 + /* ttinfos */
sp->typecnt * 6 + /* ttinfos */
sp->charcnt + /* chars */
sp->leapcnt * (stored + 4) + /* lsinfos */
ttisstdcnt + /* ttisstds */
@ -271,10 +271,10 @@ tzload(const char *name, char *canonname, struct state * sp, int doextend)
return -1;
}
}
/*
* Out-of-sort ats should mean we're running on a
* signed time_t system but using a data file with
* unsigned values (or vice versa).
* Out-of-sort ats should mean we're running on a signed time_t system
* but using a data file with unsigned values (or vice versa).
*/
for (i = 0; i < sp->timecnt - 2; ++i)
if (sp->ats[i] > sp->ats[i + 1])
@ -292,8 +292,8 @@ tzload(const char *name, char *canonname, struct state * sp, int doextend)
/*
* Ignore the beginning (harder).
*/
int j;
int j;
for (j = 0; j + i < sp->timecnt; ++j)
{
sp->ats[j] = sp->ats[j + i];
@ -303,6 +303,7 @@ tzload(const char *name, char *canonname, struct state * sp, int doextend)
}
break;
}
/*
* If this is an old file, we're done.
*/
@ -311,6 +312,7 @@ tzload(const char *name, char *canonname, struct state * sp, int doextend)
nread -= p - u.buf;
for (i = 0; i < nread; ++i)
u.buf[i] = p[i];
/*
* If this is a narrow integer time_t system, we're done.
*/
@ -321,9 +323,9 @@ tzload(const char *name, char *canonname, struct state * sp, int doextend)
u.buf[0] == '\n' && u.buf[nread - 1] == '\n' &&
sp->typecnt + 2 <= TZ_MAX_TYPES)
{
struct state ts;
int result;
struct state ts;
int result;
u.buf[nread - 1] = '\0';
result = tzparse(&u.buf[1], &ts, FALSE);
if (result == 0 && ts.typecnt == 2 &&
@ -369,9 +371,9 @@ tzload(const char *name, char *canonname, struct state * sp, int doextend)
}
static int
typesequiv(const struct state *sp, int a, int b)
typesequiv(const struct state * sp, int a, int b)
{
int result;
int result;
if (sp == NULL ||
a < 0 || a >= sp->typecnt ||
@ -428,7 +430,7 @@ getzname(const char *strp)
static const char *
getqzname(const char *strp, int delim)
{
int c;
int c;
while ((c = *strp) != '\0' && c != delim)
++strp;
@ -814,7 +816,7 @@ tzparse(const char *name, struct state * sp, int lastditch)
sp->timecnt + 2 <= TZ_MAX_TIMES;
++year)
{
pg_time_t newfirst;
pg_time_t newfirst;
starttime = transtime(janfirst, year, &start,
stdoffset);
@ -986,7 +988,7 @@ gmtload(struct state * sp)
*/
static struct pg_tm *
localsub(const pg_time_t *timep, long offset,
struct pg_tm *tmp, const pg_tz *tz)
struct pg_tm * tmp, const pg_tz *tz)
{
const struct state *sp;
const struct ttinfo *ttisp;
@ -1002,10 +1004,11 @@ localsub(const pg_time_t *timep, long offset,
pg_time_t seconds;
pg_time_t tcycles;
int64 icycles;
if (t < sp->ats[0])
seconds = sp->ats[0] - t;
else seconds = t - sp->ats[sp->timecnt - 1];
else
seconds = t - sp->ats[sp->timecnt - 1];
--seconds;
tcycles = seconds / YEARSPERREPEAT / AVGSECSPERYEAR;
++tcycles;
@ -1017,19 +1020,21 @@ localsub(const pg_time_t *timep, long offset,
seconds *= AVGSECSPERYEAR;
if (t < sp->ats[0])
newt += seconds;
else newt -= seconds;
else
newt -= seconds;
if (newt < sp->ats[0] ||
newt > sp->ats[sp->timecnt - 1])
return NULL; /* "cannot happen" */
return NULL; /* "cannot happen" */
result = localsub(&newt, offset, tmp, tz);
if (result == tmp)
{
pg_time_t newy;
pg_time_t newy;
newy = tmp->tm_year;
if (t < sp->ats[0])
newy -= icycles * YEARSPERREPEAT;
else newy += icycles * YEARSPERREPEAT;
else
newy += icycles * YEARSPERREPEAT;
tmp->tm_year = newy;
if (tmp->tm_year != newy)
return NULL;
@ -1048,16 +1053,17 @@ localsub(const pg_time_t *timep, long offset,
}
else
{
int lo = 1;
int hi = sp->timecnt;
int lo = 1;
int hi = sp->timecnt;
while (lo < hi)
{
int mid = (lo + hi) >> 1;
int mid = (lo + hi) >> 1;
if (t < sp->ats[mid])
hi = mid;
else lo = mid + 1;
else
lo = mid + 1;
}
i = (int) sp->types[lo - 1];
}
@ -1081,7 +1087,7 @@ pg_localtime(const pg_time_t *timep, const pg_tz *tz)
* gmtsub is to gmtime as localsub is to localtime.
*/
static struct pg_tm *
gmtsub(const pg_time_t *timep, long offset, struct pg_tm *tmp)
gmtsub(const pg_time_t *timep, long offset, struct pg_tm * tmp)
{
struct pg_tm *result;
@ -1125,11 +1131,11 @@ leaps_thru_end_of(const int y)
static struct pg_tm *
timesub(const pg_time_t *timep, long offset,
const struct state *sp, struct pg_tm *tmp)
const struct state * sp, struct pg_tm * tmp)
{
const struct lsinfo *lp;
pg_time_t tdays;
int idays; /* unsigned would be so 2003 */
int idays; /* unsigned would be so 2003 */
long rem;
int y;
const int *ip;
@ -1169,11 +1175,11 @@ timesub(const pg_time_t *timep, long offset,
rem = *timep - tdays * SECSPERDAY;
while (tdays < 0 || tdays >= year_lengths[isleap(y)])
{
int newy;
int newy;
pg_time_t tdelta;
int idelta;
int leapdays;
int idelta;
int leapdays;
tdelta = tdays / DAYSPERLYEAR;
idelta = tdelta;
if (tdelta - idelta >= 1 || idelta - tdelta >= 1)
@ -1190,12 +1196,13 @@ timesub(const pg_time_t *timep, long offset,
y = newy;
}
{
long seconds;
long seconds;
seconds = tdays * SECSPERDAY + 0.5;
tdays = seconds / SECSPERDAY;
rem += seconds - tdays * SECSPERDAY;
}
/*
* Given the range, we can now fearlessly cast...
*/
@ -1227,6 +1234,7 @@ timesub(const pg_time_t *timep, long offset,
if (increment_overflow(&tmp->tm_year, -TM_YEAR_BASE))
return NULL;
tmp->tm_yday = idays;
/*
* The "extra" mods below avoid overflow problems.
*/
@ -1264,7 +1272,7 @@ timesub(const pg_time_t *timep, long offset,
static int
increment_overflow(int *number, int delta)
{
int number0;
int number0;
number0 = *number;
*number += delta;
@ -1330,10 +1338,11 @@ pg_next_dst_boundary(const pg_time_t *timep,
pg_time_t tcycles;
int64 icycles;
int result;
if (t < sp->ats[0])
seconds = sp->ats[0] - t;
else seconds = t - sp->ats[sp->timecnt - 1];
else
seconds = t - sp->ats[sp->timecnt - 1];
--seconds;
tcycles = seconds / YEARSPERREPEAT / AVGSECSPERYEAR;
++tcycles;
@ -1345,10 +1354,11 @@ pg_next_dst_boundary(const pg_time_t *timep,
seconds *= AVGSECSPERYEAR;
if (t < sp->ats[0])
newt += seconds;
else newt -= seconds;
else
newt -= seconds;
if (newt < sp->ats[0] ||
newt > sp->ats[sp->timecnt - 1])
return -1; /* "cannot happen" */
return -1; /* "cannot happen" */
result = pg_next_dst_boundary(&newt, before_gmtoff,
before_isdst,
@ -1395,16 +1405,17 @@ pg_next_dst_boundary(const pg_time_t *timep,
}
/* Else search to find the containing segment */
{
int lo = 1;
int hi = sp->timecnt;
int lo = 1;
int hi = sp->timecnt;
while (lo < hi)
{
int mid = (lo + hi) >> 1;
int mid = (lo + hi) >> 1;
if (t < sp->ats[mid])
hi = mid;
else lo = mid + 1;
else
lo = mid + 1;
}
i = lo;
}

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.62 2009/01/01 17:24:04 momjian Exp $
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.63 2009/06/11 14:49:15 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -387,15 +387,15 @@ identify_system_timezone(void)
* enough to identify DST transition rules, since everybody switches on
* Sundays.) This is sufficient to cover most of the Unix time_t range,
* and we don't want to look further than that since many systems won't
* have sane TZ behavior further back anyway. The further
* back the zone matches, the better we score it. This may seem like a
* rather random way of doing things, but experience has shown that
* system-supplied timezone definitions are likely to have DST behavior
* that is right for the recent past and not so accurate further back.
* Scoring in this way allows us to recognize zones that have some
* commonality with the zic database, without insisting on exact match.
* (Note: we probe Thursdays, not Sundays, to avoid triggering
* DST-transition bugs in localtime itself.)
* have sane TZ behavior further back anyway. The further back the zone
* matches, the better we score it. This may seem like a rather random
* way of doing things, but experience has shown that system-supplied
* timezone definitions are likely to have DST behavior that is right for
* the recent past and not so accurate further back. Scoring in this way
* allows us to recognize zones that have some commonality with the zic
* database, without insisting on exact match. (Note: we probe Thursdays,
* not Sundays, to avoid triggering DST-transition bugs in localtime
* itself.)
*/
tnow = time(NULL);
tm = localtime(&tnow);
@ -404,6 +404,7 @@ identify_system_timezone(void)
thisyear = tm->tm_year + 1900;
t = build_time_t(thisyear, 1, 15);
/*
* Round back to GMT midnight Thursday. This depends on the knowledge
* that the time_t origin is Thu Jan 01 1970. (With a different origin
@ -731,7 +732,7 @@ static const struct
"Central Standard Time (Mexico)", "Central Daylight Time (Mexico)",
"America/Mexico_City"
}, /* (GMT-06:00) Guadalajara, Mexico City,
Monterrey - New */
* Monterrey - New */
{
"China Standard Time", "China Daylight Time",
"Asia/Hong_Kong"
@ -852,8 +853,8 @@ static const struct
{
"Mountain Standard Time (Mexico)", "Mountain Daylight Time (Mexico)",
"America/Chihuahua"
}, /* (GMT-07:00) Chihuahua, La Paz,
Mazatlan - New */
}, /* (GMT-07:00) Chihuahua, La Paz, Mazatlan -
* New */
{
"Myanmar Standard Time", "Myanmar Daylight Time",
"Asia/Rangoon"
@ -974,7 +975,7 @@ static const struct
"Australia/Perth"
}, /* (GMT+08:00) Perth */
/* {"W. Central Africa Standard Time", "W. Central Africa Daylight Time",
* * * * * * * ""}, Could not find a match for this one. Excluded for now. *//* (
* * * * * * * * ""}, Could not find a match for this one. Excluded for now. *//* (
* G MT+01:00) West Central Africa */
{
"W. Europe Standard Time", "W. Europe Daylight Time",
@ -1492,7 +1493,7 @@ pg_tzenumerate_next(pg_tzenum *dir)
* Load this timezone using tzload() not pg_tzset(), so we don't fill
* the cache
*/
if (tzload(fullname + dir->baselen, dir->tz.TZname, &dir->tz.state,
if (tzload(fullname + dir->baselen, dir->tz.TZname, &dir->tz.state,
TRUE) != 0)
{
/* Zone could not be loaded, ignore it */

View File

@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/pgtz.h,v 1.23 2009/01/01 17:24:04 momjian Exp $
* $PostgreSQL: pgsql/src/timezone/pgtz.h,v 1.24 2009/06/11 14:49:15 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -66,8 +66,8 @@ struct pg_tz
extern int pg_open_tzfile(const char *name, char *canonname);
/* in localtime.c */
extern int tzload(const char *name, char *canonname, struct state * sp,
int doextend);
extern int tzload(const char *name, char *canonname, struct state * sp,
int doextend);
extern int tzparse(const char *name, struct state * sp, int lastditch);
#endif /* _PGTZ_H */

View File

@ -6,7 +6,7 @@
* 1996-06-05 by Arthur David Olson.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/private.h,v 1.12 2008/02/16 21:16:04 tgl Exp $
* $PostgreSQL: pgsql/src/timezone/private.h,v 1.13 2009/06/11 14:49:15 momjian Exp $
*/
/*
@ -85,7 +85,7 @@ extern const char *scheck(const char *string, const char *format);
#ifndef TYPE_INTEGRAL
#define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
#endif /* !defined TYPE_INTEGRAL */
#endif /* !defined TYPE_INTEGRAL */
#ifndef INT_STRLEN_MAXIMUM
/*
@ -102,24 +102,24 @@ extern const char *scheck(const char *string, const char *format);
#define _(msgid) (msgid)
#ifndef YEARSPERREPEAT
#define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
#endif /* !defined YEARSPERREPEAT */
#define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
#endif /* !defined YEARSPERREPEAT */
/*
** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
*/
#ifndef AVGSECSPERYEAR
#define AVGSECSPERYEAR 31556952L
#endif /* !defined AVGSECSPERYEAR */
#define AVGSECSPERYEAR 31556952L
#endif /* !defined AVGSECSPERYEAR */
#ifndef SECSPERREPEAT
#define SECSPERREPEAT ((int64) YEARSPERREPEAT * (int64) AVGSECSPERYEAR)
#endif /* !defined SECSPERREPEAT */
#define SECSPERREPEAT ((int64) YEARSPERREPEAT * (int64) AVGSECSPERYEAR)
#endif /* !defined SECSPERREPEAT */
#ifndef SECSPERREPEAT_BITS
#define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
#endif /* !defined SECSPERREPEAT_BITS */
#define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
#endif /* !defined SECSPERREPEAT_BITS */
/*
* UNIX was a registered trademark of The Open Group in 2003.

View File

@ -15,7 +15,7 @@
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/strftime.c,v 1.13 2008/02/19 12:06:35 mha Exp $
* $PostgreSQL: pgsql/src/timezone/strftime.c,v 1.14 2009/06/11 14:49:15 momjian Exp $
*/
#include "postgres.h"
@ -92,8 +92,8 @@ 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 * _yconv(const int, const int, const int, const int,
char *, const char * const);
static char *_yconv(const int, const int, const int, const int,
char *, const char *const);
#define IN_NONE 0
#define IN_SOME 1
@ -368,11 +368,11 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim,
{
*warnp = IN_ALL;
pt = _yconv(year, base, 0, 1,
pt, ptlim);
pt, ptlim);
}
else
pt = _yconv(year, base, 1, 1,
pt, ptlim);
pt, ptlim);
}
continue;
case 'v':
@ -493,13 +493,13 @@ _add(const char *str, char *pt, const char *ptlim)
* with more only if necessary.
*/
static char *
_yconv(const int a, const int b, const int convert_top,
const int convert_yy, char *pt, const char * const ptlim)
_yconv(const int a, const int b, const int convert_top,
const int convert_yy, char *pt, const char *const ptlim)
{
int lead;
int trail;
#define DIVISOR 100
int lead;
int trail;
#define DIVISOR 100
trail = a % DIVISOR + b % DIVISOR;
lead = a / DIVISOR + b / DIVISOR + trail / DIVISOR;
trail %= DIVISOR;
@ -517,10 +517,10 @@ _yconv(const int a, const int b, const int convert_top,
{
if (lead == 0 && trail < 0)
pt = _add("-0", pt, ptlim);
else pt = _conv(lead, "%02d", pt, ptlim);
else
pt = _conv(lead, "%02d", pt, ptlim);
}
if (convert_yy)
pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim);
return pt;
}

View File

@ -6,7 +6,7 @@
* 1996-06-05 by Arthur David Olson.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/tzfile.h,v 1.7 2008/02/16 21:16:04 tgl Exp $
* $PostgreSQL: pgsql/src/timezone/tzfile.h,v 1.8 2009/06/11 14:49:15 momjian Exp $
*/
/*
@ -133,16 +133,16 @@ struct tzhead
/*
* Since everything in isleap is modulo 400 (or a factor of 400), we know that
* isleap(y) == isleap(y % 400)
* isleap(y) == isleap(y % 400)
* and so
* isleap(a + b) == isleap((a + b) % 400)
* isleap(a + b) == isleap((a + b) % 400)
* or
* isleap(a + b) == isleap(a % 400 + b % 400)
* isleap(a + b) == isleap(a % 400 + b % 400)
* This is true even if % means modulo rather than Fortran remainder
* (which is allowed by C89 but not C99).
* We use this to avoid addition overflow problems.
*/
#define isleap_sum(a, b) isleap((a) % 400 + (b) % 400)
#define isleap_sum(a, b) isleap((a) % 400 + (b) % 400)
#endif /* !defined TZFILE_H */

View File

@ -3,7 +3,7 @@
* 2006-07-17 by Arthur David Olson.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/zic.c,v 1.23 2008/02/16 21:16:04 tgl Exp $
* $PostgreSQL: pgsql/src/timezone/zic.c,v 1.24 2009/06/11 14:49:15 momjian Exp $
*/
#include "postgres_fe.h"
@ -21,13 +21,13 @@ extern char *optarg;
#include "pgtz.h"
#include "tzfile.h"
#define ZIC_VERSION '2'
#define ZIC_VERSION '2'
typedef int64 zic_t;
typedef int64 zic_t;
#ifndef ZIC_MAX_ABBR_LEN_WO_WARN
#define ZIC_MAX_ABBR_LEN_WO_WARN 6
#endif /* !defined ZIC_MAX_ABBR_LEN_WO_WARN */
#define ZIC_MAX_ABBR_LEN_WO_WARN 6
#endif /* !defined ZIC_MAX_ABBR_LEN_WO_WARN */
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
@ -57,9 +57,9 @@ static char elsieid[] = "@(#)zic.c 8.17";
#endif
#define OFFSET_STRLEN_MAXIMUM (7 + INT_STRLEN_MAXIMUM(long))
#define RULE_STRLEN_MAXIMUM 8 /* "Mdd.dd.d" */
#define RULE_STRLEN_MAXIMUM 8 /* "Mdd.dd.d" */
#define end(cp) (strchr((cp), '\0'))
#define end(cp) (strchr((cp), '\0'))
struct rule
{
@ -115,7 +115,7 @@ struct zone
int z_nrules;
struct rule z_untilrule;
zic_t z_untiltime;
zic_t z_untiltime;
};
extern int link(const char *fromname, const char *toname);
@ -370,7 +370,7 @@ static const int len_years[2] = {
static struct attype
{
zic_t at;
zic_t at;
unsigned char type;
} attypes[TZ_MAX_TIMES];
static long gmtoffs[TZ_MAX_TYPES];
@ -480,9 +480,10 @@ main(int argc, char *argv[])
(void) umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH));
#endif /* !WIN32 */
progname = argv[0];
if (TYPE_BIT(zic_t) < 64) {
if (TYPE_BIT(zic_t) < 64)
{
(void) fprintf(stderr, "%s: %s\n", progname,
_("wild compilation-time specification of zic_t"));
_("wild compilation-time specification of zic_t"));
exit(EXIT_FAILURE);
}
for (i = 1; i < argc; ++i)
@ -688,8 +689,8 @@ dolink(const char *fromfield, const char *tofield)
static void
setboundaries(void)
{
int i;
int i;
min_time = -1;
for (i = 0; i < TIME_T_BITS_IN_FILE - 1; ++i)
min_time *= 2;
@ -964,7 +965,8 @@ gethms(const char *string, const char *errstring, int signable)
error(errstring);
return 0;
}
if (LONG_MAX / SECSPERHOUR < hh) {
if (LONG_MAX / SECSPERHOUR < hh)
{
error(_("time overflow"));
return 0;
}
@ -1481,9 +1483,9 @@ convert(long val, char *buf)
static void
convert64(zic_t val, char *buf)
{
int i;
int shift;
int i;
int shift;
for (i = 0, shift = 56; i < 8; ++i, shift -= 8)
buf[i] = val >> shift;
}
@ -1500,8 +1502,8 @@ puttzcode(long val, FILE *fp)
static void
puttzcode64(zic_t val, FILE *fp)
{
char buf[8];
char buf[8];
convert64(val, buf);
(void) fwrite((void *) buf, (size_t) sizeof buf, (size_t) 1, fp);
}
@ -1509,9 +1511,9 @@ puttzcode64(zic_t val, FILE *fp)
static int
atcomp(const void *avp, const void *bvp)
{
const zic_t a = ((const struct attype *) avp)->at;
const zic_t b = ((const struct attype *) bvp)->at;
const zic_t a = ((const struct attype *) avp)->at;
const zic_t b = ((const struct attype *) bvp)->at;
return (a < b) ? -1 : (a > b);
}
@ -1527,8 +1529,10 @@ writezone(const char *name, const char *string)
FILE *fp;
int i,
j;
int leapcnt32, leapi32;
int timecnt32, timei32;
int leapcnt32,
leapi32;
int timecnt32,
timei32;
int pass;
static char *fullname;
static const struct tzhead tzh0;
@ -1584,17 +1588,21 @@ writezone(const char *name, const char *string)
ats[i] = attypes[i].at;
types[i] = attypes[i].type;
}
/*
* Correct for leap seconds.
*/
for (i = 0; i < timecnt; ++i) {
for (i = 0; i < timecnt; ++i)
{
j = leapcnt;
while (--j >= 0)
if (ats[i] > trans[j] - corr[j]) {
if (ats[i] > trans[j] - corr[j])
{
ats[i] = tadd(ats[i], corr[j]);
break;
}
}
/*
* Figure out 32-bit-limited starts and counts.
*/
@ -1644,23 +1652,30 @@ writezone(const char *name, const char *string)
exit(EXIT_FAILURE);
}
}
for (pass = 1; pass <= 2; ++pass) {
register int thistimei, thistimecnt;
register int thisleapi, thisleapcnt;
register int thistimelim, thisleaplim;
int writetype[TZ_MAX_TIMES];
int typemap[TZ_MAX_TYPES];
register int thistypecnt;
for (pass = 1; pass <= 2; ++pass)
{
register int thistimei,
thistimecnt;
register int thisleapi,
thisleapcnt;
register int thistimelim,
thisleaplim;
int writetype[TZ_MAX_TIMES];
int typemap[TZ_MAX_TYPES];
register int thistypecnt;
char thischars[TZ_MAX_CHARS];
char thischarcnt;
int indmap[TZ_MAX_CHARS];
int indmap[TZ_MAX_CHARS];
if (pass == 1) {
if (pass == 1)
{
thistimei = timei32;
thistimecnt = timecnt32;
thisleapi = leapi32;
thisleapcnt = leapcnt32;
} else {
}
else
{
thistimei = 0;
thistimecnt = timecnt;
thisleapi = 0;
@ -1670,31 +1685,36 @@ writezone(const char *name, const char *string)
thisleaplim = thisleapi + thisleapcnt;
for (i = 0; i < typecnt; ++i)
writetype[i] = thistimecnt == timecnt;
if (thistimecnt == 0) {
if (thistimecnt == 0)
{
/*
** No transition times fall in the current
** (32- or 64-bit) window.
*/
* * No transition times fall in the current * (32- or 64-bit)
* window.
*/
if (typecnt != 0)
writetype[typecnt - 1] = TRUE;
} else {
}
else
{
for (i = thistimei - 1; i < thistimelim; ++i)
if (i >= 0)
writetype[types[i]] = TRUE;
/*
** For America/Godthab and Antarctica/Palmer
*/
* * For America/Godthab and Antarctica/Palmer
*/
if (thistimei == 0)
writetype[0] = TRUE;
}
thistypecnt = 0;
for (i = 0; i < typecnt; ++i)
typemap[i] = writetype[i] ? thistypecnt++ : -1;
typemap[i] = writetype[i] ? thistypecnt++ : -1;
for (i = 0; i < sizeof indmap / sizeof indmap[0]; ++i)
indmap[i] = -1;
thischarcnt = 0;
for (i = 0; i < typecnt; ++i) {
register char * thisabbr;
for (i = 0; i < typecnt; ++i)
{
register char *thisabbr;
if (!writetype[i])
continue;
@ -1704,9 +1724,10 @@ writezone(const char *name, const char *string)
for (j = 0; j < thischarcnt; ++j)
if (strcmp(&thischars[j], thisabbr) == 0)
break;
if (j == thischarcnt) {
if (j == thischarcnt)
{
(void) strcpy(&thischars[(int) thischarcnt],
thisabbr);
thisabbr);
thischarcnt += strlen(thisabbr) + 1;
}
indmap[abbrinds[i]] = j;
@ -1735,49 +1756,61 @@ writezone(const char *name, const char *string)
for (i = thistimei; i < thistimelim; ++i)
if (pass == 1)
puttzcode((long) ats[i], fp);
else puttzcode64(ats[i], fp);
for (i = thistimei; i < thistimelim; ++i) {
unsigned char uc;
else
puttzcode64(ats[i], fp);
for (i = thistimei; i < thistimelim; ++i)
{
unsigned char uc;
uc = typemap[types[i]];
(void) fwrite((void *) &uc,
(size_t) sizeof uc,
(size_t) 1,
fp);
(size_t) sizeof uc,
(size_t) 1,
fp);
}
for (i = 0; i < typecnt; ++i)
if (writetype[i]) {
if (writetype[i])
{
puttzcode(gmtoffs[i], fp);
(void) putc(isdsts[i], fp);
(void) putc((unsigned char) indmap[abbrinds[i]], fp);
}
if (thischarcnt != 0)
(void) fwrite((void *) thischars,
(size_t) sizeof thischars[0],
(size_t) thischarcnt, fp);
for (i = thisleapi; i < thisleaplim; ++i) {
register zic_t todo;
(size_t) sizeof thischars[0],
(size_t) thischarcnt, fp);
for (i = thisleapi; i < thisleaplim; ++i)
{
register zic_t todo;
if (roll[i]) {
if (timecnt == 0 || trans[i] < ats[0]) {
if (roll[i])
{
if (timecnt == 0 || trans[i] < ats[0])
{
j = 0;
while (isdsts[j])
if (++j >= typecnt) {
if (++j >= typecnt)
{
j = 0;
break;
}
} else {
}
else
{
j = 1;
while (j < timecnt &&
trans[i] >= ats[j])
++j;
trans[i] >= ats[j])
++j;
j = types[j - 1];
}
todo = tadd(trans[i], -gmtoffs[j]);
} else todo = trans[i];
}
else
todo = trans[i];
if (pass == 1)
puttzcode((long) todo, fp);
else puttzcode64(todo, fp);
else
puttzcode64(todo, fp);
puttzcode(corr[i], fp);
}
for (i = 0; i < typecnt; ++i)
@ -1788,20 +1821,21 @@ writezone(const char *name, const char *string)
(void) putc(ttisgmts[i], fp);
}
(void) fprintf(fp, "\n%s\n", string);
if (ferror(fp) || fclose(fp)) {
if (ferror(fp) || fclose(fp))
{
(void) fprintf(stderr, _("%s: Error writing %s\n"),
progname, fullname);
progname, fullname);
exit(EXIT_FAILURE);
}
}
static void
doabbr(char *abbr, const char *format, const char *letters, int isdst,
doabbr(char *abbr, const char *format, const char *letters, int isdst,
int doquotes)
{
char * cp;
char * slashp;
int len;
char *cp;
char *slashp;
int len;
slashp = strchr(format, '/');
if (slashp == NULL)
@ -1831,7 +1865,7 @@ doabbr(char *abbr, const char *format, const char *letters, int isdst,
return;
abbr[len + 2] = '\0';
abbr[len + 1] = '>';
for ( ; len > 0; --len)
for (; len > 0; --len)
abbr[len] = abbr[len - 1];
abbr[0] = '<';
}
@ -1848,12 +1882,13 @@ updateminmax(int x)
static int
stringoffset(char *result, long offset)
{
int hours;
int minutes;
int seconds;
int hours;
int minutes;
int seconds;
result[0] = '\0';
if (offset < 0) {
if (offset < 0)
{
(void) strcpy(result, "-");
offset = -offset;
}
@ -1862,12 +1897,14 @@ stringoffset(char *result, long offset)
minutes = offset % MINSPERHOUR;
offset /= MINSPERHOUR;
hours = offset;
if (hours >= HOURSPERDAY) {
if (hours >= HOURSPERDAY)
{
result[0] = '\0';
return -1;
}
(void) sprintf(end(result), "%d", hours);
if (minutes != 0 || seconds != 0) {
if (minutes != 0 || seconds != 0)
{
(void) sprintf(end(result), ":%02d", minutes);
if (seconds != 0)
(void) sprintf(end(result), ":%02d", seconds);
@ -1876,14 +1913,15 @@ stringoffset(char *result, long offset)
}
static int
stringrule(char *result, const struct rule *rp, long dstoff, long gmtoff)
stringrule(char *result, const struct rule * rp, long dstoff, long gmtoff)
{
long tod;
long tod;
result = end(result);
if (rp->r_dycode == DC_DOM)
if (rp->r_dycode == DC_DOM)
{
int month, total;
int month,
total;
if (rp->r_dayofmonth == 29 && rp->r_month == TM_FEBRUARY)
return -1;
@ -1894,7 +1932,7 @@ stringrule(char *result, const struct rule *rp, long dstoff, long gmtoff)
}
else
{
int week;
int week;
if (rp->r_dycode == DC_DOWGEQ)
{
@ -1906,14 +1944,15 @@ stringrule(char *result, const struct rule *rp, long dstoff, long gmtoff)
{
if (rp->r_dayofmonth == len_months[1][rp->r_month])
week = 5;
else {
else
{
week = 1 + rp->r_dayofmonth / DAYSPERWEEK;
if (week * DAYSPERWEEK - 1 != rp->r_dayofmonth)
return -1;
}
}
else
return -1; /* "cannot happen" */
return -1; /* "cannot happen" */
(void) sprintf(result, "M%d.%d.%d",
rp->r_month + 1, week, rp->r_wday);
}
@ -1937,14 +1976,14 @@ stringrule(char *result, const struct rule *rp, long dstoff, long gmtoff)
}
static void
stringzone(char *result, const struct zone *zpfirst, int zonecount)
stringzone(char *result, const struct zone * zpfirst, int zonecount)
{
const struct zone * zp;
struct rule * rp;
struct rule * stdrp;
struct rule * dstrp;
const struct zone *zp;
struct rule *rp;
struct rule *stdrp;
struct rule *dstrp;
int i;
const char * abbrvar;
const char *abbrvar;
result[0] = '\0';
zp = zpfirst + zonecount - 1;
@ -1956,38 +1995,42 @@ stringzone(char *result, const struct zone *zpfirst, int zonecount)
continue;
if (rp->r_yrtype != NULL)
continue;
if (rp->r_stdoff == 0) {
if (rp->r_stdoff == 0)
{
if (stdrp == NULL)
stdrp = rp;
else return;
else
return;
}
else
{
if (dstrp == NULL)
dstrp = rp;
else return;
else
return;
}
}
if (stdrp == NULL && dstrp == NULL)
{
/*
* There are no rules running through "max".
* Let's find the latest rule.
* There are no rules running through "max". Let's find the latest
* rule.
*/
for (i = 0; i < zp->z_nrules; ++i)
{
rp = &zp->z_rules[i];
if (stdrp == NULL || rp->r_hiyear > stdrp->r_hiyear ||
(rp->r_hiyear == stdrp->r_hiyear &&
rp->r_month > stdrp->r_month))
stdrp = rp;
rp->r_month > stdrp->r_month))
stdrp = rp;
}
if (stdrp != NULL && stdrp->r_stdoff != 0)
return; /* We end up in DST (a POSIX no-no). */
return; /* We end up in DST (a POSIX no-no). */
/*
* Horrid special case: if year is 2037,
* presume this is a zone handled on a year-by-year basis;
* do not try to apply a rule to the zone.
* Horrid special case: if year is 2037, presume this is a zone
* handled on a year-by-year basis; do not try to apply a rule to the
* zone.
*/
if (stdrp != NULL && stdrp->r_hiyear == 2037)
return;
@ -1996,7 +2039,8 @@ stringzone(char *result, const struct zone *zpfirst, int zonecount)
return;
abbrvar = (stdrp == NULL) ? "" : stdrp->r_abbrvar;
doabbr(result, zp->z_format, abbrvar, FALSE, TRUE);
if (stringoffset(end(result), -zp->z_gmtoff) != 0) {
if (stringoffset(end(result), -zp->z_gmtoff) != 0)
{
result[0] = '\0';
return;
}
@ -2005,17 +2049,20 @@ stringzone(char *result, const struct zone *zpfirst, int zonecount)
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) {
result[0] = '\0';
return;
-(zp->z_gmtoff + dstrp->r_stdoff)) != 0)
{
result[0] = '\0';
return;
}
(void) strcat(result, ",");
if (stringrule(result, dstrp, dstrp->r_stdoff, zp->z_gmtoff) != 0) {
if (stringrule(result, dstrp, dstrp->r_stdoff, zp->z_gmtoff) != 0)
{
result[0] = '\0';
return;
}
(void) strcat(result, ",");
if (stringrule(result, stdrp, dstrp->r_stdoff, zp->z_gmtoff) != 0) {
if (stringrule(result, stdrp, dstrp->r_stdoff, zp->z_gmtoff) != 0)
{
result[0] = '\0';
return;
}
@ -2059,8 +2106,8 @@ outzone(const struct zone * zpfirst, int zonecount)
charcnt = 0;
/*
* Thanks to Earl Chew for noting the need to
* unconditionally initialize startttisstd.
* Thanks to Earl Chew for noting the need to unconditionally initialize
* startttisstd.
*/
startttisstd = FALSE;
startttisgmt = FALSE;
@ -2084,12 +2131,14 @@ outzone(const struct zone * zpfirst, int zonecount)
updateminmax(rp->r_hiyear);
}
}
/*
* Generate lots of data if a rule can't cover all future times.
*/
stringzone(envvar, zpfirst, zonecount);
if (noise && envvar[0] == '\0') {
char * wp;
if (noise && envvar[0] == '\0')
{
char *wp;
wp = ecpyalloc(_("no POSIX environment variable for zone"));
wp = ecatalloc(wp, " ");
@ -2101,14 +2150,16 @@ outzone(const struct zone * zpfirst, int zonecount)
{
if (min_year >= INT_MIN + YEARSPERREPEAT)
min_year -= YEARSPERREPEAT;
else min_year = INT_MIN;
else
min_year = INT_MIN;
if (max_year <= INT_MAX - YEARSPERREPEAT)
max_year += YEARSPERREPEAT;
else max_year = INT_MAX;
else
max_year = INT_MAX;
}
/*
* For the benefit of older systems,
* generate data from 1900 through 2037.
* For the benefit of older systems, generate data from 1900 through 2037.
*/
if (min_year > 1900)
min_year = 1900;
@ -2235,7 +2286,7 @@ outzone(const struct zone * zpfirst, int zonecount)
FALSE);
continue;
}
if (*startbuf == '\0' &&
if (*startbuf == '\0' &&
startoff == oadd(zp->z_gmtoff, stdoff))
{
doabbr(startbuf,
@ -2366,7 +2417,8 @@ addtype(long gmtoff, const char *abbr, int isdst,
error(_("too many local time types"));
exit(EXIT_FAILURE);
}
if (! (-1L - 2147483647L <= gmtoff && gmtoff <= 2147483647L)) {
if (!(-1L - 2147483647L <= gmtoff && gmtoff <= 2147483647L))
{
error(_("UTC offset out of range"));
exit(EXIT_FAILURE);
}
@ -2585,7 +2637,7 @@ oadd(long t1, long t2)
static zic_t
tadd(const zic_t t1, long t2)
{
zic_t t;
zic_t t;
if (t1 == max_time && t2 > 0)
return max_time;
@ -2612,7 +2664,7 @@ rpytime(const struct rule * rp, int wantedy)
m,
i;
long dayoff; /* with a nod to Margaret O. */
zic_t t;
zic_t t;
if (wantedy == INT_MIN)
return min_time;
@ -2699,6 +2751,7 @@ will not work with pre-2004 versions of zic"));
if (dayoff > max_time / SECSPERDAY)
return max_time;
t = (zic_t) dayoff *SECSPERDAY;
return tadd(t, rp->r_tod);
}
@ -2709,12 +2762,12 @@ newabbr(const char *string)
if (strcmp(string, GRANDPARENTED) != 0)
{
const char * cp;
char * wp;
const char *cp;
char *wp;
/*
* Want one to ZIC_MAX_ABBR_LEN_WO_WARN alphabetics
* optionally followed by a + or - and a number from 1 to 14.
* Want one to ZIC_MAX_ABBR_LEN_WO_WARN alphabetics optionally
* followed by a + or - and a number from 1 to 14.
*/
cp = string;
wp = NULL;
@ -2727,7 +2780,8 @@ newabbr(const char *string)
wp = _("time zone abbreviation has more than 3 alphabetics");
if (cp - string > ZIC_MAX_ABBR_LEN_WO_WARN)
wp = _("time zone abbreviation has too many alphabetics");
if (wp == NULL && (*cp == '+' || *cp == '-')) {
if (wp == NULL && (*cp == '+' || *cp == '-'))
{
++cp;
if (isascii((unsigned char) *cp) &&
isdigit((unsigned char) *cp))
@ -2737,7 +2791,8 @@ newabbr(const char *string)
}
if (*cp != '\0')
wp = _("time zone abbreviation differs from POSIX standard");
if (wp != NULL) {
if (wp != NULL)
{
wp = ecpyalloc(wp);
wp = ecatalloc(wp, " (");
wp = ecatalloc(wp, string);