8 date 93.02.26.22.07.40; author jromine; state Exp;
13 date 92.12.15.00.20.22; author jromine; state Exp;
18 date 92.05.19.21.26.05; author jromine; state Exp;
23 date 92.05.19.21.25.17; author jromine; state Exp;
28 date 92.02.10.20.32.29; author jromine; state Exp;
33 date 92.02.09.22.41.24; author jromine; state Exp;
38 date 92.02.07.01.04.07; author jromine; state Exp;
43 date 92.02.07.00.46.23; author jromine; state Exp;
48 date 92.02.07.00.45.31; author jromine; state Exp;
53 date 92.02.07.00.25.45; author jromine; state Exp;
58 date 92.02.07.00.10.21; author jromine; state Exp;
63 date 92.02.07.00.07.37; author jromine; state Exp;
68 date 92.02.07.00.03.39; author jromine; state Exp;
73 date 92.02.07.00.02.09; author jromine; state Exp;
78 date 92.02.06.23.56.12; author jromine; state Exp;
83 date 92.02.06.23.36.10; author jromine; state Exp;
88 date 90.04.05.15.55.07; author sources; state Exp;
93 date 90.03.21.15.34.15; author sources; state Exp;
98 date 90.02.23.13.42.22; author sources; state Exp;
103 date 90.02.08.14.12.10; author sources; state Exp;
108 date 90.02.06.16.31.28; author sources; state Exp;
113 date 90.02.06.16.29.08; author sources; state Exp;
118 date 90.02.06.15.57.59; author sources; state Exp;
123 date 90.02.06.13.42.29; author sources; state Exp;
128 date 90.02.01.14.43.27; author sources; state Exp;
133 date 90.02.01.14.41.24; author sources; state Exp;
160 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
175 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
183 static char ident[] = "@@(#)$Id: dtimep.lex,v 2.14 1992/12/15 00:20:22 jromine Exp jromine $";
186 #include "../h/strings.h"
188 #include <sys/types.h>
189 #if !defined(SYS5) && !defined(ZONEINFO)
190 #include <sys/timeb.h>
191 #endif /* !defined(SYS5) && !defined(ZONEINFO) */
195 extern long timezone;
196 extern char *tzname[];
200 * Patchable flag that says how to interpret NN/NN/NN dates. When
201 * true, we do it European style: DD/MM/YY. When false, we do it
202 * American style: MM/DD/YY. Of course, these are all non-RFC822
205 int europeandate = 0;
208 * Table to convert month names to numeric month. We use the
209 * fact that the low order 5 bits of the sum of the 2nd & 3rd
210 * characters of the name is a hash with no collisions for the 12
211 * valid month names. (The mask to 5 bits maps any combination of
212 * upper and lower case into the same hash value).
214 static int month_map[] = {
246 * Same trick for day-of-week using the hash function
247 * (c1 & 7) + (c2 & 4)
249 static int day_map[] = {
263 #define SETDAY { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)];\
264 tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP;\
266 #define SETMONTH { tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; gotdate++;\
269 #define CVT1OR2 (i=(*cp++ - '0'), isdigit(*cp)? i*10 + (*cp++ - '0') : i)
270 #define CVT2 ((cp[0] - '0')*10 + (cp[1] - '0'))
271 #define CVT4 ((((cp[0] - '0')*10 + (cp[1] - '0'))*10 + \
272 (cp[2] - '0'))*10 + (cp[3] - '0'))
273 #define SKIPD { while ( !isdigit(*cp++) ) ; --cp; }
274 #define EXPZONE { tw.tw_flags &= ~TW_SZONE; tw.tw_flags |= TW_SZEXP; }
275 #define ZONE(x) { tw.tw_zone=(x); EXPZONE; }
276 #define ZONED(x) { ZONE(x); tw.tw_flags |= TW_DST; }
277 #define LC(c) (isupper (c) ? tolower (c) : (c))
281 #include <sys/time.h>
287 #include <sys/time.h>
292 register struct tws *tw;
294 register struct tm *tm;
296 if (twclock (tw) == -1L)
299 tm = localtime (&tw -> tw_clock);
300 if (tm -> tm_isdst) {
301 tw -> tw_flags |= TW_DST;
309 struct tws *dparsetime (str)
313 static struct tws tw;
315 register int gotdate = 0;
322 #endif /* ZONEINFO */
323 #endif /* not SYS5 */
328 /* Zero out the struct. */
329 bzero( (char *) &tw, sizeof tw);
331 /* Set default time zone. */
334 tw.tw_zone = -(timezone / 60);
338 tm = localtime(&clock);
339 tw.tw_zone = tm->tm_gmtoff / 60;
340 if (tm -> tm_isdst) /* if DST is in effect */
341 tw.tw_zone -= 60; /* reset to normal offset */
344 tw.tw_zone = -tb.timezone;
345 #endif /* ZONEINFO */
348 while (isspace(*str))
351 switch (cp = str, *cp ? lex_string( &str, start_cond) : 0) {
354 if (!gotdate || tw.tw_year == 0)
355 return (struct tws *)0;
358 if ( tw.tw_year == 0 ) {
359 /* Set default year. */
361 tw.tw_year = localtime(&tclock)->tm_year + 1900;
363 else if (tw.tw_year < 100) {
364 /* assume no 2-digit years > 1999 */
375 {D}(("-"{D}"-")|("/"{D}"/")){D}?{d}{d}{w} {
377 /* European: DD/MM/YY */
378 tw.tw_mday = CVT1OR2;
380 tw.tw_mon = CVT1OR2 - 1;
382 /* American: MM/DD/YY */
383 tw.tw_mon = CVT1OR2 - 1;
385 tw.tw_mday = CVT1OR2;
388 for (i = 0; isdigit(*cp); )
389 i = i*10 + (*cp++ - '0');
395 tw.tw_mday = CVT1OR2; cp++;
396 tw.tw_mon = CVT1OR2 - 1;
398 tw.tw_mon = CVT1OR2 - 1; cp++;
399 tw.tw_mday = CVT1OR2;
403 {D}{w}(-)?{w}{MONTH}{w}(-)?{w}{D}?{d}{d}({W}at)?{w} {
404 tw.tw_mday = CVT1OR2;
405 while ( !isalpha(*cp++) )
408 for (i = 0; isdigit(*cp); )
409 i = i*10 + (*cp++ - '0');
412 {D}"-"?{MONTH}({W}at)?{w} {
413 tw.tw_mday = CVT1OR2;
414 while ( ! isalpha( *cp++ ) )
418 {MONTH}{W}{D}","{W}{D}?{d}{d}{w} {
421 tw.tw_mday = CVT1OR2;
423 for (i = 0; isdigit(*cp); )
424 i = i*10 + (*cp++ - '0');
430 tw.tw_mday = CVT1OR2;
433 {D}:{D}:{D}{W}19[6-9]{d} { /* hack: ctime w/o TZ */
434 tw.tw_hour = CVT1OR2; cp++;
435 tw.tw_min = CVT1OR2; cp++;
438 tw.tw_year = CVT4; cp+=4;
441 tw.tw_hour = CVT1OR2; cp++;
442 tw.tw_min = CVT1OR2; cp++;
447 tw.tw_hour = CVT1OR2; cp++;
452 tw.tw_hour = CVT1OR2; cp++;
453 if (tw.tw_hour == 12)
458 {D}:{D}:{D}{w}am{w} {
459 tw.tw_hour = CVT1OR2; cp++;
460 if (tw.tw_hour == 12)
462 tw.tw_min = CVT1OR2; cp++;
467 tw.tw_hour = CVT1OR2; cp++;
468 if (tw.tw_hour != 12)
473 {D}:{D}:{D}{w}pm{w} {
474 tw.tw_hour = CVT1OR2; cp++;
475 if (tw.tw_hour != 12)
477 tw.tw_min = CVT1OR2; cp++;
481 [0-2]{d}{d}{d}{d}{d}{w} {
482 tw.tw_hour = CVT2; cp+=2;
483 tw.tw_min = CVT2; cp+=2;
484 tw.tw_sec = CVT2; cp+=2;
489 * Luckly, 4 digit times in the range
490 * 1960-1999 aren't legal as hour
493 tw.tw_year = CVT4; cp+=4;
496 if (tw.tw_hour || tw.tw_min
498 tw.tw_year = CVT4; cp+=4;
501 tw.tw_hour = CVT2; cp+=2;
502 tw.tw_min = CVT2; cp+=2;
506 <Z>"-"?ut ZONE(0 * 60);
507 <Z>"-"?gmt ZONE(0 * 60);
508 <Z>"-"?jst ZONE(2 * 60);
509 <Z>"-"?jdt ZONED(2 * 60);
510 <Z>"-"?est ZONE(-5 * 60);
511 <Z>"-"?edt ZONED(-5 * 60);
512 <Z>"-"?cst ZONE(-6 * 60);
513 <Z>"-"?cdt ZONED(-6 * 60);
514 <Z>"-"?mst ZONE(-7 * 60);
515 <Z>"-"?mdt ZONED(-7 * 60);
516 <Z>"-"?pst ZONE(-8 * 60);
517 <Z>"-"?pdt ZONED(-8 * 60);
518 <Z>"-"?nst ZONE(-(3 * 60 + 30));
519 <Z>"-"?ast ZONE(-4 * 60);
520 <Z>"-"?adt ZONED(-4 * 60);
521 <Z>"-"?yst ZONE(-9 * 60);
522 <Z>"-"?ydt ZONED(-9 * 60);
523 <Z>"-"?hst ZONE(-10 * 60);
524 <Z>"-"?hdt ZONED(-10 * 60);
525 <Z>"-"?bst ZONED(-1 * 60);
527 tw.tw_zone = 60 * (('a'-1) - LC(*cp));
531 tw.tw_zone = 60 * ('a' - LC(*cp));
535 tw.tw_zone = 60 * (LC(*cp) - 'm');
538 <Z>"+"[0-1]{d}{d}{d} {
540 tw.tw_zone = ((cp[0] * 10 + cp[1])
541 -('0' * 10 + '0'))*60
542 +((cp[2] * 10 + cp[3])
550 <Z>"-"[0-1]{d}{d}{d} {
552 tw.tw_zone = (('0' * 10 + '0')
553 -(cp[0] * 10 + cp[1]))*60
555 -(cp[2] * 10 + cp[3]));
564 tw.tw_year = CVT4; cp+=4;
579 static char ident[] = "@@(#)$Id: dtimep.lex,v 2.13 1992/05/19 21:26:05 jromine Exp jromine $";
585 #endif /* not SYS5 */
589 #endif /* not SYS5 */
597 tw.tw_zone = -(timezone / 60);
609 static char ident[] = "@@(#)$Id: dtimep.lex,v 2.12 1992/05/19 21:25:17 jromine Exp jromine $";
650 static char ident[] = "@@(#)$Id: dtimep.lex,v 2.11 1992/02/10 20:32:29 jromine Exp jromine $";
663 static char ident[] = "@@(#)$Id: dtimep.lex,v 2.10 1992/02/09 22:41:24 jromine Exp jromine $";
666 #define CVT2 ((*cp++ - '0')*10 + (*cp++ - '0'))
667 #define CVT3 (((*cp++ - '0')*10 + (*cp++ - '0'))*10 + (*cp++ - '0'))
668 #define CVT4 ((((*cp++ - '0')*10 + (*cp++ - '0'))*10 + \
669 (*cp++ - '0'))*10 + (*cp++ - '0'))
696 @make all years 4-digit
701 static char ident[] = "@@(#)$Id: dtimep.lex,v 2.9 1992/02/07 01:04:07 jromine Exp jromine $";
708 tw.tw_year = localtime(&clock)->tm_year + 1900;
719 static char ident[] = "@@(#)$Id: dtimep.lex,v 2.8 1992/02/07 00:46:23 jromine Exp jromine $";
731 static char ident[] = "@@(#)$Id: dtimep.lex,v 2.7 1992/02/07 00:45:31 jromine Exp jromine $";
734 {D}{w}(-)?{w}{MONTH}{w}(-){w}{D}?{d}{d}({W}at)?{w} {
745 static char ident[] = "@@(#)$Id: dtimep.lex,v 2.6 1992/02/07 00:25:45 jromine Exp $";
748 tw.tw_year = localtime( &clock ) -> tm_year;
749 if (tw.tw_year < 100)
750 tw.tw_year += CENTURY;
761 static char ident[] = "@@(#)$Id: dtimep.lex,v 2.5 1992/02/07 00:10:21 jromine Exp jromine $";
773 static char ident[] = "@@(#)$Id: dtimep.lex,v 1.10 1990/04/05 15:55:07 sources Exp $";
776 {D}(("-"{MONTH}"-")|(" "{MONTH}" ")|({MONTH})){D}?{d}{d}({W}at)?{w} {
779 tw.tw_year = CVT1OR2;
818 tw.tw_hour = CVT2; cp++;
819 tw.tw_min = CVT2; cp++;
821 while( !isdigit(*cp++) )
835 {D}{w}(-)?{w}{MONTH}{w}(-)?{w}(19)?{D}{w}(\,{w}|at{W})? {
838 tw.tw_year = i % 100;
844 @start merging changes from the Jef Poskanzer version
849 #define CVT2 (i=(*cp++ - '0'),isdigit(*cp)? i*10 + (*cp++ - '0') : i)
853 tw.tw_hour = CVT2; cp++;
854 tw.tw_min = CVT2; cp++;
858 tw.tw_hour = CVT2; cp++;
862 tw.tw_hour = CVT2; cp++;
869 tw.tw_hour = CVT2; cp++;
888 static char ident[] = "@@(#)$Id:$";
896 {D}"/"{D}"/"(19)?[0-9][0-9]{w} {
902 tw.tw_mon = CVT2 - 1;
905 tw.tw_mon = CVT2 - 1;
911 tw.tw_year = i % 100;
917 {MONTH}{W}{D}","{W}(19)?{D}{w} {
923 tw.tw_year = i % 100;
931 <Z>"-"?bst ZONED(0 * 60);
935 while( !isdigit(*cp++) )
946 @fix for numeric tz parsing
955 @many changes to make parsing more lax.
960 tw.tw_zone = ZONE(0 * 60);/* GMT */
974 #define SETDAY tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)];\
975 tw.tw_flags |= TW_SEXP;\
977 #define SETMONTH tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; gotdate++;\
983 #define SKIPD while ( !isdigit(*cp++) ) ; --cp;
984 #define ZONE(x) tw.tw_zone=(x);
985 #define ZONED(x) tw.tw_zone=(x); tw.tw_flags |= TW_DST;
989 switch (cp = str, lex_string( &str, start_cond)) {
992 "("{DAY}")"(","?) cp++, SETDAY;
994 {D}"/"{D}"/"19[0-9][0-9]{w} {
995 tw.tw_mday = CVT2; cp++;
996 tw.tw_mon = CVT2 - 1; cp += 3;
1001 {D}"/"{D}"/"[0-9][0-9]{w} {
1002 tw.tw_mday = CVT2; cp++;
1003 tw.tw_mon = CVT2 - 1; cp++;
1008 {D}("-"|{W})?{MONTH}("-"|{W})?(19)?{D}({W}at{W})? {
1012 <Z>[a-i] tw.tw_zone = 60 * (('a'-1) - LC (*cp));
1013 <Z>[k-m] tw.tw_zone = 60 * ('a' - LC (*cp));
1014 <Z>[n-y] tw.tw_zone = 60 * (LC (*cp) - 'm');
1020 @allow lwsp between digits and month name
1025 <Z>"-"?bst ZONED(-1 * 60);
1031 @move zonehack() routine to top
1036 {D}[- ]?{MONTH}[- ]?(19)?{D}({W}at{W})? {
1042 @fix for dates with no timezone
1050 #include <sys/time.h>
1061 static zonehack (tw)
1062 register struct tws *tw;
1064 register struct tm *tm;
1066 if (twclock (tw) == -1L)
1069 tm = localtime (&tw -> tw_clock);
1070 if (tm -> tm_isdst) {
1071 tw -> tw_flags |= TW_DST;
1072 tw -> tw_zone -= 60;
1094 @move some #include up a bit
1111 #include <sys/time.h>