summaryrefslogtreecommitdiffstats
path: root/m_option.c
diff options
context:
space:
mode:
authorcigaes <cigaes@b3059339-0415-0410-9bf9-f77b7e298cf2>2010-10-18 20:56:52 +0000
committerUoti Urpala <uau@glyph.nonexistent.invalid>2010-11-02 04:18:38 +0200
commitbc347d88cc914590d497161ee4698876b79f9273 (patch)
tree06f37850c7b423eb056e227a552f12a1e10f52da /m_option.c
parentce9fcc0730882e7f8d669e1b1bd7efbdfc998246 (diff)
downloadmpv-bc347d88cc914590d497161ee4698876b79f9273.tar.bz2
mpv-bc347d88cc914590d497161ee4698876b79f9273.tar.xz
options: modify parse_timestring(), make public
Make the parse_timestring public, with a slightly extended API. As a consequence, "2 hours" is no longer recognized as a valid timestamp meaning "2 seconds". git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32514 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'm_option.c')
-rw-r--r--m_option.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/m_option.c b/m_option.c
index b1b37ffc87..6e814bf8b5 100644
--- a/m_option.c
+++ b/m_option.c
@@ -1285,17 +1285,22 @@ const m_option_type_t m_option_type_afmt = {
};
-static double parse_timestring(const char *str)
+int parse_timestring(const char *str, double *time, char endchar)
{
- int a, b;
+ int a, b, len;
double d;
- if (sscanf(str, "%d:%d:%lf", &a, &b, &d) == 3)
- return 3600*a + 60*b + d;
- else if (sscanf(str, "%d:%lf", &a, &d) == 2)
- return 60*a + d;
- else if (sscanf(str, "%lf", &d) == 1)
- return d;
- return -1e100;
+ *time = 0; /* ensure initialization for error cases */
+ if (sscanf(str, "%d:%d:%lf%n", &a, &b, &d, &len) >= 3)
+ *time = 3600*a + 60*b + d;
+ else if (sscanf(str, "%d:%lf%n", &a, &d, &len) >= 2)
+ *time = 60*a + d;
+ else if (sscanf(str, "%lf%n", &d, &len) >= 1)
+ *time = d;
+ else
+ return 0; /* unsupported time format */
+ if (str[len] && str[len] != endchar)
+ return 0; /* invalid extra characters at the end */
+ return len;
}
@@ -1306,8 +1311,7 @@ static int parse_time(const m_option_t* opt,const char *name, const char *param,
if (param == NULL || strlen(param) == 0)
return M_OPT_MISSING_PARAM;
- time = parse_timestring(param);
- if (time == -1e100) {
+ if (!parse_timestring(param, &time, 0)) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: invalid time: '%s'\n",
name,param);
return M_OPT_INVALID;
@@ -1365,7 +1369,7 @@ static int parse_time_size(const m_option_t* opt,const char *name, const char *p
/* End at time parsing. This has to be last because the parsing accepts
* even a number followed by garbage */
- if ((end_at = parse_timestring(param)) == -1e100) {
+ if (!parse_timestring(param, &end_at, 0)) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: invalid time or size: '%s'\n",
name,param);
return M_OPT_INVALID;