summaryrefslogtreecommitdiffstats
path: root/m_option.h
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 /m_option.h
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.)
Diffstat (limited to 'm_option.h')
-rw-r--r--m_option.h16
1 files changed, 10 insertions, 6 deletions
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.