diff options
author | wm4 <wm4@nowhere> | 2012-09-21 09:22:25 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-02-09 00:21:17 +0100 |
commit | 267a889cc2c5ca688a2b8fc93cf8e5349a3c8a44 (patch) | |
tree | ee2561f256db05092e61fa797be4b7ecaf3db991 /core/parser-cfg.c | |
parent | 5412993724aee1126bfc8dfbc0422ebe5251b9b6 (diff) | |
download | mpv-267a889cc2c5ca688a2b8fc93cf8e5349a3c8a44.tar.bz2 mpv-267a889cc2c5ca688a2b8fc93cf8e5349a3c8a44.tar.xz |
options: unify single dash and double dash options
There were two option syntax variations:
"old": -opt value
"new": --opt=value
"-opt=value" was invalid, and "--opt value" meant "--opt=" followed by
a separate option "value" (i.e. interpreted as filename). There isn't
really any reason to do this. The "old" syntax used to be ambiguous
(you had to call the option parser to know whether the following
argument is an option value or a new option), but that has been removed.
Further, using "=" in the option string is always unambiguous.
Since the distinction between the two option variants is confusing,
just remove the difference and allow "--opt value" and "-opt=value".
To make this easier, do some other cleanups as well (e.g. avoid having
to do a manual lookup of the option just to check for M_OPT_PRE_PARSE,
which somehow ended up with finally getting rid of the m_config.mode
member).
Error reporting is still a mess, and we opt for reporting too many
rather than too few errors to the user.
There shouldn't be many user-visible changes. The --framedrop and
--term-osd options now always require parameters.
The --mute option is intentionally made ambiguous: it works like a flag
option, but a value can be passed to it explicitly ("--mute=auto"). If
the interpretation of the option is ambiguous (like "--mute auto"), the
second string is interpreted as separate option or filename. (Normal
flag options are actually ambiguous in this way too.)
Diffstat (limited to 'core/parser-cfg.c')
-rw-r--r-- | core/parser-cfg.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/core/parser-cfg.c b/core/parser-cfg.c index 1a67389854..e5bf6eb3b5 100644 --- a/core/parser-cfg.c +++ b/core/parser-cfg.c @@ -61,7 +61,6 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile) int param_pos; /* param pos */ int ret = 1; int errors = 0; - int prev_mode = config->mode; m_profile_t *profile = NULL; mp_msg(MSGT_CFGPARSER, MSGL_V, "Reading config file %s", conffile); @@ -71,9 +70,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile) ": too deep 'include'. check your configfiles\n"); ret = -1; goto out; - } else - - config->mode = M_CONFIG_FILE; + } if ((line = malloc(MAX_LINE_LEN + 1)) == NULL) { mp_msg(MSGT_CFGPARSER, MSGL_FATAL, @@ -145,10 +142,13 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile) ++line_pos; param_pos = 0; + bool param_set = false; /* check '=' */ if (line[line_pos] == '=') { line_pos++; + param_set = true; + /* whitespaces... */ while (isspace(line[line_pos])) ++line_pos; @@ -197,23 +197,34 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile) ret = -1; } + bstr bopt = bstr0(opt); + bstr bparam = bstr0(param); + + tmp = m_config_map_option(config, &bopt, &bparam, false); + if (tmp > 0 && !param_set) + tmp = M_OPT_MISSING_PARAM; + if (tmp < 0) { + PRINT_LINENUM; + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "error parsing option %s=%s: %s\n", + opt, param, m_option_strerror(tmp)); + continue; + } + if (profile) { if (!strcmp(opt, "profile-desc")) m_profile_set_desc(profile, param), tmp = 1; else tmp = m_config_set_profile_option(config, profile, - opt, param); - } else - tmp = m_config_set_option0(config, opt, param); + bopt, bparam); + } else { + tmp = m_config_set_option_ext(config, bopt, bparam, + M_SETOPT_FROM_CONFIG_FILE); + } if (tmp < 0) { PRINT_LINENUM; - if (tmp == M_OPT_UNKNOWN) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "unknown option '%s'\n", opt); - continue; - } mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "setting option %s='%s' failed\n", opt, param); + "setting option %s='%s' failed.\n", opt, param); continue; /* break */ } @@ -225,7 +236,6 @@ out: free(line); if (fp) fclose(fp); - config->mode = prev_mode; --recursion_depth; if (ret < 0) { mp_msg(MSGT_CFGPARSER, MSGL_FATAL, "Error loading config file %s.\n", |