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.) --- m_config.h | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'm_config.h') 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, -- cgit v1.2.3