/* Parse a time duration and return a seconds count
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
Written by Bruce Korb <bkorb@gnu.org>, 2008.
This program is free software: you can redistribute it and/or modify
}
static time_t
-parse_non_iso8601(cch_t * pz)
+parse_non_iso8601 (cch_t * pz)
{
whats_done_t whatd_we_do = NOTHING_IS_DONE;
time_t
parse_duration (char const * pz)
{
- time_t res = 0;
-
while (isspace ((unsigned char)*pz))
pz++;
- do {
- if (*pz == 'P')
- {
- res = parse_period (pz + 1);
- if (res == BAD_TIME)
- break;
- return res;
- }
-
- if (*pz == 'T')
- {
- res = parse_time (pz + 1);
- if (res == BAD_TIME)
- break;
- return res;
- }
-
- if (! isdigit ((unsigned char)*pz))
- break;
+ switch (*pz)
+ {
+ case 'P':
+ return parse_period (pz + 1);
- res = parse_non_iso8601 (pz);
- if (res != BAD_TIME)
- return res;
+ case 'T':
+ return parse_time (pz + 1);
- } while (0);
+ default:
+ if (isdigit ((unsigned char)*pz))
+ return parse_non_iso8601 (pz);
- return BAD_TIME;
+ errno = EINVAL;
+ return BAD_TIME;
+ }
}
/*