summaryrefslogtreecommitdiffstats
path: root/m_option.c
diff options
context:
space:
mode:
Diffstat (limited to 'm_option.c')
-rw-r--r--m_option.c56
1 files changed, 47 insertions, 9 deletions
diff --git a/m_option.c b/m_option.c
index f403fd684e..36e538f6f3 100644
--- a/m_option.c
+++ b/m_option.c
@@ -221,6 +221,52 @@ const m_option_type_t m_option_type_int64 = {
NULL
};
+static int parse_intpair(const struct m_option *opt, const char *name,
+ const char *param, void *dst, int src)
+{
+ if (param == NULL)
+ return M_OPT_MISSING_PARAM;
+
+ char *s = (char *)param;
+ int start = -1;
+ int end = -1;
+ if (*s) {
+ start = strtol(s, &s, 10);
+ if (s == param)
+ goto bad;
+ }
+ if (*s) {
+ if (*s != '-')
+ goto bad;
+ s++;
+ }
+ if (*s)
+ end = strtol(s, &s, 10);
+ if (*s)
+ goto bad;
+
+ if (dst) {
+ int *p = dst;
+ p[0] = start;
+ p[1] = end;
+ }
+
+ return 1;
+
+ bad:
+ mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid integer range "
+ "specification for option %s: %s\n", name, param);
+ return M_OPT_INVALID;
+}
+
+const struct m_option_type m_option_type_intpair = {
+ .name = "Int[-Int]",
+ .size = sizeof(int[2]),
+ .parse = parse_intpair,
+ .save = copy_opt,
+ .set = copy_opt,
+};
+
// Float
#undef VAL
@@ -798,8 +844,6 @@ static void set_func_param(const m_option_t* opt, void* dst, const void* src) {
if(!s) return;
- // Revert if needed
- if(opt->priv) ((m_opt_default_func_t)opt->priv)(opt,opt->name);
for( ; s != NULL ; s = s->next)
((m_opt_func_param_t) opt->p)(opt,s->param);
}
@@ -847,18 +891,12 @@ const m_option_type_t m_option_type_func_full = {
/////////////// Func
#undef VAL
-#define VAL(x) (*(int*)(x))
static int parse_func(const m_option_t* opt,const char *name, const char *param, void* dst, int src) {
- if(dst)
- VAL(dst) += 1;
return 0;
}
static void set_func(const m_option_t* opt,void* dst, const void* src) {
- int i;
- if(opt->priv) ((m_opt_default_func_t)opt->priv)(opt,opt->name);
- for(i = 0 ; i < VAL(src) ; i++)
((m_opt_func_t) opt->p)(opt);
}
@@ -883,7 +921,7 @@ static int parse_print(const m_option_t* opt,const char *name, const char *param
else if(opt->type == CONF_TYPE_PRINT_FUNC)
return ((m_opt_func_full_t) opt->p)(opt,name,param);
else
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", (char *) opt->p);
+ mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", mp_gtext(opt->p));
if(opt->priv == NULL)
return M_OPT_EXIT;