src/utils.c: Get rid of "semantic range checks" when parsing duration

Don't restrict ranges when entering durations. We now accept duration
like "+1d42h600m". This might not seem very logical, but it's
perfectly valid, and being able to enter "+36h" is useful when you
don't want to do the maths yourself.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Baptiste Jonglez 2012-05-02 16:19:30 +02:00 committed by Lukas Fleischer
parent 6fd0ae2ea7
commit 0a352fe519

View File

@ -729,9 +729,6 @@ parse_time (const char *string, unsigned *hour, unsigned *minute)
* *
* "\d" is used as a placeholder for "(0|1|2|3|4|5|6|7|8|9)". * "\d" is used as a placeholder for "(0|1|2|3|4|5|6|7|8|9)".
* *
* Note that this function performs an additional range check on each token to
* ensure we do not accept semantically invalid strings such as "42:23".
*
* Returns 1 on success and 0 on failure. * Returns 1 on success and 0 on failure.
*/ */
int int
@ -779,15 +776,11 @@ parse_duration (const char *string, unsigned *duration)
} }
else if (*p == 'h') else if (*p == 'h')
{ {
if (in >= DAYINHOURS)
return 0;
dur += in * HOURINMIN; dur += in * HOURINMIN;
state = STATE_DDHHMM_MM; state = STATE_DDHHMM_MM;
} }
else if (*p == 'm') else if (*p == 'm')
{ {
if (in >= HOURINMIN)
return 0;
dur += in; dur += in;
state = STATE_DONE; state = STATE_DONE;
} }
@ -797,15 +790,11 @@ parse_duration (const char *string, unsigned *duration)
case STATE_DDHHMM_HH: case STATE_DDHHMM_HH:
if (*p == 'h') if (*p == 'h')
{ {
if (in >= DAYINHOURS)
return 0;
dur += in * HOURINMIN; dur += in * HOURINMIN;
state = STATE_DDHHMM_MM; state = STATE_DDHHMM_MM;
} }
else if (*p == 'm') else if (*p == 'm')
{ {
if (in >= HOURINMIN)
return 0;
dur += in; dur += in;
state = STATE_DONE; state = STATE_DONE;
} }
@ -815,8 +804,6 @@ parse_duration (const char *string, unsigned *duration)
case STATE_DDHHMM_MM: case STATE_DDHHMM_MM:
if (*p == 'm') if (*p == 'm')
{ {
if (in >= HOURINMIN)
return 0;
dur += in; dur += in;
state = STATE_DONE; state = STATE_DONE;
} }