From d7daf7444e175ba8ceb752b6ee09a35ff72e8920 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 23 Dec 1993 00:08:23 +0000 Subject: . --- lib/getdate.y | 6 ++++++ lib/strftime.c | 37 ++++++++++++++++++++++++++++++++++++- lib/strtod.c | 25 ++++++++++++++++++------- old/sh-utils/NEWS | 3 +++ src/date.c | 2 +- src/expr.c | 3 +++ 6 files changed, 67 insertions(+), 9 deletions(-) diff --git a/lib/getdate.y b/lib/getdate.y index ff0aa66a3..09340da8b 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -315,6 +315,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; diff --git a/lib/strftime.c b/lib/strftime.c index 569a3d448..360c72bd3 100644 --- a/lib/strftime.c +++ b/lib/strftime.c @@ -46,6 +46,7 @@ %p locale's AM or PM %r time, 12-hour (hh:mm:ss [AP]M) %R time, 24-hour (hh:mm) + %s time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension) %S second (00..61) %T time, 24-hour (hh:mm:ss) %X locale's time representation (%H:%M:%S) @@ -84,6 +85,7 @@ #endif #endif +#include #include #if defined(TM_IN_SYS_TIME) || (!defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME)) #include @@ -91,6 +93,10 @@ #include #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); diff --git a/lib/strtod.c b/lib/strtod.c index 4441102df..8723a82ef 100644 --- a/lib/strtod.c +++ b/lib/strtod.c @@ -16,28 +16,39 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef HAVE_CONFIG_H +#if defined (CONFIG_BROKETS) +/* We use instead of "config.h" so that a compilation + using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h + (which it would do because it found this file in $srcdir). */ +#include +#else +#include "config.h" +#endif +#endif + #include #include #include -#if STDC_HEADERS +#ifdef HAVE_FLOAT_H #include +#else +#define DBL_MAX 1.7976931348623159e+308 +#define DBL_MIN 2.2250738585072010e-308 +#endif + +#if STDC_HEADERS #include #include #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 -#if !__STDC__ -#define const -#endif - /* Convert NPTR to a double. If ENDPTR is not NULL, a pointer to the character after the last one used in the number is put in *ENDPTR. */ double diff --git a/old/sh-utils/NEWS b/old/sh-utils/NEWS index f9a42b689..2b3e26cc8 100644 --- a/old/sh-utils/NEWS +++ b/old/sh-utils/NEWS @@ -1,3 +1,6 @@ +User visible changes in release 1.10 +* date accepts new format: %s time in seconds since 00:00:00 1/1/1971 +* date -d can parse dates like `11-JUL-1991' User visible changes in release 1.9.2: * who output is better formatted on Solaris and other SysVr4 systems * fix a minor problem in formatting the output from `stty -a' diff --git a/src/date.c b/src/date.c index 08998b2e1..b6159f209 100644 --- a/src/date.c +++ b/src/date.c @@ -64,7 +64,6 @@ #endif #ifndef STDC_HEADERS -time_t mktime (); size_t strftime (); time_t time (); #endif @@ -269,6 +268,7 @@ FORMAT controls the output. Interpreted sequences are:\n\ %%n a newline\n\ %%p locale's AM or PM\n\ %%r time, 12-hour (hh:mm:ss [AP]M)\n\ + %%s seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension)\n\ %%t a horizontal tab\n\ %%w day of week (0..6)\n\ %%x locale's date representation (mm/dd/yy)\n\ diff --git a/src/expr.c b/src/expr.c index e5549140f..a3d42ff4c 100644 --- a/src/expr.c +++ b/src/expr.c @@ -316,6 +316,9 @@ toarith (v) case string: i = 0; cp = v->u.s; + /* Don't interpret the empty string as an integer. */ + if (*cp == 0) + return 0; neg = (*cp == '-'); if (neg) cp++; -- cgit v1.2.3-54-g00ecf