summaryrefslogtreecommitdiffstats
path: root/core/m_config.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-21 09:22:25 +0200
committerwm4 <wm4@nowhere>2013-02-09 00:21:17 +0100
commit267a889cc2c5ca688a2b8fc93cf8e5349a3c8a44 (patch)
treeee2561f256db05092e61fa797be4b7ecaf3db991 /core/m_config.h
parent5412993724aee1126bfc8dfbc0422ebe5251b9b6 (diff)
downloadmpv-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/m_config.h')
-rw-r--r--core/m_config.h56
1 files changed, 26 insertions, 30 deletions
diff --git a/core/m_config.h b/core/m_config.h
index 8b9b0dc7f7..57170cf48a 100644
--- a/core/m_config.h
+++ b/core/m_config.h
@@ -64,13 +64,6 @@ struct m_profile {
char **opts;
};
-enum option_source {
- // Set when parsing command line arguments.
- M_COMMAND_LINE,
- // Set when parsing from a config file.
- M_CONFIG_FILE,
-};
-
// Config object
/** \ingroup Config */
typedef struct m_config {
@@ -78,7 +71,6 @@ typedef struct m_config {
/** This contains all options and suboptions.
*/
struct m_config_option *opts;
- enum option_source mode;
// When options are set (via m_config_set_option or m_config_set_profile),
// back up the old value (unless it's already backed up). Used for restoring
// global options when per-file options are set.
@@ -114,7 +106,19 @@ void m_config_leave_file_local(struct m_config *config);
int m_config_register_options(struct m_config *config,
const struct m_option *args);
-/* Set an option.
+enum {
+ M_SETOPT_PRE_PARSE_ONLY = 1, // Silently ignore non-M_OPT_PRE_PARSE opt.
+ M_SETOPT_CHECK_ONLY = 2, // Don't set, just check name/value
+ M_SETOPT_FROM_CONFIG_FILE = 4, // Reject M_OPT_NOCFG opt. (print error)
+};
+
+// Set the named option to the given string.
+// flags: combination of M_SETOPT_* flags (0 for normal operation)
+// Returns >= 0 on success, otherwise see OptionParserReturn.
+int m_config_set_option_ext(struct m_config *config, struct bstr name,
+ struct bstr param, int flags);
+
+/* Set an option. (Like: m_config_set_option_ext(config, name, param, 0))
* \param config The config object.
* \param name The option's name.
* \param param The value of the option, can be NULL.
@@ -129,18 +133,6 @@ static inline int m_config_set_option0(struct m_config *config,
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);
-
-static inline int m_config_check_option0(struct m_config *config,
- const char *name, const char *param)
-{
- return m_config_check_option(config, bstr0(name), bstr0(param));
-}
-
int m_config_parse_suboptions(struct m_config *config, char *name,
char *subopts);
@@ -156,15 +148,19 @@ struct m_config_option *m_config_get_co(const struct m_config *config,
struct bstr name);
/* Map options like "no-opt=" to "opt=no".
- * config The config object.
- * \param name The option's name. May be set to a new name.
- * \param param The option value. May be set to a new value.
- * \return The following error codes:
- * M_OPT_UNKNOWN: option not found
- * M_OPT_INVALID: parameter non-empty in map case, prevents the mapping
- * 0: success, *name and *param have been changed (or not)
+ * config: config object.
+ * name: option's name. May be set to a new name.
+ * value: option value. May be set to a new value.
+ * ambiguous: if true, "value" may be either an option value, or a separate,
+ * unrelated option following the current option.
+ * returns the following error codes:
+ * < 0: one of the M_OPT_ error codes
+ * 0: the option is valid, *value is set implicitly
+ * ("--foo bar" maps to "--foo=yes" + "bar", *value == "yes")
+ * 1: the option is valid, *value is a proper parameter
*/
-int m_config_map_option(struct m_config *config, bstr *name, bstr *param);
+int m_config_map_option(struct m_config *config, bstr *name, bstr *value,
+ bool ambiguous);
/* Print a list of all registered options.
* \param config The config object.
@@ -204,7 +200,7 @@ void m_profile_set_desc(struct m_profile *p, char *desc);
* \param val The option's value.
*/
int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
- char *name, char *val);
+ bstr name, bstr val);
/* Enables profile usage
* Used by the config file parser when loading a profile.