parse-date: use intmax_t where appropriate
Reported-by: Ruediger Meier <ruediger.meier@ga-group.nl> Influenced-by: gnulib 30784c4 Paul Eggert <eggert@cs.ucla.edu> Signed-off-by: J William Piggott <elseifthen@gmx.com>
This commit is contained in:
parent
36a5afd8e8
commit
960f98c97a
|
@ -133,7 +133,7 @@ static unsigned char to_uchar (char ch) { return ch; }
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int negative;
|
int negative;
|
||||||
long int value;
|
intmax_t value;
|
||||||
size_t digits;
|
size_t digits;
|
||||||
} textint;
|
} textint;
|
||||||
|
|
||||||
|
@ -151,11 +151,11 @@ enum { BILLION = 1000000000, LOG10_BILLION = 9 };
|
||||||
|
|
||||||
/* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
|
/* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
long int year;
|
intmax_t year;
|
||||||
long int month;
|
intmax_t month;
|
||||||
long int day;
|
intmax_t day;
|
||||||
long int hour;
|
intmax_t hour;
|
||||||
long int minutes;
|
intmax_t minutes;
|
||||||
time_t seconds;
|
time_t seconds;
|
||||||
long int ns;
|
long int ns;
|
||||||
} relative_time;
|
} relative_time;
|
||||||
|
@ -172,7 +172,7 @@ typedef struct {
|
||||||
const char *input;
|
const char *input;
|
||||||
|
|
||||||
/* N, if this is the Nth Tuesday. */
|
/* N, if this is the Nth Tuesday. */
|
||||||
long int day_ordinal;
|
intmax_t day_ordinal;
|
||||||
|
|
||||||
/* Day of week; Sunday is 0. */
|
/* Day of week; Sunday is 0. */
|
||||||
int day_number;
|
int day_number;
|
||||||
|
@ -188,10 +188,10 @@ typedef struct {
|
||||||
|
|
||||||
/* Gregorian year, month, day, hour, minutes, seconds, and ns. */
|
/* Gregorian year, month, day, hour, minutes, seconds, and ns. */
|
||||||
textint year;
|
textint year;
|
||||||
long int month;
|
intmax_t month;
|
||||||
long int day;
|
intmax_t day;
|
||||||
long int hour;
|
intmax_t hour;
|
||||||
long int minutes;
|
intmax_t minutes;
|
||||||
struct timespec seconds; /* includes nanoseconds */
|
struct timespec seconds; /* includes nanoseconds */
|
||||||
|
|
||||||
/* Relative year, month, day, hour, minutes, seconds, and ns. */
|
/* Relative year, month, day, hour, minutes, seconds, and ns. */
|
||||||
|
@ -218,7 +218,7 @@ typedef struct {
|
||||||
union YYSTYPE;
|
union YYSTYPE;
|
||||||
static int yylex (union YYSTYPE *, parser_control *);
|
static int yylex (union YYSTYPE *, parser_control *);
|
||||||
static int yyerror (parser_control const *, char const *);
|
static int yyerror (parser_control const *, char const *);
|
||||||
static long int time_zone_hhmm (parser_control *, textint, long int);
|
static long int time_zone_hhmm (parser_control *, textint, intmax_t);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract into *PC any date and time info from a string of digits
|
* Extract into *PC any date and time info from a string of digits
|
||||||
|
@ -271,7 +271,7 @@ static void apply_relative_time(parser_control *pc, relative_time rel,
|
||||||
|
|
||||||
/* Set PC-> hour, minutes, seconds and nanoseconds members from arguments. */
|
/* Set PC-> hour, minutes, seconds and nanoseconds members from arguments. */
|
||||||
static void
|
static void
|
||||||
set_hhmmss(parser_control *pc, long int hour, long int minutes,
|
set_hhmmss(parser_control *pc, intmax_t hour, intmax_t minutes,
|
||||||
time_t sec, long int nsec)
|
time_t sec, long int nsec)
|
||||||
{
|
{
|
||||||
pc->hour = hour;
|
pc->hour = hour;
|
||||||
|
@ -294,7 +294,7 @@ set_hhmmss(parser_control *pc, long int hour, long int minutes,
|
||||||
%expect 31
|
%expect 31
|
||||||
|
|
||||||
%union {
|
%union {
|
||||||
long int intval;
|
intmax_t intval;
|
||||||
textint textintval;
|
textint textintval;
|
||||||
struct timespec timespec;
|
struct timespec timespec;
|
||||||
relative_time rel;
|
relative_time rel;
|
||||||
|
@ -870,9 +870,9 @@ static table const military_table[] = {
|
||||||
* minutes specified.
|
* minutes specified.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static long int time_zone_hhmm(parser_control *pc, textint s, long int mm)
|
static long int time_zone_hhmm(parser_control *pc, textint s, intmax_t mm)
|
||||||
{
|
{
|
||||||
long int n_minutes;
|
intmax_t n_minutes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the length of S is 1 or 2 and no minutes are specified,
|
* If the length of S is 1 or 2 and no minutes are specified,
|
||||||
|
@ -897,7 +897,7 @@ static long int time_zone_hhmm(parser_control *pc, textint s, long int mm)
|
||||||
return n_minutes;
|
return n_minutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int to_hour(long int hours, int meridian)
|
static int to_hour(intmax_t hours, int meridian)
|
||||||
{
|
{
|
||||||
switch (meridian) {
|
switch (meridian) {
|
||||||
default: /* Pacify GCC. */
|
default: /* Pacify GCC. */
|
||||||
|
@ -912,7 +912,7 @@ static int to_hour(long int hours, int meridian)
|
||||||
|
|
||||||
static long int to_year(textint textyear)
|
static long int to_year(textint textyear)
|
||||||
{
|
{
|
||||||
long int year = textyear.value;
|
intmax_t year = textyear.value;
|
||||||
|
|
||||||
if (year < 0)
|
if (year < 0)
|
||||||
year = -year;
|
year = -year;
|
||||||
|
@ -1265,7 +1265,7 @@ int parse_date(struct timespec *result, char const *p,
|
||||||
struct timespec const *now)
|
struct timespec const *now)
|
||||||
{
|
{
|
||||||
time_t Start;
|
time_t Start;
|
||||||
long int Start_ns;
|
intmax_t Start_ns;
|
||||||
struct tm const *tmp;
|
struct tm const *tmp;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
struct tm tm0;
|
struct tm tm0;
|
||||||
|
@ -1501,12 +1501,12 @@ int parse_date(struct timespec *result, char const *p,
|
||||||
* TZ="XXX1:00" and try mktime again.
|
* TZ="XXX1:00" and try mktime again.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
long int time_zone = pc.time_zone;
|
intmax_t time_zone = pc.time_zone;
|
||||||
|
|
||||||
long int abs_time_zone = time_zone < 0
|
intmax_t abs_time_zone = time_zone < 0
|
||||||
? - time_zone : time_zone;
|
? - time_zone : time_zone;
|
||||||
|
|
||||||
long int abs_time_zone_hour
|
intmax_t abs_time_zone_hour
|
||||||
= abs_time_zone / 60;
|
= abs_time_zone / 60;
|
||||||
|
|
||||||
int abs_time_zone_min = abs_time_zone % 60;
|
int abs_time_zone_min = abs_time_zone % 60;
|
||||||
|
@ -1572,7 +1572,7 @@ int parse_date(struct timespec *result, char const *p,
|
||||||
* so this block must follow others that clobber Start.
|
* so this block must follow others that clobber Start.
|
||||||
*/
|
*/
|
||||||
if (pc.zones_seen) {
|
if (pc.zones_seen) {
|
||||||
long int delta = pc.time_zone * 60;
|
intmax_t delta = pc.time_zone * 60;
|
||||||
time_t t1;
|
time_t t1;
|
||||||
#ifdef HAVE_TM_GMTOFF
|
#ifdef HAVE_TM_GMTOFF
|
||||||
delta -= tm.tm_gmtoff;
|
delta -= tm.tm_gmtoff;
|
||||||
|
@ -1600,16 +1600,16 @@ int parse_date(struct timespec *result, char const *p,
|
||||||
* zone indicator must be applied before relative times, and if
|
* zone indicator must be applied before relative times, and if
|
||||||
* mktime is applied again the time zone will be lost.
|
* mktime is applied again the time zone will be lost.
|
||||||
*/
|
*/
|
||||||
long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns;
|
intmax_t sum_ns = pc.seconds.tv_nsec + pc.rel.ns;
|
||||||
long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION;
|
intmax_t normalized_ns = (sum_ns % BILLION + BILLION) % BILLION;
|
||||||
time_t t0 = Start;
|
time_t t0 = Start;
|
||||||
long int d1 = 60 * 60 * pc.rel.hour;
|
intmax_t d1 = 60 * 60 * pc.rel.hour;
|
||||||
time_t t1 = t0 + d1;
|
time_t t1 = t0 + d1;
|
||||||
long int d2 = 60 * pc.rel.minutes;
|
intmax_t d2 = 60 * pc.rel.minutes;
|
||||||
time_t t2 = t1 + d2;
|
time_t t2 = t1 + d2;
|
||||||
time_t d3 = pc.rel.seconds;
|
time_t d3 = pc.rel.seconds;
|
||||||
time_t t3 = t2 + d3;
|
time_t t3 = t2 + d3;
|
||||||
long int d4 = (sum_ns - normalized_ns) / BILLION;
|
intmax_t d4 = (sum_ns - normalized_ns) / BILLION;
|
||||||
time_t t4 = t3 + d4;
|
time_t t4 = t3 + d4;
|
||||||
time_t t5 = t4;
|
time_t t5 = t4;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue