#include <inttypes.h>
#include <c-ctype.h>
#include <stdarg.h>
+#include <stdckdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
apply_relative_time (parser_control *pc, relative_time rel, int factor)
{
if (factor < 0
- ? (INT_SUBTRACT_WRAPV (pc->rel.ns, rel.ns, &pc->rel.ns)
- | INT_SUBTRACT_WRAPV (pc->rel.seconds, rel.seconds, &pc->rel.seconds)
- | INT_SUBTRACT_WRAPV (pc->rel.minutes, rel.minutes, &pc->rel.minutes)
- | INT_SUBTRACT_WRAPV (pc->rel.hour, rel.hour, &pc->rel.hour)
- | INT_SUBTRACT_WRAPV (pc->rel.day, rel.day, &pc->rel.day)
- | INT_SUBTRACT_WRAPV (pc->rel.month, rel.month, &pc->rel.month)
- | INT_SUBTRACT_WRAPV (pc->rel.year, rel.year, &pc->rel.year))
- : (INT_ADD_WRAPV (pc->rel.ns, rel.ns, &pc->rel.ns)
- | INT_ADD_WRAPV (pc->rel.seconds, rel.seconds, &pc->rel.seconds)
- | INT_ADD_WRAPV (pc->rel.minutes, rel.minutes, &pc->rel.minutes)
- | INT_ADD_WRAPV (pc->rel.hour, rel.hour, &pc->rel.hour)
- | INT_ADD_WRAPV (pc->rel.day, rel.day, &pc->rel.day)
- | INT_ADD_WRAPV (pc->rel.month, rel.month, &pc->rel.month)
- | INT_ADD_WRAPV (pc->rel.year, rel.year, &pc->rel.year)))
+ ? (ckd_sub (&pc->rel.ns, pc->rel.ns, rel.ns)
+ | ckd_sub (&pc->rel.seconds, pc->rel.seconds, rel.seconds)
+ | ckd_sub (&pc->rel.minutes, pc->rel.minutes, rel.minutes)
+ | ckd_sub (&pc->rel.hour, pc->rel.hour, rel.hour)
+ | ckd_sub (&pc->rel.day, pc->rel.day, rel.day)
+ | ckd_sub (&pc->rel.month, pc->rel.month, rel.month)
+ | ckd_sub (&pc->rel.year, pc->rel.year, rel.year))
+ : (ckd_add (&pc->rel.ns, pc->rel.ns, rel.ns)
+ | ckd_add (&pc->rel.seconds, pc->rel.seconds, rel.seconds)
+ | ckd_add (&pc->rel.minutes, pc->rel.minutes, rel.minutes)
+ | ckd_add (&pc->rel.hour, pc->rel.hour, rel.hour)
+ | ckd_add (&pc->rel.day, pc->rel.day, rel.day)
+ | ckd_add (&pc->rel.month, pc->rel.month, rel.month)
+ | ckd_add (&pc->rel.year, pc->rel.year, rel.year)))
return false;
pc->rels_seen = true;
return true;
}
| tZONE tSNUMBER o_colon_minutes
{ if (! time_zone_hhmm (pc, $2, $3)) YYABORT;
- if (INT_ADD_WRAPV (pc->time_zone, $1, &pc->time_zone)) YYABORT; }
+ if (ckd_add (&pc->time_zone, pc->time_zone, $1)) YYABORT; }
| tDAYZONE
{ pc->time_zone = $1 + 60 * 60; }
| tZONE tDST
/* E.g., 17-JUN-1992. */
pc->day = $1.value;
pc->month = $2;
- if (INT_SUBTRACT_WRAPV (0, $3.value, &pc->year.value)) YYABORT;
+ if (ckd_sub (&pc->year.value, 0, $3.value)) YYABORT;
pc->year.digits = $3.digits;
}
| tMONTH tSNUMBER tSNUMBER
{
/* E.g., JUN-17-1992. */
pc->month = $1;
- if (INT_SUBTRACT_WRAPV (0, $2.value, &pc->day)) YYABORT;
- if (INT_SUBTRACT_WRAPV (0, $3.value, &pc->year.value)) YYABORT;
+ if (ckd_sub (&pc->day, 0, $2.value)) YYABORT;
+ if (ckd_sub (&pc->year.value, 0, $3.value)) YYABORT;
pc->year.digits = $3.digits;
}
| tMONTH tUNUMBER
{
/* ISO 8601 format. YYYY-MM-DD. */
pc->year = $1;
- if (INT_SUBTRACT_WRAPV (0, $2.value, &pc->month)) YYABORT;
- if (INT_SUBTRACT_WRAPV (0, $3.value, &pc->day)) YYABORT;
+ if (ckd_sub (&pc->month, 0, $2.value)) YYABORT;
+ if (ckd_sub (&pc->day, 0, $3.value)) YYABORT;
}
;
{ $$ = RELATIVE_TIME_0; $$.month = 1; }
| tORDINAL tDAY_UNIT
{ $$ = RELATIVE_TIME_0;
- if (INT_MULTIPLY_WRAPV ($1, $2, &$$.day)) YYABORT; }
+ if (ckd_mul (&$$.day, $1, $2)) YYABORT; }
| tUNUMBER tDAY_UNIT
{ $$ = RELATIVE_TIME_0;
- if (INT_MULTIPLY_WRAPV ($1.value, $2, &$$.day)) YYABORT; }
+ if (ckd_mul (&$$.day, $1.value, $2)) YYABORT; }
| tDAY_UNIT
{ $$ = RELATIVE_TIME_0; $$.day = $1; }
| tORDINAL tHOUR_UNIT
{ $$ = RELATIVE_TIME_0; $$.month = $1.value; }
| tSNUMBER tDAY_UNIT
{ $$ = RELATIVE_TIME_0;
- if (INT_MULTIPLY_WRAPV ($1.value, $2, &$$.day)) YYABORT; }
+ if (ckd_mul (&$$.day, $1.value, $2)) YYABORT; }
| tSNUMBER tHOUR_UNIT
{ $$ = RELATIVE_TIME_0; $$.hour = $1.value; }
| tSNUMBER tMINUTE_UNIT
n_minutes = (s.value / 100) * 60 + s.value % 100;
else
{
- overflow |= INT_MULTIPLY_WRAPV (s.value, 60, &n_minutes);
+ overflow |= ckd_mul (&n_minutes, s.value, 60);
overflow |= (s.negative
- ? INT_SUBTRACT_WRAPV (n_minutes, mm, &n_minutes)
- : INT_ADD_WRAPV (n_minutes, mm, &n_minutes));
+ ? ckd_sub (&n_minutes, n_minutes, mm)
+ : ckd_add (&n_minutes, n_minutes, mm));
}
if (overflow || ! (-24 * 60 <= n_minutes && n_minutes <= 24 * 60))
}
if (year < 0
- ? INT_SUBTRACT_WRAPV (-TM_YEAR_BASE, year, tm_year)
- : INT_SUBTRACT_WRAPV (year, TM_YEAR_BASE, tm_year))
+ ? ckd_sub (tm_year, -TM_YEAR_BASE, year)
+ : ckd_sub (tm_year, year, TM_YEAR_BASE))
{
if (debug)
dbg_printf (_("error: out-of-range year %"PRIdMAX"\n"), year);
time_t value = 0;
do
{
- if (INT_MULTIPLY_WRAPV (value, 10, &value))
+ if (ckd_mul (&value, value, 10))
return '?';
- if (INT_ADD_WRAPV (value, sign < 0 ? '0' - c : c - '0', &value))
+ if (ckd_add (&value, value, sign < 0 ? '0' - c : c - '0'))
return '?';
c = *++p;
}
negative. */
if (sign < 0 && ns)
{
- if (INT_SUBTRACT_WRAPV (s, 1, &s))
+ if (ckd_sub (&s, s, 1))
return '?';
ns = BILLION - ns;
}
#ifdef GNULIB_PARSE_DATETIME2
pc.parse_datetime_debug = (flags & PARSE_DATETIME_DEBUG) != 0;
#endif
- if (INT_ADD_WRAPV (tmp.tm_year, TM_YEAR_BASE, &pc.year.value))
+ if (ckd_add (&pc.year.value, tmp.tm_year, TM_YEAR_BASE))
{
if (debugging (&pc))
dbg_printf (_("error: initial year out of range\n"));
for (quarter = 1; quarter <= 3; quarter++)
{
time_t probe;
- if (INT_ADD_WRAPV (Start, quarter * (90 * 24 * 60 * 60), &probe))
+ if (ckd_add (&probe, Start, quarter * (90 * 24 * 60 * 60)))
break;
struct tm probe_tm;
if (localtime_rz (tz, &probe, &probe_tm) && probe_tm.tm_zone
}
if (! to_tm_year (pc.year, debugging (&pc), &tm.tm_year)
- || INT_ADD_WRAPV (pc.month, -1, &tm.tm_mon)
- || INT_ADD_WRAPV (pc.day, 0, &tm.tm_mday))
+ || ckd_add (&tm.tm_mon, pc.month, -1)
+ || ckd_add (&tm.tm_mday, pc.day, 0))
{
if (debugging (&pc))
dbg_printf (_("error: year, month, or day overflow\n"));
{
intmax_t dayincr;
tm.tm_yday = -1;
- if (! (INT_MULTIPLY_WRAPV ((pc.day_ordinal
- - (0 < pc.day_ordinal
- && tm.tm_wday != pc.day_number)),
- 7, &dayincr)
- || INT_ADD_WRAPV ((pc.day_number - tm.tm_wday + 7) % 7,
- dayincr, &dayincr)
- || INT_ADD_WRAPV (dayincr, tm.tm_mday, &tm.tm_mday)))
+ intmax_t day_ordinal = (pc.day_ordinal
+ - (0 < pc.day_ordinal
+ && tm.tm_wday != pc.day_number));
+ if (! (ckd_mul (&dayincr, day_ordinal, 7)
+ || ckd_add (&dayincr, (pc.day_number - tm.tm_wday + 7) % 7,
+ dayincr)
+ || ckd_add (&tm.tm_mday, dayincr, tm.tm_mday)))
{
tm.tm_isdst = -1;
Start = mktime_z (tz, &tm);
}
int year, month, day;
- if (INT_ADD_WRAPV (tm.tm_year, pc.rel.year, &year)
- || INT_ADD_WRAPV (tm.tm_mon, pc.rel.month, &month)
- || INT_ADD_WRAPV (tm.tm_mday, pc.rel.day, &day))
+ if (ckd_add (&year, tm.tm_year, pc.rel.year)
+ || ckd_add (&month, tm.tm_mon, pc.rel.month)
+ || ckd_add (&day, tm.tm_mday, pc.rel.day))
{
if (debugging (&pc))
dbg_printf (_("error: %s:%d\n"), __FILE__, __LINE__);
: (overflow = true, 0));
#endif
intmax_t delta;
- overflow |= INT_SUBTRACT_WRAPV (pc.time_zone, utcoff, &delta);
+ overflow |= ckd_sub (&delta, pc.time_zone, utcoff);
time_t t1;
- overflow |= INT_SUBTRACT_WRAPV (Start, delta, &t1);
+ overflow |= ckd_sub (&t1, Start, delta);
if (overflow)
{
if (debugging (&pc))
int d4 = (sum_ns - normalized_ns) / BILLION;
intmax_t d1, t1, d2, t2, t3;
time_t t4;
- if (INT_MULTIPLY_WRAPV (pc.rel.hour, 60 * 60, &d1)
- || INT_ADD_WRAPV (Start, d1, &t1)
- || INT_MULTIPLY_WRAPV (pc.rel.minutes, 60, &d2)
- || INT_ADD_WRAPV (t1, d2, &t2)
- || INT_ADD_WRAPV (t2, pc.rel.seconds, &t3)
- || INT_ADD_WRAPV (t3, d4, &t4))
+ if (ckd_mul (&d1, pc.rel.hour, 60 * 60)
+ || ckd_add (&t1, Start, d1)
+ || ckd_mul (&d2, pc.rel.minutes, 60)
+ || ckd_add (&t2, t1, d2)
+ || ckd_add (&t3, t2, pc.rel.seconds)
+ || ckd_add (&t4, t3, d4))
{
if (debugging (&pc))
dbg_printf (_("error: adding relative time caused an "