From 94782e464d985b6e653618d8a61cf2ee817c3e9f Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 5 Aug 2012 23:34:28 +0200 Subject: 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.) --- cfg-mplayer.h | 15 ++- input/input.c | 4 +- m_config.c | 41 ++---- m_config.h | 26 ++-- m_option.c | 83 ++++++------ m_option.h | 16 ++- m_property.c | 3 +- m_struct.c | 2 +- mpcommon.h | 8 +- mplayer.c | 23 ++-- parser-cfg.c | 2 +- parser-mpcmd.c | 387 +++++++++++++++++++++++++++++--------------------------- parser-mpcmd.h | 11 +- stream/stream.c | 2 +- 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) { diff --git a/parser-mpcmd.c b/parser-mpcmd.c index d84ec16432..5a91c093f9 100644 --- a/parser-mpcmd.c +++ b/parser-mpcmd.c @@ -39,58 +39,120 @@ #define dvd_range(a) (a > 0 && a < 256) -static bool split_opt(struct bstr *opt, struct bstr *param, bool *old_syntax) +struct parse_state { + struct m_config *config; + int argc; + char **argv; + + bool no_more_opts; + bool error; + + const struct m_option *mp_opt; // NULL <=> it's a file arg + struct bstr arg; + struct bstr param; +}; + +// Returns 0 if a valid option/file is available, <0 on error, 1 on end of args. +static int split_opt_silent(struct parse_state *p) { - if (!bstr_startswith0(*opt, "-") || opt->len == 1) - return false; - if (bstr_startswith0(*opt, "--")) { - *old_syntax = false; - *opt = bstr_cut(*opt, 2); - *param = bstr0(NULL); - int idx = bstrchr(*opt, '='); + assert(!p->error); + + if (p->argc < 1) + return 1; + + p->mp_opt = NULL; + p->arg = bstr0(p->argv[0]); + p->param = bstr0(NULL); + + p->argc--; + p->argv++; + + if (p->no_more_opts || !bstr_startswith0(p->arg, "-") || p->arg.len == 1) + return 0; + + bool old_syntax = !bstr_startswith0(p->arg, "--"); + if (old_syntax) { + p->arg = bstr_cut(p->arg, 1); + } else { + p->arg = bstr_cut(p->arg, 2); + int idx = bstrchr(p->arg, '='); if (idx > 0) { - *param = bstr_cut(*opt, idx + 1); - *opt = bstr_splice(*opt, 0, idx); + p->param = bstr_cut(p->arg, idx + 1); + p->arg = bstr_splice(p->arg, 0, idx); } - } else { - *old_syntax = true; - *opt = bstr_cut(*opt, 1); } - return true; + + p->mp_opt = m_config_get_option(p->config, p->arg); + if (!p->mp_opt) { + // Automagic "no-" arguments: "--no-bla" turns into "--bla=no". + if (!bstr_startswith0(p->arg, "no-")) + return -1; + + struct bstr s = bstr_cut(p->arg, 3); + p->mp_opt = m_config_get_option(p->config, s); + if (!p->mp_opt || p->mp_opt->type != &m_option_type_flag) + return -1; + // Avoid allowing "--no-no-bla". + if (bstr_startswith(bstr0(p->mp_opt->name), bstr0("no-"))) + return -1; + // Flag options never have parameters. + old_syntax = false; + if (p->param.len) + return -2; + p->arg = s; + p->param = bstr0("no"); + } + + if (bstr_endswith0(p->arg, "-clr")) + old_syntax = false; + + if (old_syntax && !(p->mp_opt->type->flags & M_OPT_TYPE_OLD_SYNTAX_NO_PARAM)) + { + if (p->argc < 1) + return -3; + p->param = bstr0(p->argv[0]); + p->argc--; + p->argv++; + } + + return 0; } -static int map_to_option(struct m_config *config, bool old_syntax, - const struct m_option **mp_opt, - struct bstr *optname, struct bstr *param) +// Returns true if more args, false if all parsed or an error occurred. +static bool split_opt(struct parse_state *p) { - if (!mp_opt) - mp_opt = &(const struct m_option *){0}; - *mp_opt = m_config_get_option(config, *optname); - if (*mp_opt) - return 0; - if (!bstr_startswith0(*optname, "no-")) - return -1; - struct bstr s = bstr_cut(*optname, 3); - *mp_opt = m_config_get_option(config, s); - if (!*mp_opt || (*mp_opt)->type != &m_option_type_flag) - return -1; - if (param->len) - return -2; - if (old_syntax) - return -3; - *optname = s; - *param = bstr0("no"); - return 0; + int r = split_opt_silent(p); + if (r >= 0) + return r == 0; + p->error = true; + if (r == -2) + mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, + "A no-* option can't take parameters: --%.*s=%.*s\n", + BSTR_P(p->arg), BSTR_P(p->param)); + else if (r == -3) + mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, + "Option %.*s needs a parameter.\n", BSTR_P(p->arg)); + else + mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, + "Unknown option on the command line: %.*s\n", + BSTR_P(p->arg)); + return false; +} + +static bool parse_flag(bstr name, bstr f) +{ + struct m_option opt = {NULL, NULL, CONF_TYPE_FLAG, 0, 0, 1, NULL}; + int val = 0; + m_option_parse(&opt, name, f, &val); + return !!val; } bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, int argc, char **argv) { int mode = 0; - bool no_more_opts = false; bool opt_exit = false; // exit immediately after parsing (help options) struct playlist_entry *local_start = NULL; - struct bstr orig_opt; bool shuffle = false; int local_params_count = 0; @@ -98,8 +160,6 @@ bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, assert(config != NULL); assert(!config->file_local_mode); - assert(argv != NULL); - assert(argc >= 1); config->mode = M_COMMAND_LINE; mode = GLOBAL; @@ -108,132 +168,110 @@ bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, return true; #endif - for (int i = 1; i < argc; i++) { - //next: - struct bstr opt = bstr0(argv[i]); - orig_opt = opt; - /* check for -- (no more options id.) except --help! */ - if (!bstrcmp0(opt, "--")) { - no_more_opts = true; - continue; - } - if (!bstrcmp0(opt, "--{")) { - if (mode != GLOBAL) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "'--{' can not be nested\n"); + struct parse_state p = {config, argc, argv}; + while (split_opt(&p)) { + if (p.mp_opt) { + int r; + if (mode == GLOBAL && !(p.mp_opt->flags & M_OPT_PRE_PARSE)) { + r = m_config_set_option(config, p.arg, p.param); + } else { + r = m_config_check_option(config, p.arg, p.param); + } + if (r <= M_OPT_EXIT) { + opt_exit = true; + r = M_OPT_EXIT - r; + } else if (r < 0) { + char *msg = m_option_strerror(r); + if (!msg) + goto print_err; + mp_tmsg(MSGT_CFGPARSER, MSGL_FATAL, + "Error parsing commandline option %.*s: %s\n", + BSTR_P(p.arg), msg); goto err_out; } - mode = LOCAL; - // Needed for option checking. - m_config_enter_file_local(config); - assert(!local_start); - local_start = files->last; - continue; - } - if (!bstrcmp0(opt, "--}")) { - if (mode != LOCAL) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too many closing '--}'\n"); - goto err_out; + // Handle some special arguments outside option parser. + + if (!bstrcmp0(p.arg, "{")) { + if (mode != GLOBAL) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "'--{' can not be nested.\n"); + goto err_out; + } + mode = LOCAL; + // Needed for option checking. + m_config_enter_file_local(config); + assert(!local_start); + local_start = files->last; + continue; } - if (local_params_count) { - // The files added between '{' and '}' are the entries from the - // entry _after_ local_start, until the end of the list. If - // local_start is NULL, the list was empty on '{', and we want - // all files in the list. - struct playlist_entry *cur - = local_start ? local_start->next : files->first; - if (!cur) - mp_msg(MSGT_CFGPARSER, MSGL_WARN, "ignored options\n"); - while (cur) { - playlist_entry_add_params(cur, local_params, - local_params_count); - cur = cur->next; + + if (!bstrcmp0(p.arg, "}")) { + if (mode != LOCAL) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Too many closing '--}'.\n"); + goto err_out; + } + if (local_params_count) { + // The files added between '{' and '}' are the entries from + // the entry _after_ local_start, until the end of the list. + // If local_start is NULL, the list was empty on '{', and we + // want all files in the list. + struct playlist_entry *cur + = local_start ? local_start->next : files->first; + if (!cur) + mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Ignored options!\n"); + while (cur) { + playlist_entry_add_params(cur, local_params, + local_params_count); + cur = cur->next; + } } + local_params_count = 0; + mode = GLOBAL; + m_config_leave_file_local(config); + local_start = NULL; + shuffle = false; + continue; } - local_params_count = 0; - mode = GLOBAL; - m_config_leave_file_local(config); - local_start = NULL; - continue; - } - struct bstr param = bstr0(i+1 < argc ? argv[i+1] : NULL); - bool old_syntax; - if (!no_more_opts && split_opt(&opt, ¶m, &old_syntax)) { - const struct m_option *mp_opt; - int ok = map_to_option(config, old_syntax, &mp_opt, &opt, ¶m); - if (ok < 0) { - if (ok == -3) - mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, - "Option --%.*s can't be used with single-dash " - "syntax\n", BSTR_P(opt)); - else if (ok == -2) - mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, - "A --no-* option can't take parameters: " - "--%.*s=%.*s\n", BSTR_P(opt), BSTR_P(param)); - else - mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, - "Unknown option on the command line: --%.*s\n", - BSTR_P(opt)); - goto print_err; + if (bstrcmp0(p.arg, "shuffle") == 0) { + shuffle = parse_flag(p.arg, p.param); + continue; } - // Handle some special arguments outside option parser. - // --loop when it applies to a group of files (per-file is option) - if (bstrcasecmp0(opt, "shuffle") == 0) { - shuffle = true; - } else if (bstrcasecmp0(opt, "no-shuffle") == 0) { - shuffle = false; - } else if (bstrcasecmp0(opt, "playlist") == 0) { - if (param.len <= 0) - goto print_err; + + if (bstrcmp0(p.arg, "playlist") == 0) { // append the playlist to the local args - char *param0 = bstrdup0(NULL, param); + char *param0 = bstrdup0(NULL, p.param); struct playlist *pl = playlist_parse_file(param0); talloc_free(param0); if (!pl) goto print_err; playlist_transfer_entries(files, pl); talloc_free(pl); - i += old_syntax; - } else { - // "normal" options - int r; - if (mode == GLOBAL) { - r = m_config_set_option(config, opt, param, old_syntax); - } else { - r = m_config_check_option(config, opt, param, old_syntax); - if (r >= 0) { - if (r == 0) - param = bstr0(NULL); // for old_syntax case - struct playlist_param p = {opt, param}; - MP_TARRAY_APPEND(NULL, local_params, - local_params_count, p); - } - } - if (r <= M_OPT_EXIT) { - opt_exit = true; - r = M_OPT_EXIT - r; - } else if (r < 0) { - char *msg = m_option_strerror(r); - if (!msg) - goto print_err; - mp_tmsg(MSGT_CFGPARSER, MSGL_FATAL, - "Error parsing commandline option \"%.*s\": %s\n", - BSTR_P(orig_opt), msg); - goto err_out; - } - if (old_syntax) - i += r; + continue; + } + + if (bstrcmp0(p.arg, "v") == 0) { + verbose++; + continue; } - } else { /* filename */ - int is_dvdnav = strstr(argv[i], "dvdnav://") != NULL; - mp_msg(MSGT_CFGPARSER, MSGL_DBG2, "Adding file %s\n", argv[i]); + + if (mode == LOCAL) { + MP_TARRAY_APPEND(NULL, local_params, local_params_count, + (struct playlist_param) {p.arg, p.param}); + } + } else { + // filename + bstr file = p.arg; + char *file0 = bstrdup0(NULL, p.arg); + int is_dvdnav = bstr_startswith0(file, "dvdnav://"); // expand DVD filename entries like dvd://1-3 into component titles - if (strstr(argv[i], "dvd://") != NULL || is_dvdnav) { + if (bstr_startswith0(file, "dvd://") || is_dvdnav) { int offset = is_dvdnav ? 9 : 6; - char *splitpos = strstr(argv[i] + offset, "-"); + char *splitpos = strstr(file0 + offset, "-"); if (splitpos != NULL) { - int start_title = strtol(argv[i] + offset, NULL, 10); + int start_title = strtol(file0 + offset, NULL, 10); int end_title; //entries like dvd://-2 imply start at title 1 if (start_title < 0) { @@ -252,20 +290,21 @@ bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, } } else mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, - "Invalid play entry %s\n", argv[i]); + "Invalid play entry %s\n", file0); } else // dvd:// or dvd://x entry - playlist_add_file(files, argv[i]); + playlist_add_file(files, file0); } else - playlist_add_file(files, argv[i]); + playlist_add_file(files, file0); + talloc_free(file0); // Lock stdin if it will be used as input - if (strcasecmp(argv[i], "-") == 0) - m_config_set_option0(config, "consolecontrols", "no", false); + if (bstrcmp0(file, "-") == 0) + m_config_set_option0(config, "consolecontrols", "no"); } } - if (opt_exit) + if (p.error) goto err_out; if (mode != GLOBAL) { @@ -274,6 +313,9 @@ bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, goto err_out; } + if (opt_exit) + goto err_out; + if (shuffle) playlist_shuffle(files); @@ -283,8 +325,7 @@ bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, print_err: mp_tmsg(MSGT_CFGPARSER, MSGL_FATAL, - "Error parsing option on the command line: %.*s\n", - BSTR_P(orig_opt)); + "Error parsing option on the command line: %.*s\n", BSTR_P(p.arg)); err_out: talloc_free(local_params); if (config->file_local_mode) @@ -299,43 +340,21 @@ extern int mp_msg_levels[]; * command line parsing), and --really-quiet suppresses messages printed * during normal options parsing. */ -int m_config_preparse_command_line(m_config_t *config, int argc, char **argv, - int *verbose) +void m_config_preparse_command_line(m_config_t *config, int argc, char **argv) { - int ret = 0; - // Hack to shut up parser error messages int msg_lvl_backup = mp_msg_levels[MSGT_CFGPARSER]; mp_msg_levels[MSGT_CFGPARSER] = -11; - config->mode = M_COMMAND_LINE_PRE_PARSE; - - for (int i = 1 ; i < argc ; i++) { - struct bstr opt = bstr0(argv[i]); - // No more options after -- - if (!bstrcmp0(opt, "--")) - break; - struct bstr param = bstr0(i+1 < argc ? argv[i+1] : NULL); - bool old_syntax; - if (!split_opt(&opt, ¶m, &old_syntax)) - continue; // Ignore non-option arguments - // Ignore invalid options - if (map_to_option(config, old_syntax, NULL, &opt, ¶m) < 0) - continue; - // "-v" is handled here - if (!bstrcmp0(opt, "v")) { - (*verbose)++; - continue; + struct parse_state p = {config, argc, argv}; + while (split_opt_silent(&p) == 0) { + if (p.mp_opt) { + // Ignore non-pre-parse options. They will be set later. + // Option parsing errors will be handled later as well. + if (p.mp_opt->flags & M_OPT_PRE_PARSE) + m_config_set_option(config, p.arg, p.param); } - // Set, non-pre-parse options will be ignored - int r = m_config_set_option(config, opt, param, old_syntax); - if (r < 0) - ret = r; - else if (old_syntax) - i += r; } mp_msg_levels[MSGT_CFGPARSER] = msg_lvl_backup; - - return ret; } diff --git a/parser-mpcmd.h b/parser-mpcmd.h index b21348590a..674903fe4d 100644 --- a/parser-mpcmd.h +++ b/parser-mpcmd.h @@ -20,11 +20,14 @@ #define MPLAYER_PARSER_MPCMD_H #include -#include "m_config.h" -bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, +struct playlist; +struct m_config; + +bool m_config_parse_mp_command_line(struct m_config *config, + struct playlist *files, + int argc, char **argv); +void m_config_preparse_command_line(struct m_config *config, int argc, char **argv); -int m_config_preparse_command_line(m_config_t *config, int argc, char **argv, - int *verbose); #endif /* MPLAYER_PARSER_MPCMD_H */ diff --git a/stream/stream.c b/stream/stream.c index db389c45c7..d4f0c8ae97 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -160,7 +160,7 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo, if(sinfo->opts_url) { m_option_t url_opt = { "stream url", arg , CONF_TYPE_CUSTOM_URL, 0, 0 ,0, (void *)sinfo->opts }; - if (m_option_parse(&url_opt, bstr0("stream url"), bstr0(filename), false, arg) < 0) { + if (m_option_parse(&url_opt, bstr0("stream url"), bstr0(filename), arg) < 0) { mp_tmsg(MSGT_OPEN,MSGL_ERR, "URL parsing failed on url %s\n",filename); m_struct_free(desc,arg); return NULL; -- cgit v1.2.3