%n2500
%a5000
%{
-#include <h/nmh.h>
+#include <time.h>
+#include <ctype.h>
#include <h/tws.h>
/*
*/
int europeandate = 0;
-/*
-** Table to convert month names to numeric month. We use the
-** fact that the low order 5 bits of the sum of the 2nd & 3rd
-** characters of the name is a hash with no collisions for the 12
-** valid month names. (The mask to 5 bits maps any combination of
-** upper and lower case into the same hash value).
-*/
-static int month_map[] = {
- 0,
- 6, /* 1 - Jul */
- 3, /* 2 - Apr */
- 5, /* 3 - Jun */
- 0,
- 10, /* 5 - Nov */
- 0,
- 1, /* 7 - Feb */
- 11, /* 8 - Dec */
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0, /*15 - Jan */
- 0,
- 0,
- 0,
- 2, /*19 - Mar */
- 0,
- 8, /*21 - Sep */
- 0,
- 9, /*23 - Oct */
- 0,
- 0,
- 4, /*26 - May */
- 0,
- 7 /*28 - Aug */
-};
+static int
+name2num(char *name, char *names[])
+{
+ int i;
-/*
-** Lookup table for day-of-week using the same hash trick as for above
-** name-of-month table, but using the first and second character, not
-** second and third.
-**
-** Compute index into table using: (day_name[0] & 7) + (day_name[1] & 4)
-*/
-static int day_map[] = {
- 0,
- 0,
- 0,
- 6, /* 3 - Sat */
- 4, /* 4 - Thu */
- 0,
- 5, /* 6 - Fri */
- 0, /* 7 - Sun */
- 2, /* 8 - Tue */
- 1 /* 9 - Mon */,
- 0,
- 3 /*11 - Wed */
-};
+ for (i=0; names[i]; i++) {
+ if (strncasecmp(name, names[i], strlen(names[i]))==0) {
+ return i;
+ }
+ }
+ return 0;
+}
/*
** The SET* macros will parse for the appropriate field, and leave the
*/
#define INIT() { cp = yytext;}
-#define SETWDAY() { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \
+#define SETWDAY() { tw.tw_wday = name2num(cp, tw_dotw); \
tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP; SKIPA(); }
-#define SETMON() { cp++; tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; \
- SKIPA(); }
+#define SETMON() { tw.tw_mon = name2num(cp, tw_moty); SKIPA(); }
#define SETMON_NUM() { tw.tw_mon = atoi(cp)-1; SKIPD(); }
#define SETYEAR() { tw.tw_year = atoi(cp); SKIPD(); }
#define SETDAY() { tw.tw_mday = atoi(cp); tw.tw_flags |= TW_YES; SKIPD(); }
tw.tw_sec = atoi(++cp); SKIPD(); } }
#define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \
tw.tw_flags |= TW_SZEXP; SKIPD(); }
+#define SETZONEC(h, m) { tw.tw_zone = (h)*60+(m); \
+ tw.tw_flags |= TW_SZEXP; SKIPD(); }
#define SETDST() { tw.tw_flags |= TW_DST; }
#define SKIPD() { while ( isdigit(*cp++) ) ; --cp; }
#define SKIPTOD() { while ( !isdigit(*cp++) ) ; --cp; }
static void
zonehack (struct tws *tw)
{
- register struct tm *tm;
+ struct tm *tm;
if (dmktime (tw) == (time_t) -1)
return;
#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
%}
-sun ([Ss]un(day)?)
-mon ([Mm]on(day)?)
-tue ([Tt]ue(sday)?)
-wed ([Ww]ed(nesday)?)
-thu ([Tt]hu(rsday)?)
-fri ([Ff]ri(day)?)
-sat ([Ss]at(urday)?)
+sun ([Ss][Uu][Nn]([Dd][Aa][Yy])?)
+mon ([Mm][Oo][Nn]([Dd][Aa][Yy])?)
+tue ([Tt][Uu][Ee]([Ss][Dd][Aa][Yy])?)
+wed ([Ww][Ee][Dd]([Nn][Ee][Ss][Dd][Aa][Yy])?)
+thu ([Tt][Hh][Uu]([Rr][Ss][Dd][Aa][Yy])?)
+fri ([Ff][Rr][Ii]([Dd][Aa][Yy])?)
+sat ([Ss][Aa][Tt]([Uu][Rr][Dd][Aa][Yy])?)
DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
-jan ([Jj]an(uary)?)
-feb ([Ff]eb(ruary)?)
-mar ([Mm]ar(ch)?)
-apr ([Aa]pr(il)?)
-may ([Mm]ay)
-jun ([Jj]un(e)?)
-jul ([Jj]ul(y)?)
-aug ([Aa]ug(ust)?)
-sep ([Ss]ep(tember)?)
-oct ([Oo]ct(ober)?)
-nov ([Nn]ov(ember)?)
-dec ([Dd]ec(ember)?)
+jan ([Jj][Aa][Nn]([Uu][Aa][Rr][Yy])?)
+feb ([Ff][Ee][Bb]([Rr][Uu][Aa][Rr][Yy])?)
+mar ([Mm][Aa][Rr]([Cc][Hh])?)
+apr ([Aa][Pp][Rr]([Ii][Ll])?)
+may ([Mm][Aa][Yy])
+jun ([Jj][Uu][Nn]([Ee])?)
+jul ([Jj][Uu][Ll]([Yy])?)
+aug ([Aa][Uu][Gg]([Uu][Ss][Tt])?)
+sep ([Ss][Ee][Pp]([Tt][Ee][Mm][Bb][Ee][Rr])?)
+oct ([Oo][Cc][Tt]([Oo][Bb][Ee][Rr])?)
+nov ([Nn][Oo][Vv]([Ee][Mm][Bb][Ee][Rr])?)
+dec ([Dd][Ee][Cc]([Ee][Mm][Bb][Ee][Rr])?)
MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
*/
YY_BUFFER_STATE lexhandle;
- register unsigned char *cp;
+ unsigned char *cp;
static struct tws tw;
memset(&tw,0,sizeof(struct tws));
SKIPTOD();
SETYEAR();
}
-{D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME} {
+{d}{4}"-"{d}{2}"-"{d}{2}(" "|"T"){TIME} {
+ INIT();
+ SETYEAR();
+ SKIPTOD();
+ SETMON_NUM();
+ SKIPTOD();
+ SETDAY();
+ SKIPTOD();
+ SETTIME();
+}
+{d}{4}"-"{d}{2}"-"{d}{2} {
+ INIT();
+ SETYEAR();
+ SKIPTOD();
+ SETMON_NUM();
+ SKIPTOD();
+ SETDAY();
+}
+{d}{2}"-"{d}{2}"-"{d}{2} {
+ fprintf(stderr, "the highly ambiguous date format XX-XX-XX..."
+ " is no longer supported\n");
+}
+{D}"/"{D}"/"{YEAR}{W}{TIME} {
INIT();
if(europeandate) {
/* DD/MM/YY */
SKIPTOD();
SETTIME();
}
-{D}("-"|"/"){D}("-"|"/"){YEAR} {
+{D}"/"{D}"/"{YEAR} {
INIT();
if(europeandate) {
/* DD/MM/YY */
yyterminate();
}
+"+"{d}{d}":"{d}{d} {
+ INIT();
+ SKIPTOD();
+ SETZONEC(atoi(cp), atoi(cp+3));
+#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
+ zonehack (&tw);
+#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
+ yyterminate();
+}
+"-"{d}{d}":"{d}{d} {
+ INIT();
+ SKIPTOD();
+ SETZONEC(-atoi(cp), -atoi(cp+3));
+#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
+ zonehack (&tw);
+#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
+ yyterminate();
+
+}
{nl}("ut"|"UT") INIT(); SETZONE(0); yyterminate();
{nl}("gmt"|"GMT") INIT(); SETZONE(0); yyterminate();
{nl}("est"|"EST") INIT(); SETZONE(-500); yyterminate();