~mnordhoff/pytz/pytz-2008c

« back to all changes in this revision

Viewing changes to elsie.nci.nih.gov/src/localtime.c

  • Committer: Stuart Bishop
  • Date: 2008-01-02 02:02:13 UTC
  • mfrom: (143.1.7 pytz-2007k)
  • Revision ID: stuart@stuartbishop.net-20080102020213-hx49suyl8r1b55n3
Merge from  bzr+ssh://bazaar.launchpad.net/~mnordhoff/pytz/pytz-2007k

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
#ifndef lint
7
7
#ifndef NOID
8
 
static char     elsieid[] = "@(#)localtime.c    8.5";
 
8
static char     elsieid[] = "@(#)localtime.c    8.8";
9
9
#endif /* !defined NOID */
10
10
#endif /* !defined lint */
11
11
 
136
136
** Prototypes for static functions.
137
137
*/
138
138
 
139
 
static long             detzcode P((const char * codep));
140
 
static time_t           detzcode64 P((const char * codep));
141
 
static int              differ_by_repeat P((time_t t1, time_t t0));
142
 
static const char *     getzname P((const char * strp));
143
 
static const char *     getqzname P((const char * strp, const int delim));
144
 
static const char *     getnum P((const char * strp, int * nump, int min,
145
 
                                int max));
146
 
static const char *     getsecs P((const char * strp, long * secsp));
147
 
static const char *     getoffset P((const char * strp, long * offsetp));
148
 
static const char *     getrule P((const char * strp, struct rule * rulep));
149
 
static void             gmtload P((struct state * sp));
150
 
static struct tm *      gmtsub P((const time_t * timep, long offset,
151
 
                                struct tm * tmp));
152
 
static struct tm *      localsub P((const time_t * timep, long offset,
153
 
                                struct tm * tmp));
154
 
static int              increment_overflow P((int * number, int delta));
155
 
static int              leaps_thru_end_of P((int y));
156
 
static int              long_increment_overflow P((long * number, int delta));
157
 
static int              long_normalize_overflow P((long * tensptr,
158
 
                                int * unitsptr, int base));
159
 
static int              normalize_overflow P((int * tensptr, int * unitsptr,
160
 
                                int base));
161
 
static void             settzname P((void));
162
 
static time_t           time1 P((struct tm * tmp,
163
 
                                struct tm * (*funcp) P((const time_t *,
164
 
                                long, struct tm *)),
165
 
                                long offset));
166
 
static time_t           time2 P((struct tm *tmp,
167
 
                                struct tm * (*funcp) P((const time_t *,
168
 
                                long, struct tm*)),
169
 
                                long offset, int * okayp));
170
 
static time_t           time2sub P((struct tm *tmp,
171
 
                                struct tm * (*funcp) P((const time_t *,
172
 
                                long, struct tm*)),
173
 
                                long offset, int * okayp, int do_norm_secs));
174
 
static struct tm *      timesub P((const time_t * timep, long offset,
175
 
                                const struct state * sp, struct tm * tmp));
176
 
static int              tmcomp P((const struct tm * atmp,
177
 
                                const struct tm * btmp));
178
 
static time_t           transtime P((time_t janfirst, int year,
179
 
                                const struct rule * rulep, long offset));
180
 
static int              tzload P((const char * name, struct state * sp,
181
 
                                int doextend));
182
 
static int              tzparse P((const char * name, struct state * sp,
183
 
                                int lastditch));
 
139
static long             detzcode(const char * codep);
 
140
static time_t           detzcode64(const char * codep);
 
141
static int              differ_by_repeat(time_t t1, time_t t0);
 
142
static const char *     getzname(const char * strp);
 
143
static const char *     getqzname(const char * strp, const int delim);
 
144
static const char *     getnum(const char * strp, int * nump, int min,
 
145
                                int max);
 
146
static const char *     getsecs(const char * strp, long * secsp);
 
147
static const char *     getoffset(const char * strp, long * offsetp);
 
148
static const char *     getrule(const char * strp, struct rule * rulep);
 
149
static void             gmtload(struct state * sp);
 
150
static struct tm *      gmtsub(const time_t * timep, long offset,
 
151
                                struct tm * tmp);
 
152
static struct tm *      localsub(const time_t * timep, long offset,
 
153
                                struct tm * tmp);
 
154
static int              increment_overflow(int * number, int delta);
 
155
static int              leaps_thru_end_of(int y);
 
156
static int              long_increment_overflow(long * number, int delta);
 
157
static int              long_normalize_overflow(long * tensptr,
 
158
                                int * unitsptr, int base);
 
159
static int              normalize_overflow(int * tensptr, int * unitsptr,
 
160
                                int base);
 
161
static void             settzname(void);
 
162
static time_t           time1(struct tm * tmp,
 
163
                                struct tm * (*funcp)(const time_t *,
 
164
                                long, struct tm *),
 
165
                                long offset);
 
166
static time_t           time2(struct tm *tmp,
 
167
                                struct tm * (*funcp)(const time_t *,
 
168
                                long, struct tm*),
 
169
                                long offset, int * okayp);
 
170
static time_t           time2sub(struct tm *tmp,
 
171
                                struct tm * (*funcp)(const time_t *,
 
172
                                long, struct tm*),
 
173
                                long offset, int * okayp, int do_norm_secs);
 
174
static struct tm *      timesub(const time_t * timep, long offset,
 
175
                                const struct state * sp, struct tm * tmp);
 
176
static int              tmcomp(const struct tm * atmp,
 
177
                                const struct tm * btmp);
 
178
static time_t           transtime(time_t janfirst, int year,
 
179
                                const struct rule * rulep, long offset);
 
