1 /* dtimep.lex exceeds the default table capacities for some old versions
2 * of lex (and the minimum defaults as specified by POSIX). The following
3 * choices meet or exceed the lex defaults for older SunOS4.x, Solaris,
14 /* Since we're looking at a string at a time, don't worry about
15 * wrapping to the next buffer.
18 #define YY_SKIP_YYWRAP
22 /* This is the tricky thing that makes this function cool. We
23 * replace the traditional int yylex(void) declaration with our
24 * dparsetime() declaration, essentially piggy-backing off the
25 * utility of the yylex() function and adding what we need to make
26 * the parsing function useful to us.
28 #define YY_DECL struct tws *dparsetime(char *lexstr)
30 /* yyerminate() is called after the input string is matched to
31 * completion (actually, when the lexer reaches an EOF). The only
32 * thing that really needs to be in this macro function is the
33 * return call, which must be substituted inline into dparsetime.
36 #define yyterminate() (void)yy_delete_buffer(lexhandle); \
37 if(!(tw.tw_flags & TW_SUCC)) { \
38 return (struct tws *)NULL; \
40 if(tw.tw_year < 1970) \
42 if(tw.tw_year < 1970) \
47 * Patchable flag that says how to interpret NN/NN/NN dates. When
48 * true, we do it European style: DD/MM/YY. When false, we do it
49 * American style: MM/DD/YY. Of course, these are all non-RFC822
55 * Table to convert month names to numeric month. We use the
56 * fact that the low order 5 bits of the sum of the 2nd & 3rd
57 * characters of the name is a hash with no collisions for the 12
58 * valid month names. (The mask to 5 bits maps any combination of
59 * upper and lower case into the same hash value).
61 static int month_map[] = {
94 * Lookup table for day-of-week using the same hash trick as for above name-of-
95 * month table, but using the first and second character, not second and third.
97 * Compute index into table using: (day_name[0] & 7) + (day_name[1] & 4)
99 static int day_map[] = {
114 /* The SET* macros will parse for the appropriate field, and leave the
115 * cp pointer at the first character after the desired field. Be
116 * careful with variable-length fields or alpha-num mixes.
118 * The SKIP* macros skip over characters of a particular class and
119 * leave cp at the position of the first character that doesn't match
120 * that class. Correspondingly, SKIPTO* skips until it reaches a
121 * character of a particular class.
124 #define INIT() { cp = yytext;}
125 #define SETWDAY() { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \
126 tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP; \
128 #define SETMON() { cp++; \
129 tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; \
131 #define SETMON_NUM() { tw.tw_mon = atoi(cp)-1; \
133 #define SETYEAR() { tw.tw_year = atoi(cp); \
135 #define SETDAY() { tw.tw_mday = atoi(cp); \
136 tw.tw_flags |= TW_YES; \
138 #define SETTIME() { tw.tw_hour = atoi(cp); \
141 tw.tw_min = atoi(cp); \
144 tw.tw_sec = atoi(++cp); SKIPD(); } }
145 #define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \
146 tw.tw_flags |= TW_SZEXP; \
148 #define SETDST() { tw.tw_flags |= TW_DST; }
149 #define SKIPD() { while ( isdigit(*cp++) ) ; \
151 #define SKIPTOD() { while ( !isdigit(*cp++) ) ; \
153 #define SKIPA() { while ( isalpha(*cp++) ) ; \
155 #define SKIPTOA() { while ( !isalpha(*cp++) ) ; \
157 #define SKIPSP() { while ( isspace(*cp++) ) ; \
159 #define SKIPTOSP() { while ( !isspace(*cp++) ) ; \
162 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
163 # ifdef HAVE_SYS_TIME_H
164 # include <sys/time.h>
169 zonehack (struct tws *tw)
171 register struct tm *tm;
173 if (dmktime (tw) == (time_t) -1)
176 tm = localtime (&tw->tw_clock);
178 tw->tw_flags |= TW_DST;
182 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
188 wed ([Ww]ed(nesday)?)
193 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
203 sep ([Ss]ep(tember)?)
208 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
210 TIME ({D}:{d}{d}(:{d}{d})?)
212 /* The year can either be 2 digits, or 4. However, after
213 Y2K, we found that some MUA were reporting the year 100, hence
214 the middle term here. yyterminate() resolves the actual
215 issues with 2-digit years.
218 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;
233 register unsigned char *cp;
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 {nl}("ut"|"UT") INIT(); SETZONE(0); yyterminate();
374 {nl}("gmt"|"GMT") INIT(); SETZONE(0); yyterminate();
375 {nl}("est"|"EST") INIT(); SETZONE(-500); yyterminate();
376 {nl}("edt"|"EDT") { INIT(); SETDST(); SETZONE(-500);
378 {nl}("cst"|"CST") INIT(); SETZONE(-600); yyterminate();
379 {nl}("cdt"|"CDT") { INIT(); SETDST(); SETZONE(-600);
381 {nl}("mst"|"MST") INIT(); SETZONE(-700); yyterminate();
382 {nl}("mdt"|"MDT") { INIT(); SETDST(); SETZONE(-700);
384 {nl}("pst"|"PST") INIT(); SETZONE(-800); yyterminate();
385 {nl}("pdt"|"PDT") { INIT(); SETDST(); SETZONE(-800);
387 {nl}("nst"|"NST") INIT(); SETZONE(-330); yyterminate();
388 {nl}("ast"|"AST") INIT(); SETZONE(-400); yyterminate();
389 {nl}("adt"|"ADT") { INIT(); SETDST(); SETZONE(-400);
391 {nl}("hst"|"HST") INIT(); SETZONE(-1000); yyterminate();
392 {nl}("hdt"|"HDT") { INIT(); SETDST(); SETZONE(-1000);
397 /* This is a portable way to squash a warning about the yyunput()
398 * function being static but never used. It costs us a tiny amount
399 * of extra code in the binary but the other options are:
400 * "%option nounput" which is flex-specific
401 * makefile hackery just to compile dtimep.c with different flags
403 void dtimep_yyunput(int c)