]> diplodocus.org Git - nmh/blobdiff - sbr/dtimep.l
new.c: Order two return statements to match comment.
[nmh] / sbr / dtimep.l
index bae6ac5c64e6dc1ce2bdf609f165cf365f721211..bd36c64aaf7b459d373f579811a0090cbf67d5cf 100644 (file)
@@ -1,4 +1,6 @@
-/* dtimep.lex exceeds the default table capacities for some old versions
+/* dtimep.l -- parse dates and times.
+ *
+ * This 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.
  * 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.
 %a5000
 %{
 #include <h/nmh.h>
 %a5000
 %{
 #include <h/nmh.h>
+#include <h/mh.h>
+#include <h/utils.h>
 #include <h/tws.h>
 
   /* Since we're looking at a string at a time, don't worry about
    *  wrapping to the next buffer.
    */
 #include <h/tws.h>
 
   /* Since we're looking at a string at a time, don't worry about
    *  wrapping to the next buffer.
    */
+#if YY_FLEX_MAJOR_VERSION == 2 && \
+    YY_FLEX_MINOR_VERSION == 6 && \
+    YY_FLEX_SUBMINOR_VERSION == 3
+/* https://github.com/westes/flex/issues/162 */
+#undef yywrap
+#endif
 #define yywrap() 1
 #define YY_SKIP_YYWRAP
 
 #define yywrap() 1
 #define YY_SKIP_YYWRAP
 
@@ -27,7 +37,7 @@
    */
 #define YY_DECL struct tws *dparsetime(char *lexstr)
 
    */
 #define YY_DECL struct tws *dparsetime(char *lexstr)
 
-  /* yyerminate() is called after the input string is matched to
+  /* yyterminate() is called after the input string is matched to
    * completion (actually, when the lexer reaches an EOF).  The only
    * thing that really needs to be in this macro function is the
    * return call, which must be substituted inline into dparsetime.
    * completion (actually, when the lexer reaches an EOF).  The only
    * thing that really needs to be in this macro function is the
    * return call, which must be substituted inline into dparsetime.
 
 #define yyterminate() (void)yy_delete_buffer(lexhandle); \
   if(!(tw.tw_flags & TW_SUCC)) { \
 
 #define yyterminate() (void)yy_delete_buffer(lexhandle); \
   if(!(tw.tw_flags & TW_SUCC)) { \
-    return (struct tws *)NULL; \
+    return NULL; \
   } \
   if(tw.tw_year < 1970) \
     tw.tw_year += 1900; \
   if(tw.tw_year < 1970) \
     tw.tw_year += 100; \
   } \
   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
- * true, we do it European style: DD/MM/YY. When false, we do it
- * American style: MM/DD/YY.  Of course, these are all non-RFC822
- * compliant.
- */
-int europeandate = 0;
+  return &tw
 
 /*
  * Table to convert month names to numeric month.  We use the
 
 /*
  * Table to convert month names to numeric month.  We use the
@@ -133,7 +135,7 @@ static int day_map[] = {
 #define SETYEAR()    { tw.tw_year = atoi(cp); \
                       SKIPD(); }
 #define SETDAY()     { tw.tw_mday = atoi(cp); \
 #define SETYEAR()    { tw.tw_year = atoi(cp); \
                       SKIPD(); }
 #define SETDAY()     { tw.tw_mday = atoi(cp); \
-                       tw.tw_flags |= TW_YES; \
+                       tw.tw_flags |= TW_SUCC; \
                       SKIPD(); }
 #define SETTIME()    { tw.tw_hour = atoi(cp); \
                        cp += 2; \
                       SKIPD(); }
 #define SETTIME()    { tw.tw_hour = atoi(cp); \
                        cp += 2; \
@@ -159,7 +161,6 @@ static int day_map[] = {
 #define SKIPTOSP()   { while ( !isspace((unsigned char) *cp++) ) ; \
                        --cp; }
 
 #define SKIPTOSP()   { while ( !isspace((unsigned char) *cp++) ) ; \
                        --cp; }
 
-#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
 # ifdef HAVE_SYS_TIME_H
 #  include <sys/time.h>
 # endif
 # ifdef HAVE_SYS_TIME_H
 #  include <sys/time.h>
 # endif
@@ -168,7 +169,7 @@ static int day_map[] = {
 static void
 zonehack (struct tws *tw)
 {
 static void
 zonehack (struct tws *tw)
 {
-    register struct tm *tm;
+    struct tm *tm;
 
     if (dmktime (tw) == (time_t) -1)
        return;
 
     if (dmktime (tw) == (time_t) -1)
        return;
@@ -179,35 +180,34 @@ zonehack (struct tws *tw)
        tw->tw_zone -= 60;
     }
 }
        tw->tw_zone -= 60;
     }
 }
-#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)?)
-
-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)?)
-
-MONTH  ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
-
-TIME    ({D}:{d}{d}(:{d}{d})?)
+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)?
+
+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]une?
+jul    [Jj]uly?
+aug    [Aa]ug(ust)?
+sep    [Ss]ep(tember)?
+oct    [Oo]ct(ober)?
+nov    [Nn]ov(ember)?
+dec    [Dd]ec(ember)?
+
+MONTH  {jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec}
+
+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 year can either be 2 digits, or 4. However, after
        Y2K, we found that some MUA were reporting the year 100, hence
@@ -215,11 +215,11 @@ TIME    ({D}:{d}{d}(:{d}{d})?)
         issues with 2-digit years.
      */
 
         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])
