1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-08 22:02:03 +03:00

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))
char *imalloc(const int n)
char *
imalloc(const int n)
{
return malloc((size_t) nonzero(n));
}
char *icalloc(int nelem, int elsize)
char *
icalloc(int nelem, int elsize)
{
if (nelem == 0 || elsize == 0)
nelem = elsize = 1;
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)
return imalloc(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 int oldsize, newsize;
register int oldsize,
newsize;
newsize = (new == NULL) ? 0 : strlen(new);
if (old == NULL)
oldsize = 0;
else if (newsize == 0)
return old;
else oldsize = strlen(old);
else
oldsize = strlen(old);
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
if (new != NULL)
(void) strcpy(result + oldsize, new);
return result;
}
char *icpyalloc(const char *string)
char *
icpyalloc(const char *string)
{
return icatalloc((char *) NULL, string);
}
void ifree(char *p)
void
ifree(char *p)
{
if (p != NULL)
(void) free(p);
}
void icfree(char *p)
void
icfree(char *p)
{
if (p != NULL)
(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
*
* 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_MONTH (60*60*24*30)
struct tztry {
time_t std_t,dst_t;
char std_time[TZ_STRLEN_MAX+1],dst_time[TZ_STRLEN_MAX+1];
int std_ofs,dst_ofs;
struct tm std_tm, dst_tm;
struct tztry
{
time_t std_t,
dst_t;
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 ||
s->tm_min != p->tm_min ||
s->tm_hour != p->tm_hour ||
@ -69,11 +76,14 @@ static bool compare_tm(struct tm *s, struct pg_tm *p) {
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;
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 */
pgtm = pg_localtime(&(tt->std_t));
@ -95,7 +105,9 @@ static bool try_timezone(char *tzname, struct tztry *tt, bool checkdst) {
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)
return tm->tm_gmtoff;
#elif defined(HAVE_INT_TIMEZONE)
@ -113,12 +125,15 @@ static int get_timezone_offset(struct tm *tm) {
#ifdef WIN32
#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];
int l = 0;
char *c;
for (c = tz; *c; c++) {
for (c = tz; *c; c++)
{
if (isupper(*c))
w32tzabbr[l++] = *c;
}
@ -153,10 +168,12 @@ identify_system_timezone(void)
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);
if (tm->tm_isdst == 0 && !std_found) {
if (tm->tm_isdst == 0 && !std_found)
{
/* Standard time */
memcpy(&tt.std_tm, tm, sizeof(struct tm));
memset(cbuf, 0, sizeof(cbuf));
@ -166,7 +183,8 @@ identify_system_timezone(void)
tt.std_t = t;
std_found = true;
}
else if (tm->tm_isdst == 1 && !dst_found) {
else if (tm->tm_isdst == 1 && !dst_found)
{
/* Daylight time */
memcpy(&tt.dst_tm, tm, sizeof(struct tm));
memset(cbuf, 0, sizeof(cbuf));
@ -189,7 +207,8 @@ identify_system_timezone(void)
return NULL; /* go to GMT */
}
if (dst_found) {
if (dst_found)
{
/* Try STD<ofs>DST */
sprintf(__tzbuf, "%s%d%s", tt.std_time, -tt.std_ofs / 3600, tt.dst_time);
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
* 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? */
if (strcmp(GetConfigOption("timezone"), "UNKNOWN") == 0) {
if (strcmp(GetConfigOption("timezone"), "UNKNOWN") == 0)
{
const char *def_tz;
/* Select setting */

View File

@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
* 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
extern int unlink(const char *filename);
#define remove unlink
#endif /* !defined remove */

View File

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

View File

@ -25,7 +25,8 @@
#include "tzfile.h"
struct lc_time_T {
struct lc_time_T
{
const char *mon[MONSPERYEAR];
const char *month[MONSPERYEAR];
const char *wday[DAYSPERWEEK];
@ -59,20 +60,15 @@ 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",
@ -96,7 +92,8 @@ static char * _fmt (const char *, const struct pg_tm *, char *, const char *, in
#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;
int warn;
@ -109,12 +106,16 @@ size_t pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_
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:
switch (*++format) {
switch (*++format)
{
case '\0':
--format;
break;
@ -144,12 +145,11 @@ label:
pt, ptlim);
continue;
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);
@ -173,14 +173,12 @@ label:
continue;
case 'E':
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,20 +199,20 @@ label:
pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
continue;
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;
#ifdef KITCHEN_SINK
case 'K':
/*
* * After all this time, still unclaimed!
*/
@ -222,14 +220,13 @@ label:
continue;
#endif /* defined KITCHEN_SINK */
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.
** (ado, 1993-05-24)
* * 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) ?
(t->tm_hour % 12) : 12,
@ -286,11 +283,11 @@ label:
"%02d", pt, ptlim);
continue;
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,
@ -326,7 +323,8 @@ label:
year = t->tm_year + TM_YEAR_BASE;
yday = t->tm_yday;
wday = t->tm_wday;
for ( ; ; ) {
for (;;)
{
int len;
int bot;
int top;
@ -334,27 +332,31 @@ label:
len = isleap(year) ?
DAYSPERLYEAR :
DAYSPERNYEAR;
/*
** What yday (-3 ... 3) does
** the ISO year begin on?
* * What yday (-3 ... 3) does * the ISO year
* begin on?
*/
bot = ((yday + 11 - wday) %
DAYSPERWEEK) - 3;
/*
** What yday does the NEXT
** ISO year begin on?
* * What yday does the NEXT * ISO year begin
* on?
*/
top = bot -
(len % DAYSPERWEEK);
if (top < -3)
top += DAYSPERWEEK;
top += len;
if (yday >= top) {
if (yday >= top)
{
++year;
w = 1;
break;
}
if (yday >= bot) {
if (yday >= bot)
{
w = 1 + ((yday - bot) /
DAYSPERWEEK);
break;
@ -367,19 +369,22 @@ label:
if (*format == 'V')
pt = _conv(w, "%02d",
pt, ptlim);
else if (*format == 'g') {
else if (*format == 'g')
{
*warnp = IN_ALL;
pt = _conv(year % 100, "%02d",
pt, ptlim);
} else pt = _conv(year, "%04d",
}
else
pt = _conv(year, "%04d",
pt, ptlim);
}
continue;
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;
@ -419,10 +424,10 @@ label:
case 'Z':
if (t->tm_zone != NULL)
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':
@ -433,10 +438,13 @@ label:
if (t->tm_isdst < 0)
continue;
diff = t->tm_gmtoff;
if (diff < 0) {
if (diff < 0)
{
sign = "-";
diff = -diff;
} else sign = "+";
}
else
sign = "+";
pt = _add(sign, pt, ptlim);
diff /= 60;
pt = _conv((diff / 60) * 100 + diff % 60,
@ -448,10 +456,11 @@ label:
warnp);
continue;
case '%':
/*
** 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.
* * 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:
break;
@ -464,7 +473,8 @@ label:
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];
@ -472,7 +482,8 @@ static char * _conv(const int n, const char *format, char *pt, const char *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')
++pt;

View File

@ -28,11 +28,14 @@
#define TZ_MAGIC "TZif"
struct tzhead {
struct tzhead
{
char tzh_magic[4]; /* TZ_MAGIC */
char tzh_reserved[16]; /* reserved for future use */
char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
char tzh_ttisgmtcnt[4]; /* coded number of trans. time
* flags */
char tzh_ttisstdcnt[4]; /* coded number of trans. time
* flags */
char tzh_leapcnt[4]; /* coded number of leap seconds */
char tzh_timecnt[4]; /* coded number of transition times */
char tzh_typecnt[4]; /* coded number of local time types */
@ -77,12 +80,15 @@ struct tzhead {
*/
#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) */
#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 MINSPERHOUR 60

File diff suppressed because it is too large Load Diff