GNU shell utilities SHELLUTILS-1_9_2a
authorJim Meyering <jim@meyering.net>
Thu, 23 Dec 1993 00:29:36 +0000 (00:29 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 23 Dec 1993 00:29:36 +0000 (00:29 +0000)
lib/getdate.y
lib/strftime.c
lib/strtod.c

index ff0aa66..35d064f 100644 (file)
    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__
-#define alloca __builtin_alloca
-#else
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#else
-#ifdef _AIX
- #pragma alloca
-#else
-void *alloca ();
-#endif
-#endif
-#endif
 
 #ifdef __GNUC__
 #undef alloca
@@ -315,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;
@@ -376,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;
+               }
            }
        }
        ;
index 569a3d4..071d5dd 100644 (file)
@@ -36,6 +36,7 @@
    Numeric modifiers (a nonstandard extension):
    -   do not pad the field
    _   pad the field with spaces
+   %s   time in seconds since 00:00:00, Jan 1, 1970
 
    Time fields:
    %H  hour (00..23)
@@ -84,6 +85,7 @@
 #endif
 #endif
 
+#include <stdio.h>
 #include <sys/types.h>
 #if defined(TM_IN_SYS_TIME) || (!defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME))
 #include <sys/time.h>
 #include <time.h>
 #endif
 
+#ifndef STDC_HEADERS
+time_t mktime ();
+#endif
+
 #if defined(HAVE_TZNAME)
 extern char *tzname[2];
 #endif
@@ -175,7 +181,7 @@ add_num3 (string, num, max, pad)
 static int
 add_str (to, from, max)
      char *to;
-     char *from;
+     const char *from;
      int max;
 {
   int i;
@@ -185,6 +191,25 @@ add_str (to, from, max)
   return i;
 }
 
+static int
+add_num_time_t (string, max, num)
+     char *string;
+     int max;
+     time_t num;
+{
+  /* This buffer is large enough to hold the character representation
+     (including the trailing NUL) of any unsigned decimal quantity
+     whose binary representation fits in 128 bits.  */
+  char buf[40];
+  int length;
+
+  if (sizeof (num) > 16)
+    abort ();
+  sprintf (buf, "%lu", (unsigned long) num);
+  length = add_str (string, buf, max);
+  return length;
+}
+
 /* Return the week in the year of the time in TM, with the weeks
    starting on Sundays. */
 
@@ -330,6 +355,16 @@ strftime (string, max, format, tm)
              length +=
                strftime (&string[length], max - length, "%H:%M", tm);
              break;
+
+           case 's':
+             {
+               struct tm writable_tm;
+               writable_tm = *tm;
+               length += add_num_time_t (&string[length], max - length,
+                                         mktime (&writable_tm));
+             }
+             break;
+
            case 'S':
              length +=
                add_num2 (&string[length], tm->tm_sec, max - length, pad);
index d289753..01dafc8 100644 (file)
@@ -31,16 +31,20 @@ Cambridge, MA 02139, USA.  */
 #include <ctype.h>
 #include <math.h>
 
-#if STDC_HEADERS
+#ifdef HAVE_FLOAT_H
 #include <float.h>
+#else
+#define DBL_MAX 1.7976931348623159e+308
+#define DBL_MIN 2.2250738585072010e-308
+#endif
+#endif
+
+#if STDC_HEADERS
 #include <stdlib.h>
 #include <string.h>
 #else
 #define NULL 0
-#define DBL_MAX 1.7976931348623159e+308
-#define DBL_MIN 2.2250738585072010e-308
 extern int errno;
-#endif
 #ifndef HUGE_VAL
 #define HUGE_VAL HUGE
 #endif