.
[gnulib.git] / lib / getdate.y
index ebfb7c9..f3014fb 100644 (file)
@@ -6,11 +6,11 @@
 **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
 **  send any email to Rich.
 **
-**  This grammar has nine shift/reduce conflicts.
+**  This grammar has 10 shift/reduce conflicts.
 **
 **  This code is in the public domain and has no copyright.
 */
-/* SUPPRESS 287 on yaccpar_sccsid *//* Unusd static variable */
+/* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
 /* SUPPRESS 288 on yyerrlab *//* Label unused */
 
 #ifdef HAVE_CONFIG_H
 #undef static
 #endif
 
+/* The following block of alloca-related preprocessor directives is here
+   solely to allow compilation by non GNU-C compilers of the C parser
+   produced from this file by old versions of bison.  Newer versions of
+   bison include a block similar to this one in bison.simple.  */
+
 #ifdef __GNUC__
 #undef alloca
 #define alloca __builtin_alloca
@@ -41,7 +46,7 @@
 #ifdef _AIX /* for Bison */
  #pragma alloca
 #else
-char *alloca ();
+void *alloca ();
 #endif
 #endif
 #endif
@@ -78,7 +83,7 @@ char *alloca ();
 #undef timezone /* needed for sgi */
 #endif
 
-#if defined(HAVE_SYS_TIMEB_H) || (!defined(USG) && defined(HAVE_FTIME))
+#if defined(HAVE_SYS_TIMEB_H)
 #include <sys/timeb.h>
 #else
 /*
@@ -119,7 +124,7 @@ static int yyerror ();
 
 #if    !defined(lint) && !defined(SABER)
 static char RCS[] =
-       "$Header: /w/src/cvsroot/shellutils/lib/getdate.y,v 1.5 1993/09/08 18:23:16 meyering Exp $";
+       "$Header: str2date.y,v 2.1 90/09/06 08:15:06 cronan Exp $";
 #endif /* !defined(lint) && !defined(SABER) */
 
 
@@ -296,6 +301,12 @@ date       : tUNUMBER '/' tUNUMBER {
            yyMonth = -$2;
            yyDay = -$3;
        }
+       | tUNUMBER tMONTH tSNUMBER {
+           /* e.g. 17-JUN-1992.  */
+           yyDay = $1;
+           yyMonth = $2;
+           yyYear = -$3;
+       }
        | tMONTH tUNUMBER {
            yyMonth = $1;
            yyDay = $2;
@@ -357,25 +368,24 @@ number    : tUNUMBER {
                yyYear = $1;
            else {
                if($1>10000) {
-                   time_t date_part;
-
-                   date_part= $1/10000;
                    yyHaveDate++;
-                   yyDay= (date_part)%100;
-                   yyMonth= (date_part/100)%100;
-                   yyYear = date_part/10000;
-               } 
-               yyHaveTime++;
-               if ($1 < 100) {
-                   yyHour = $1;
-                   yyMinutes = 0;
+                   yyDay= ($1)%100;
+                   yyMonth= ($1/100)%100;
+                   yyYear = $1/10000;
                }
                else {
-                   yyHour = $1 / 100;
-                   yyMinutes = $1 % 100;
-               }
-               yySeconds = 0;
-               yyMeridian = MER24;
+                   yyHaveTime++;
+                   if ($1 < 100) {
+                       yyHour = $1;
+                       yyMinutes = 0;
+                   }
+                   else {
+                       yyHour = $1 / 100;
+                       yyMinutes = $1 % 100;
+                   }
+                   yySeconds = 0;
+                   yyMeridian = MER24;
+               }
            }
        }
        ;
@@ -608,6 +618,8 @@ ToSeconds(Hours, Minutes, Seconds, Meridian)
        if (Hours < 1 || Hours > 12)
            return -1;
        return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
+    default:
+       abort ();
     }
     /* NOTREACHED */
 }
@@ -871,53 +883,38 @@ yylex()
     }
 }
 
-
-#define TM_YEAR_ORIGIN 1900
-
-/* Yield A - B, measured in seconds.  */
-static time_t
-difftm(a, b)
-     struct tm *a, *b;
-{
-  int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
-  int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
-  return
-    (
-     (
-      (
-       /* difference in day of year */
-       a->tm_yday - b->tm_yday
-       /* + intervening leap days */
-       +  ((ay >> 2) - (by >> 2))
-       -  (ay/100 - by/100)
-       +  ((ay/100 >> 2) - (by/100 >> 2))
-       /* + difference in years * 365 */
-       +  (time_t)(ay-by) * 365
-       )*24 + (a->tm_hour - b->tm_hour)
-      )*60 + (a->tm_min - b->tm_min)
-     )*60 + (a->tm_sec - b->tm_sec);
-}
-
 time_t
 get_date(p, now)
     char               *p;
     struct timeb       *now;
 {
-    struct tm          *tm, gmt;
+    struct tm          *tm;
     struct timeb       ftz;
     time_t             Start;
     time_t             tod;
 
     yyInput = p;
-    if (now == NULL) {
+    if (now == NULL)
+      {
+       int tz;
+       struct tm *tmp;
+       time_t epoch = 0;
+
         now = &ftz;
        (void)time(&ftz.time);
 
-       if (! (tm = gmtime (&ftz.time)))
-           return -1;
-       gmt = *tm;      /* Make a copy, in case localtime modifies *tm.  */
-       ftz.timezone = difftm (&gmt, localtime (&ftz.time)) / 60;
-    }
+       /* Compute local timezone.  Do *not* take daylight savings
+          into account here.  */
+       tmp = localtime (&epoch);
+       tz = tmp->tm_hour * 60 + tmp->tm_min;   /* Minutes east of UTC.  */
+       if (tz > 0)
+         {
+           tz = 24 * 60 - tz;                  /* Minutes west of UTC.  */
+           if (tmp->tm_year == 70)
+             tz -= 24 * 60;                    /* Account for date line.  */
+         }
+       ftz.timezone = tz;
+      }
 
     tm = localtime(&now->time);
     yyYear = tm->tm_year;