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
59 static char *monthnames[] = {
60 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
61 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
65 static char *daynames[] = {
66 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
70 name2num(char *name, char *names[])
74 for (i=0; names[i]; i++) {
75 if (strncasecmp(name, names[i], strlen(names[i]))==0) {
83 ** The SET* macros will parse for the appropriate field, and leave the
84 ** cp pointer at the first character after the desired field. Be
85 ** careful with variable-length fields or alpha-num mixes.
87 ** The SKIP* macros skip over characters of a particular class and
88 ** leave cp at the position of the first character that doesn't match
89 ** that class. Correspondingly, SKIPTO* skips until it reaches a
90 ** character of a particular class.
93 #define INIT() { cp = yytext;}
94 #define SETWDAY() { tw.tw_wday = name2num(cp, daynames); \
95 tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP; SKIPA(); }
96 #define SETMON() { tw.tw_mon = name2num(cp, monthnames); SKIPA(); }
97 #define SETMON_NUM() { tw.tw_mon = atoi(cp)-1; SKIPD(); }
98 #define SETYEAR() { tw.tw_year = atoi(cp); SKIPD(); }
99 #define SETDAY() { tw.tw_mday = atoi(cp); tw.tw_flags |= TW_YES; SKIPD(); }
100 #define SETTIME() { tw.tw_hour = atoi(cp); cp += 2; SKIPTOD(); \
101 tw.tw_min = atoi(cp); cp += 2; if(*cp == ':') { \
102 tw.tw_sec = atoi(++cp); SKIPD(); } }
103 #define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \
104 tw.tw_flags |= TW_SZEXP; SKIPD(); }
105 #define SETZONEC(h, m) { tw.tw_zone = (h)*60+(m); \
106 tw.tw_flags |= TW_SZEXP; SKIPD(); }
107 #define SETDST() { tw.tw_flags |= TW_DST; }
108 #define SKIPD() { while ( isdigit(*cp++) ) ; --cp; }
109 #define SKIPTOD() { while ( !isdigit(*cp++) ) ; --cp; }
110 #define SKIPA() { while ( isalpha(*cp++) ) ; --cp; }
111 #define SKIPTOA() { while ( !isalpha(*cp++) ) ; --cp; }
112 #define SKIPSP() { while ( isspace(*cp++) ) ; --cp; }
113 #define SKIPTOSP() { while ( !isspace(*cp++) ) ; --cp; }
115 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
116 # ifdef HAVE_SYS_TIME_H
117 # include <sys/time.h>
122 zonehack (struct tws *tw)
126 if (dmktime (tw) == (time_t) -1)
129 tm = localtime (&tw->tw_clock);
131 tw->tw_flags |= TW_DST;
135 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
141 wed ([Ww]ed(nesday)?)
146 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
156 sep ([Ss]ep(tember)?)
161 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
163 TIME ({D}:{d}{d}(:{d}{d})?)
166 ** The year can either be 2 digits, or 4. However, after
167 ** Y2K, we found that some MUA were reporting the year 100, hence
168 ** the middle term here. yyterminate() resolves the actual
169 ** issues with 2-digit years.
172 YEAR (({d}{d})|(1{d}{d})|({d}{4}))
183 ** This section begins the definition of dparsetime().
184 ** Put here any local variable definitions and initializations
186 YY_BUFFER_STATE lexhandle;
189 static struct tws tw;
191 memset(&tw,0,sizeof(struct tws));
193 lexhandle = yy_scan_string(lexstr);
196 {DAY}","?{W}{MONTH}{W}{D}{W}{TIME}{W}{YEAR} {
209 {DAY}","?{W}{D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
221 {D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
231 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR}","?{W}{TIME} {
243 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR} {
253 {MONTH}{W}{D}","?{W}{YEAR}","?{W}{DAY} {
263 {MONTH}{W}{D}","?{W}{YEAR} {
271 {d}{4}"-"{d}{2}"-"{d}{2}(" "|"T"){TIME} {
281 {d}{4}"-"{d}{2}"-"{d}{2} {
289 {d}{2}"-"{d}{2}"-"{d}{2} {
290 fprintf(stderr, "the highly ambiguous date format XX-XX-XX..."
291 " is no longer supported\n");
293 {D}"/"{D}"/"{YEAR}{W}{TIME} {
329 "[Pp][Mm]" tw.tw_hour += 12;
335 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
337 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
344 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
346 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
353 SETZONEC(atoi(cp), atoi(cp+3));
354 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
356 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
362 SETZONEC(-atoi(cp), -atoi(cp+3));
363 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
365 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
369 {nl}("ut"|"UT") INIT(); SETZONE(0); yyterminate();
370 {nl}("gmt"|"GMT") INIT(); SETZONE(0); yyterminate();
371 {nl}("est"|"EST") INIT(); SETZONE(-500); yyterminate();
372 {nl}("edt"|"EDT") { INIT(); SETDST(); SETZONE(-500); yyterminate(); }
373 {nl}("cst"|"CST") INIT(); SETZONE(-600); yyterminate();
374 {nl}("cdt"|"CDT") { INIT(); SETDST(); SETZONE(-600); yyterminate(); }
375 {nl}("mst"|"MST") INIT(); SETZONE(-700); yyterminate();
376 {nl}("mdt"|"MDT") { INIT(); SETDST(); SETZONE(-700); yyterminate(); }
377 {nl}("pst"|"PST") INIT(); SETZONE(-800); yyterminate();
378 {nl}("pdt"|"PDT") { INIT(); SETDST(); SETZONE(-800); yyterminate(); }
379 {nl}("nst"|"NST") INIT(); SETZONE(-330); yyterminate();
380 {nl}("ast"|"AST") INIT(); SETZONE(-400); yyterminate();
381 {nl}("adt"|"ADT") { INIT(); SETDST(); SETZONE(-400); yyterminate(); }
382 {nl}("hst"|"HST") INIT(); SETZONE(-1000); yyterminate();
383 {nl}("hdt"|"HDT") { INIT(); SETDST(); SETZONE(-1000); yyterminate(); }
388 ** This is a portable way to squash a warning about the yyunput()
389 ** function being static but never used. It costs us a tiny amount
390 ** of extra code in the binary but the other options are:
391 ** "%option nounput" which is flex-specific
392 ** makefile hackery just to compile dtimep.c with different flags
394 void dtimep_yyunput(int c)