Take out memory hints, since we are assuming flex over lex, so this shouldn't be...
[mmh] / sbr / dtimep.lex
index 4f01980..8e78245 100644 (file)
@@ -1,7 +1,3 @@
-%e 2000
-%p 5000
-%n 1000
-%a 4000
 %{
 #include <h/nmh.h>
 #include <h/tws.h>
@@ -86,8 +82,10 @@ static int month_map[] = {
 };
 
 /*
- * Same trick for day-of-week using the hash function
- *  (c1 & 7) + (c2 & 4)
+ * 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,
@@ -115,8 +113,7 @@ static int day_map[] = {
  */
 
 #define INIT()       { cp = yytext;} 
-#define SETWDAY()    { cp++; \
-                       tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \
+#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++; \
@@ -152,6 +149,34 @@ static int day_map[] = {
                        --cp; }
 #define SKIPTOSP()   { while ( !isspace(*cp++) ) ; \
                        --cp; }
+
+#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
+# ifdef TIME_WITH_SYS_TIME
+#  include <sys/time.h>
+#  include <time.h>
+# else
+#  ifdef HAVE_SYS_TIME_H
+#   include <sys/time.h>
+#  else
+#   include <time.h>
+#  endif
+# endif
+
+static void
+zonehack (struct tws *tw)
+{
+    register struct tm *tm;
+
+    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;
+    }
+}
+#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
 %}
 
 sun    ([Ss]un(day)?)
@@ -326,16 +351,23 @@ d [0-9]
                                     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);
-"-"?("jst"|"JST")                  INIT(); SETZONE(200);
-"-"?("jdt"|"JDT")                  INIT(); SETDST(); SETZONE(2);
 "-"?("est"|"EST")                  INIT(); SETZONE(-500);
 "-"?("edt"|"EDT")                  INIT(); SETDST(); SETZONE(-500);
 "-"?("cst"|"CST")                  INIT(); SETZONE(-600);
@@ -347,21 +379,7 @@ d  [0-9]
 "-"?("nst"|"NST")                  INIT(); SETZONE(-330);
 "-"?("ast"|"AST")                  INIT(); SETZONE(-400);
 "-"?("adt"|"ADT")                  INIT(); SETDST(); SETZONE(-400);
-"-"?("yst"|"YST")                  INIT(); SETZONE(-900);
-"-"?("ydt"|"YDT")                  INIT(); SETDST(); SETZONE(-900);
 "-"?("hst"|"HST")                  INIT(); SETZONE(-1000);
 "-"?("hdt"|"HDT")                  INIT(); SETDST(); SETZONE(-1000);
-"-"?("bst"|"BST")                  INIT(); SETDST(); SETZONE(-100);
-[a-iA-I]                           {
-                                       INIT();
-                                       SETZONE(100*(('a'-1) - tolower(*cp)));
-                                   }
-[k-mK-M]                           {
-                                       INIT();
-                                       SETZONE(100*('a' - tolower(*cp)));
-                                   }
-[n-yN-Y]                           {
-                                       INIT();
-                                       SETZONE(100*(tolower(*cp) - 'm'));
-                                    }
+"-"?([a-z]{3}|[A-Z]{3})                    ;
 .|\n