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 * Same trick for day-of-week using the hash function
92 static int day_map[] = {
107 /* The SET* macros will parse for the appropriate field, and leave the
108 * cp pointer at the first character after the desired field. Be
109 * careful with variable-length fields or alpha-num mixes.
111 * The SKIP* macros skip over characters of a particular class and
112 * leave cp at the position of the first character that doesn't match
113 * that class. Correspondingly, SKIPTO* skips until it reaches a
114 * character of a particular class.
117 #define INIT() { cp = yytext;}
118 #define SETWDAY() { cp++; \
119 tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \
120 tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP; \
122 #define SETMON() { cp++; \
123 tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; \
125 #define SETMON_NUM() { tw.tw_mon = atoi(cp)-1; \
127 #define SETYEAR() { tw.tw_year = atoi(cp); \
129 #define SETDAY() { tw.tw_mday = atoi(cp); \
130 tw.tw_flags |= TW_YES; \
132 #define SETTIME() { tw.tw_hour = atoi(cp); \
135 tw.tw_min = atoi(cp); \
138 tw.tw_sec = atoi(++cp); SKIPD(); } }
139 #define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \
140 tw.tw_flags |= TW_SZEXP; \
142 #define SETDST() { tw.tw_flags |= TW_DST; }
143 #define SKIPD() { while ( isdigit(*cp++) ) ; \
145 #define SKIPTOD() { while ( !isdigit(*cp++) ) ; \
147 #define SKIPA() { while ( isalpha(*cp++) ) ; \
149 #define SKIPTOA() { while ( !isalpha(*cp++) ) ; \
151 #define SKIPSP() { while ( isspace(*cp++) ) ; \
153 #define SKIPTOSP() { while ( !isspace(*cp++) ) ; \
160 wed ([Ww]ed(nesday)?)
165 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
175 sep ([Ss]ep(tember)?)
180 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
182 TIME ({D}:{d}{d}(:{d}{d})?)
184 /* The year can either be 2 digits, or 4. However, after
185 Y2K, we found that some MUA were reporting the year 100, hence
186 the middle term here. yyterminate() resolves the actual
187 issues with 2-digit years.
190 YEAR (({d}{d})|(1{d}{d})|({d}{4}))
199 /* This section begins the definition of dparsetime().
200 Put here any local variable definitions and initializations */
202 YY_BUFFER_STATE lexhandle;
205 static struct tws tw;
207 memset(&tw,0,sizeof(struct tws));
209 lexhandle = yy_scan_string(lexstr);
212 {DAY}","?{W}{MONTH}{W}{D}{W}{TIME}{W}{YEAR} {
225 {DAY}","?{W}{D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
237 {D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
247 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR}","?{W}{TIME} {
259 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR} {
269 {MONTH}{W}{D}","?{W}{YEAR}","?{W}{DAY} {
279 {MONTH}{W}{D}","?{W}{YEAR} {
287 {D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME} {
305 {D}("-"|"/"){D}("-"|"/"){YEAR} {
323 "[Pp][Mm]" tw.tw_hour += 12;
335 "-"?("ut"|"UT") INIT(); SETZONE(0);
336 "-"?("gmt"|"GMT") INIT(); SETZONE(0);
337 "-"?("jst"|"JST") INIT(); SETZONE(200);
338 "-"?("jdt"|"JDT") INIT(); SETDST(); SETZONE(2);
339 "-"?("est"|"EST") INIT(); SETZONE(-500);
340 "-"?("edt"|"EDT") INIT(); SETDST(); SETZONE(-500);
341 "-"?("cst"|"CST") INIT(); SETZONE(-600);
342 "-"?("cdt"|"CDT") INIT(); SETDST(); SETZONE(-600);
343 "-"?("mst"|"MST") INIT(); SETZONE(-700);
344 "-"?("mdt"|"MDT") INIT(); SETDST(); SETZONE(-700);
345 "-"?("pst"|"PST") INIT(); SETZONE(-800);
346 "-"?("pdt"|"PDT") INIT(); SETDST(); SETZONE(-800);
347 "-"?("nst"|"NST") INIT(); SETZONE(-330);
348 "-"?("ast"|"AST") INIT(); SETZONE(-400);
349 "-"?("adt"|"ADT") INIT(); SETDST(); SETZONE(-400);
350 "-"?("yst"|"YST") INIT(); SETZONE(-900);
351 "-"?("ydt"|"YDT") INIT(); SETDST(); SETZONE(-900);
352 "-"?("hst"|"HST") INIT(); SETZONE(-1000);
353 "-"?("hdt"|"HDT") INIT(); SETDST(); SETZONE(-1000);
354 "-"?("bst"|"BST") INIT(); SETDST(); SETZONE(-100);
357 SETZONE(100*(('a'-1) - tolower(*cp)));
361 SETZONE(100*('a' - tolower(*cp)));
365 SETZONE(100*(tolower(*cp) - 'm'));