+w      [ \t]*
+W      [ \t]+
+D      [0-9]?[0-9]
 d      [0-9]
 nl      [ \t\n()]
 
 d      [0-9]
 nl      [ \t\n()]
 
@@ -233,7 +233,7 @@ nl      [ \t\n()]
   char *cp;
   static struct tws tw; 
 
   char *cp;
   static struct tws tw; 
 
-  memset(&tw,0,sizeof(struct tws));
+  ZERO(&tw);
 
   lexhandle = yy_scan_string(lexstr);
 %}
 
   lexhandle = yy_scan_string(lexstr);
 %}
@@ -315,17 +315,10 @@ nl      [ \t\n()]
                                      }
 {D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME}       {
                                      INIT();
                                      }
 {D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME}       {
                                      INIT();
-                                    if(europeandate) {
-                                      /* DD/MM/YY */
-                                    SETDAY();
-                                    SKIPTOD();
-                                    SETMON_NUM();
-                                    } else {
-                                      /* MM/DD/YY */
+                                    /* MM/DD/YY */
                                     SETMON_NUM();
                                     SKIPTOD();
                                     SETDAY();
                                     SETMON_NUM();
                                     SKIPTOD();
                                     SETDAY();
-                                    }
                                     SKIPTOD();
                                     SETYEAR();
                                     SKIPTOD();
                                     SKIPTOD();
                                     SETYEAR();
                                     SKIPTOD();
@@ -333,17 +326,10 @@ nl      [ \t\n()]
                                      }
 {D}("-"|"/"){D}("-"|"/"){YEAR}                {
                                      INIT();
                                      }
 {D}("-"|"/"){D}("-"|"/"){YEAR}                {
                                      INIT();
-                                    if(europeandate) {
-                                      /* DD/MM/YY */
-                                    SETDAY();
-                                    SKIPTOD();
-                                    SETMON_NUM();
-                                    } else {
-                                      /* MM/DD/YY */
+                                    /* MM/DD/YY */
                                     SETMON_NUM();
                                     SKIPTOD();
                                     SETDAY();
                                     SETMON_NUM();
                                     SKIPTOD();
                                     SETDAY();
-                                    }
                                     SKIPTOD();
                                     SETYEAR();
                                      }
                                     SKIPTOD();
                                     SETYEAR();
                                      }
@@ -355,18 +341,14 @@ nl      [ \t\n()]
                                     INIT();
                                     SKIPTOD();
                                     SETZONE(atoi(cp));
                                     INIT();
                                     SKIPTOD();
                                     SETZONE(atoi(cp));
-#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
                                    zonehack (&tw);
                                    zonehack (&tw);
-#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
                                    yyterminate();
                                     }
 "-"{D}{d}{d}                                  {
                                     INIT();
                                     SKIPTOD();
                                     SETZONE(-atoi(cp));
                                    yyterminate();
                                     }
 "-"{D}{d}{d}                                  {
                                     INIT();
                                     SKIPTOD();
                                     SETZONE(-atoi(cp));
-#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
                                    zonehack (&tw);
                                    zonehack (&tw);
-#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
                                    yyterminate();
                                    
                                     }
                                    yyterminate();
                                    
                                     }
@@ -404,4 +386,3 @@ void dtimep_yyunput(int c)
 {
     unput(c);
 }
 {
     unput(c);
 }
-