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 name2num(char *name, char *names[])
64 for (i=0; names[i]; i++) {
65 if (strncasecmp(name, names[i], strlen(names[i]))==0) {
73 ** The SET* macros will parse for the appropriate field, and leave the
74 ** cp pointer at the first character after the desired field. Be
75 ** careful with variable-length fields or alpha-num mixes.
77 ** The SKIP* macros skip over characters of a particular class and
78 ** leave cp at the position of the first character that doesn't match
79 ** that class. Correspondingly, SKIPTO* skips until it reaches a
80 ** character of a particular class.
83 #define INIT() { cp = yytext;}
84 #define SETWDAY() { tw.tw_wday = name2num(cp, tw_dotw); \
85 tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP; SKIPA(); }
86 #define SETMON() { tw.tw_mon = name2num(cp, tw_moty); SKIPA(); }
87 #define SETMON_NUM() { tw.tw_mon = atoi(cp)-1; SKIPD(); }
88 #define SETYEAR() { tw.tw_year = atoi(cp); SKIPD(); }
89 #define SETDAY() { tw.tw_mday = atoi(cp); tw.tw_flags |= TW_YES; SKIPD(); }
90 #define SETTIME() { tw.tw_hour = atoi(cp); cp += 2; SKIPTOD(); \
91 tw.tw_min = atoi(cp); cp += 2; if(*cp == ':') { \
92 tw.tw_sec = atoi(++cp); SKIPD(); } }
93 #define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \
94 tw.tw_flags |= TW_SZEXP; SKIPD(); }
95 #define SETZONEC(h, m) { tw.tw_zone = (h)*60+(m); \
96 tw.tw_flags |= TW_SZEXP; SKIPD(); }
97 #define SETDST() { tw.tw_flags |= TW_DST; }
98 #define SKIPD() { while ( isdigit(*cp++) ) ; --cp; }
99 #define SKIPTOD() { while ( !isdigit(*cp++) ) ; --cp; }
100 #define SKIPA() { while ( isalpha(*cp++) ) ; --cp; }
101 #define SKIPTOA() { while ( !isalpha(*cp++) ) ; --cp; }
102 #define SKIPSP() { while ( isspace(*cp++) ) ; --cp; }
103 #define SKIPTOSP() { while ( !isspace(*cp++) ) ; --cp; }
105 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
106 # ifdef HAVE_SYS_TIME_H
107 # include <sys/time.h>
112 zonehack (struct tws *tw)
116 if (dmktime (tw) == (time_t) -1)
119 tm = localtime (&tw->tw_clock);
121 tw->tw_flags |= TW_DST;
125 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
128 sun ([Ss][Uu][Nn]([Dd][Aa][Yy])?)
129 mon ([Mm][Oo][Nn]([Dd][Aa][Yy])?)
130 tue ([Tt][Uu][Ee]([Ss][Dd][Aa][Yy])?)
131 wed ([Ww][Ee][Dd]([Nn][Ee][Ss][Dd][Aa][Yy])?)
132 thu ([Tt][Hh][Uu]([Rr][Ss][Dd][Aa][Yy])?)
133 fri ([Ff][Rr][Ii]([Dd][Aa][Yy])?)
134 sat ([Ss][Aa][Tt]([Uu][Rr][Dd][Aa][Yy])?)
136 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
138 jan ([Jj][Aa][Nn]([Uu][Aa][Rr][Yy])?)
139 feb ([Ff][Ee][Bb]([Rr][Uu][Aa][Rr][Yy])?)
140 mar ([Mm][Aa][Rr]([Cc][Hh])?)
141 apr ([Aa][Pp][Rr]([Ii][Ll])?)
143 jun ([Jj][Uu][Nn]([Ee])?)
144 jul ([Jj][Uu][Ll]([Yy])?)
145 aug ([Aa][Uu][Gg]([Uu][Ss][Tt])?)
146 sep ([Ss][Ee][Pp]([Tt][Ee][Mm][Bb][Ee][Rr])?)
147 oct ([Oo][Cc][Tt]([Oo][Bb][Ee][Rr])?)
148 nov ([Nn][Oo][Vv]([Ee][Mm][Bb][Ee][Rr])?)
149 dec ([Dd][Ee][Cc]([Ee][Mm][Bb][Ee][Rr])?)
151 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
153 TIME ({D}:{d}{d}(:{d}{d})?)
156 ** The year can either be 2 digits, or 4. However, after
157 ** Y2K, we found that some MUA were reporting the year 100, hence
158 ** the middle term here. yyterminate() resolves the actual
159 ** issues with 2-digit years.
162 YEAR (({d}{d})|(1{d}{d})|({d}{4}))
173 ** This section begins the definition of dparsetime().
174 ** Put here any local variable definitions and initializations
176 YY_BUFFER_STATE lexhandle;
179 static struct tws tw;
181 memset(&tw,0,sizeof(struct tws));
183 lexhandle = yy_scan_string(lexstr);
186 {DAY}","?{W}{MONTH}{W}{D}{W}{TIME}{W}{YEAR} {
199 {DAY}","?{W}{D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
211 {D}{W}{MONTH}{W}{YEAR}{W}{TIME} {
221 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR}","?{W}{TIME} {
233 {DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR} {
243 {MONTH}{W}{D}","?{W}{YEAR}","?{W}{DAY} {
253 {MONTH}{W}{D}","?{W}{YEAR} {
261 {d}{4}"-"{d}{2}"-"{d}{2}(" "|"T"){TIME} {
271 {d}{4}"-"{d}{2}"-"{d}{2} {
279 {d}{2}"-"{d}{2}"-"{d}{2} {
280 fprintf(stderr, "the highly ambiguous date format XX-XX-XX..."
281 " is no longer supported\n");
283 {D}"/"{D}"/"{YEAR}{W}{TIME} {
319 "[Pp][Mm]" tw.tw_hour += 12;
325 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
327 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
334 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
336 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
343 SETZONEC(atoi(cp), atoi(cp+3));
344 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
346 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
352 SETZONEC(-atoi(cp), -atoi(cp+3));
353 #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
355 #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
359 {nl}("ut"|"UT") INIT(); SETZONE(0); yyterminate();
360 {nl}("gmt"|"GMT") INIT(); SETZONE(0); yyterminate();
361 {nl}("est"|"EST") INIT(); SETZONE(-500); yyterminate();
362 {nl}("edt"|"EDT") { INIT(); SETDST(); SETZONE(-500); yyterminate(); }
363 {nl}("cst"|"CST") INIT(); SETZONE(-600); yyterminate();
364 {nl}("cdt"|"CDT") { INIT(); SETDST(); SETZONE(-600); yyterminate(); }
365 {nl}("mst"|"MST") INIT(); SETZONE(-700); yyterminate();
366 {nl}("mdt"|"MDT") { INIT(); SETDST(); SETZONE(-700); yyterminate(); }
367 {nl}("pst"|"PST") INIT(); SETZONE(-800); yyterminate();
368 {nl}("pdt"|"PDT") { INIT(); SETDST(); SETZONE(-800); yyterminate(); }
369 {nl}("nst"|"NST") INIT(); SETZONE(-330); yyterminate();
370 {nl}("ast"|"AST") INIT(); SETZONE(-400); yyterminate();
371 {nl}("adt"|"ADT") { INIT(); SETDST(); SETZONE(-400); yyterminate(); }
372 {nl}("hst"|"HST") INIT(); SETZONE(-1000); yyterminate();
373 {nl}("hdt"|"HDT") { INIT(); SETDST(); SETZONE(-1000); yyterminate(); }
378 ** This is a portable way to squash a warning about the yyunput()
379 ** function being static but never used. It costs us a tiny amount
380 ** of extra code in the binary but the other options are:
381 ** "%option nounput" which is flex-specific
382 ** makefile hackery just to compile dtimep.c with different flags
384 void dtimep_yyunput(int c)