180
static int              typesequiv(const struct state * sp, int a, int b);
 
181
static int              tzload(const char * name, struct state * sp,
 
182
                                int doextend);
 
183
static int              tzparse(const char * name, struct state * sp,
 
184
                                int lastditch);
184
185
 
185
186
#ifdef ALL_STATE
186
187
static struct state *   lclptr;
253
254
}
254
255
 
255
256
static void
256
 
settzname P((void))
 
257
settzname(void)
257
258
{
258
259
        register struct state * const   sp = lclptr;
259
260
        register int                    i;
556
557
        }
557
558
        i = 2 * YEARSPERREPEAT;
558
559
        sp->goback = sp->goahead = sp->timecnt > i;
559
 
        sp->goback = sp->goback && sp->types[i] == sp->types[0] &&
 
560
        sp->goback = sp->goback &&
 
561
                typesequiv(sp, sp->types[i], sp->types[0]) &&
560
562
                differ_by_repeat(sp->ats[i], sp->ats[0]);
561
563
        sp->goahead = sp->goahead &&
562
 
                sp->types[sp->timecnt - 1] == sp->types[sp->timecnt - 1 - i] &&
 
564
                typesequiv(sp, sp->types[sp->timecnt - 1],
 
565
                sp->types[sp->timecnt - 1 - i]) &&
563
566
                differ_by_repeat(sp->ats[sp->timecnt - 1],
564
567
                         sp->ats[sp->timecnt - 1 - i]);
565
568
        return 0;
566
569
}
567
570
 
 
571
static int
 
572
typesequiv(sp, a, b)
 
573
const struct state * const      sp;
 
574
const int                       a;
 
575
const int                       b;
 
576
{
 
577
        register int    result;
 
578
 
 
579
        if (sp == NULL ||
 
580
                a < 0 || a >= sp->typecnt ||
 
581
                b < 0 || b >= sp->typecnt)
 
582
                        result = FALSE;
 
583
        else {
 
584
                register const struct ttinfo *  ap = &sp->ttis[a];
 
585
                register const struct ttinfo *  bp = &sp->ttis[b];
 
586
                result = ap->tt_gmtoff == bp->tt_gmtoff &&
 
587
                        ap->tt_isdst == bp->tt_isdst &&
 
588
                        ap->tt_ttisstd == bp->tt_ttisstd &&
 
589
                        ap->tt_ttisgmt == bp->tt_ttisgmt &&
 
590
                        strcmp(&sp->chars[ap->tt_abbrind],
 
591
                        &sp->chars[bp->tt_abbrind]) == 0;
 
592
        }
 
593
        return result;
 
594
}
 
595
 
568
596
static const int        mon_lengths[2][MONSPERYEAR] = {
569
597
        { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
570
598
        { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
1120
1148
static
1121
1149
#endif /* !defined STD_INSPIRED */
1122
1150
void
1123
 
tzsetwall P((void))
 
1151
tzsetwall(void)
1124
1152
{
1125
1153
        if (lcl_is_set < 0)
1126
1154
                return;
1141
1169
}
1142
1170
 
1143
1171
void
1144
 
tzset P((void))
 
1172
tzset(void)
1145
1173
{
1146
1174
        register const char *   name;
1147
1175
 
1639
1667
static time_t
1640
1668
time2sub(tmp, funcp, offset, okayp, do_norm_secs)
1641
1669
struct tm * const       tmp;
1642
 
struct tm * (* const    funcp) P((const time_t*, long, struct tm*));
 
1670
struct tm * (* const    funcp)(const time_t*, long, struct tm*);
1643
1671
const long              offset;
1644
1672
int * const             okayp;
1645
1673
const int               do_norm_secs;
1781
1809
                ** It's okay to guess wrong since the guess
1782
1810
                ** gets checked.
1783
1811
                */
1784
 
                /*
1785
 
                ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
1786
 
                */
1787
1812
                sp = (const struct state *)
1788
 
                        (((void *) funcp == (void *) localsub) ?
1789
 
                        lclptr : gmtptr);
 
1813
                        ((funcp == localsub) ? lclptr : gmtptr);
1790
1814
#ifdef ALL_STATE
1791
1815
                if (sp == NULL)
1792
1816
                        return WRONG;
1827
1851
static time_t
1828
1852
time2(tmp, funcp, offset, okayp)
1829
1853
struct tm * const       tmp;
1830
 
struct tm * (* const    funcp) P((const time_t*, long, struct tm*));
 
1854
struct tm * (* const    funcp)(const time_t*, long, struct tm*);
1831
1855
const long              offset;
1832
1856
int * const             okayp;
1833
1857
{
1845
1869
static time_t
1846
1870
time1(tmp, funcp, offset)
1847
1871
struct tm * const       tmp;
1848
 
struct tm * (* const    funcp) P((const time_t *, long, struct tm *));
 
1872
struct tm * (* const    funcp)(const time_t *, long, struct tm *);
1849
1873
const long              offset;
1850
1874
{
1851
1875
        register time_t                 t;
1880
1904
        ** We try to divine the type they started from and adjust to the
1881
1905
        ** type they need.
1882
1906
        */
1883
 
        /*
1884
 
        ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
1885
 
        */
1886
 
        sp = (const struct state *) (((void *) funcp == (void *) localsub) ?
1887
 
                lclptr : gmtptr);
 
1907
        sp = (const struct state *) ((funcp == localsub) ?  lclptr : gmtptr);
1888
1908
#ifdef ALL_STATE
1889
1909
        if (sp == NULL)
1890
1910
                return WRONG;