9 /* Since we're looking at a string at a time, don't worry about
10 * wrapping to the next buffer.
13 #define YY_SKIP_YYWRAP
17 /* This is the tricky thing that makes this function cool. We
18 * replace the traditional int yylex(void) declaration with our
19 * dparsetime() declaration, essentially piggy-backing off the
20 * utility of the yylex() function and adding what we need to make
21 * the parsing function useful to us.
23 #define YY_DECL struct tws *dparsetime(char *lexstr)
25 /* yyerminate() is called after the input string is matched to
26 * completion (actually, when the lexer reaches an EOF). The only
27 * thing that really needs to be in this macro function is the
28 * return call, which must be substituted inline into dparsetime.
31 #define yyterminate() (void)yy_delete_buffer(lexhandle); \
32 if(!(tw.tw_flags & TW_SUCC)) { \
33 return (struct tws *)NULL; \
35 if(tw.tw_year < 1960) \
37 if(tw.tw_year < 1960) \
42 * Patchable flag that says how to interpret NN/NN/NN dates. When
43 * true, we do it European style: DD/MM/YY. When false, we do it
44 * American style: MM/DD/YY. Of course, these are all non-RFC822
50 * Table to convert month names to numeric month. We use the
51 * fact that the low order 5 bits of the sum of the 2nd & 3rd
52 * characters of the name is a hash with no collisions for the 12
53 * valid month names. (The mask to 5 bits maps any combination of
54 * upper and lower case into the same hash value).
56 static int month_map[] = {
89 * Lookup table for day-of-week using the same hash trick as for above name-of-
90 * month table, but using the first and second character, not second and third.
92 * Compute index into table using: (day_name[0] & 7) + (day_name[1] & 4)
94 static int day_map[] = {
109 /* The SET* macros will parse for the appropriate field, and leave the
110 * cp pointer at the first character after the desired field. Be
111 * careful with variable-length fields or alpha-num mixes.
113 * The SKIP* macros skip over characters of a particular class and
114 * leave cp at the position of the first character that doesn't match
115 * that class. Correspondingly, SKIPTO* skips until it reaches a
116 * character of a particular class.
119 #define INIT() { cp = yytext;}
120 #define SETWDAY() { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \
121 tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP; \
123 #define SETMON() { cp++; \
124 tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; \
126 #define SETMON_NUM() { tw.tw_mon = atoi(cp)-1; \
128 #define SETYEAR() { tw.tw_year = atoi(cp); \
130 #define SETDAY() { tw.tw_mday = atoi(cp); \
131 tw.tw_flags |= TW_YES; \
133 #define SETTIME() { tw.tw_hour = atoi(cp); \
136 tw.tw_min = atoi(cp); \
139 tw.tw_sec = atoi(++cp); SKIPD(); } }
140 #define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \
141 tw.tw_flags |= TW_SZEXP; \
143 #define SETDST() { tw.tw_flags |= TW_DST; }
144 #define SKIPD() { while ( isdigit(*cp++) ) ; \
146 #define SKIPTOD() { while ( !isdigit(*cp++) ) ; \
148 #define SKIPA() { while ( isalpha(*cp++) ) ; \
150 #define SKIPTOA() { while ( !isalpha(*cp++) ) ; \
152 #define SKIPSP() { while ( isspace(*cp++) ) ; \
154 #define SKIPTOSP() { while ( !isspace(*cp++) ) ; \
157 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
158 # ifdef TIME_WITH_SYS_TIME
159 # include <sys/time.h>
162 # ifdef HAVE_SYS_TIME_H
163 # include <sys/time.h>
170 zonehack (struct tws *tw)
172 register struct tm *tm;
174 if (dmktime (tw) == (time_t) -1)
177 tm = localtime (&tw->tw_clock);
179 tw->tw_flags |= TW_DST;
183 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
189 wed ([Ww]ed(nesday)?)
194 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
204 sep ([Ss]ep(tember)?)
209 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
211 TIME ({D}:{d}{d}(:{d}{d})?)
213 /* The year can either be 2 digits, or 4. However, after
214 Y2K, we found that some MUA were reporting the year 100, hence
215 the middle term here. yyterminate() resolves the actual
216 issues with 2-digit years.
219 YEAR (({d}{d})|(1{d}{d})|({d}{4}))
228 /* This section begins the definition of dparsetime().
229 Put here any local variable definitions and initializations */
231 YY_BUFFER_STATE lexhandle;
234 static struct tws tw;
236 memset(&tw,0,sizeof(struct tws));
238 lexhandle = yy_scan_string(lexstr);
241 {DAY}","?{W}{MONTH}{W}{D}{W}{TIME}{W}{YEAR} {
254 {DAY}","?{W}{D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
266 {D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
276 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR}","?{W}{TIME} {
288 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR} {
298 {MONTH}{W}{D}","?{W}{YEAR}","?{W}{DAY} {
308 {MONTH}{W}{D}","?{W}{YEAR} {
316 {D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME} {
334 {D}("-"|"/"){D}("-"|"/"){YEAR} {
352 "[Pp][Mm]" tw.tw_hour += 12;
358 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
360 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
367 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
369 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
373 "-"?("ut"|"UT") INIT(); SETZONE(0);
374 "-"?("gmt"|"GMT") INIT(); SETZONE(0);
375 "-"?("jst"|"JST") INIT(); SETZONE(200);
376 "-"?("jdt"|"JDT") INIT(); SETDST(); SETZONE(2);
377 "-"?("est"|"EST") INIT(); SETZONE(-500);
378 "-"?("edt"|"EDT") INIT(); SETDST(); SETZONE(-500);
379 "-"?("cst"|"CST") INIT(); SETZONE(-600);
380 "-"?("cdt"|"CDT") INIT(); SETDST(); SETZONE(-600);
381 "-"?("mst"|"MST") INIT(); SETZONE(-700);
382 "-"?("mdt"|"MDT") INIT(); SETDST(); SETZONE(-700);
383 "-"?("pst"|"PST") INIT(); SETZONE(-800);
384 "-"?("pdt"|"PDT") INIT(); SETDST(); SETZONE(-800);
385 "-"?("nst"|"NST") INIT(); SETZONE(-330);
386 "-"?("ast"|"AST") INIT(); SETZONE(-400);
387 "-"?("adt"|"ADT") INIT(); SETDST(); SETZONE(-400);
388 "-"?("yst"|"YST") INIT(); SETZONE(-900);
389 "-"?("ydt"|"YDT") INIT(); SETDST(); SETZONE(-900);
390 "-"?("hst"|"HST") INIT(); SETZONE(-1000);
391 "-"?("hdt"|"HDT") INIT(); SETDST(); SETZONE(-1000);
392 "-"?("bst"|"BST") INIT(); SETDST(); SETZONE(-100);
393 "-"?([a-z]{3}|[A-Z]{3}) ;