%{
/* Parse a string into an internal time stamp.
- Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
of `digit' even when the host does not conform to POSIX. */
#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
-#ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
-# define __attribute__(x)
-# endif
-#endif
-
-#ifndef ATTRIBUTE_UNUSED
-# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
-#endif
-
/* Shift A right by B bits portably, by dividing A by 2**B and
truncating towards minus infinity. A and B should be free of side
effects, and B should be in the range 0 <= B <= INT_BITS - 2, where
#define HOUR(x) ((x) * 60)
-/* Lots of this code assumes time_t and time_t-like values fit into
- long int. It also assumes that signed integer overflow silently
- wraps around, but there's no portable way to check for that at
- compile-time. */
+/* long_time_t is a signed integer type that contains all time_t values. */
verify (TYPE_IS_INTEGER (time_t));
-verify (LONG_MIN <= TYPE_MINIMUM (time_t) && TYPE_MAXIMUM (time_t) <= LONG_MAX);
+#if TIME_T_FITS_IN_LONG_INT
+typedef long int long_time_t;
+#else
+typedef time_t long_time_t;
+#endif
+
+/* Lots of this code assumes time_t and time_t-like values fit into
+ long_time_t. */
+verify (TYPE_MINIMUM (long_time_t) <= TYPE_MINIMUM (time_t)
+ && TYPE_MAXIMUM (time_t) <= TYPE_MAXIMUM (long_time_t));
+
+/* FIXME: It also assumes that signed integer overflow silently wraps around,
+ but this is not true any more with recent versions of GCC 4. */
/* An integer value, and the number of digits in its textual
representation. */
long int day;
long int hour;
long int minutes;
- long int seconds;
+ long_time_t seconds;
long int ns;
} relative_time;
day:
tDAY
{
- pc->day_ordinal = 1;
+ pc->day_ordinal = 0;
pc->day_number = $1;
}
| tDAY ','
{
- pc->day_ordinal = 1;
+ pc->day_ordinal = 0;
pc->day_number = $1;
}
| tORDINAL tDAY
/* Do nothing if the parser reports an error. */
static int
-yyerror (parser_control const *pc ATTRIBUTE_UNUSED,
- char const *s ATTRIBUTE_UNUSED)
+yyerror (parser_control const *pc _UNUSED_PARAMETER_,
+ char const *s _UNUSED_PARAMETER_)
{
return 0;
}
if (pc.days_seen && ! pc.dates_seen)
{
tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
- + 7 * (pc.day_ordinal - (0 < pc.day_ordinal)));
+ + 7 * (pc.day_ordinal
+ - (0 < pc.day_ordinal
+ && tm.tm_wday != pc.day_number)));
tm.tm_isdst = -1;
Start = mktime (&tm);
if (Start == (time_t) -1)
time_t t1 = t0 + d1;
long int d2 = 60 * pc.rel.minutes;
time_t t2 = t1 + d2;
- long int d3 = pc.rel.seconds;
- time_t t3 = t2 + d3;
+ long_time_t d3 = pc.rel.seconds;
+ long_time_t t3 = t2 + d3;
long int d4 = (sum_ns - normalized_ns) / BILLION;
- time_t t4 = t3 + d4;
+ long_time_t t4 = t3 + d4;
+ time_t t5 = t4;
if ((d1 / (60 * 60) ^ pc.rel.hour)
| (d2 / 60 ^ pc.rel.minutes)
| ((t1 < t0) ^ (d1 < 0))
| ((t2 < t1) ^ (d2 < 0))
| ((t3 < t2) ^ (d3 < 0))
- | ((t4 < t3) ^ (d4 < 0)))
+ | ((t4 < t3) ^ (d4 < 0))
+ | (t5 != t4))
goto fail;
- result->tv_sec = t4;
+ result->tv_sec = t5;
result->tv_nsec = normalized_ns;
}
}