X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fdtimep.lex;h=b5fac4fd15ed3034590a7e75576e0f5035788138;hp=3a3782576dd4804805121482716947cfd637a99d;hb=74ed4c043b3e22fa7e16fd892c381e9b16ca8c27;hpb=5b26f4fcdfeb7153b92c18f1478a0626341c609d diff --git a/sbr/dtimep.lex b/sbr/dtimep.lex index 3a37825..b5fac4f 100644 --- a/sbr/dtimep.lex +++ b/sbr/dtimep.lex @@ -1,10 +1,16 @@ -%e 2000 -%p 5000 -%n 1000 -%a 4000 +/* dtimep.lex exceeds the default table capacities for some old versions + * of lex (and the minimum defaults as specified by POSIX). The following + * choices meet or exceed the lex defaults for older SunOS4.x, Solaris, + * HPUX, and AIX. + */ +%e4000 +%p7000 +%n2500 +%a5000 %{ #include #include +#include /* Since we're looking at a string at a time, don't worry about * wrapping to the next buffer. @@ -12,7 +18,7 @@ #define yywrap() 1 #define YY_SKIP_YYWRAP -#define YY_NO_UNPUT +#define YY_NO_INPUT /* This is the tricky thing that makes this function cool. We * replace the traditional int yylex(void) declaration with our @@ -29,14 +35,14 @@ */ #define yyterminate() (void)yy_delete_buffer(lexhandle); \ - if(!(tw.tw_flags & TW_SUCC)) { \ - return (struct tws *)NULL; \ - } \ - if(tw.tw_year < 1960) \ - tw.tw_year += 1900; \ - if(tw.tw_year < 1960) \ - tw.tw_year += 100; \ - return(&tw) + if(!(tw.tw_flags & TW_SUCC)) { \ + return (struct tws *)NULL; \ + } \ + if(tw.tw_year < 1970) \ + tw.tw_year += 1900; \ + if(tw.tw_year < 1970) \ + tw.tw_year += 100; \ + return(&tw) /* * Patchable flag that says how to interpret NN/NN/NN dates. When @@ -116,43 +122,26 @@ static int day_map[] = { * character of a particular class. */ -#define INIT() { cp = yytext;} -#define SETWDAY() { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \ - 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_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(); } -#define SETTIME() { tw.tw_hour = atoi(cp); \ - cp += 2; \ - SKIPTOD(); \ - tw.tw_min = atoi(cp); \ - cp += 2; \ - if(*cp == ':') { \ - tw.tw_sec = atoi(++cp); SKIPD(); } } -#define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \ - 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; } -#define SKIPA() { while ( isalpha(*cp++) ) ; \ - --cp; } -#define SKIPTOA() { while ( !isalpha(*cp++) ) ; \ - --cp; } -#define SKIPSP() { while ( isspace(*cp++) ) ; \ - --cp; } -#define SKIPTOSP() { while ( !isspace(*cp++) ) ; \ - --cp; } +#define INIT() { cp = yytext;} +#define SETWDAY() { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \ + 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_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(); } +#define SETTIME() { tw.tw_hour = atoi(cp); cp += 2; SKIPTOD(); \ + tw.tw_min = atoi(cp); cp += 2; if(*cp == ':') { \ + tw.tw_sec = atoi(++cp); SKIPD(); } } +#define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \ + 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; } +#define SKIPA() { while ( isalpha(*cp++) ) ; --cp; } +#define SKIPTOA() { while ( !isalpha(*cp++) ) ; --cp; } +#define SKIPSP() { while ( isspace(*cp++) ) ; --cp; } +#define SKIPTOSP() { while ( !isspace(*cp++) ) ; --cp; } #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST # ifdef TIME_WITH_SYS_TIME @@ -169,18 +158,18 @@ static int day_map[] = { static void zonehack (struct tws *tw) { - register struct tm *tm; + register struct tm *tm; - if (dmktime (tw) == (time_t) -1) - return; + if (dmktime (tw) == (time_t) -1) + return; - tm = localtime (&tw->tw_clock); - if (tm->tm_isdst) { - tw->tw_flags |= TW_DST; - tw->tw_zone -= 60; - } + tm = localtime (&tw->tw_clock); + if (tm->tm_isdst) { + tw->tw_flags |= TW_DST; + tw->tw_zone -= 60; + } } -#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ +#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ %} sun ([Ss]un(day)?) @@ -208,182 +197,195 @@ dec ([Dd]ec(ember)?) MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec}) -TIME ({D}:{d}{d}(:{d}{d})?) +TIME ({D}:{d}{d}(:{d}{d})?) - /* The year can either be 2 digits, or 4. However, after - Y2K, we found that some MUA were reporting the year 100, hence - the middle term here. yyterminate() resolves the actual - issues with 2-digit years. - */ +/* + * The year can either be 2 digits, or 4. However, after + * Y2K, we found that some MUA were reporting the year 100, hence + * the middle term here. yyterminate() resolves the actual + * issues with 2-digit years. + */ -YEAR (({d}{d})|(1{d}{d})|({d}{4})) +YEAR (({d}{d})|(1{d}{d})|({d}{4})) w ([ \t]*) W ([ \t]+) D ([0-9]?[0-9]) d [0-9] +nl [ \t\n()] %% %{ - /* This section begins the definition of dparsetime(). - Put here any local variable definitions and initializations */ - - YY_BUFFER_STATE lexhandle; + /* This section begins the definition of dparsetime(). + * Put here any local variable definitions and initializations */ + + YY_BUFFER_STATE lexhandle; - register char *cp; - static struct tws tw; + register unsigned char *cp; + static struct tws tw; - memset(&tw,0,sizeof(struct tws)); + memset(&tw,0,sizeof(struct tws)); - lexhandle = yy_scan_string(lexstr); + lexhandle = yy_scan_string(lexstr); %} -{DAY}","?{W}{MONTH}{W}{D}{W}{TIME}{W}{YEAR} { - INIT(); - SETWDAY(); - SKIPTOA(); - SETMON(); - SKIPTOD(); - SETDAY(); - SKIPTOD(); - SETTIME(); - SKIPTOD(); - SETYEAR(); - } - -{DAY}","?{W}{D}{W}{MONTH}{W}{YEAR}{W}{TIME} { - INIT(); - SETWDAY(); - SKIPTOD(); - SETDAY(); - SKIPTOA(); - SETMON(); - SKIPTOD(); - SETYEAR(); - SKIPTOD(); - SETTIME(); - } -{D}{W}{MONTH}{W}{YEAR}{W}{TIME} { - INIT(); - SETDAY(); - SKIPTOA(); - SETMON(); - SKIPTOD(); - SETYEAR(); - SKIPTOD(); - SETTIME(); - } -{DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR}","?{W}{TIME} { - INIT(); - SETWDAY(); - SKIPTOA(); - SETMON(); - SKIPTOD(); - SETDAY(); - SKIPTOD(); - SETYEAR(); - SKIPTOD(); - SETTIME(); - } -{DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR} { - INIT(); - SETWDAY(); - SKIPTOA(); - SETMON(); - SKIPTOD(); - SETDAY(); - SKIPTOD(); - SETYEAR(); - } -{MONTH}{W}{D}","?{W}{YEAR}","?{W}{DAY} { - INIT(); - SETMON(); - SKIPTOD(); - SETDAY(); - SKIPTOD(); - SETYEAR(); - SKIPTOA(); - SETWDAY(); - } -{MONTH}{W}{D}","?{W}{YEAR} { - INIT(); - SETMON(); - SKIPTOD(); - SETDAY(); - SKIPTOD(); - SETYEAR(); - } -{D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME} { - INIT(); - if(europeandate) { - /* DD/MM/YY */ - SETDAY(); - SKIPTOD(); - SETMON_NUM(); - } else { - /* MM/DD/YY */ - SETMON_NUM(); - SKIPTOD(); - SETDAY(); - } - SKIPTOD(); - SETYEAR(); - SKIPTOD(); - SETTIME(); - } -{D}("-"|"/"){D}("-"|"/"){YEAR} { - INIT(); - if(europeandate) { - /* DD/MM/YY */ - SETDAY(); - SKIPTOD(); - SETMON_NUM(); - } else { - /* MM/DD/YY */ - SETMON_NUM(); - SKIPTOD(); - SETDAY(); - } - SKIPTOD(); - SETYEAR(); - } +{DAY}","?{W}{MONTH}{W}{D}{W}{TIME}{W}{YEAR} { + INIT(); + SETWDAY(); + SKIPTOA(); + SETMON(); + SKIPTOD(); + SETDAY(); + SKIPTOD(); + SETTIME(); + SKIPTOD(); + SETYEAR(); +} + +{DAY}","?{W}{D}{W}{MONTH}{W}{YEAR}{W}{TIME} { + INIT(); + SETWDAY(); + SKIPTOD(); + SETDAY(); + SKIPTOA(); + SETMON(); + SKIPTOD(); + SETYEAR(); + SKIPTOD(); + SETTIME(); +} +{D}{W}{MONTH}{W}{YEAR}{W}{TIME} { + INIT(); + SETDAY(); + SKIPTOA(); + SETMON(); + SKIPTOD(); + SETYEAR(); + SKIPTOD(); + SETTIME(); +} +{DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR}","?{W}{TIME} { + INIT(); + SETWDAY(); + SKIPTOA(); + SETMON(); + SKIPTOD(); + SETDAY(); + SKIPTOD(); + SETYEAR(); + SKIPTOD(); + SETTIME(); +} +{DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR} { + INIT(); + SETWDAY(); + SKIPTOA(); + SETMON(); + SKIPTOD(); + SETDAY(); + SKIPTOD(); + SETYEAR(); +} +{MONTH}{W}{D}","?{W}{YEAR}","?{W}{DAY} { + INIT(); + SETMON(); + SKIPTOD(); + SETDAY(); + SKIPTOD(); + SETYEAR(); + SKIPTOA(); + SETWDAY(); +} +{MONTH}{W}{D}","?{W}{YEAR} { + INIT(); + SETMON(); + SKIPTOD(); + SETDAY(); + SKIPTOD(); + SETYEAR(); +} +{D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME} { + INIT(); + if(europeandate) { + /* DD/MM/YY */ + SETDAY(); + SKIPTOD(); + SETMON_NUM(); + } else { + /* MM/DD/YY */ + SETMON_NUM(); + SKIPTOD(); + SETDAY(); + } + SKIPTOD(); + SETYEAR(); + SKIPTOD(); + SETTIME(); +} +{D}("-"|"/"){D}("-"|"/"){YEAR} { + INIT(); + if(europeandate) { + /* DD/MM/YY */ + SETDAY(); + SKIPTOD(); + SETMON_NUM(); + } else { + /* MM/DD/YY */ + SETMON_NUM(); + SKIPTOD(); + SETDAY(); + } + SKIPTOD(); + SETYEAR(); +} "[Aa][Mm]" -"[Pp][Mm]" tw.tw_hour += 12; - -"+"{D}{d}{d} { - INIT(); - SKIPTOD(); - SETZONE(atoi(cp)); -#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST - zonehack (&tw); -#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ - // yyterminate(); - } -"-"{D}{d}{d} { - INIT(); - SKIPTOD(); - SETZONE(-atoi(cp)); -#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST - zonehack (&tw); -#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ - // yyterminate(); - - } -"-"?("ut"|"UT") INIT(); SETZONE(0); -"-"?("gmt"|"GMT") INIT(); SETZONE(0); -"-"?("est"|"EST") INIT(); SETZONE(-500); -"-"?("edt"|"EDT") INIT(); SETDST(); SETZONE(-500); -"-"?("cst"|"CST") INIT(); SETZONE(-600); -"-"?("cdt"|"CDT") INIT(); SETDST(); SETZONE(-600); -"-"?("mst"|"MST") INIT(); SETZONE(-700); -"-"?("mdt"|"MDT") INIT(); SETDST(); SETZONE(-700); -"-"?("pst"|"PST") INIT(); SETZONE(-800); -"-"?("pdt"|"PDT") INIT(); SETDST(); SETZONE(-800); -"-"?("nst"|"NST") INIT(); SETZONE(-330); -"-"?("ast"|"AST") INIT(); SETZONE(-400); -"-"?("adt"|"ADT") INIT(); SETDST(); SETZONE(-400); -"-"?("hst"|"HST") INIT(); SETZONE(-1000); -"-"?("hdt"|"HDT") INIT(); SETDST(); SETZONE(-1000); -"-"?([a-z]{3}|[A-Z]{3}) ; +"[Pp][Mm]" tw.tw_hour += 12; + +"+"{D}{d}{d} { + INIT(); + SKIPTOD(); + SETZONE(atoi(cp)); +#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST + zonehack (&tw); +#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ + yyterminate(); +} +"-"{D}{d}{d} { + INIT(); + SKIPTOD(); + SETZONE(-atoi(cp)); +#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(); +{nl}("edt"|"EDT") { INIT(); SETDST(); SETZONE(-500); yyterminate(); } +{nl}("cst"|"CST") INIT(); SETZONE(-600); yyterminate(); +{nl}("cdt"|"CDT") { INIT(); SETDST(); SETZONE(-600); yyterminate(); } +{nl}("mst"|"MST") INIT(); SETZONE(-700); yyterminate(); +{nl}("mdt"|"MDT") { INIT(); SETDST(); SETZONE(-700); yyterminate(); } +{nl}("pst"|"PST") INIT(); SETZONE(-800); yyterminate(); +{nl}("pdt"|"PDT") { INIT(); SETDST(); SETZONE(-800); yyterminate(); } +{nl}("nst"|"NST") INIT(); SETZONE(-330); yyterminate(); +{nl}("ast"|"AST") INIT(); SETZONE(-400); yyterminate(); +{nl}("adt"|"ADT") { INIT(); SETDST(); SETZONE(-400); yyterminate(); } +{nl}("hst"|"HST") INIT(); SETZONE(-1000); yyterminate(); +{nl}("hdt"|"HDT") { INIT(); SETDST(); SETZONE(-1000); yyterminate(); } .|\n + +%% +/* This is a portable way to squash a warning about the yyunput() + * function being static but never used. It costs us a tiny amount + * of extra code in the binary but the other options are: + * "%option nounput" which is flex-specific + * makefile hackery just to compile dtimep.c with different flags + */ +void dtimep_yyunput(int c) +{ + unput(c); +}