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 SETDST() { tw.tw_flags |= TW_DST; }
106 #define SKIPD() { while ( isdigit(*cp++) ) ; --cp; }
107 #define SKIPTOD() { while ( !isdigit(*cp++) ) ; --cp; }
108 #define SKIPA() { while ( isalpha(*cp++) ) ; --cp; }
109 #define SKIPTOA() { while ( !isalpha(*cp++) ) ; --cp; }
110 #define SKIPSP() { while ( isspace(*cp++) ) ; --cp; }
111 #define SKIPTOSP() { while ( !isspace(*cp++) ) ; --cp; }
113 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
114 # ifdef HAVE_SYS_TIME_H
115 # include <sys/time.h>
120 zonehack (struct tws *tw)
124 if (dmktime (tw) == (time_t) -1)
127 tm = localtime (&tw->tw_clock);
129 tw->tw_flags |= TW_DST;
133 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
139 wed ([Ww]ed(nesday)?)
144 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
154 sep ([Ss]ep(tember)?)
159 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
161 TIME ({D}:{d}{d}(:{d}{d})?)
164 ** The year can either be 2 digits, or 4. However, after
165 ** Y2K, we found that some MUA were reporting the year 100, hence
166 ** the middle term here. yyterminate() resolves the actual
167 ** issues with 2-digit years.
170 YEAR (({d}{d})|(1{d}{d})|({d}{4}))
181 ** This section begins the definition of dparsetime().
182 ** Put here any local variable definitions and initializations
184 YY_BUFFER_STATE lexhandle;
187 static struct tws tw;
189 memset(&tw,0,sizeof(struct tws));
191 lexhandle = yy_scan_string(lexstr);
194 {DAY}","?{W}{MONTH}{W}{D}{W}{TIME}{W}{YEAR} {
207 {DAY}","?{W}{D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
219 {D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
229 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR}","?{W}{TIME} {
241 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR} {
251 {MONTH}{W}{D}","?{W}{YEAR}","?{W}{DAY} {
261 {MONTH}{W}{D}","?{W}{YEAR} {
269 {D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME} {
287 {D}("-"|"/"){D}("-"|"/"){YEAR} {
305 "[Pp][Mm]" tw.tw_hour += 12;
311 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
313 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
320 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
322 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
326 {nl}("ut"|"UT") INIT(); SETZONE(0); yyterminate();
327 {nl}("gmt"|"GMT") INIT(); SETZONE(0); yyterminate();
328 {nl}("est"|"EST") INIT(); SETZONE(-500); yyterminate();
329 {nl}("edt"|"EDT") { INIT(); SETDST(); SETZONE(-500); yyterminate(); }
330 {nl}("cst"|"CST") INIT(); SETZONE(-600); yyterminate();
331 {nl}("cdt"|"CDT") { INIT(); SETDST(); SETZONE(-600); yyterminate(); }
332 {nl}("mst"|"MST") INIT(); SETZONE(-700); yyterminate();
333 {nl}("mdt"|"MDT") { INIT(); SETDST(); SETZONE(-700); yyterminate(); }
334 {nl}("pst"|"PST") INIT(); SETZONE(-800); yyterminate();
335 {nl}("pdt"|"PDT") { INIT(); SETDST(); SETZONE(-800); yyterminate(); }
336 {nl}("nst"|"NST") INIT(); SETZONE(-330); yyterminate();
337 {nl}("ast"|"AST") INIT(); SETZONE(-400); yyterminate();
338 {nl}("adt"|"ADT") { INIT(); SETDST(); SETZONE(-400); yyterminate(); }
339 {nl}("hst"|"HST") INIT(); SETZONE(-1000); yyterminate();
340 {nl}("hdt"|"HDT") { INIT(); SETDST(); SETZONE(-1000); yyterminate(); }
345 ** This is a portable way to squash a warning about the yyunput()
346 ** function being static but never used. It costs us a tiny amount
347 ** of extra code in the binary but the other options are:
348 ** "%option nounput" which is flex-specific
349 ** makefile hackery just to compile dtimep.c with different flags
351 void dtimep_yyunput(int c)