summaryrefslogtreecommitdiffstats
path: root/m_option.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-18 15:31:46 +0200
committerwm4 <wm4@nowhere>2012-10-12 10:10:31 +0200
commit69ce4591d09f1fda85c6a71d452d26a2712cda4e (patch)
tree27284241b989d6d78710151617f98c698b4f6b69 /m_option.c
parentf607d104b60b48cd293fbc057ba0a4ddaf9f8a73 (diff)
downloadmpv-69ce4591d09f1fda85c6a71d452d26a2712cda4e.tar.bz2
mpv-69ce4591d09f1fda85c6a71d452d26a2712cda4e.tar.xz
commands: generally handle property formatting with m_option
Use the m_option code by default to format property values, instead of having separate code in m_property. To facilitate that, add a pretty_print callback to option types. These format values in a more human readable and user friendly way, as opposed to the print callback, which produces parseable values. This also changes the strings used with flags. Instead of "enabled" and "disabled", flags are formatted as "yes" and "no". (We could use the pretty_print callback to deal with this, but we don't for consistency.)
Diffstat (limited to 'm_option.c')
-rw-r--r--m_option.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/m_option.c b/m_option.c
index 14a1a0a3d7..62887f4c48 100644
--- a/m_option.c
+++ b/m_option.c
@@ -489,10 +489,14 @@ static int parse_double(const m_option_t *opt, struct bstr name,
static char *print_double(const m_option_t *opt, const void *val)
{
- opt = NULL;
return talloc_asprintf(NULL, "%f", VAL(val));
}
+static char *print_double_f2(const m_option_t *opt, const void *val)
+{
+ return talloc_asprintf(NULL, "%.2f", VAL(val));
+}
+
static void add_double(const m_option_t *opt, void *val, double add, bool wrap)
{
double v = VAL(val);
@@ -516,6 +520,7 @@ const m_option_type_t m_option_type_double = {
.size = sizeof(double),
.parse = parse_double,
.print = print_double,
+ .pretty_print = print_double_f2,
.copy = copy_opt,
};
@@ -534,10 +539,14 @@ static int parse_float(const m_option_t *opt, struct bstr name,
static char *print_float(const m_option_t *opt, const void *val)
{
- opt = NULL;
return talloc_asprintf(NULL, "%f", VAL(val));
}
+static char *print_float_f2(const m_option_t *opt, const void *val)
+{
+ return talloc_asprintf(NULL, "%.2f", VAL(val));
+}
+
static void add_float(const m_option_t *opt, void *val, double add, bool wrap)
{
double tmp = VAL(val);
@@ -551,6 +560,7 @@ const m_option_type_t m_option_type_float = {
.size = sizeof(float),
.parse = parse_float,
.print = print_float,
+ .pretty_print = print_float_f2,
.copy = copy_opt,
.add = add_float,
};
@@ -1135,11 +1145,17 @@ static int parse_time(const m_option_t *opt, struct bstr name,
return 1;
}
+static char *pretty_print_time(const m_option_t *opt, const void *val)
+{
+ return mp_format_time(*(double *)val, false);
+}
+
const m_option_type_t m_option_type_time = {
.name = "Time",
.size = sizeof(double),
.parse = parse_time,
.print = print_double,
+ .pretty_print = pretty_print_time,
.copy = copy_opt,
.add = add_double,
};