summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-09-08 18:23:12 +0000
committerJim Meyering <jim@meyering.net>1993-09-08 18:23:12 +0000
commitae0074289cd7d70cf8fb1d96f2625b2b9bb62b29 (patch)
treed5eab2eede21baf91b94efaf06e0df67cca78887 /lib
parent219bbb0758350d94610e967f31b5f9fdb0728354 (diff)
downloadcoreutils-ae0074289cd7d70cf8fb1d96f2625b2b9bb62b29.tar.xz
merge with 1.8.1 + partial --version and --help
Diffstat (limited to 'lib')
-rw-r--r--lib/getdate.y117
-rw-r--r--lib/putenv.c21
-rw-r--r--lib/strftime.c4
3 files changed, 83 insertions, 59 deletions
diff --git a/lib/getdate.y b/lib/getdate.y
index 4d2af5c5e..cdc2b5565 100644
--- a/lib/getdate.y
+++ b/lib/getdate.y
@@ -1,6 +1,5 @@
%{
-/* $Revision: 1.2 $
-**
+/*
** Originally written by Steven M. Bellovin <smb@research.att.com> while
** at the University of North Carolina at Chapel Hill. Later tweaked by
** a couple of people on Usenet. Completely overhauled by Rich $alz
@@ -18,7 +17,18 @@
#include "config.h"
#endif
+/* Since the code of getdate.y is not included in the Emacs executable
+ itself, there is no need to #define static in this file. Even if
+ the code were included in the Emacs executable, it probably
+ wouldn't do any harm to #undef it here; this will only cause
+ problems if we try to write to a static variable, which I don't
+ think this code needs to do. */
+#ifdef emacs
+#undef static
+#endif
+
#ifdef __GNUC__
+#undef alloca
#define alloca __builtin_alloca
#else
#ifdef HAVE_ALLOCA_H
@@ -49,33 +59,36 @@ char *alloca ();
#include <sys/types.h>
-#if sgi
-#undef timezone
-#endif
-
-#if !(defined (USG) || defined (sgi) || defined (__386BSD__)) || defined(BSD4_2) || defined(BSD4_1C) || (defined (hp9000) && !defined (hpux)) || defined(_AIX)
+#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
+#endif
-#if defined(USG) || !defined(HAVE_FTIME)
+#ifdef timezone
+#undef timezone /* needed for sgi */
+#endif
+
+#if defined(HAVE_SYS_TIMEB_H) || (!defined(USG) && defined(HAVE_FTIME))
+#include <sys/timeb.h>
+#else
/*
-** If you need to do a tzset() call to set the
-** timezone, and don't have ftime().
+** We use the obsolete `struct timeb' as part of our interface!
+** Since the system doesn't have it, we define it here;
+** our callers must do likewise.
*/
struct timeb {
time_t time; /* Seconds since the epoch */
unsigned short millitm; /* Field not used */
- short timezone;
+ short timezone; /* Minutes west of GMT */
short dstflag; /* Field not used */
};
-
-#else
-
-#include <sys/timeb.h>
-
-#endif /* defined(USG) && !defined(HAVE_FTIME) */
+#endif /* defined(HAVE_SYS_TIMEB_H) */
#endif /* defined(vms) */
@@ -83,6 +96,14 @@ struct timeb {
#include <string.h>
#endif
+/* Some old versions of bison generate parsers that use bcopy.
+ That loses on systems that don't provide the function, so we have
+ to redefine it here. */
+#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
+#define bcopy(from, to, len) memcpy ((to), (from), (len))
+#endif
+
+extern struct tm *gmtime();
extern struct tm *localtime();
#define yyparse getdate_yyparse
@@ -94,7 +115,7 @@ static int yyerror ();
#if !defined(lint) && !defined(SABER)
static char RCS[] =
- "$Header: /w/src/cvsroot/fileutils/lib/getdate.y,v 1.2 1993/04/04 15:21:49 meyering Exp $";
+ "$Header: str2date.y,v 2.1 90/09/06 08:15:06 cronan Exp $";
#endif /* !defined(lint) && !defined(SABER) */
@@ -847,12 +868,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;
+ struct tm *tm, gmt;
struct timeb ftz;
time_t Start;
time_t tod;
@@ -860,34 +907,12 @@ get_date(p, now)
yyInput = p;
if (now == NULL) {
now = &ftz;
-#if !defined(HAVE_FTIME)
(void)time(&ftz.time);
- /* Set the timezone global. */
- tzset();
- {
-#if sgi
- ftz.timezone = (int) _timezone / 60;
-#else /* not sgi */
-#ifdef __386BSD__
- ftz.timezone = 0;
-#else /* neither sgi nor 386BSD */
-#if defined (USG)
- extern time_t timezone;
-
- ftz.timezone = (int) timezone / 60;
-#else /* neither sgi nor 386BSD nor USG */
- struct timeval tv;
- struct timezone tz;
-
- gettimeofday (&tv, &tz);
- ftz.timezone = (int) tz.tz_minuteswest;
-#endif /* neither sgi nor 386BSD nor USG */
-#endif /* neither sgi nor 386BSD */
-#endif /* not sgi */
- }
-#else /* HAVE_FTIME */
- (void)ftime(&ftz);
-#endif /* HAVE_FTIME */
+
+ 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;
}
tm = localtime(&now->time);
diff --git a/lib/putenv.c b/lib/putenv.c
index d1fb726f3..c39d1b71e 100644
--- a/lib/putenv.c
+++ b/lib/putenv.c
@@ -18,13 +18,20 @@ Cambridge, MA 02139, USA. */
#include <sys/types.h>
#include <errno.h>
-#ifdef STDC_HEADERS
+
+/* This needs to come after some library #include
+ to get __GNU_LIBRARY__ defined. */
+#ifdef __GNU_LIBRARY__
+/* Don't include stdlib.h for non-GNU C libraries because some of them
+ contain conflicting prototypes for getopt. */
#include <stdlib.h>
-#else
+#endif /* GNU C library. */
+
+#ifndef STDC_HEADERS
extern int errno;
#endif
-#if defined(STDC_HEADERS) || defined(USG)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#ifndef index
#define index strchr
@@ -32,9 +39,9 @@ extern int errno;
#ifndef bcopy
#define bcopy(s, d, n) memcpy((d), (s), (n))
#endif
-#else /* not (STDC_HEADERS or USG) */
+#else
#include <strings.h>
-#endif /* STDC_HEADERS or USG */
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -44,10 +51,6 @@ extern int errno;
#define NULL 0
#endif
-#if !__STDC__
-#define const
-#endif
-
extern char **environ;
/* Put STRING, which is of the form "NAME=VALUE", in the environment. */
diff --git a/lib/strftime.c b/lib/strftime.c
index b6695342a..a07571750 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -84,10 +84,6 @@
extern char *tzname[2];
#endif
-#if !__STDC__
-#define const
-#endif
-
/* Types of padding for numbers in date and time. */
enum padding
{