changeset 145:be5d47496dc0

GNU shell utilities
author Jim Meyering <jim@meyering.net>
date Thu, 23 Dec 1993 00:29:36 +0000
parents fe6152b2dbb2
children 59f482e5924b
files lib/getdate.y lib/strftime.c lib/strtod.c
diffstat 3 files changed, 65 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/lib/getdate.y
+++ b/lib/getdate.y
@@ -35,20 +35,6 @@
    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 @@
 	    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 @@
 		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;
+	        }
 	    }
 	}
 	;
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -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>
@@ -91,6 +93,10 @@
 #include <time.h>
 #endif
 
+#ifndef STDC_HEADERS
+time_t mktime ();
+#endif
+
 #if defined(HAVE_TZNAME)
 extern char *tzname[2];
 #endif
@@ -175,7 +181,7 @@
 static int
 add_str (to, from, max)
      char *to;
-     char *from;
+     const char *from;
      int max;
 {
   int i;
@@ -185,6 +191,25 @@
   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 @@
 	      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);
--- a/lib/strtod.c
+++ b/lib/strtod.c
@@ -31,16 +31,20 @@
 #include <ctype.h>
 #include <math.h>
 
+#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 <float.h>
 #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