From 9b7fb867f77bf0819bdfe1a4ceb55aade7db6f1b Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 21 Feb 2013 22:10:21 +0100 Subject: options: drop --opt:subopt option names For all suboptions, "flat" options were available by separating the parent option and the sub option with ":", e.g. "--rawvideo:w=123". Drop this syntax and use "-" as separator. This means even suboptions are available as normal options now, e.g. "--rawvideo-w=123". The old syntax doesn't work anymore. Note that this is completely separate from actual suboptions. For example, "-rawvideo w=123:h=123" still works. (Not that this syntax is worth supporting, but it's needed anyway, for for other things like vf and vo suboptions.) As a consequence of this change, we also have to add new "no-" prefixed options for flag suboptions, so that "--no-input-default-bindings" works. ("--input-no-default-bindings" also works as a consequence of allowing "-input no-default-bindings" - they are handled by the same underlying option.) For --input, always use the full syntax in the manpage. There exist suboptions other than --input (like --tv, --rawvideo, etc.), but since they might be handled differently in the future, don't touch these yet. M_OPT_PREFIXED becomes the default, so remove it. As a minor unrelated cleanup, get rid of M_OPT_MERGE too and use the OPT_SUBSTRUCT() macro in some places. Unrelated: remove the duplicated --tv:buffersize option, fix a typo in changes.rst. --- core/cfg-mplayer.h | 16 ++++------------ core/m_config.c | 46 +++++++++++++++++++++++++++++----------------- core/m_config.h | 2 +- core/m_option.h | 14 ++++---------- 4 files changed, 38 insertions(+), 40 deletions(-) (limited to 'core') diff --git a/core/cfg-mplayer.h b/core/cfg-mplayer.h index 3a79702959..30096ff295 100644 --- a/core/cfg-mplayer.h +++ b/core/cfg-mplayer.h @@ -95,11 +95,8 @@ const m_option_t tvopts_conf[]={ {"saturation", &stream_tv_defaults.saturation, CONF_TYPE_INT, CONF_RANGE, -100, 100, NULL}, {"gain", &stream_tv_defaults.gain, CONF_TYPE_INT, CONF_RANGE, -1, 100, NULL}, #if defined(CONFIG_TV_V4L2) - {"buffersize", &stream_tv_defaults.buffer_size, CONF_TYPE_INT, CONF_RANGE, 16, 1024, NULL}, {"amode", &stream_tv_defaults.amode, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL}, {"volume", &stream_tv_defaults.volume, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL}, -#endif -#if defined(CONFIG_TV_V4L2) {"bass", &stream_tv_defaults.bass, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL}, {"treble", &stream_tv_defaults.treble, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL}, {"balance", &stream_tv_defaults.balance, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL}, @@ -502,12 +499,8 @@ const m_option_t common_opts[] = { OPT_FLAG("osd-bar", osd_bar_visible, 0), OPT_FLOATRANGE("osd-bar-align-x", osd_bar_align_x, 0, -1.0, +1.0), OPT_FLOATRANGE("osd-bar-align-y", osd_bar_align_y, 0, -1.0, +1.0), - OPT_GENERAL("osd", osd_style, M_OPT_PREFIXED, - .type = &m_option_type_subconfig_struct, - .priv = (void*)&osd_style_conf), - OPT_GENERAL("sub-text", sub_text_style, M_OPT_PREFIXED, - .type = &m_option_type_subconfig_struct, - .priv = (void*)&osd_style_conf), + OPT_SUBSTRUCT("osd", osd_style, osd_style_conf, 0), + OPT_SUBSTRUCT("sub-text", sub_text_style, osd_style_conf, 0), {NULL, NULL, 0, 0, 0, 0, NULL} }; @@ -523,7 +516,7 @@ const m_option_t tvscan_conf[]={ extern const struct m_sub_options image_writer_conf; const m_option_t screenshot_conf[] = { - OPT_SUBSTRUCT(screenshot_image_opts, image_writer_conf, M_OPT_MERGE), + OPT_SUBSTRUCT("", screenshot_image_opts, image_writer_conf, 0), OPT_STRING("template", screenshot_template, 0), {0}, }; @@ -694,8 +687,7 @@ const m_option_t mplayer_opts[]={ {"tvscan", (void *) tvscan_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL}, #endif /* CONFIG_TV */ - {"screenshot", (void *) screenshot_conf, CONF_TYPE_SUBCONFIG, - M_OPT_PREFIXED, 0, 0, NULL}, + {"screenshot", (void *) screenshot_conf, CONF_TYPE_SUBCONFIG}, OPT_FLAG("list-properties", list_properties, CONF_GLOBAL), {"identify", &mp_msg_levels[MSGT_IDENTIFY], CONF_TYPE_FLAG, CONF_GLOBAL, 0, MSGL_V, NULL}, diff --git a/core/m_config.c b/core/m_config.c index 6ecfa13a39..b6c15d3d9a 100644 --- a/core/m_config.c +++ b/core/m_config.c @@ -154,6 +154,7 @@ static void substruct_write_ptr(void *ptr, void *val) } static void m_config_add_option(struct m_config *config, + const char *prefix, struct m_config_option *parent, const struct m_option *arg); @@ -205,7 +206,7 @@ struct m_config *m_config_new(void *optstruct, *p = (struct m_option){ "include", NULL, CONF_TYPE_STRING, 0, }; - m_config_add_option(config, NULL, p); + m_config_add_option(config, "", NULL, p); config->includefunc = includefunc; } @@ -285,13 +286,22 @@ static void add_negation_option(struct m_config *config, .name = talloc_asprintf(no_opt, "no-%s", opt->name), .type = CONF_TYPE_STORE, .flags = opt->flags & (M_OPT_NOCFG | M_OPT_GLOBAL | M_OPT_LOCAL | - M_OPT_PRE_PARSE | M_OPT_PREFIXED | M_OPT_MERGE), + M_OPT_PRE_PARSE), .new = opt->new, .p = opt->p, .offset = opt->offset, .max = value, }; - m_config_add_option(config, parent, no_opt); + m_config_add_option(config, "", parent, no_opt); + // Consider a parent option "--sub" and a subopt "opt". Then the above + // call will add "no-opt". Add "--no-sub-opt" too. (This former call will + // also generate "--sub-no-opt", which is not really needed or wanted, but + // is a consequence of supporting "--sub=...:no-opt".) + if (parent && parent->name && strlen(parent->name)) { + no_opt = talloc_memdup(config, no_opt, sizeof(*no_opt)); + no_opt->name = opt->name; + m_config_add_option(config, "no-", parent, no_opt); + } } static void add_options(struct m_config *config, @@ -299,20 +309,25 @@ static void add_options(struct m_config *config, const struct m_option *defs) { for (int i = 0; defs[i].name; i++) - m_config_add_option(config, parent, defs + i); + m_config_add_option(config, "", parent, defs + i); +} + +// Sub-config that adds all its children to the parent. +static bool is_merge_opt(const struct m_option *opt) +{ + return (opt->type->flags & M_OPT_TYPE_HAS_CHILD) && strlen(opt->name) == 0; } static void m_config_add_option(struct m_config *config, + const char *prefix, struct m_config_option *parent, const struct m_option *arg) { - struct m_config_option *co; - assert(config != NULL); assert(arg != NULL); // Allocate a new entry for this option - co = talloc_zero(config, struct m_config_option); + struct m_config_option *co = talloc_zero(config, struct m_config_option); co->opt = arg; void *optstruct = config->optstruct; @@ -323,19 +338,16 @@ static void m_config_add_option(struct m_config *config, if (parent) { // Merge case: pretend it has no parent (note that we still must follow // the "real" parent for accessing struct fields) - if (parent->opt->flags & M_OPT_MERGE) - co->parent = parent->parent; - else - co->parent = parent; + co->parent = is_merge_opt(parent->opt) ? parent->parent : parent; } // Fill in the full name if (co->parent) { - const char *sep = (co->parent->opt->flags & M_OPT_PREFIXED) ? "-" : ":"; - co->name = talloc_asprintf(co, "%s%s%s", co->parent->name, sep, - arg->name); - } else + co->name = talloc_asprintf(co, "%s-%s", co->parent->name, arg->name); + } else { co->name = (char *)arg->name; + } + co->name = talloc_asprintf(co, "%s%s", prefix, co->name); // Option with children -> add them if (arg->type->flags & M_OPT_TYPE_HAS_CHILD) { @@ -385,7 +397,7 @@ static void m_config_add_option(struct m_config *config, } // pretend that merge options don't exist (only their children matter) - if (!(arg->flags & M_OPT_MERGE)) { + if (!is_merge_opt(co->opt)) { co->next = config->opts; config->opts = co; } @@ -465,7 +477,7 @@ static int m_config_parse_option(struct m_config *config, void *optstruct, if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) { char prefix[110]; assert(strlen(co->name) < 100); - sprintf(prefix, "%s:", co->name); + sprintf(prefix, "%s-", co->name); return parse_subopts(config, optstruct, co->name, prefix, param, flags); } diff --git a/core/m_config.h b/core/m_config.h index 86376e4849..345141a72a 100644 --- a/core/m_config.h +++ b/core/m_config.h @@ -35,7 +35,7 @@ struct m_sub_options; // Config option struct m_config_option { struct m_config_option *next; - // Full name (ie option:subopt). + // Full name (ie option-subopt). char *name; // Option description. const struct m_option *opt; diff --git a/core/m_option.h b/core/m_option.h index bbf1efaec7..7b1e36eed7 100644 --- a/core/m_option.h +++ b/core/m_option.h @@ -355,14 +355,6 @@ struct m_option { // The option should be set during command line pre-parsing #define M_OPT_PRE_PARSE (1 << 6) -// For options with children, add all children as top-level arguments -// (e.g. "--parent=child=value" becomes "--parent-child=value") -#define M_OPT_PREFIXED (1 << 8) - -// Similar to M_OPT_PREFIXED, but drop the prefix. -// (e.g. "--parent=child=value" becomes "--child=value") -#define M_OPT_MERGE (1 << 9) - // See M_OPT_TYPE_OPTIONAL_PARAM. #define M_OPT_OPTIONAL_PARAM (1 << 10) @@ -555,10 +547,12 @@ static inline void m_option_free(const m_option_t *opt, void *dst) #define OPT_TRACKCHOICE(name, var) OPT_CHOICE_OR_INT(name, var, 0, 0, 8190, ({"no", -2}, {"auto", -1})) // subconf must have the type struct m_sub_options. -// flagv should be M_OPT_MERGE or M_OPT_FLATTEN. +// All sub-options are prefixed with "name-" and are added to the current +// (containing) option list. +// If name is "", add the sub-options directly instead. // varname refers to the field, that must be a pointer to a field described by // the subconf struct. -#define OPT_SUBSTRUCT(varname, subconf, flagv) OPT_GENERAL("-", varname, flagv, .type = &m_option_type_subconfig_struct, .priv = (void*)&subconf) +#define OPT_SUBSTRUCT(name, varname, subconf, flagv) OPT_GENERAL(name, varname, flagv, .type = &m_option_type_subconfig_struct, .priv = (void*)&subconf) #define OPT_BASE_STRUCT struct MPOpts -- cgit v1.2.3