diff options
author | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2017-06-23 18:00:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-23 18:00:51 +0200 |
commit | 2b209348bd2a90afbe1782b0b321d99892b7002b (patch) | |
tree | 9979ef7b68148c7112d411b0a0b81c9f8bb5e78a /src | |
parent | 28d82c8f639d08eac17030dba47b3e02a9158167 (diff) | |
parent | 7354a74c654f1717d08a37c2b118141655974bc0 (diff) | |
download | irssi-2b209348bd2a90afbe1782b0b321d99892b7002b.zip |
Merge pull request #722 from dequis/back-to-the-future
parse_time_interval: Allow negative time in settings
Diffstat (limited to 'src')
-rw-r--r-- | src/core/misc.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/core/misc.c b/src/core/misc.c index 0f038cbb..ce49925b 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -781,24 +781,35 @@ int parse_uint(const char *nptr, char **endptr, int base, guint *number) return TRUE; } +static int parse_number_sign(const char *input, char **endptr, int *sign) +{ + int sign_ = 1; + + while (i_isspace(*input)) + input++; + + if (*input == '-') { + sign_ = -sign_; + input++; + } + + *sign = sign_; + *endptr = (char *) input; + return TRUE; +} + static int parse_time_interval_uint(const char *time, guint *msecs) { const char *desc; guint number; - int sign, len, ret, digits; + int len, ret, digits; *msecs = 0; /* max. return value is around 24 days */ - number = 0; sign = 1; ret = TRUE; digits = FALSE; + number = 0; ret = TRUE; digits = FALSE; while (i_isspace(*time)) time++; - if (*time == '-') { - sign = -sign; - time++; - while (i_isspace(*time)) - time++; - } for (;;) { if (i_isdigit(*time)) { char *endptr; @@ -828,7 +839,6 @@ static int parse_time_interval_uint(const char *time, guint *msecs) if (*time != '\0') return FALSE; *msecs += number * 1000; /* assume seconds */ - *msecs *= sign; return TRUE; } @@ -866,7 +876,6 @@ static int parse_time_interval_uint(const char *time, guint *msecs) digits = FALSE; } - *msecs *= sign; return ret; } @@ -960,15 +969,18 @@ int parse_size(const char *size, int *bytes) int parse_time_interval(const char *time, int *msecs) { guint msecs_; - int ret; + char *number; + int ret, sign; + + parse_number_sign(time, &number, &sign); - ret = parse_time_interval_uint(time, &msecs_); + ret = parse_time_interval_uint(number, &msecs_); if (msecs_ > (1U << 31)) { return FALSE; } - *msecs = msecs_; + *msecs = msecs_ * sign; return ret; } |