Pgindent timezone file, per request from Tom.

This commit is contained in:
Bruce Momjian 2004-05-21 12:30:25 +00:00
parent 63bd0db121
commit 0a19fb42c2
9 changed files with 2226 additions and 1754 deletions

View File

@ -5,54 +5,63 @@
#define nonzero(n) (((n) == 0) ? 1 : (n)) #define nonzero(n) (((n) == 0) ? 1 : (n))
char *imalloc(const int n) char *
imalloc(const int n)
{ {
return malloc((size_t) nonzero(n)); return malloc((size_t) nonzero(n));
} }
char *icalloc(int nelem, int elsize) char *
icalloc(int nelem, int elsize)
{ {
if (nelem == 0 || elsize == 0) if (nelem == 0 || elsize == 0)
nelem = elsize = 1; nelem = elsize = 1;
return calloc((size_t) nelem, (size_t) elsize); return calloc((size_t) nelem, (size_t) elsize);
} }
void *irealloc(void *pointer, const int size) void *
irealloc(void *pointer, const int size)
{ {
if (pointer == NULL) if (pointer == NULL)
return imalloc(size); return imalloc(size);
return realloc((void *) pointer, (size_t) nonzero(size)); return realloc((void *) pointer, (size_t) nonzero(size));
} }
char *icatalloc(char *old, const char *new) char *
icatalloc(char *old, const char *new)
{ {
register char *result; register char *result;
register int oldsize, newsize; register int oldsize,
newsize;
newsize = (new == NULL) ? 0 : strlen(new); newsize = (new == NULL) ? 0 : strlen(new);
if (old == NULL) if (old == NULL)
oldsize = 0; oldsize = 0;
else if (newsize == 0) else if (newsize == 0)
return old; return old;
else oldsize = strlen(old); else
oldsize = strlen(old);
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL) if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
if (new != NULL) if (new != NULL)
(void) strcpy(result + oldsize, new); (void) strcpy(result + oldsize, new);
return result; return result;
} }
char *icpyalloc(const char *string) char *
icpyalloc(const char *string)
{ {
return icatalloc((char *) NULL, string); return icatalloc((char *) NULL, string);
} }
void ifree(char *p) void
ifree(char *p)
{ {
if (p != NULL) if (p != NULL)
(void) free(p); (void) free(p);
} }
void icfree(char *p) void
icfree(char *p)
{ {
if (p != NULL) if (p != NULL)
(void) free(p); (void) free(p);

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.10 2004/05/21 05:08:06 tgl Exp $ * $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.11 2004/05/21 12:30:25 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -47,15 +47,22 @@ pg_TZDIR(void)
#define T_YEAR (60*60*24*365) #define T_YEAR (60*60*24*365)
#define T_MONTH (60*60*24*30) #define T_MONTH (60*60*24*30)
struct tztry { struct tztry
time_t std_t,dst_t; {
char std_time[TZ_STRLEN_MAX+1],dst_time[TZ_STRLEN_MAX+1]; time_t std_t,
int std_ofs,dst_ofs; dst_t;
struct tm std_tm, dst_tm; char std_time[TZ_STRLEN_MAX + 1],
dst_time[TZ_STRLEN_MAX + 1];
int std_ofs,
dst_ofs;
struct tm std_tm,
dst_tm;
}; };
static bool compare_tm(struct tm *s, struct pg_tm *p) { static bool
compare_tm(struct tm * s, struct pg_tm * p)
{
if (s->tm_sec != p->tm_sec || if (s->tm_sec != p->tm_sec ||
s->tm_min != p->tm_min || s->tm_min != p->tm_min ||
s->tm_hour != p->tm_hour || s->tm_hour != p->tm_hour ||
@ -69,11 +76,14 @@ static bool compare_tm(struct tm *s, struct pg_tm *p) {
return true; return true;
} }
static bool try_timezone(char *tzname, struct tztry *tt, bool checkdst) { static bool
try_timezone(char *tzname, struct tztry * tt, bool checkdst)
{
struct pg_tm *pgtm; struct pg_tm *pgtm;
if (!pg_tzset(tzname)) if (!pg_tzset(tzname))
return false; /* If this timezone couldn't be picked at all */ return false; /* If this timezone couldn't be picked at
* all */
/* Verify standard time */ /* Verify standard time */
pgtm = pg_localtime(&(tt->std_t)); pgtm = pg_localtime(&(tt->std_t));
@ -95,7 +105,9 @@ static bool try_timezone(char *tzname, struct tztry *tt, bool checkdst) {
return true; return true;
} }
static int get_timezone_offset(struct tm *tm) { static int
get_timezone_offset(struct tm * tm)
{
#if defined(HAVE_STRUCT_TM_TM_ZONE) #if defined(HAVE_STRUCT_TM_TM_ZONE)
return tm->tm_gmtoff; return tm->tm_gmtoff;
#elif defined(HAVE_INT_TIMEZONE) #elif defined(HAVE_INT_TIMEZONE)
@ -113,12 +125,15 @@ static int get_timezone_offset(struct tm *tm) {
#ifdef WIN32 #ifdef WIN32
#define TZABBREV(tz) win32_get_timezone_abbrev(tz) #define TZABBREV(tz) win32_get_timezone_abbrev(tz)
static char *win32_get_timezone_abbrev(char *tz) { static char *
win32_get_timezone_abbrev(char *tz)
{
static char w32tzabbr[TZ_STRLEN_MAX + 1]; static char w32tzabbr[TZ_STRLEN_MAX + 1];
int l = 0; int l = 0;
char *c; char *c;
for (c = tz; *c; c++) { for (c = tz; *c; c++)
{
if (isupper(*c)) if (isupper(*c))
w32tzabbr[l++] = *c; w32tzabbr[l++] = *c;
} }
@ -153,10 +168,12 @@ identify_system_timezone(void)
memset(&tt, 0, sizeof(tt)); memset(&tt, 0, sizeof(tt));
for (t = tnow; t < tnow+T_YEAR; t += T_MONTH) { for (t = tnow; t < tnow + T_YEAR; t += T_MONTH)
{
struct tm *tm = localtime(&t); struct tm *tm = localtime(&t);
if (tm->tm_isdst == 0 && !std_found) { if (tm->tm_isdst == 0 && !std_found)
{
/* Standard time */ /* Standard time */
memcpy(&tt.std_tm, tm, sizeof(struct tm)); memcpy(&tt.std_tm, tm, sizeof(struct tm));
memset(cbuf, 0, sizeof(cbuf)); memset(cbuf, 0, sizeof(cbuf));
@ -166,7 +183,8 @@ identify_system_timezone(void)
tt.std_t = t; tt.std_t = t;
std_found = true; std_found = true;
} }
else if (tm->tm_isdst == 1 && !dst_found) { else if (tm->tm_isdst == 1 && !dst_found)
{
/* Daylight time */ /* Daylight time */
memcpy(&tt.dst_tm, tm, sizeof(struct tm)); memcpy(&tt.dst_tm, tm, sizeof(struct tm));
memset(cbuf, 0, sizeof(cbuf)); memset(cbuf, 0, sizeof(cbuf));
@ -189,7 +207,8 @@ identify_system_timezone(void)
return NULL; /* go to GMT */ return NULL; /* go to GMT */
} }
if (dst_found) { if (dst_found)
{
/* Try STD<ofs>DST */ /* Try STD<ofs>DST */
sprintf(__tzbuf, "%s%d%s", tt.std_time, -tt.std_ofs / 3600, tt.dst_time); sprintf(__tzbuf, "%s%d%s", tt.std_time, -tt.std_ofs / 3600, tt.dst_time);
if (try_timezone(__tzbuf, &tt, dst_found)) if (try_timezone(__tzbuf, &tt, dst_found))
@ -280,9 +299,12 @@ select_default_timezone(void)
* This is called after initial loading of postgresql.conf. If no TimeZone * This is called after initial loading of postgresql.conf. If no TimeZone
* setting was found therein, we try to derive one from the environment. * setting was found therein, we try to derive one from the environment.
*/ */
void pg_timezone_initialize(void) { void
pg_timezone_initialize(void)
{
/* Do we need to try to figure the timezone? */ /* Do we need to try to figure the timezone? */
if (strcmp(GetConfigOption("timezone"), "UNKNOWN") == 0) { if (strcmp(GetConfigOption("timezone"), "UNKNOWN") == 0)
{
const char *def_tz; const char *def_tz;
/* Select setting */ /* Select setting */

View File

@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/timezone/pgtz.h,v 1.7 2004/05/21 05:08:06 tgl Exp $ * $PostgreSQL: pgsql/src/timezone/pgtz.h,v 1.8 2004/05/21 12:30:25 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */

View File

@ -53,6 +53,7 @@
#ifndef remove #ifndef remove
extern int unlink(const char *filename); extern int unlink(const char *filename);
#define remove unlink #define remove unlink
#endif /* !defined remove */ #endif /* !defined remove */

View File

@ -3,7 +3,8 @@
#include "private.h" #include "private.h"
char *scheck(const char *string, const char *format) char *
scheck(const char *string, const char *format)
{ {
register char *fbuf; register char *fbuf;
register const char *fp; register const char *fp;
@ -21,10 +22,12 @@ char *scheck(const char *string, const char *format)
return result; return result;
fp = format; fp = format;
tp = fbuf; tp = fbuf;
while ((*tp++ = c = *fp++) != '\0') { while ((*tp++ = c = *fp++) != '\0')
{
if (c != '%') if (c != '%')
continue; continue;
if (*fp == '%') { if (*fp == '%')
{
*tp++ = *fp++; *tp++ = *fp++;
continue; continue;
} }
@ -36,7 +39,8 @@ char *scheck(const char *string, const char *format)
if (*fp == 'l' || *fp == 'h') if (*fp == 'l' || *fp == 'h')
*tp++ = *fp++; *tp++ = *fp++;
else if (*fp == '[') else if (*fp == '[')
do *tp++ = *fp++; do
*tp++ = *fp++;
while (*fp != '\0' && *fp != ']'); while (*fp != '\0' && *fp != ']');
if ((*tp++ = *fp++) == '\0') if ((*tp++ = *fp++) == '\0')
break; break;

View File

@ -25,7 +25,8 @@
#include "tzfile.h" #include "tzfile.h"
struct lc_time_T { struct lc_time_T
{
const char *mon[MONSPERYEAR]; const char *mon[MONSPERYEAR];
const char *month[MONSPERYEAR]; const char *month[MONSPERYEAR];
const char *wday[DAYSPERWEEK]; const char *wday[DAYSPERWEEK];
@ -59,20 +60,15 @@ static const struct lc_time_T C_time_locale = {
"%H:%M:%S", "%H:%M:%S",
/* /*
** x_fmt * * x_fmt * C99 requires this format. * Using just numbers (as here)
** C99 requires this format. * makes Quakers happier; * it's also compatible with SVR4.
** Using just numbers (as here) makes Quakers happier;
** it's also compatible with SVR4.
*/ */
"%m/%d/%y", "%m/%d/%y",
/* /*
** c_fmt * * c_fmt * C99 requires this format. * Previously this code used "%D
** C99 requires this format. * %X", but we now conform to C99. * Note that * "%a %b %d
** Previously this code used "%D %X", but we now conform to C99. * %H:%M:%S %Y" * is used by Solaris 2.3.
** Note that
** "%a %b %d %H:%M:%S %Y"
** is used by Solaris 2.3.
*/ */
"%a %b %e %T %Y", "%a %b %e %T %Y",
@ -96,7 +92,8 @@ static char * _fmt (const char *, const struct pg_tm *, char *, const char *, in
#define IN_ALL 3 #define IN_ALL 3
size_t pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm *t) size_t
pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm * t)
{ {
char *p; char *p;
int warn; int warn;
@ -109,12 +106,16 @@ size_t pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_
return p - s; return p - s;
} }
static char * _fmt(const char *format, const struct pg_tm *t, char *pt, const char *ptlim, int *warnp) static char *
_fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim, int *warnp)
{
for (; *format; ++format)
{
if (*format == '%')
{ {
for ( ; *format; ++format) {
if (*format == '%') {
label: label:
switch (*++format) { switch (*++format)
{
case '\0': case '\0':
--format; --format;
break; break;
@ -144,12 +145,11 @@ label:
pt, ptlim); pt, ptlim);
continue; continue;
case 'C': case 'C':
/* /*
** %C used to do a... * * %C used to do a... * _fmt("%a %b %e %X %Y", t); *
** _fmt("%a %b %e %X %Y", t); * ...whereas now POSIX 1003.2 calls for * something
** ...whereas now POSIX 1003.2 calls for * completely different. * (ado, 1993-05-24)
** something completely different.
** (ado, 1993-05-24)
*/ */
pt = _conv((t->tm_year + TM_YEAR_BASE) / 100, pt = _conv((t->tm_year + TM_YEAR_BASE) / 100,
"%02d", pt, ptlim); "%02d", pt, ptlim);
@ -173,14 +173,12 @@ label:
continue; continue;
case 'E': case 'E':
case 'O': case 'O':
/* /*
** C99 locale modifiers. * * C99 locale modifiers. * The sequences * %Ec %EC
** The sequences * %Ex %EX %Ey %EY * %Od %oe %OH %OI %Om %OM * %OS
** %Ec %EC %Ex %EX %Ey %EY * %Ou %OU %OV %Ow %OW %Oy * are supposed to provide
** %Od %oe %OH %OI %Om %OM * alternate * representations.
** %OS %Ou %OU %OV %Ow %OW %Oy
** are supposed to provide alternate
** representations.
*/ */
goto label; goto label;
case 'e': case 'e':
@ -201,20 +199,20 @@ label:
pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim); pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
continue; continue;
case 'k': case 'k':
/* /*
** This used to be... * * This used to be... * _conv(t->tm_hour % 12 ? *
** _conv(t->tm_hour % 12 ? * t->tm_hour % 12 : 12, 2, ' '); * ...and has been
** t->tm_hour % 12 : 12, 2, ' '); * changed to the below to * match SunOS 4.1.1 and
** ...and has been changed to the below to * Arnold Robbins' * strftime version 3.0. That is,
** match SunOS 4.1.1 and Arnold Robbins' * "%k" and * "%l" have been swapped. * (ado,
** strftime version 3.0. That is, "%k" and * 1993-05-24)
** "%l" have been swapped.
** (ado, 1993-05-24)
*/ */
pt = _conv(t->tm_hour, "%2d", pt, ptlim); pt = _conv(t->tm_hour, "%2d", pt, ptlim);
continue; continue;
#ifdef KITCHEN_SINK #ifdef KITCHEN_SINK
case 'K': case 'K':
/* /*
* * After all this time, still unclaimed! * * After all this time, still unclaimed!
*/ */
@ -222,14 +220,13 @@ label:
continue; continue;
#endif /* defined KITCHEN_SINK */ #endif /* defined KITCHEN_SINK */
case 'l': case 'l':
/* /*
** This used to be... * * This used to be... * _conv(t->tm_hour, 2, ' '); *
** _conv(t->tm_hour, 2, ' '); * ...and has been changed to the below to * match
** ...and has been changed to the below to * SunOS 4.1.1 and Arnold Robbin's * strftime version
** match SunOS 4.1.1 and Arnold Robbin's * 3.0. That is, "%k" and * "%l" have been swapped. *
** strftime version 3.0. That is, "%k" and * (ado, 1993-05-24)
** "%l" have been swapped.
** (ado, 1993-05-24)
*/ */
pt = _conv((t->tm_hour % 12) ? pt = _conv((t->tm_hour % 12) ?
(t->tm_hour % 12) : 12, (t->tm_hour % 12) : 12,
@ -286,11 +283,11 @@ label:
"%02d", pt, ptlim); "%02d", pt, ptlim);
continue; continue;
case 'u': case 'u':
/* /*
** From Arnold Robbins' strftime version 3.0: * * From Arnold Robbins' strftime version 3.0: * "ISO
** "ISO 8601: Weekday as a decimal number * 8601: Weekday as a decimal number * [1 (Monday) -
** [1 (Monday) - 7]" * 7]" * (ado, 1993-05-24)
** (ado, 1993-05-24)
*/ */
pt = _conv((t->tm_wday == 0) ? pt = _conv((t->tm_wday == 0) ?
DAYSPERWEEK : t->tm_wday, DAYSPERWEEK : t->tm_wday,
@ -326,7 +323,8 @@ label:
year = t->tm_year + TM_YEAR_BASE; year = t->tm_year + TM_YEAR_BASE;
yday = t->tm_yday; yday = t->tm_yday;
wday = t->tm_wday; wday = t->tm_wday;
for ( ; ; ) { for (;;)
{
int len; int len;
int bot; int bot;
int top; int top;
@ -334,27 +332,31 @@ label:
len = isleap(year) ? len = isleap(year) ?
DAYSPERLYEAR : DAYSPERLYEAR :
DAYSPERNYEAR; DAYSPERNYEAR;
/* /*
** What yday (-3 ... 3) does * * What yday (-3 ... 3) does * the ISO year
** the ISO year begin on? * begin on?
*/ */
bot = ((yday + 11 - wday) % bot = ((yday + 11 - wday) %
DAYSPERWEEK) - 3; DAYSPERWEEK) - 3;
/* /*
** What yday does the NEXT * * What yday does the NEXT * ISO year begin
** ISO year begin on? * on?
*/ */
top = bot - top = bot -
(len % DAYSPERWEEK); (len % DAYSPERWEEK);
if (top < -3) if (top < -3)
top += DAYSPERWEEK; top += DAYSPERWEEK;
top += len; top += len;
if (yday >= top) { if (yday >= top)
{
++year; ++year;
w = 1; w = 1;
break; break;
} }
if (yday >= bot) { if (yday >= bot)
{
w = 1 + ((yday - bot) / w = 1 + ((yday - bot) /
DAYSPERWEEK); DAYSPERWEEK);
break; break;
@ -367,19 +369,22 @@ label:
if (*format == 'V') if (*format == 'V')
pt = _conv(w, "%02d", pt = _conv(w, "%02d",
pt, ptlim); pt, ptlim);
else if (*format == 'g') { else if (*format == 'g')
{
*warnp = IN_ALL; *warnp = IN_ALL;
pt = _conv(year % 100, "%02d", pt = _conv(year % 100, "%02d",
pt, ptlim); pt, ptlim);
} else pt = _conv(year, "%04d", }
else
pt = _conv(year, "%04d",
pt, ptlim); pt, ptlim);
} }
continue; continue;
case 'v': case 'v':
/* /*
** From Arnold Robbins' strftime version 3.0: * * From Arnold Robbins' strftime version 3.0: *
** "date as dd-bbb-YYYY" * "date as dd-bbb-YYYY" * (ado, 1993-05-24)
** (ado, 1993-05-24)
*/ */
pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp); pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
continue; continue;
@ -419,10 +424,10 @@ label:
case 'Z': case 'Z':
if (t->tm_zone != NULL) if (t->tm_zone != NULL)
pt = _add(t->tm_zone, pt, ptlim); pt = _add(t->tm_zone, pt, ptlim);
/* /*
** C99 says that %Z must be replaced by the * * C99 says that %Z must be replaced by the * empty
** empty string if the time zone is not * string if the time zone is not * determinable.
** determinable.
*/ */
continue; continue;
case 'z': case 'z':
@ -433,10 +438,13 @@ label:
if (t->tm_isdst < 0) if (t->tm_isdst < 0)
continue; continue;
diff = t->tm_gmtoff; diff = t->tm_gmtoff;
if (diff < 0) { if (diff < 0)
{
sign = "-"; sign = "-";
diff = -diff; diff = -diff;
} else sign = "+"; }
else
sign = "+";
pt = _add(sign, pt, ptlim); pt = _add(sign, pt, ptlim);
diff /= 60; diff /= 60;
pt = _conv((diff / 60) * 100 + diff % 60, pt = _conv((diff / 60) * 100 + diff % 60,
@ -448,10 +456,11 @@ label:
warnp); warnp);
continue; continue;
case '%': case '%':
/* /*
** X311J/88-090 (4.12.3.5): if conversion char is * * X311J/88-090 (4.12.3.5): if conversion char is *
** undefined, behavior is undefined. Print out the * undefined, behavior is undefined. Print out the *
** character itself as printf(3) also does. * character itself as printf(3) also does.
*/ */
default: default:
break; break;
@ -464,7 +473,8 @@ label:
return pt; return pt;
} }
static char * _conv(const int n, const char *format, char *pt, const char *ptlim) static char *
_conv(const int n, const char *format, char *pt, const char *ptlim)
{ {
char buf[INT_STRLEN_MAXIMUM(int) +1]; char buf[INT_STRLEN_MAXIMUM(int) +1];
@ -472,7 +482,8 @@ static char * _conv(const int n, const char *format, char *pt, const char *ptlim
return _add(buf, pt, ptlim); return _add(buf, pt, ptlim);
} }
static char *_add(const char *str, char *pt, const char *ptlim) static char *
_add(const char *str, char *pt, const char *ptlim)
{ {
while (pt < ptlim && (*pt = *str++) != '\0') while (pt < ptlim && (*pt = *str++) != '\0')
++pt; ++pt;

View File

@ -28,11 +28,14 @@
#define TZ_MAGIC "TZif" #define TZ_MAGIC "TZif"
struct tzhead { struct tzhead
{
char tzh_magic[4]; /* TZ_MAGIC */ char tzh_magic[4]; /* TZ_MAGIC */
char tzh_reserved[16]; /* reserved for future use */ char tzh_reserved[16]; /* reserved for future use */
char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ char tzh_ttisgmtcnt[4]; /* coded number of trans. time
char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ * flags */
char tzh_ttisstdcnt[4]; /* coded number of trans. time
* flags */
char tzh_leapcnt[4]; /* coded number of leap seconds */ char tzh_leapcnt[4]; /* coded number of leap seconds */
char tzh_timecnt[4]; /* coded number of transition times */ char tzh_timecnt[4]; /* coded number of transition times */
char tzh_typecnt[4]; /* coded number of local time types */ char tzh_typecnt[4]; /* coded number of local time types */
@ -77,12 +80,15 @@ struct tzhead {
*/ */
#define TZ_MAX_TIMES 370 #define TZ_MAX_TIMES 370
#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ #define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can
* hold */
#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ #define TZ_MAX_CHARS 50 /* Maximum number of abbreviation
* characters */
/* (limited by what unsigned chars can hold) */ /* (limited by what unsigned chars can hold) */
#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ #define TZ_MAX_LEAPS 50 /* Maximum number of leap second
* corrections */
#define SECSPERMIN 60 #define SECSPERMIN 60
#define MINSPERHOUR 60 #define MINSPERHOUR 60

File diff suppressed because it is too large Load Diff