2 ** dtimep.lex exceeds the default table capacities for some old versions
3 ** of lex (and the minimum defaults as specified by POSIX). The following
4 ** choices meet or exceed the lex defaults for older SunOS4.x, Solaris,
17 ** Since we're looking at a string at a time, don't worry about
18 ** wrapping to the next buffer.
21 #define YY_SKIP_YYWRAP
26 ** This is the tricky thing that makes this function cool. We
27 ** replace the traditional int yylex(void) declaration with our
28 ** dparsetime() declaration, essentially piggy-backing off the
29 ** utility of the yylex() function and adding what we need to make
30 ** the parsing function useful to us.
32 #define YY_DECL struct tws *dparsetime(char *lexstr)
35 ** yyerminate() is called after the input string is matched to
36 ** completion (actually, when the lexer reaches an EOF). The only
37 ** thing that really needs to be in this macro function is the
38 ** return call, which must be substituted inline into dparsetime.
41 #define yyterminate() (void)yy_delete_buffer(lexhandle); \
42 if(!(tw.tw_flags & TW_SUCC)) { \
43 return (struct tws *)NULL; \
45 if(tw.tw_year < 1970) \
47 if(tw.tw_year < 1970) \
52 ** Patchable flag that says how to interpret NN/NN/NN dates. When
53 ** true, we do it European style: DD/MM/YY. When false, we do it
54 ** American style: MM/DD/YY. Of course, these are all non-RFC822
60 ** Table to convert month names to numeric month. We use the
61 ** fact that the low order 5 bits of the sum of the 2nd & 3rd
62 ** characters of the name is a hash with no collisions for the 12
63 ** valid month names. (The mask to 5 bits maps any combination of
64 ** upper and lower case into the same hash value).
66 static int month_map[] = {
99 ** Lookup table for day-of-week using the same hash trick as for above
100 ** name-of-month table, but using the first and second character, not
103 ** Compute index into table using: (day_name[0] & 7) + (day_name[1] & 4)
105 static int day_map[] = {
121 ** The SET* macros will parse for the appropriate field, and leave the
122 ** cp pointer at the first character after the desired field. Be
123 ** careful with variable-length fields or alpha-num mixes.
125 ** The SKIP* macros skip over characters of a particular class and
126 ** leave cp at the position of the first character that doesn't match
127 ** that class. Correspondingly, SKIPTO* skips until it reaches a
128 ** character of a particular class.
131 #define INIT() { cp = yytext;}
132 #define SETWDAY() { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \
133 tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP; SKIPA(); }
134 #define SETMON() { cp++; tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; \
136 #define SETMON_NUM() { tw.tw_mon = atoi(cp)-1; SKIPD(); }
137 #define SETYEAR() { tw.tw_year = atoi(cp); SKIPD(); }
138 #define SETDAY() { tw.tw_mday = atoi(cp); tw.tw_flags |= TW_YES; SKIPD(); }
139 #define SETTIME() { tw.tw_hour = atoi(cp); cp += 2; SKIPTOD(); \
140 tw.tw_min = atoi(cp); cp += 2; if(*cp == ':') { \
141 tw.tw_sec = atoi(++cp); SKIPD(); } }
142 #define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \
143 tw.tw_flags |= TW_SZEXP; SKIPD(); }
144 #define SETDST() { tw.tw_flags |= TW_DST; }
145 #define SKIPD() { while ( isdigit(*cp++) ) ; --cp; }
146 #define SKIPTOD() { while ( !isdigit(*cp++) ) ; --cp; }
147 #define SKIPA() { while ( isalpha(*cp++) ) ; --cp; }
148 #define SKIPTOA() { while ( !isalpha(*cp++) ) ; --cp; }
149 #define SKIPSP() { while ( isspace(*cp++) ) ; --cp; }
150 #define SKIPTOSP() { while ( !isspace(*cp++) ) ; --cp; }
152 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
153 # ifdef HAVE_SYS_TIME_H
154 # include <sys/time.h>
159 zonehack (struct tws *tw)
163 if (dmktime (tw) == (time_t) -1)
166 tm = localtime (&tw->tw_clock);
168 tw->tw_flags |= TW_DST;
172 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
178 wed ([Ww]ed(nesday)?)
183 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
193 sep ([Ss]ep(tember)?)
198 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
200 TIME ({D}:{d}{d}(:{d}{d})?)
203 ** The year can either be 2 digits, or 4. However, after
204 ** Y2K, we found that some MUA were reporting the year 100, hence
205 ** the middle term here. yyterminate() resolves the actual
206 ** issues with 2-digit years.
209 YEAR (({d}{d})|(1{d}{d})|({d}{4}))
220 ** This section begins the definition of dparsetime().
221 ** Put here any local variable definitions and initializations
223 YY_BUFFER_STATE lexhandle;
226 static struct tws tw;
228 memset(&tw,0,sizeof(struct tws));
230 lexhandle = yy_scan_string(lexstr);
233 {DAY}","?{W}{MONTH}{W}{D}{W}{TIME}{W}{YEAR} {
246 {DAY}","?{W}{D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
258 {D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
268 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR}","?{W}{TIME} {
280 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR} {
290 {MONTH}{W}{D}","?{W}{YEAR}","?{W}{DAY} {
300 {MONTH}{W}{D}","?{W}{YEAR} {
308 {D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME} {
326 {D}("-"|"/"){D}("-"|"/"){YEAR} {
344 "[Pp][Mm]" tw.tw_hour += 12;
350 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
352 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
359 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
361 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
365 {nl}("ut"|"UT") INIT(); SETZONE(0); yyterminate();
366 {nl}("gmt"|"GMT") INIT(); SETZONE(0); yyterminate();
367 {nl}("est"|"EST") INIT(); SETZONE(-500); yyterminate();
368 {nl}("edt"|"EDT") { INIT(); SETDST(); SETZONE(-500); yyterminate(); }
369 {nl}("cst"|"CST") INIT(); SETZONE(-600); yyterminate();
370 {nl}("cdt"|"CDT") { INIT(); SETDST(); SETZONE(-600); yyterminate(); }
371 {nl}("mst"|"MST") INIT(); SETZONE(-700); yyterminate();
372 {nl}("mdt"|"MDT") { INIT(); SETDST(); SETZONE(-700); yyterminate(); }
373 {nl}("pst"|"PST") INIT(); SETZONE(-800); yyterminate();
374 {nl}("pdt"|"PDT") { INIT(); SETDST(); SETZONE(-800); yyterminate(); }
375 {nl}("nst"|"NST") INIT(); SETZONE(-330); yyterminate();
376 {nl}("ast"|"AST") INIT(); SETZONE(-400); yyterminate();
377 {nl}("adt"|"ADT") { INIT(); SETDST(); SETZONE(-400); yyterminate(); }
378 {nl}("hst"|"HST") INIT(); SETZONE(-1000); yyterminate();
379 {nl}("hdt"|"HDT") { INIT(); SETDST(); SETZONE(-1000); yyterminate(); }
384 ** This is a portable way to squash a warning about the yyunput()
385 ** function being static but never used. It costs us a tiny amount
386 ** of extra code in the binary but the other options are:
387 ** "%option nounput" which is flex-specific
388 ** makefile hackery just to compile dtimep.c with different flags
390 void dtimep_yyunput(int c)