5 /* Since we're looking at a string at a time, don't worry about
6 * wrapping to the next buffer.
13 /* This is the tricky thing that makes this function cool. We
14 * replace the traditional int yylex(void) declaration with our
15 * dparsetime() declaration, essentially piggy-backing off the
16 * utility of the yylex() function and adding what we need to make
17 * the parsing function useful to us.
19 #define YY_DECL struct tws *dparsetime(char *lexstr)
21 /* yyerminate() is called after the input string is matched to
22 * completion (actually, when the lexer reaches an EOF). The only
23 * thing that really needs to be in this macro function is the
24 * return call, which must be substituted inline into dparsetime.
27 #define yyterminate() (void)yy_delete_buffer(lexhandle); \
28 if(!(tw.tw_flags & TW_SUCC)) { \
29 return (struct tws *)NULL; \
31 if(tw.tw_year < 1970) \
33 if(tw.tw_year < 1970) \
38 * Patchable flag that says how to interpret NN/NN/NN dates. When
39 * true, we do it European style: DD/MM/YY. When false, we do it
40 * American style: MM/DD/YY. Of course, these are all non-RFC822
46 * Table to convert month names to numeric month. We use the
47 * fact that the low order 5 bits of the sum of the 2nd & 3rd
48 * characters of the name is a hash with no collisions for the 12
49 * valid month names. (The mask to 5 bits maps any combination of
50 * upper and lower case into the same hash value).
52 static int month_map[] = {
85 * Lookup table for day-of-week using the same hash trick as for above name-of-
86 * month table, but using the first and second character, not second and third.
88 * Compute index into table using: (day_name[0] & 7) + (day_name[1] & 4)
90 static int day_map[] = {
105 /* The SET* macros will parse for the appropriate field, and leave the
106 * cp pointer at the first character after the desired field. Be
107 * careful with variable-length fields or alpha-num mixes.
109 * The SKIP* macros skip over characters of a particular class and
110 * leave cp at the position of the first character that doesn't match
111 * that class. Correspondingly, SKIPTO* skips until it reaches a
112 * character of a particular class.
115 #define INIT() { cp = yytext;}
116 #define SETWDAY() { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \
117 tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP; \
119 #define SETMON() { cp++; \
120 tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; \
122 #define SETMON_NUM() { tw.tw_mon = atoi(cp)-1; \
124 #define SETYEAR() { tw.tw_year = atoi(cp); \
126 #define SETDAY() { tw.tw_mday = atoi(cp); \
127 tw.tw_flags |= TW_YES; \
129 #define SETTIME() { tw.tw_hour = atoi(cp); \
132 tw.tw_min = atoi(cp); \
135 tw.tw_sec = atoi(++cp); SKIPD(); } }
136 #define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \
137 tw.tw_flags |= TW_SZEXP; \
139 #define SETDST() { tw.tw_flags |= TW_DST; }
140 #define SKIPD() { while ( isdigit(*cp++) ) ; \
142 #define SKIPTOD() { while ( !isdigit(*cp++) ) ; \
144 #define SKIPA() { while ( isalpha(*cp++) ) ; \
146 #define SKIPTOA() { while ( !isalpha(*cp++) ) ; \
148 #define SKIPSP() { while ( isspace(*cp++) ) ; \
150 #define SKIPTOSP() { while ( !isspace(*cp++) ) ; \
153 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
154 # ifdef TIME_WITH_SYS_TIME
155 # include <sys/time.h>
158 # ifdef HAVE_SYS_TIME_H
159 # include <sys/time.h>
166 zonehack (struct tws *tw)
168 register struct tm *tm;
170 if (dmktime (tw) == (time_t) -1)
173 tm = localtime (&tw->tw_clock);
175 tw->tw_flags |= TW_DST;
179 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
185 wed ([Ww]ed(nesday)?)
190 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
200 sep ([Ss]ep(tember)?)
205 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
207 TIME ({D}:{d}{d}(:{d}{d})?)
209 /* The year can either be 2 digits, or 4. However, after
210 Y2K, we found that some MUA were reporting the year 100, hence
211 the middle term here. yyterminate() resolves the actual
212 issues with 2-digit years.
215 YEAR (({d}{d})|(1{d}{d})|({d}{4}))
225 /* This section begins the definition of dparsetime().
226 Put here any local variable definitions and initializations */
228 YY_BUFFER_STATE lexhandle;
231 static struct tws tw;
233 memset(&tw,0,sizeof(struct tws));
235 lexhandle = yy_scan_string(lexstr);
238 {DAY}","?{W}{MONTH}{W}{D}{W}{TIME}{W}{YEAR} {
251 {DAY}","?{W}{D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
263 {D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
273 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR}","?{W}{TIME} {
285 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR} {
295 {MONTH}{W}{D}","?{W}{YEAR}","?{W}{DAY} {
305 {MONTH}{W}{D}","?{W}{YEAR} {
313 {D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME} {
331 {D}("-"|"/"){D}("-"|"/"){YEAR} {
349 "[Pp][Mm]" tw.tw_hour += 12;
355 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
357 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
364 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
366 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
370 {nl}("ut"|"UT") INIT(); SETZONE(0); yyterminate();
371 {nl}("gmt"|"GMT") INIT(); SETZONE(0); yyterminate();
372 {nl}("est"|"EST") INIT(); SETZONE(-500); yyterminate();
373 {nl}("edt"|"EDT") { INIT(); SETDST(); SETZONE(-500);
375 {nl}("cst"|"CST") INIT(); SETZONE(-600); yyterminate();
376 {nl}("cdt"|"CDT") { INIT(); SETDST(); SETZONE(-600);
378 {nl}("mst"|"MST") INIT(); SETZONE(-700); yyterminate();
379 {nl}("mdt"|"MDT") { INIT(); SETDST(); SETZONE(-700);
381 {nl}("pst"|"PST") INIT(); SETZONE(-800); yyterminate();
382 {nl}("pdt"|"PDT") { INIT(); SETDST(); SETZONE(-800);
384 {nl}("nst"|"NST") INIT(); SETZONE(-330); yyterminate();
385 {nl}("ast"|"AST") INIT(); SETZONE(-400); yyterminate();
386 {nl}("adt"|"ADT") { INIT(); SETDST(); SETZONE(-400);
388 {nl}("hst"|"HST") INIT(); SETZONE(-1000); yyterminate();
389 {nl}("hdt"|"HDT") { INIT(); SETDST(); SETZONE(-1000);