summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2011-09-04 14:34:45 +0300
committerUoti Urpala <uau@mplayer2.org>2011-09-04 14:36:09 +0300
commit89b37a32dabc456f35a8e3d828a22861bd292ca8 (patch)
tree607fbba9d6fd42d6700a5bab5282d2ea1fdef17a
parent79469244f72d4350b630b21eac034a81b7b24cba (diff)
downloadmpv-89b37a32dabc456f35a8e3d828a22861bd292ca8.tar.bz2
mpv-89b37a32dabc456f35a8e3d828a22861bd292ca8.tar.xz
options: add "disabled option" functionality
Add functionality to mark options that depend on features disabled at compile time as disabled rather than not compiling the option definitions at all. This allows printing a warning about the option not being available because of a disabled feature, instead of just "unknown option". Because the option definitions are still compiled fully, this only works for definitions that do not reference symbols which are not available if the feature is disabled. Use the new functionality for options depending on libass.
-rw-r--r--cfg-mplayer.h4
-rw-r--r--m_config.c47
-rw-r--r--m_config.h2
-rw-r--r--m_option.h5
4 files changed, 44 insertions, 14 deletions
diff --git a/cfg-mplayer.h b/cfg-mplayer.h
index fc87ed88d8..48890eab26 100644
--- a/cfg-mplayer.h
+++ b/cfg-mplayer.h
@@ -691,7 +691,7 @@ const m_option_t common_opts[] = {
{"subfont-outline", &subtitle_font_thickness, CONF_TYPE_FLOAT, CONF_RANGE, 0, 8, NULL},
{"subfont-autoscale", &subtitle_autoscale, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL},
#endif
-#ifdef CONFIG_ASS
+ OPT_START_CONDITIONAL(CONFIG_ASS, "libass"),
OPT_MAKE_FLAGS("ass", ass_enabled, 0),
OPT_FLOATRANGE("ass-font-scale", ass_font_scale, 0, 0, 100),
OPT_FLOATRANGE("ass-line-spacing", ass_line_spacing, 0, -1000, 1000),
@@ -705,7 +705,7 @@ const m_option_t common_opts[] = {
OPT_STRING("ass-border-color", ass_border_color, 0),
OPT_STRING("ass-styles", ass_styles_file, 0),
OPT_INTRANGE("ass-hinting", ass_hinting, 0, 0, 7),
-#endif
+ OPT_START_CONDITIONAL(1, ""),
#ifdef CONFIG_FONTCONFIG
{"fontconfig", &font_fontconfig, CONF_TYPE_FLAG, 0, -1, 1, NULL},
{"nofontconfig", &font_fontconfig, CONF_TYPE_FLAG, 0, 1, -1, NULL},
diff --git a/m_config.c b/m_config.c
index 3cf8c721ac..94d7e26b2e 100644
--- a/m_config.c
+++ b/m_config.c
@@ -169,7 +169,7 @@ static void m_option_set(const struct m_config *config,
static void m_config_add_option(struct m_config *config,
const struct m_option *arg,
- const char *prefix);
+ const char *prefix, char *disabled_feature);
struct m_config *m_config_new(void *optstruct,
int includefunc(struct m_option *conf,
@@ -205,7 +205,7 @@ struct m_config *m_config_new(void *optstruct,
"include", includefunc, CONF_TYPE_FUNC_PARAM,
CONF_NOSAVE, 0, 0, config
};
- m_config_add_option(config, p, NULL);
+ m_config_add_option(config, p, NULL, NULL);
}
config->optstruct = optstruct;
@@ -302,8 +302,30 @@ void m_config_pop(struct m_config *config)
mp_msg(MSGT_CFGPARSER, MSGL_DBG2, "Config poped level=%d\n", config->lvl);
}
+static void add_options(struct m_config *config, const struct m_option *defs,
+ const char *prefix, char *disabled_feature)
+{
+ char *dis = disabled_feature;
+ const char marker[] = "conditional functionality: ";
+ for (int i = 0; defs[i].name; i++) {
+ if (!strncmp(defs[i].name, marker, strlen(marker))) {
+ // If a subconfig entry itself is disabled, everything
+ // under it is already disabled for the same reason.
+ if (!disabled_feature) {
+ if (!strcmp(defs[i].name + strlen(marker), "1"))
+ dis = NULL;
+ else
+ dis = defs[i].p;
+ }
+ continue;
+ }
+ m_config_add_option(config, defs + i, prefix, dis);
+ }
+}
+
static void m_config_add_option(struct m_config *config,
- const struct m_option *arg, const char *prefix)
+ const struct m_option *arg, const char *prefix,
+ char *disabled_feature)
{
struct m_config_option *co;
struct m_config_save_slot *sl;
@@ -316,6 +338,7 @@ static void m_config_add_option(struct m_config *config,
co = talloc_zero_size(config,
sizeof(struct m_config_option) + arg->type->size);
co->opt = arg;
+ co->disabled_feature = disabled_feature;
// Fill in the full name
if (prefix && *prefix)
@@ -325,11 +348,7 @@ static void m_config_add_option(struct m_config *config,
// Option with children -> add them
if (arg->type->flags & M_OPT_TYPE_HAS_CHILD) {
- const struct m_option *ol = arg->p;
- int i;
- co->slots = NULL;
- for (i = 0; ol[i].name != NULL; i++)
- m_config_add_option(config, &ol[i], co->name);
+ add_options(config, arg->p, co->name, disabled_feature);
} else {
struct m_config_option *i;
// Check if there is already an option pointing to this address
@@ -374,14 +393,11 @@ static void m_config_add_option(struct m_config *config,
int m_config_register_options(struct m_config *config,
const struct m_option *args)
{
- int i;
-
assert(config != NULL);
assert(config->lvl > 0);
assert(args != NULL);
- for (i = 0; args[i].name != NULL; i++)
- m_config_add_option(config, &args[i], NULL);
+ add_options(config, args, NULL, NULL);
return 1;
}
@@ -418,6 +434,13 @@ static int m_config_parse_option(const struct m_config *config,
co = m_config_get_co(config, name);
if (!co)
return M_OPT_UNKNOWN;
+ if (co->disabled_feature) {
+ mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
+ "Option \"%.*s\" is not available in this version of mplayer2, "
+ "because it has been compiled with feature \"%s\" disabled.\n",
+ BSTR_P(name), co->disabled_feature);
+ return M_OPT_UNKNOWN;
+ }
// This is the only mandatory function
assert(co->opt->type->parse);
diff --git a/m_config.h b/m_config.h
index 75dd85ac14..91ee7ffe43 100644
--- a/m_config.h
+++ b/m_config.h
@@ -47,6 +47,8 @@ struct m_config_option {
struct m_config_option *next;
// Full name (ie option:subopt).
char *name;
+ // Compiled without support for this option? If so set to name of feature
+ char *disabled_feature;
// Option description.
const struct m_option *opt;
// Save slot stack.
diff --git a/m_option.h b/m_option.h
index 78ed856f6d..5b7e051290 100644
--- a/m_option.h
+++ b/m_option.h
@@ -486,6 +486,11 @@ static inline void m_option_free(const m_option_t *opt, void *dst)
#define OPTION_PATH_SEPARATOR ':'
#endif
+// The code will interpret arguments different from 1 as disabled, thus
+// CONFIG_FOO etc mean disabled if no such macro is defined.
+#define OPT_START_CONDITIONAL(enable, featurename) OPT_START_CONDITIONAL_AFTERMACROEVAL(enable, featurename)
+#define OPT_START_CONDITIONAL_AFTERMACROEVAL(enable, featurename) {"conditional functionality: " #enable, .p = featurename}
+
#define OPT_FLAG_ON(optname, varname, flags) {optname, NULL, &m_option_type_flag, flags, 0, 1, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_FLAG_OFF(optname, varname, flags) {optname, NULL, &m_option_type_flag, flags, 1, 0, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_MAKE_FLAGS(optname, varname, flags) OPT_FLAG_ON(optname, varname, flags), OPT_FLAG_OFF("no" optname, varname, flags)