summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-08-05 23:34:28 +0200
committerwm4 <wm4@nowhere>2012-08-05 23:51:49 +0200
commit94782e464d985b6e653618d8a61cf2ee817c3e9f (patch)
treeab0aa78634cff9e743340d86537e8ec1a94d989a
parent039a6194a473564f37525e94b689494c00145c5d (diff)
downloadmpv-94782e464d985b6e653618d8a61cf2ee817c3e9f.tar.bz2
mpv-94782e464d985b6e653618d8a61cf2ee817c3e9f.tar.xz
options: get rid of ambiguous option parsing
Options parsing used to be ambiguous, as in the splitting into option and values pairs was ambiguous. Example: -option -something It wasn't clear whether -option actually takes an argument or not. The string "-something" could either be a separate option, or an argument to "-option". The code had to call the option specific parser function to resolve this. This made everything complicated and didn't even have a real use. There was only one case where this was actually used: string lists (m_option_type_string_list) and options based on it. That is because this option type actually turns a single option into a proxy for several real arguments, e.g. "vf*" can handle "-vf-add" and "-vf-clr". Options suffixed with "-clr" are the only options of this group which take no arguments. This is ambiguous only with the "old syntax" (as shown above). The "new" option syntax always puts option name and value into same argument. (E.g. "--option=--something" or "--option" "--something".) Simplify the code by making it statically known whether an option takes a parameter or not with the flag M_OPT_TYPE_OLD_SYNTAX_NO_PARAM. If it's set, the option parser assumes the option takes no argument. The only real ambiguity left, string list options that end on "-clr", are special cased in the parser. Remove some duplication of the logic in the command line parser by moving all argument splitting logic into split_opt(). (It's arguable whether that can be considered code duplication, but now the code is a bit simpler anyway. This might be subjective.) Remove the "ambiguous" parameter from all option parsing related code. Make m_config unaware of the pre-parsing concept. Make most CONF_NOCFG options also CONF_GLOBAL (except those explicitly usable as per-file options.)
-rw-r--r--cfg-mplayer.h15
-rw-r--r--input/input.c4
-rw-r--r--m_config.c41
-rw-r--r--m_config.h26
-rw-r--r--m_option.c83
-rw-r--r--m_option.h16
-rw-r--r--m_property.c3
-rw-r--r--m_struct.c2
-rw-r--r--mpcommon.h8
-rw-r--r--mplayer.c23
-rw-r--r--parser-cfg.c2
-rw-r--r--parser-mpcmd.c387
-rw-r--r--parser-mpcmd.h11
-rw-r--r--stream/stream.c2
14 files changed, 317 insertions, 306 deletions
diff --git a/cfg-mplayer.h b/cfg-mplayer.h
index 78d615e911..dc261af027 100644
--- a/cfg-mplayer.h
+++ b/cfg-mplayer.h
@@ -343,7 +343,7 @@ const m_option_t msgl_config[]={
" ass - libass messages\n"
" statusline - playback/encoding status line\n"
" fixme - messages not yet fixed to map to module\n"
- "\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
+ "\n", CONF_TYPE_PRINT, CONF_GLOBAL | CONF_NOCFG, 0, 0, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
@@ -356,8 +356,8 @@ const m_option_t common_opts[] = {
OPT_MAKE_FLAGS("quiet", quiet, CONF_GLOBAL),
{"really-quiet", &verbose, CONF_TYPE_FLAG, CONF_GLOBAL|CONF_PRE_PARSE, 0, -10, NULL},
// -v is handled in command line preparser
- {"v", NULL, CONF_TYPE_FLAG, CONF_NOCFG, 0, 0, NULL},
- {"msglevel", (void *) msgl_config, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
+ {"v", NULL, CONF_TYPE_FLAG, CONF_GLOBAL | CONF_NOCFG, 0, 0, NULL},
+ {"msglevel", (void *) msgl_config, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
{"msgcolor", &mp_msg_color, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
{"msgmodule", &mp_msg_module, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
#ifdef CONFIG_PRIORITY
@@ -537,7 +537,7 @@ const m_option_t common_opts[] = {
// postprocessing:
{"pp", &divx_quality, CONF_TYPE_INT, 0, 0, 0, NULL},
#ifdef CONFIG_LIBPOSTPROC
- {"pphelp", &pp_help, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
+ {"pphelp", &pp_help, CONF_TYPE_PRINT, CONF_GLOBAL | CONF_NOCFG, 0, 0, NULL},
#endif
// scaling:
@@ -549,7 +549,6 @@ const m_option_t common_opts[] = {
OPT_FLOATRANGE("xy", screen_size_xy, 0, 0.001, 4096),
OPT_FLAG_CONSTANTS("flip", flip, 0, -1, 1),
- OPT_FLAG_CONSTANTS("no-flip", flip, 0, -1, 0),
// draw by slices or whole frame (useful with libmpeg2/libavcodec)
OPT_MAKE_FLAGS("slices", vd_use_slices, 0),
@@ -632,7 +631,6 @@ const m_option_t mplayer_opts[]={
OPT_MAKE_FLAGS("ontop", vo_ontop, 0),
{"rootwin", &vo_rootwin, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"border", &vo_border, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"no-border", &vo_border, CONF_TYPE_FLAG, 0, 1, 0, NULL},
OPT_STRING("mixer", mixer_device, 0),
OPT_STRING("mixer-channel", mixer_channel, 0),
@@ -752,8 +750,11 @@ const m_option_t mplayer_opts[]={
OPT_FLAG_CONSTANTS("no-loop", loop_times, 0, 0, -1),
OPT_INTRANGE("loop", loop_times, 0, -1, 10000),
- {"playlist", NULL, CONF_TYPE_STRING, CONF_NOCFG, 0, 0, NULL},
+
+ {"playlist", NULL, CONF_TYPE_STRING, CONF_NOCFG | M_OPT_MIN, 1, 0, NULL},
{"shuffle", NULL, CONF_TYPE_FLAG, CONF_NOCFG, 0, 0, NULL},
+ {"{", NULL, CONF_TYPE_FLAG, CONF_NOCFG, 0, 0, NULL},
+ {"}", NULL, CONF_TYPE_FLAG, CONF_NOCFG, 0, 0, NULL},
OPT_MAKE_FLAGS("ordered-chapters", ordered_chapters, 0),
OPT_INTRANGE("chapter-merge-threshold", chapter_merge_threshold, 0, 0, 10000),
diff --git a/input/input.c b/input/input.c
index 496c5ca46e..690321f7fe 100644
--- a/input/input.c
+++ b/input/input.c
@@ -484,8 +484,8 @@ static const m_option_t input_conf[] = {
OPT_STRING("conf", input.config_file, CONF_GLOBAL, OPTDEF_STR("input.conf")),
OPT_INT("ar-delay", input.ar_delay, CONF_GLOBAL),
OPT_INT("ar-rate", input.ar_rate, CONF_GLOBAL),
- { "keylist", print_key_list, CONF_TYPE_PRINT_FUNC, CONF_NOCFG },
- { "cmdlist", print_cmd_list, CONF_TYPE_PRINT_FUNC, CONF_NOCFG },
+ { "keylist", print_key_list, CONF_TYPE_PRINT_FUNC, CONF_GLOBAL | CONF_NOCFG },
+ { "cmdlist", print_cmd_list, CONF_TYPE_PRINT_FUNC, CONF_GLOBAL | CONF_NOCFG },
OPT_STRING("js-dev", input.js_dev, CONF_GLOBAL),
OPT_STRING("ar-dev", input.ar_dev, CONF_GLOBAL),
OPT_STRING("file", input.in_file, CONF_GLOBAL),
diff --git a/m_config.c b/m_config.c
index b1c732fb71..7ae95de40c 100644
--- a/m_config.c
+++ b/m_config.c
@@ -67,7 +67,7 @@ static int parse_profile(struct m_config *config, const struct m_option *opt,
}
char **list = NULL;
- int r = m_option_type_string_list.parse(opt, name, param, false, &list);
+ int r = m_option_type_string_list.parse(opt, name, param, &list);
if (r < 0)
return r;
if (!list || !list[0])
@@ -197,7 +197,8 @@ struct m_config *m_config_new(void *optstruct,
{
static const struct m_option ref_opts[] = {
{ "profile", NULL, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL },
- { "show-profile", show_profile, CONF_TYPE_PRINT_FUNC, CONF_NOCFG },
+ { "show-profile", show_profile, &m_option_type_print_func_param,
+ CONF_NOCFG },
{ "list-options", list_options, CONF_TYPE_PRINT_FUNC, CONF_NOCFG },
{ NULL }
};
@@ -380,8 +381,7 @@ static int parse_subopts(struct m_config *config, void *optstruct, char *name,
char *prefix, struct bstr param, bool set);
static int m_config_parse_option(struct m_config *config, void *optstruct,
- struct bstr name, struct bstr param,
- bool ambiguous_param, bool set)
+ struct bstr name, struct bstr param, bool set)
{
assert(config != NULL);
assert(name.len != 0);
@@ -419,13 +419,6 @@ static int m_config_parse_option(struct m_config *config, void *optstruct,
BSTR_P(name));
return M_OPT_INVALID;
}
- // During command line preparse set only pre-parse options
- // Otherwise only set pre-parse option if they were not already set.
- if (((config->mode == M_COMMAND_LINE_PRE_PARSE) &&
- !(co->opt->flags & M_OPT_PRE_PARSE)) ||
- ((config->mode != M_COMMAND_LINE_PRE_PARSE) &&
- (co->opt->flags & M_OPT_PRE_PARSE) && (co->flags & M_CFG_OPT_SET)))
- set = 0;
if (config->includefunc && !bstrcmp0(name, "include")) {
return parse_include(config, param, set);
@@ -444,14 +437,7 @@ static int m_config_parse_option(struct m_config *config, void *optstruct,
ensure_backup(config, co);
void *dst = set ? m_option_get_ptr(co->opt, optstruct) : NULL;
- int r = m_option_parse(co->opt, name, param, ambiguous_param, dst);
- // Parsing failed ?
- if (r < 0)
- return r;
- else if (set)
- co->flags |= M_CFG_OPT_SET;
-
- return r;
+ return m_option_parse(co->opt, name, param, dst);
}
static int parse_subopts(struct m_config *config, void *optstruct, char *name,
@@ -459,7 +445,7 @@ static int parse_subopts(struct m_config *config, void *optstruct, char *name,
{
char **lst = NULL;
// Split the argument into child options
- int r = m_option_type_subconfig.parse(NULL, bstr0(""), param, false, &lst);
+ int r = m_option_type_subconfig.parse(NULL, bstr0(""), param, &lst);
if (r < 0)
return r;
// Parse the child options
@@ -491,7 +477,7 @@ static int parse_subopts(struct m_config *config, void *optstruct, char *name,
lst[2 * i + 1] = "no";
}
int sr = m_config_parse_option(config, optstruct, bstr0(n),
- bstr0(lst[2 * i + 1]), false, set);
+ bstr0(lst[2 * i + 1]), set);
if (sr < 0) {
if (sr == M_OPT_MISSING_PARAM) {
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
@@ -508,21 +494,20 @@ static int parse_subopts(struct m_config *config, void *optstruct, char *name,
}
int m_config_set_option(struct m_config *config, struct bstr name,
- struct bstr param, bool ambiguous_param)
+ struct bstr param)
{
mp_msg(MSGT_CFGPARSER, MSGL_DBG2, "Setting %.*s=%.*s\n", BSTR_P(name),
BSTR_P(param));
- return m_config_parse_option(config, config->optstruct, name, param,
- ambiguous_param, true);
+ return m_config_parse_option(config, config->optstruct, name, param, true);
}
int m_config_check_option(struct m_config *config, struct bstr name,
- struct bstr param, bool ambiguous_param)
+ struct bstr param)
{
int r;
mp_msg(MSGT_CFGPARSER, MSGL_DBG2, "Checking %.*s=%.*s\n", BSTR_P(name),
BSTR_P(param));
- r = m_config_parse_option(config, NULL, name, param, ambiguous_param, 0);
+ r = m_config_parse_option(config, NULL, name, param, 0);
if (r == M_OPT_MISSING_PARAM) {
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
"Error: option '%.*s' must have a parameter!\n", BSTR_P(name));
@@ -623,7 +608,7 @@ void m_profile_set_desc(struct m_profile *p, char *desc)
int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
char *name, char *val)
{
- int i = m_config_check_option0(config, name, val, false);
+ int i = m_config_check_option0(config, name, val);
if (i < 0)
return i;
p->opts = talloc_realloc(p, p->opts, char *, 2 * (p->num_opts + 2));
@@ -646,7 +631,7 @@ void m_config_set_profile(struct m_config *config, struct m_profile *p)
config->mode = M_CONFIG_FILE;
config->profile_depth++;
for (i = 0; i < p->num_opts; i++)
- m_config_set_option0(config, p->opts[2 * i], p->opts[2 * i + 1], false);
+ m_config_set_option0(config, p->opts[2 * i], p->opts[2 * i + 1]);
config->profile_depth--;
config->mode = prev_mode;
}
diff --git a/m_config.h b/m_config.h
index 3441350c0e..19d8005d3c 100644
--- a/m_config.h
+++ b/m_config.h
@@ -60,12 +60,10 @@ struct m_profile {
};
enum option_source {
- // Set when parsing from a config file.
- M_CONFIG_FILE,
// Set when parsing command line arguments.
M_COMMAND_LINE,
- // Set when pre-parsing the command line
- M_COMMAND_LINE_PRE_PARSE,
+ // Set when parsing from a config file.
+ M_CONFIG_FILE,
};
// Config object
@@ -90,10 +88,6 @@ typedef struct m_config {
int (*includefunc)(struct m_config *conf, char *filename);
} m_config_t;
-
-// Set if an option has been set at the current level.
-#define M_CFG_OPT_SET (1 << 0)
-
// Set if another option already uses the same variable.
#define M_CFG_OPT_ALIAS (1 << 1)
@@ -122,31 +116,27 @@ int m_config_register_options(struct m_config *config,
* \param config The config object.
* \param name The option's name.
* \param param The value of the option, can be NULL.
- * \param ambiguous_param: old style cmdline option, "param" may be a
- parameter to this option or something entirely unrelated
* \return See \ref OptionParserReturn.
*/
int m_config_set_option(struct m_config *config, struct bstr name,
- struct bstr param, bool ambiguous_param);
+ struct bstr param);
static inline int m_config_set_option0(struct m_config *config,
- const char *name, const char *param,
- bool ambiguous)
+ const char *name, const char *param)
{
- return m_config_set_option(config, bstr0(name), bstr0(param), ambiguous);
+ return m_config_set_option(config, bstr0(name), bstr0(param));
}
/* Check if an option setting is valid.
* Same as above m_config_set_option() but doesn't actually set anything.
*/
int m_config_check_option(struct m_config *config, struct bstr name,
- struct bstr param, bool ambiguous_param);
+ struct bstr param);
static inline int m_config_check_option0(struct m_config *config,
- const char *name, const char *param,
- bool ambiguous)
+ const char *name, const char *param)
{
- return m_config_check_option(config, bstr0(name), bstr0(param), ambiguous);
+ return m_config_check_option(config, bstr0(name), bstr0(param));
}
int m_config_parse_suboptions(struct m_config *config, char *name,
diff --git a/m_option.c b/m_option.c
index ddd538d4aa..35b5efc98d 100644
--- a/m_option.c
+++ b/m_option.c
@@ -88,9 +88,9 @@ static void copy_opt(const m_option_t *opt, void *dst, const void *src)
#define VAL(x) (*(int *)(x))
static int parse_flag(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
- if (param.len && !ambiguous_param) {
+ if (param.len) {
char * const enable[] = { "yes", "on", "ja", "si", "igen", "y", "j",
"i", "tak", "ja", "true", "1" };
for (int i = 0; i < sizeof(enable) / sizeof(enable[0]); i++) {
@@ -132,6 +132,7 @@ const m_option_type_t m_option_type_flag = {
// need yes or no in config files
.name = "Flag",
.size = sizeof(int),
+ .flags = M_OPT_TYPE_OLD_SYNTAX_NO_PARAM,
.parse = parse_flag,
.print = print_flag,
.copy = copy_opt,
@@ -140,7 +141,7 @@ const m_option_type_t m_option_type_flag = {
// Integer
static int parse_longlong(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
if (param.len == 0)
return M_OPT_MISSING_PARAM;
@@ -177,20 +178,20 @@ static int parse_longlong(const m_option_t *opt, struct bstr name,
}
static int parse_int(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
long long tmp;
- int r = parse_longlong(opt, name, param, false, &tmp);
+ int r = parse_longlong(opt, name, param, &tmp);
if (r >= 0 && dst)
*(int *)dst = tmp;
return r;
}
static int parse_int64(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
long long tmp;
- int r = parse_longlong(opt, name, param, false, &tmp);
+ int r = parse_longlong(opt, name, param, &tmp);
if (r >= 0 && dst)
*(int64_t *)dst = tmp;
return r;
@@ -221,7 +222,7 @@ const m_option_type_t m_option_type_int64 = {
};
static int parse_intpair(const struct m_option *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
if (param.len == 0)
return M_OPT_MISSING_PARAM;
@@ -264,13 +265,13 @@ const struct m_option_type m_option_type_intpair = {
};
static int parse_choice(const struct m_option *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
bool allow_empty = opt->flags & M_OPT_IMPLICIT_DEFAULT;
int ret;
struct m_opt_choice_alternatives *alt = opt->priv;
- if (param.len == 0 || (ambiguous_param && allow_empty)) {
+ if (param.len == 0) {
if (!allow_empty)
return M_OPT_MISSING_PARAM;
ret = 0;
@@ -320,7 +321,7 @@ const struct m_option_type m_option_type_choice = {
#define VAL(x) (*(double *)(x))
static int parse_double(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
if (param.len == 0)
return M_OPT_MISSING_PARAM;
@@ -394,10 +395,10 @@ const m_option_type_t m_option_type_double = {
#define VAL(x) (*(float *)(x))
static int parse_float(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
double tmp;
- int r = parse_double(opt, name, param, false, &tmp);
+ int r = parse_double(opt, name, param, &tmp);
if (r == 1 && dst)
VAL(dst) = tmp;
return r;
@@ -423,10 +424,10 @@ const m_option_type_t m_option_type_float = {
#define VAL(x) (*(off_t *)(x))
static int parse_position(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
long long tmp;
- int r = parse_longlong(opt, name, param, false, &tmp);
+ int r = parse_longlong(opt, name, param, &tmp);
if (r >= 0 && dst)
*(off_t *)dst = tmp;
return r;
@@ -453,7 +454,7 @@ const m_option_type_t m_option_type_position = {
#define VAL(x) (*(char **)(x))
static int parse_str(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
if (param.start == NULL)
return M_OPT_MISSING_PARAM;
@@ -642,7 +643,7 @@ static struct bstr get_nextsep(struct bstr *ptr, char sep, bool modify)
}
static int parse_str_list(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
char **res;
int op = OP_NONE;
@@ -788,17 +789,18 @@ const m_option_type_t m_option_type_string_list = {
/////////////////// Print
static int parse_print(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
- if (opt->type == CONF_TYPE_PRINT_FUNC) {
+ if (opt->type == CONF_TYPE_PRINT) {
+ mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", mp_gtext(opt->p));
+ } else {
char *name0 = bstrdup0(NULL, name);
char *param0 = bstrdup0(NULL, param);
int r = ((m_opt_func_full_t) opt->p)(opt, name0, param0);
talloc_free(name0);
talloc_free(param0);
return r;
- } else
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", mp_gtext(opt->p));
+ }
if (opt->priv == NULL)
return M_OPT_EXIT;
@@ -807,22 +809,29 @@ static int parse_print(const m_option_t *opt, struct bstr name,
const m_option_type_t m_option_type_print = {
.name = "Print",
+ .flags = M_OPT_TYPE_OLD_SYNTAX_NO_PARAM,
.parse = parse_print,
};
-const m_option_type_t m_option_type_print_func = {
+const m_option_type_t m_option_type_print_func_param = {
.name = "Print",
.flags = M_OPT_TYPE_ALLOW_WILDCARD,
.parse = parse_print,
};
+const m_option_type_t m_option_type_print_func = {
+ .name = "Print",
+ .flags = M_OPT_TYPE_ALLOW_WILDCARD | M_OPT_TYPE_OLD_SYNTAX_NO_PARAM,
+ .parse = parse_print,
+};
+
/////////////////////// Subconfig
#undef VAL
#define VAL(x) (*(char ***)(x))
static int parse_subconf(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
int nr = 0;
char **lst = NULL;
@@ -982,7 +991,7 @@ static struct {
};
static int parse_imgfmt(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
uint32_t fmt = 0;
int i;
@@ -1072,7 +1081,7 @@ static struct {
};
static int parse_afmt(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
uint32_t fmt = 0;
int i;
@@ -1140,7 +1149,7 @@ static int parse_timestring(struct bstr str, double *time, char endchar)
static int parse_time(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
double time;
@@ -1170,7 +1179,7 @@ const m_option_type_t m_option_type_time = {
// Time or size (-endpos)
static int parse_time_size(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
m_time_size_t ts;
char unit[4];
@@ -1267,7 +1276,7 @@ static int get_obj_param(struct bstr opt_name, struct bstr obj_name,
BSTR_P(opt_name), BSTR_P(obj_name), BSTR_P(str));
return M_OPT_UNKNOWN;
}
- r = m_option_parse(opt, str, p, false, NULL);
+ r = m_option_parse(opt, str, p, NULL);
if (r < 0) {
if (r > M_OPT_EXIT)
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: "
@@ -1287,7 +1296,7 @@ static int get_obj_param(struct bstr opt_name, struct bstr obj_name,
return M_OPT_OUT_OF_RANGE;
}
opt = &desc->fields[(*nold)];
- r = m_option_parse(opt, bstr0(opt->name), str, false, NULL);
+ r = m_option_parse(opt, bstr0(opt->name), str, NULL);
if (r < 0) {
if (r > M_OPT_EXIT)
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: "
@@ -1402,7 +1411,7 @@ static int get_obj_params(struct bstr opt_name, struct bstr name,
}
static int parse_obj_params(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+ struct bstr param, void *dst)
{
char **opts;
int r;
@@ -1510,7 +1519,7 @@ static int parse_obj_settings(struct bstr opt, struct bstr str,
}
static int obj_settings_list_del(struct bstr opt_name, struct bstr param,
- bool ambiguous_param, void *dst)
+ void *dst)
{
char **str_list = NULL;
int r, i, idx_max = 0;
@@ -1534,7 +1543,7 @@ static int obj_settings_list_del(struct bstr opt_name, struct bstr param,
/* NOP */;
}
- r = m_option_parse(&list_opt, opt_name, param, false, &str_list);
+ r = m_option_parse(&list_opt, opt_name, param, &str_list);
if (r < 0 || !str_list)
return r;
@@ -1599,8 +1608,7 @@ static void free_obj_settings_list(void *dst)
}
static int parse_obj_settings_list(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param,
- void *dst)
+ struct bstr param, void *dst)
{
int len = strlen(opt->name);
m_obj_settings_t *res = NULL, *queue = NULL, *head = NULL;
@@ -1662,7 +1670,7 @@ static int parse_obj_settings_list(const m_option_t *opt, struct bstr name,
queue = VAL(dst);
break;
case OP_DEL:
- return obj_settings_list_del(name, param, false, dst);
+ return obj_settings_list_del(name, param, dst);
case OP_NONE:
if (dst && VAL(dst))
free_obj_settings_list(dst);
@@ -1773,8 +1781,7 @@ const m_option_type_t m_option_type_obj_settings_list = {
static int parse_obj_presets(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param,
- void *dst)
+ struct bstr param, void *dst)
{
m_obj_presets_t *obj_p = (m_obj_presets_t *)opt->priv;
const m_struct_t *in_desc;
@@ -1849,7 +1856,7 @@ const m_option_type_t m_option_type_obj_presets = {
};
static int parse_custom_url(const m_option_t *opt, struct bstr name,
- struct bstr url, bool ambiguous_param, void *dst)
+ struct bstr url, void *dst)
{
int r;
m_struct_t *desc = opt->priv;
diff --git a/m_option.h b/m_option.h
index 6ff6ec2f14..416471ea0e 100644
--- a/m_option.h
+++ b/m_option.h
@@ -50,6 +50,7 @@ extern const m_option_type_t m_option_type_choice;
extern const m_option_type_t m_option_type_print;
extern const m_option_type_t m_option_type_print_func;
+extern const m_option_type_t m_option_type_print_func_param;
extern const m_option_type_t m_option_type_subconfig;
extern const m_option_type_t m_option_type_imgfmt;
extern const m_option_type_t m_option_type_afmt;
@@ -177,7 +178,7 @@ struct m_option_type {
const char *name;
// Size needed for the data.
unsigned int size;
- // See \ref OptionTypeFlags.
+ // One of M_OPT_TYPE*.
unsigned int flags;
// Parse the data from a string.
@@ -186,7 +187,6 @@ struct m_option_type {
* \param opt The option that is parsed.
* \param name The full option name.
* \param param The parameter to parse.
- * \param ambiguous_param: "param" old cmdline style, "param" may or
* may not be an argument meant for this option
* \param dst Pointer to the memory where the data should be written.
* If NULL the parameter validity should still be checked.
@@ -194,7 +194,7 @@ struct m_option_type {
* of arguments consumed. For details see \ref OptionParserReturn.
*/
int (*parse)(const m_option_t *opt, struct bstr name, struct bstr param,
- bool ambiguous_param, void *dst);
+ void *dst);
// Print back a value in string form.
/** \param opt The option to print.
@@ -325,6 +325,11 @@ struct m_option {
*/
#define M_OPT_TYPE_DYNAMIC (1 << 2)
+// The parameter is optional and by default no parameter is preferred. If the
+// "old syntax" is used, the command line parser will assume that the argument
+// takes no parameter.
+#define M_OPT_TYPE_OLD_SYNTAX_NO_PARAM (1 << 3)
+
///////////////////////////// Parser flags /////////////////////////////////
// On success parsers return the number of arguments consumed: 0 or 1.
@@ -377,10 +382,9 @@ static inline void *m_option_get_ptr(const struct m_option *opt,
// Helper to parse options, see \ref m_option_type::parse.
static inline int m_option_parse(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param,
- void *dst)
+ struct bstr param, void *dst)
{
- return opt->type->parse(opt, name, param, ambiguous_param, dst);
+ return opt->type->parse(opt, name, param, dst);
}
// Helper to print options, see \ref m_option_type::print.
diff --git a/m_property.c b/m_property.c
index 6eaaf92eeb..35c2c0e3b1 100644
--- a/m_property.c
+++ b/m_property.c
@@ -108,8 +108,7 @@ int m_property_do(const m_option_t *prop_list, const char *name,
if (!arg)
return M_PROPERTY_ERROR;
val = calloc(1, opt->type->size);
- if ((r = m_option_parse(opt, bstr0(opt->name), bstr0(arg), false,
- val)) <= 0) {
+ if ((r = m_option_parse(opt, bstr0(opt->name), bstr0(arg), val)) <= 0) {
free(val);
return r;
}
diff --git a/m_struct.c b/m_struct.c
index 82cdc0ee27..7b885cc905 100644
--- a/m_struct.c
+++ b/m_struct.c
@@ -71,7 +71,7 @@ int m_struct_set(const m_struct_t *st, void *obj, const char *field,
return 0;
}
- if(f->type->parse(f, bstr0(field), param, false, M_ST_MB_P(obj,f->p)) < 0) {
+ if(f->type->parse(f, bstr0(field), param, M_ST_MB_P(obj,f->p)) < 0) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s, field %s parsing error: %.*s\n",
st->name, field, BSTR_P(param));
return 0;
diff --git a/mpcommon.h b/mpcommon.h
index 87f074c6f2..d4ececc4b1 100644
--- a/mpcommon.h
+++ b/mpcommon.h
@@ -26,6 +26,8 @@
#define ROUND(x) ((int)((x) < 0 ? (x) - 0.5 : (x) + 0.5))
+#define MP_EXPAND_ARGS(...) __VA_ARGS__
+
#define MP_TALLOC_ELEMS(p) (talloc_get_size(p) / sizeof((p)[0]))
#define MP_GROW_ARRAY(p, nextidx) do { \
if ((nextidx) == MP_TALLOC_ELEMS(p)) \
@@ -43,15 +45,13 @@
(nextidx_ + 1) * sizeof((p)[0]) * 2);\
} while (0)
-#define MP_TARRAY_APPEND(ctx, p, idxvar, val) \
+#define MP_TARRAY_APPEND(ctx, p, idxvar, ...) \
do { \
MP_TARRAY_GROW(ctx, p, idxvar); \
- p[idxvar] = (val); \
+ p[idxvar] = (MP_EXPAND_ARGS(__VA_ARGS__)); \
idxvar++; \
} while (0)
-#define MP_EXPAND_ARGS(...) __VA_ARGS__
-
#define talloc_struct(ctx, type, ...) \
talloc_memdup(ctx, &(type) MP_EXPAND_ARGS(__VA_ARGS__), sizeof(type))
diff --git a/mplayer.c b/mplayer.c
index 5ce422c25e..31218cdd02 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -853,7 +853,7 @@ static void load_per_file_options(m_config_t *conf,
int params_count)
{
for (int n = 0; n < params_count; n++)
- m_config_set_option(conf, params[n].name, params[n].value, false);
+ m_config_set_option(conf, params[n].name, params[n].value);
}
/* When libmpdemux performs a blocking operation (network connection or
@@ -4211,8 +4211,13 @@ int main(int argc, char *argv[])
{
osdep_preinit(&argc, &argv);
- if (argc > 1 && (!strcmp(argv[1], "-leak-report")
- || !strcmp(argv[1], "--leak-report")))
+ if (argc >= 1) {
+ argc--;
+ argv++;
+ }
+
+ if (argc > 0 && (!strcmp(argv[0], "-leak-report")
+ || !strcmp(argv[0], "--leak-report")))
talloc_enable_leak_report();
struct MPContext *mpctx = talloc(NULL, MPContext);
@@ -4224,6 +4229,7 @@ int main(int argc, char *argv[])
.file_format = DEMUXER_TYPE_UNKNOWN,
.last_dvb_step = 1,
.terminal_osd_text = talloc_strdup(mpctx, ""),
+ .playlist = talloc_struct(mpctx, struct playlist, {0}),
};
mp_msg_init();
@@ -4239,7 +4245,7 @@ int main(int argc, char *argv[])
mp_input_register_options(mpctx->mconfig);
// Preparse the command line
- m_config_preparse_command_line(mpctx->mconfig, argc, argv, &verbose);
+ m_config_preparse_command_line(mpctx->mconfig, argc, argv);
print_version(false);
print_libav_versions();
@@ -4247,12 +4253,9 @@ int main(int argc, char *argv[])
if (!parse_cfgfiles(mpctx, mpctx->mconfig))
exit_player(mpctx, EXIT_NONE, 1);
- mpctx->playlist = talloc_struct(mpctx, struct playlist, {0});
- if (m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist,
- argc, argv))
+ if (!m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist,
+ argc, argv))
{
- mpctx->playlist->current = mpctx->playlist->first;
- } else {
exit_player(mpctx, EXIT_ERROR, 1);
}
@@ -4269,7 +4272,6 @@ int main(int argc, char *argv[])
mp_msg(MSGT_CPLAYER, MSGL_V, "\n");
if (!mpctx->playlist->first && !opts->player_idle_mode) {
- // no file/vcd/dvd -> show HELP:
print_version(true);
mp_msg(MSGT_CPLAYER, MSGL_INFO, "%s", mp_gtext(help_text));
exit_player(mpctx, EXIT_NONE, 0);
@@ -4287,6 +4289,7 @@ int main(int argc, char *argv[])
init_input(mpctx);
+ mpctx->playlist->current = mpctx->playlist->first;
play_files(mpctx);
exit_player(mpctx, EXIT_EOF, mpctx->quit_player_rc);
diff --git a/parser-cfg.c b/parser-cfg.c
index 91ef37be53..75a0457153 100644
--- a/parser-cfg.c
+++ b/parser-cfg.c
@@ -225,7 +225,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile)
tmp = m_config_set_profile_option(config, profile,
opt, param);
} else
- tmp = m_config_set_option0(config, opt, param, false);
+ tmp = m_config_set_option0(config, opt, param);
if (tmp < 0) {
PRINT_LINENUM;
if (tmp == M_OPT_UNKNOWN)