X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgetdate.y;h=3159c6d9a0d73547dc5d557f2001092b746aedb9;hb=refs%2Ftags%2Fss-940725-22h45;hp=cdc2b5565dbd13e45fbd89fd4fcd2f29a99ae538;hpb=65eb90523786b69dc0a52b2dfcf1b0f2822f25ab;p=gnulib.git diff --git a/lib/getdate.y b/lib/getdate.y index cdc2b5565..3159c6d9a 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -6,16 +6,20 @@ ** and Jim Berets 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 +#if defined (emacs) || defined (CONFIG_BROKETS) +#include +#else #include "config.h" #endif +#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 @@ -27,21 +31,6 @@ #undef static #endif -#ifdef __GNUC__ -#undef alloca -#define alloca __builtin_alloca -#else -#ifdef HAVE_ALLOCA_H -#include -#else -#ifdef _AIX /* for Bison */ - #pragma alloca -#else -char *alloca (); -#endif -#endif -#endif - #include #include @@ -74,7 +63,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 #else /* @@ -113,12 +102,6 @@ extern struct tm *localtime(); static int yylex (); static int yyerror (); -#if !defined(lint) && !defined(SABER) -static char RCS[] = - "$Header: str2date.y,v 2.1 90/09/06 08:15:06 cronan Exp $"; -#endif /* !defined(lint) && !defined(SABER) */ - - #define EPOCH 1970 #define HOUR(x) ((time_t)(x) * 60) #define SECSPERDAY (24L * 60L * 60L) @@ -292,6 +275,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; @@ -353,25 +342,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; + } } } ; @@ -604,6 +592,8 @@ ToSeconds(Hours, Minutes, Seconds, Meridian) if (Hours < 1 || Hours > 12) return -1; return ((Hours + 12) * 60L + Minutes) * 60L + Seconds; + default: + abort (); } /* NOTREACHED */ } @@ -867,31 +857,28 @@ yylex() } } - #define TM_YEAR_ORIGIN 1900 /* Yield A - B, measured in seconds. */ -static time_t -difftm(a, b) +static long +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); + int days = ( + /* 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 */ + + (long)(ay-by) * 365 + ); + return (60*(60*(24*days + (a->tm_hour - b->tm_hour)) + + (a->tm_min - b->tm_min)) + + (a->tm_sec - b->tm_sec)); } time_t @@ -912,7 +899,13 @@ get_date(p, now) 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; + + if (! (tm = localtime (&ftz.time))) + return -1; + + ftz.timezone = difftm (&gmt, tm) / 60; + if(tm->tm_isdst) + ftz.timezone += 60; } tm = localtime(&now->time); @@ -966,6 +959,7 @@ get_date(p, now) #if defined(TEST) /* ARGSUSED */ +int main(ac, av) int ac; char *av[];