summaryrefslogtreecommitdiffstats
path: root/options/m_property.c
diff options
context:
space:
mode:
Diffstat (limited to 'options/m_property.c')
-rw-r--r--options/m_property.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/options/m_property.c b/options/m_property.c
index 431e16a51a..eb3f78e847 100644
--- a/options/m_property.c
+++ b/options/m_property.c
@@ -18,8 +18,6 @@
/// \file
/// \ingroup Properties
-#include "config.h"
-
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -40,7 +38,7 @@ static int m_property_multiply(struct mp_log *log,
const struct m_property *prop_list,
const char *property, double f, void *ctx)
{
- union m_option_value val = {0};
+ union m_option_value val = m_option_value_default;
struct m_option opt = {0};
int r;
@@ -100,7 +98,7 @@ static int do_action(const struct m_property *prop_list, const char *name,
int m_property_do(struct mp_log *log, const struct m_property *prop_list,
const char *name, int action, void *arg, void *ctx)
{
- union m_option_value val = {0};
+ union m_option_value val = m_option_value_default;
int r;
struct m_option opt = {0};
@@ -110,13 +108,14 @@ int m_property_do(struct mp_log *log, const struct m_property *prop_list,
assert(opt.type);
switch (action) {
+ case M_PROPERTY_FIXED_LEN_PRINT:
case M_PROPERTY_PRINT: {
- if ((r = do_action(prop_list, name, M_PROPERTY_PRINT, arg, ctx)) >= 0)
+ if ((r = do_action(prop_list, name, action, arg, ctx)) >= 0)
return r;
// Fallback to m_option
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
return r;
- char *str = m_option_pretty_print(&opt, &val);
+ char *str = m_option_pretty_print(&opt, &val, action == M_PROPERTY_FIXED_LEN_PRINT);
m_option_free(&opt, &val);
*(char **)arg = str;
return str != NULL;
@@ -159,7 +158,8 @@ int m_property_do(struct mp_log *log, const struct m_property *prop_list,
return r;
}
case M_PROPERTY_GET_CONSTRICTED_TYPE: {
- if ((r = do_action(prop_list, name, action, arg, ctx)) >= 0)
+ r = do_action(prop_list, name, action, arg, ctx);
+ if (r >= 0 || r == M_PROPERTY_UNAVAILABLE)
return r;
if ((r = do_action(prop_list, name, M_PROPERTY_GET_TYPE, arg, ctx)) >= 0)
return r;
@@ -238,11 +238,10 @@ static void m_property_unkey(int *action, void **arg)
static int m_property_do_bstr(const struct m_property *prop_list, bstr name,
int action, void *arg, void *ctx)
{
- char name0[64];
- if (name.len >= sizeof(name0))
- return M_PROPERTY_UNKNOWN;
- snprintf(name0, sizeof(name0), "%.*s", BSTR_P(name));
- return m_property_do(NULL, prop_list, name0, action, arg, ctx);
+ char *name0 = bstrdup0(NULL, name);
+ int ret = m_property_do(NULL, prop_list, name0, action, arg, ctx);
+ talloc_free(name0);
+ return ret;
}
static void append_str(char **s, int *len, bstr append)
@@ -260,11 +259,13 @@ static int expand_property(const struct m_property *prop_list, char **ret,
bool cond_no = !cond_yes && bstr_eatstart0(&prop, "!");
bool test = cond_yes || cond_no;
bool raw = bstr_eatstart0(&prop, "=");
+ bool fixed_len = !raw && bstr_eatstart0(&prop, ">");
bstr comp_with = {0};
bool comp = test && bstr_split_tok(prop, "==", &prop, &comp_with);
if (test && !comp)
raw = true;
int method = raw ? M_PROPERTY_GET_STRING : M_PROPERTY_PRINT;
+ method = fixed_len ? M_PROPERTY_FIXED_LEN_PRINT : method;
char *s = NULL;
int r = m_property_do_bstr(prop_list, prop, method, &s, ctx);
@@ -354,14 +355,14 @@ void m_properties_print_help_list(struct mp_log *log,
mp_info(log, "\nTotal: %d properties\n", count);
}
-int m_property_flag_ro(int action, void* arg, int var)
+int m_property_bool_ro(int action, void* arg, bool var)
{
switch (action) {
case M_PROPERTY_GET:
- *(int *)arg = !!var;
+ *(bool *)arg = !!var;
return M_PROPERTY_OK;
case M_PROPERTY_GET_TYPE:
- *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_FLAG};
+ *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_BOOL};
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
@@ -434,6 +435,23 @@ int m_property_strdup_ro(int action, void* arg, const char *var)
return M_PROPERTY_NOT_IMPLEMENTED;
}
+int m_property_read_sub_validate(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ m_property_unkey(&action, &arg);
+ switch (action) {
+ case M_PROPERTY_GET_TYPE:
+ *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE};
+ return M_PROPERTY_OK;
+ case M_PROPERTY_GET:
+ case M_PROPERTY_PRINT:
+ case M_PROPERTY_KEY_ACTION:
+ return M_PROPERTY_VALID;
+ default:
+ return M_PROPERTY_NOT_IMPLEMENTED;
+ };
+}
+
// This allows you to make a list of values (like from a struct) available
// as a number of sub-properties. The property list is set up with the current
// property values on the stack before calling this function.
@@ -547,7 +565,7 @@ int m_property_read_list(int action, void *arg, int count,
r = get_item(n, M_PROPERTY_GET_TYPE, &opt, ctx);
if (r != M_PROPERTY_OK)
goto err;
- union m_option_value val = {0};
+ union m_option_value val = m_option_value_default;
r = get_item(n, M_PROPERTY_GET, &val, ctx);
if (r != M_PROPERTY_OK)
goto err;