summaryrefslogtreecommitdiffstats
path: root/m_property.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-18 20:07:24 +0200
committerwm4 <wm4@nowhere>2012-10-12 10:10:31 +0200
commitdec53f760e12254e4baa4f7cee59010b3b10b6be (patch)
tree41edc95ce49dca2a7188bc88f9a7a9eb2964963c /m_property.c
parent28f43ce9a9d543fccb10aaf574282c349408946f (diff)
downloadmpv-dec53f760e12254e4baa4f7cee59010b3b10b6be.tar.bz2
mpv-dec53f760e12254e4baa4f7cee59010b3b10b6be.tar.xz
commands: add more property-option bridge uses, rename some options
Make more properties use the property-to-option bridge to reduce code size and to enforce consistency. Some options are renamed to the same as the properties (the property names are better in all cases). Do some other minor cleanups. One bigger issue was memory management of strings: M_PROPERTY_TO_STRING assumed the strings were statically allocated, and no dynamic allocations could be returned. Fix this in case the need for such properties arises in the future. Get rid of m_property_string_ro(), because it's not always clear that the "action" parameter is M_PROPERTY_SET and the string argument will be used.
Diffstat (limited to 'm_property.c')
-rw-r--r--m_property.c71
1 files changed, 14 insertions, 57 deletions
diff --git a/m_property.c b/m_property.c
index af5d51dd21..536049020c 100644
--- a/m_property.c
+++ b/m_property.c
@@ -82,6 +82,7 @@ int m_property_do(const m_option_t *prop_list, const char *name,
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
return r;
str = m_option_pretty_print(opt, &val);
+ m_option_free(opt, &val);
*(char **)arg = str;
return str != NULL;
case M_PROPERTY_TO_STRING:
@@ -95,6 +96,7 @@ int m_property_do(const m_option_t *prop_list, const char *name,
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
return r;
str = m_option_print(opt, &val);
+ m_option_free(opt, &val);
*(char **)arg = str;
return str != NULL;
case M_PROPERTY_PARSE:
@@ -215,9 +217,14 @@ char *m_properties_expand_string(const m_option_t *prop_list, char *str,
char pname[pl + 1];
memcpy(pname, str + (is_not ? 3 : 2), pl);
pname[pl] = 0;
- if (m_property_do(prop_list, pname, M_PROPERTY_GET, NULL, ctx) < 0) {
+ struct m_option *opt;
+ union m_option_value val = {0};
+ if (m_property_do(prop_list, pname, M_PROPERTY_GET_TYPE, &opt, ctx) <= 0 &&
+ m_property_do(prop_list, pname, M_PROPERTY_GET, &val, ctx) <= 0)
+ {
if (!is_not)
skip = 1, skip_lvl = lvl;
+ m_option_free(opt, &val);
} else if (is_not)
skip = 1, skip_lvl = lvl;
}
@@ -270,82 +277,32 @@ void m_properties_print_help_list(const m_option_t *list)
mp_tmsg(MSGT_CFGPARSER, MSGL_INFO, "\nTotal: %d properties\n", count);
}
-// Some generic property implementations
-
int m_property_int_ro(const m_option_t *prop, int action,
void *arg, int var)
{
- switch (action) {
- case M_PROPERTY_GET:
+ if (action == M_PROPERTY_GET) {
*(int *)arg = var;
- return 1;
+ return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
-int m_property_int_range(const m_option_t *prop, int action,
- void *arg, int *var)
-{
- switch (action) {
- case M_PROPERTY_SET:
- *var = *(int *)arg;
- return 1;
- }
- return m_property_int_ro(prop, action, arg, *var);
-}
-
-int m_property_flag_ro(const m_option_t *prop, int action,
- void *arg, int var)
-{
- return m_property_int_ro(prop, action, arg, var);
-}
-
-int m_property_flag(const m_option_t *prop, int action,
- void *arg, int *var)
-{
- return m_property_int_range(prop, action, arg, var);
-}
-
int m_property_float_ro(const m_option_t *prop, int action,
void *arg, float var)
{
- switch (action) {
- case M_PROPERTY_GET:
+ if (action == M_PROPERTY_GET) {
*(float *)arg = var;
- return 1;
+ return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
-int m_property_float_range(const m_option_t *prop, int action,
- void *arg, float *var)
-{
- switch (action) {
- case M_PROPERTY_SET:
- *var = *(float *)arg;
- return 1;
- }
- return m_property_float_ro(prop, action, arg, *var);
-}
-
int m_property_double_ro(const m_option_t *prop, int action,
void *arg, double var)
{
- switch (action) {
- case M_PROPERTY_GET:
+ if (action == M_PROPERTY_GET) {
*(double *)arg = var;
- return 1;
- }
- return M_PROPERTY_NOT_IMPLEMENTED;
-}
-
-int m_property_string_ro(const m_option_t *prop, int action, void *arg,
- char *str)
-{
- switch (action) {
- case M_PROPERTY_GET:
- *(char **)arg = str;
- return 1;
+ return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}