diff options
Diffstat (limited to 'options')
-rw-r--r-- | options/m_config_frontend.c | 2 | ||||
-rw-r--r-- | options/m_option.c | 22 | ||||
-rw-r--r-- | options/m_option.h | 13 | ||||
-rw-r--r-- | options/m_property.c | 7 | ||||
-rw-r--r-- | options/m_property.h | 6 |
5 files changed, 30 insertions, 20 deletions
diff --git a/options/m_config_frontend.c b/options/m_config_frontend.c index 9b5438926c..d800cdb75d 100644 --- a/options/m_config_frontend.c +++ b/options/m_config_frontend.c @@ -871,7 +871,7 @@ void m_config_print_option_list(const struct m_config *config, const char *name) if (!defptr) defptr = &m_option_value_default; if (defptr) - def = m_option_pretty_print(opt, defptr); + def = m_option_pretty_print(opt, defptr, false); if (def) { MP_INFO(config, " (default: %s)", def); talloc_free(def); diff --git a/options/m_option.c b/options/m_option.c index 66d68398f4..4646510f21 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1023,17 +1023,12 @@ static char *print_double(const m_option_t *opt, const void *val) return talloc_asprintf(NULL, "%f", f); } -static char *print_double_7g(const m_option_t *opt, const void *val) +static char *pretty_print_double(const m_option_t *opt, const void *val) { double f = VAL(val); if (isnan(f)) return print_double(opt, val); - // Truncate anything < 1e-4 to avoid switching to scientific notation - if (fabs(f) < 1e-4) { - return talloc_strdup(NULL, "0"); - } else { - return talloc_asprintf(NULL, "%.7g", f); - } + return mp_format_double(NULL, f, 4, false, false, !(opt->flags & M_OPT_FIXED_LEN_PRINT)); } static void add_double(const m_option_t *opt, void *val, double add, bool wrap) @@ -1105,7 +1100,7 @@ const m_option_type_t m_option_type_double = { .size = sizeof(double), .parse = parse_double, .print = print_double, - .pretty_print = print_double_7g, + .pretty_print = pretty_print_double, .copy = copy_opt, .add = add_double, .multiply = multiply_double, @@ -1131,7 +1126,7 @@ const m_option_type_t m_option_type_aspect = { .flags = M_OPT_TYPE_CHOICE | M_OPT_TYPE_USES_RANGE, .parse = parse_double_aspect, .print = print_double, - .pretty_print = print_double_7g, + .pretty_print = pretty_print_double, .copy = copy_opt, .add = add_double, .multiply = multiply_double, @@ -1159,10 +1154,10 @@ static char *print_float(const m_option_t *opt, const void *val) return print_double(opt, &tmp); } -static char *print_float_f3(const m_option_t *opt, const void *val) +static char *pretty_print_float(const m_option_t *opt, const void *val) { double tmp = VAL(val); - return print_double_7g(opt, &tmp); + return pretty_print_double(opt, &tmp); } static void add_float(const m_option_t *opt, void *val, double add, bool wrap) @@ -1207,7 +1202,7 @@ const m_option_type_t m_option_type_float = { .size = sizeof(float), .parse = parse_float, .print = print_float, - .pretty_print = print_float_f3, + .pretty_print = pretty_print_float, .copy = copy_opt, .add = add_float, .multiply = multiply_float, @@ -2827,8 +2822,7 @@ static char *print_rel_time(const m_option_t *opt, const void *val) case REL_TIME_ABSOLUTE: return talloc_asprintf(NULL, "%g", t->pos); case REL_TIME_RELATIVE: - return talloc_asprintf(NULL, "%s%g", - (t->pos >= 0) ? "+" : "-", fabs(t->pos)); + return talloc_asprintf(NULL, "%+g", t->pos); case REL_TIME_CHAPTER: return talloc_asprintf(NULL, "#%g", t->pos); case REL_TIME_PERCENT: diff --git a/options/m_option.h b/options/m_option.h index 891b51794e..530c0a3d50 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -463,6 +463,9 @@ char *format_file_size(int64_t size); // type channels: disallow "auto" (still accept ""), limit list to at most 1 item. #define M_OPT_CHANNELS_LIMITED (1 << 27) +// type_float/type_double: controls if pretty print should trim trailing zeros +#define M_OPT_FIXED_LEN_PRINT (1 << 28) + // Like M_OPT_TYPE_OPTIONAL_PARAM. #define M_OPT_OPTIONAL_PARAM (1 << 30) @@ -536,12 +539,16 @@ static inline char *m_option_print(const m_option_t *opt, const void *val_ptr) } static inline char *m_option_pretty_print(const m_option_t *opt, - const void *val_ptr) + const void *val_ptr, + bool fixed_len) { + m_option_t o = *opt; + if (fixed_len) + o.flags |= M_OPT_FIXED_LEN_PRINT; if (opt->type->pretty_print) - return opt->type->pretty_print(opt, val_ptr); + return opt->type->pretty_print(&o, val_ptr); else - return m_option_print(opt, val_ptr); + return m_option_print(&o, val_ptr); } // Helper around \ref m_option_type::copy. diff --git a/options/m_property.c b/options/m_property.c index 1b76f05e7d..eb3f78e847 100644 --- a/options/m_property.c +++ b/options/m_property.c @@ -108,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; @@ -258,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); diff --git a/options/m_property.h b/options/m_property.h index 0dce24600c..9fa01e0ccc 100644 --- a/options/m_property.h +++ b/options/m_property.h @@ -48,6 +48,12 @@ enum mp_property_action { // arg: char** M_PROPERTY_PRINT, + // Get human readable fixed length string representing the current value. + // If unimplemented, the property wrapper uses the property type as + // fallback. + // arg: char** + M_PROPERTY_FIXED_LEN_PRINT, + // Like M_PROPERTY_GET_TYPE, but get a type that is compatible to the real // type, but reflect practical limits, such as runtime-available values. // This is mostly used for "UI" related things. |