Commit 0a19fb42 authored by Bruce Momjian's avatar Bruce Momjian

Pgindent timezone file, per request from Tom.

parent 63bd0db1
......@@ -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 char *result;
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);
......
This diff is collapsed.
......@@ -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 w32tzabbr[TZ_STRLEN_MAX+1];
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;
}
......@@ -140,37 +155,40 @@ static char *win32_get_timezone_abbrev(char *tz) {
static char *
identify_system_timezone(void)
{
static char __tzbuf[TZ_STRLEN_MAX+1];
bool std_found=false,
dst_found=false;
static char __tzbuf[TZ_STRLEN_MAX + 1];
bool std_found = false,
dst_found = false;
time_t tnow = time(NULL);
time_t t;
struct tztry tt;
char cbuf[TZ_STRLEN_MAX+1];
char cbuf[TZ_STRLEN_MAX + 1];
/* Initialize OS timezone library */
tzset();
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));
strftime(cbuf, sizeof(cbuf)-1, "%Z", tm); /* zone abbr */
memset(cbuf, 0, sizeof(cbuf));
strftime(cbuf, sizeof(cbuf) - 1, "%Z", tm); /* zone abbr */
strcpy(tt.std_time, TZABBREV(cbuf));
tt.std_ofs = get_timezone_offset(tm);
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));
strftime(cbuf, sizeof(cbuf)-1, "%Z", tm); /* zone abbr */
memset(cbuf, 0, sizeof(cbuf));
strftime(cbuf, sizeof(cbuf) - 1, "%Z", tm); /* zone abbr */
strcpy(tt.dst_time, TZABBREV(cbuf));
tt.dst_ofs = get_timezone_offset(tm);
tt.dst_t = t;
......@@ -189,20 +207,21 @@ 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);
sprintf(__tzbuf, "%s%d%s", tt.std_time, -tt.std_ofs / 3600, tt.dst_time);
if (try_timezone(__tzbuf, &tt, dst_found))
return __tzbuf;
}
/* Try just the STD timezone */
strcpy(__tzbuf,tt.std_time);
strcpy(__tzbuf, tt.std_time);
if (try_timezone(__tzbuf, &tt, dst_found))
return __tzbuf;
/* Did not find the timezone. Fallback to try a GMT zone. */
sprintf(__tzbuf,"Etc/GMT%s%d",
(-tt.std_ofs<0)?"+":"",tt.std_ofs/3600);
sprintf(__tzbuf, "Etc/GMT%s%d",
(-tt.std_ofs < 0) ? "+" : "", tt.std_ofs / 3600);
ereport(LOG,
(errmsg("could not recognize system timezone, defaulting to \"%s\"",
__tzbuf),
......@@ -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 */
......
......@@ -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 $
*
*-------------------------------------------------------------------------
*/
......
......@@ -52,21 +52,22 @@
*/
#ifndef remove
extern int unlink (const char * filename);
extern int unlink(const char *filename);
#define remove unlink
#endif /* !defined remove */
/*
* Private function declarations.
*/
extern char *icalloc (int nelem, int elsize);
extern char *icatalloc (char *old, const char *new);
extern char *icpyalloc (const char *string);
extern char *imalloc (int n);
extern void *irealloc (void *pointer, int size);
extern void icfree (char *pointer);
extern void ifree (char *pointer);
extern char *scheck (const char *string, const char *format);
extern char *icalloc(int nelem, int elsize);
extern char *icatalloc(char *old, const char *new);
extern char *icpyalloc(const char *string);
extern char *imalloc(int n);
extern void *irealloc(void *pointer, int size);
extern void icfree(char *pointer);
extern void ifree(char *pointer);
extern char *scheck(const char *string, const char *format);
/*
......
......@@ -3,13 +3,14 @@
#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;
register char * tp;
register char *fbuf;
register const char *fp;
register char *tp;
register int c;
register char * result;
register char *result;
char dummy;
static char nada;
......@@ -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;
......
......@@ -25,17 +25,18 @@
#include "tzfile.h"
struct lc_time_T {
const char * mon[MONSPERYEAR];
const char * month[MONSPERYEAR];
const char * wday[DAYSPERWEEK];
const char * weekday[DAYSPERWEEK];
const char * X_fmt;
const char * x_fmt;
const char * c_fmt;
const char * am;
const char * pm;
const char * date_fmt;
struct lc_time_T
{
const char *mon[MONSPERYEAR];
const char *month[MONSPERYEAR];
const char *wday[DAYSPERWEEK];
const char *weekday[DAYSPERWEEK];
const char *X_fmt;
const char *x_fmt;
const char *c_fmt;
const char *am;
const char *pm;
const char *date_fmt;
};
#define Locale (&C_time_locale)
......@@ -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",
......@@ -86,9 +82,9 @@ static const struct lc_time_T C_time_locale = {
"%a %b %e %H:%M:%S %Z %Y"
};
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 *_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 *);
#define IN_NONE 0
#define IN_SOME 1
......@@ -96,9 +92,10 @@ 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;
char *p;
int warn;
warn = IN_NONE;
......@@ -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 == '%') {
label:
switch (*++format) {
for (; *format; ++format)
{
if (*format == '%')
{
label:
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,35 +199,34 @@ 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!
* * After all this time, still unclaimed!
*/
pt = _add("kitchen sink", pt, ptlim);
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,
......@@ -262,7 +259,7 @@ label:
case 's':
{
struct pg_tm tm;
char buf[INT_STRLEN_MAXIMUM(time_t) + 1];
char buf[INT_STRLEN_MAXIMUM(time_t) +1];
time_t mkt;
tm = *t;
......@@ -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,27 +424,30 @@ 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':
{
int diff;
char const * sign;
char const *sign;
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,
pt = _conv((diff / 60) * 100 + diff % 60,
"%04d", pt, ptlim);
}
continue;
......@@ -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,15 +473,17 @@ 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];
char buf[INT_STRLEN_MAXIMUM(int) +1];
(void) sprintf(buf, format, n);
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;
......
......@@ -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
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment