5 "@(#) $Header: dtimep.lex,v 1.15 90/10/16 14:57:20 leres Exp $ (LBL) (flex generated scanner)";
7 "@(#) $Header: dtimep.lex,v 1.15 90/10/16 14:57:20 leres Exp $ (LBL) (lex generated scanner)";
27 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
42 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
53 * Patchable flag that says how to interpret NN/NN/NN dates. When
54 * true, we do it European style: DD/MM/YY. When false, we do it
55 * American style: MM/DD/YY.
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[] = {
98 * Same trick for day-of-week using the hash function
101 static int day_map[] = {
115 #define SETDAY { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)];\
116 tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP;\
118 #define SETMONTH { tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; gotdate++;\
121 #define CVT2 (i=(*cp++ - '0'),isdigit(*cp)? i*10 + (*cp++ - '0') : i)
122 #define SKIPD { while ( !isdigit(*cp++) ) ; --cp; }
123 #define EXPZONE { tw.tw_flags &= ~TW_SZONE; tw.tw_flags |= TW_SZEXP; }
124 #define ZONE(x) { tw.tw_zone=(x); EXPZONE; }
125 #define ZONED(x) { ZONE(x); tw.tw_flags |= TW_DST; }
126 #define LC(c) (isupper(c) ? tolower(c) : (c))
129 /* We get passed a string and return a pointer to a static tws struct */
131 #define YY_DECL struct tws *dparsetime(str) char *str;
133 /* We assume that we're never passed more than max_size characters */
135 #define YY_INPUT(buf,result,max_size) \
139 while (isspace(*xp)) \
142 while (*xp != '\0') \
144 result = xp - gstr; \
145 bcopy(gstr, buf, result); \
150 /* Date strings aren't usually very long */
151 #undef YY_READ_BUF_SIZE
152 #define YY_READ_BUF_SIZE 128
154 /* Use mh error reporting routine */
155 #undef YY_FATAL_ERROR
156 #define YY_FATAL_ERROR(s) adios("dparsetime()", s);
158 /* We need a pointer to the matched text we can modify */
159 #undef YY_USER_ACTION
160 #define YY_USER_ACTION cp = yytext
162 /* Used to initialize */
163 static struct tws ztw = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
165 /* Global for use by YY_INPUT() macro */
172 register int i, gotdate;
174 static struct tws tw;
175 static void zonehack();
189 {D}"/"{D}"/"(19)?[0-9][0-9]{w} {
191 /* European: DD/MM/YY */
194 tw.tw_mon = CVT2 - 1;
196 /* American: MM/DD/YY */
197 tw.tw_mon = CVT2 - 1;
202 for (i = 0; isdigit(*cp); )
203 i = i*10 + (*cp++ - '0');
204 tw.tw_year = i % 100;
207 {D}{w}(-)?{w}{MONTH}{w}(-)?{w}(19)?{D}{w}(\,{w}|at{W})? {
209 while (!isalpha(*cp++))
212 for (i = 0; isdigit(*cp); )
213 i = i*10 + (*cp++ - '0');
214 tw.tw_year = i % 100;
216 {MONTH}{W}{D}","{W}(19)?{D}{w} {
221 for (i = 0; isdigit(*cp); )
222 i = i*10 + (*cp++ - '0');
223 tw.tw_year = i % 100;
233 tw.tw_hour = CVT2; cp++;
234 tw.tw_min = CVT2; cp++;
239 tw.tw_hour = CVT2; cp++;
244 tw.tw_hour = CVT2; cp++;
245 if (tw.tw_hour == 12)
251 tw.tw_hour = CVT2; cp++;
252 if (tw.tw_hour != 12)
257 [0-2]{d}{d}{d}{d}{d}{w} {
265 * Luckly, 4 digit times in the range
266 * 1960-1999 aren't legal as hour
267 * and minutes. This rule must come
268 * the 4 digit hour and minute rule.
278 <Z>"-"?ut ZONE(0 * 60);
279 <Z>"-"?gmt ZONE(0 * 60);
280 <Z>"-"?jst ZONE(2 * 60);
281 <Z>"-"?jdt ZONED(2 * 60);
282 <Z>"-"?est ZONE(-5 * 60);
283 <Z>"-"?edt ZONED(-5 * 60);
284 <Z>"-"?cst ZONE(-6 * 60);
285 <Z>"-"?cdt ZONED(-6 * 60);
286 <Z>"-"?mst ZONE(-7 * 60);
287 <Z>"-"?mdt ZONED(-7 * 60);
288 <Z>"-"?pst ZONE(-8 * 60);
289 <Z>"-"?pdt ZONED(-8 * 60);
290 <Z>"-"?nst ZONE(-(3 * 60 + 30));
291 <Z>"-"?ast ZONE(-4 * 60);
292 <Z>"-"?adt ZONED(-4 * 60);
293 <Z>"-"?yst ZONE(-9 * 60);
294 <Z>"-"?ydt ZONED(-9 * 60);
295 <Z>"-"?hst ZONE(-10 * 60);
296 <Z>"-"?hdt ZONED(-10 * 60);
297 <Z>"-"?bst ZONED(-1 * 60);
299 tw.tw_zone = 60 * (('a'-1) - LC(*cp));
303 tw.tw_zone = 60 * ('a' - LC(*cp));
307 tw.tw_zone = 60 * (LC(*cp) - 'm');
310 <Z>"+"[0-1]{d}{d}{d} {
312 tw.tw_zone = ((cp[0] * 10 + cp[1])
313 -('0' * 10 + '0'))*60
314 +((cp[2] * 10 + cp[3])
322 <Z>"-"[0-1]{d}{d}{d} {
324 tw.tw_zone = (('0' * 10 + '0')
325 -(cp[0] * 10 + cp[1]))*60
327 -(cp[2] * 10 + cp[3]));
338 <INITIAL,Z><<EOF>> return(&tw);
342 * We jammed; it's an error if we
343 * didn't parse anything.
345 if (!gotdate || tw.tw_year == 0)
353 #include <sys/types.h>
357 #include <sys/time.h>
362 register struct tws *tw;
364 register struct tm *tm;
366 if (twclock (tw) == -1L)
369 tm = localtime (&tw -> tw_clock);
370 if (tm -> tm_isdst) {
371 tw -> tw_flags |= TW_DST;