summaryrefslogtreecommitdiffstats
path: root/options/m_option.c
diff options
context:
space:
mode:
Diffstat (limited to 'options/m_option.c')
-rw-r--r--options/m_option.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/options/m_option.c b/options/m_option.c
index 1b1ac0a..4646510 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,
@@ -1517,6 +1512,7 @@ static char *print_str_list(const m_option_t *opt, const void *src)
{
char **lst = NULL;
char *ret = NULL;
+ const char sep = opt->priv ? *(char *)opt->priv : OPTION_LIST_SEPARATOR;
if (!(src && VAL(src)))
return talloc_strdup(NULL, "");
@@ -1524,7 +1520,7 @@ static char *print_str_list(const m_option_t *opt, const void *src)
for (int i = 0; lst[i]; i++) {
if (ret)
- ret = talloc_strdup_append_buffer(ret, ",");
+ ret = talloc_strndup_append_buffer(ret, &sep, 1);
ret = talloc_strdup_append_buffer(ret, lst[i]);
}
return ret;
@@ -2826,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:
@@ -3398,15 +3393,21 @@ static int parse_obj_settings_list(struct mp_log *log, const m_option_t *opt,
if (r == 0) {
r = parse_obj_settings(log, name, op, &param, ol, dst ? &res : NULL);
}
- if (r < 0)
+ if (r < 0) {
+ free_obj_settings_list(&res);
return r;
+ }
if (param.len > 0) {
const char sep[2] = {OPTION_LIST_SEPARATOR, 0};
- if (!bstr_eatstart0(&param, sep))
+ if (!bstr_eatstart0(&param, sep)) {
+ free_obj_settings_list(&res);
return M_OPT_INVALID;
+ }
if (param.len == 0) {
- if (!ol->allow_trailer)
+ if (!ol->allow_trailer) {
+ free_obj_settings_list(&res);
return M_OPT_INVALID;
+ }
if (dst) {
m_obj_settings_t item = {
.name = talloc_strdup(NULL, ""),
@@ -3421,6 +3422,7 @@ static int parse_obj_settings_list(struct mp_log *log, const m_option_t *opt,
if (op == OP_APPEND) {
mp_err(log, "Option %.*s: -append takes only 1 filter (no ',').\n",
BSTR_P(name));
+ free_obj_settings_list(&res);
return M_OPT_INVALID;
}
mp_warn(log, "Passing more than 1 argument to %.*s is deprecated!\n",
@@ -3784,7 +3786,7 @@ static void dup_node(void *ta_parent, struct mpv_node *node)
static void copy_node(const m_option_t *opt, void *dst, const void *src)
{
- assert(sizeof(struct mpv_node) <= sizeof(union m_option_value));
+ static_assert(sizeof(struct mpv_node) <= sizeof(union m_option_value), "");
if (!(dst && src))
return;