diff options
| author | Bruce Momjian | 2009-06-11 14:49:15 +0000 |
|---|---|---|
| committer | Bruce Momjian | 2009-06-11 14:49:15 +0000 |
| commit | d7471402794266078953f1bd113dab4913d631a1 (patch) | |
| tree | 618e392a84eaf837e00bf78f8694097b78fec227 /src/timezone/localtime.c | |
| parent | 4e86efb4e51b66ef57b3fe6f28576de23a1bf1c6 (diff) | |
8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list
provided by Andrew.
Diffstat (limited to 'src/timezone/localtime.c')
| -rw-r--r-- | src/timezone/localtime.c | 139 |
1 files changed, 75 insertions, 64 deletions
diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c index 2efa3ecc0e..869b446209 100644 --- a/src/timezone/localtime.c +++ b/src/timezone/localtime.c @@ -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; } |
