summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralbeu <albeu@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-04-13 19:18:51 +0000
committeralbeu <albeu@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-04-13 19:18:51 +0000
commite4dc453ea095c1c3e282d5b6cc1370c74abb76cf (patch)
tree8a849caffbabb6308b2fb54e3581fa5797391513
parentd08bf2fc44100bc4ee8400de1b8704519225533c (diff)
downloadmpv-e4dc453ea095c1c3e282d5b6cc1370c74abb76cf.tar.bz2
mpv-e4dc453ea095c1c3e282d5b6cc1370c74abb76cf.tar.xz
Replace the trivial command line preparser with a more robust version
allowing all kind of options to be used. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@26440 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--cfg-common-opts.h2
-rw-r--r--m_config.c7
-rw-r--r--m_option.h6
-rw-r--r--mencoder.c11
-rw-r--r--mplayer.c14
-rw-r--r--parser-cfg.c38
-rw-r--r--parser-cfg.h2
7 files changed, 67 insertions, 13 deletions
diff --git a/cfg-common-opts.h b/cfg-common-opts.h
index 244e064529..f59efc94e9 100644
--- a/cfg-common-opts.h
+++ b/cfg-common-opts.h
@@ -6,7 +6,7 @@
// ------------------------- common options --------------------
{"quiet", &quiet, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
{"noquiet", &quiet, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL},
- {"really-quiet", &verbose, CONF_TYPE_FLAG, CONF_GLOBAL, 0, -10, NULL},
+ {"really-quiet", &verbose, CONF_TYPE_FLAG, CONF_GLOBAL|CONF_PRE_PARSE, 0, -10, NULL},
{"v", cfg_inc_verbose, CONF_TYPE_FUNC, CONF_GLOBAL|CONF_NOSAVE, 0, 0, NULL},
{"msglevel", msgl_config, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
{"msgcolor", &mp_msg_color, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
diff --git a/m_config.c b/m_config.c
index c030b13233..263144813e 100644
--- a/m_config.c
+++ b/m_config.c
@@ -308,6 +308,13 @@ m_config_parse_option(m_config_t *config, char* arg, char* param,int set) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_InvalidCmdlineOption,arg);
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;
// Option with children are a bit different to parse
if(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) {
diff --git a/m_option.h b/m_option.h
index 13451390db..a54aac540f 100644
--- a/m_option.h
+++ b/m_option.h
@@ -321,6 +321,9 @@ struct m_option {
/// option only if it was set by the user.
#define M_OPT_OLD (1<<6)
+/// The option should be set during command line pre-parsing
+#define M_OPT_PRE_PARSE (1<<7)
+
/// \defgroup OldOptionFlags Backward compatibility
///
/// These are kept for compatibility with older code.
@@ -333,6 +336,7 @@ struct m_option {
#define CONF_GLOBAL M_OPT_GLOBAL
#define CONF_NOSAVE M_OPT_NOSAVE
#define CONF_OLD M_OPT_OLD
+#define CONF_PRE_PARSE M_OPT_PRE_PARSE
///@}
///@}
@@ -395,6 +399,8 @@ struct m_option {
#define M_CONFIG_FILE 0
/// Set when parsing command line arguments.
#define M_COMMAND_LINE 1
+/// Set when pre-parsing the command line
+#define M_COMMAND_LINE_PRE_PARSE 2
///@}
diff --git a/mencoder.c b/mencoder.c
index f4df17fdea..1274244a54 100644
--- a/mencoder.c
+++ b/mencoder.c
@@ -408,9 +408,12 @@ user_correct_pts = 0;
mp_msg_init();
- for(i=1; i<argc; i++)
- if(!strcmp(argv[i], "-really-quiet"))
- verbose= -10;
+ // Create the config context and register the options
+ mconfig = m_config_new();
+ m_config_register_options(mconfig,mencoder_opts);
+
+ // Preparse the command line
+ m_config_preparse_command_line(mconfig,argc,argv);
mp_msg(MSGT_CPLAYER,MSGL_INFO, "MEncoder " VERSION " (C) 2000-2008 MPlayer Team\n");
@@ -465,8 +468,6 @@ if(!codecs_file || !parse_codec_cfg(codecs_file)){
}
}
- mconfig = m_config_new();
- m_config_register_options(mconfig,mencoder_opts);
parse_cfgfiles(mconfig);
filelist = m_config_parse_me_command_line(mconfig, argc, argv);
if(!filelist) mencoder_exit(1, MSGTR_ErrorParsingCommandLine);
diff --git a/mplayer.c b/mplayer.c
index 810e4d8041..e005496ac5 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -2554,9 +2554,13 @@ int gui_no_filename=0;
mp_msg_init();
- for(i=1; i<argc; i++)
- if(!strcmp(argv[i], "-really-quiet"))
- verbose= -10;
+ // Create the config context and register the options
+ mconfig = m_config_new();
+ m_config_register_options(mconfig,mplayer_opts);
+ mp_input_register_options(mconfig);
+
+ // Preparse the command line
+ m_config_preparse_command_line(mconfig,argc,argv);
print_version();
#if defined(WIN32) && defined(USE_WIN32DLL)
@@ -2582,10 +2586,6 @@ int gui_no_filename=0;
use_gui=1;
}
- mconfig = m_config_new();
- m_config_register_options(mconfig,mplayer_opts);
- // TODO : add something to let modules register their options
- mp_input_register_options(mconfig);
parse_cfgfiles(mconfig);
#ifdef HAVE_NEW_GUI
diff --git a/parser-cfg.c b/parser-cfg.c
index 28fc2d4a57..eec28f5bf1 100644
--- a/parser-cfg.c
+++ b/parser-cfg.c
@@ -245,4 +245,42 @@ out:
return ret;
}
+extern int mp_msg_levels[];
+
+/// Parse the command line option that must be handled at startup.
+int m_config_preparse_command_line(m_config_t *config, int argc, char **argv)
+{
+ int msg_lvl, i, r, ret = 0;
+ char* arg;
+ m_option_t* opt;
+
+ // Hack to shutup the parser error messages.
+ msg_lvl = mp_msg_levels[MSGT_CFGPARSER];
+ mp_msg_levels[MSGT_CFGPARSER] = -11;
+
+ config->mode = M_COMMAND_LINE_PRE_PARSE;
+
+ for(i = 1 ; i < argc ; i++) {
+ arg = argv[i];
+ // Ignore non option
+ if(arg[0] != '-' || arg[1] == 0) continue;
+ arg++;
+ // No more options after --
+ if(arg[0] == '-' && arg[1] == 0) break;
+
+ opt = m_config_get_option(config,arg);
+ // Ignore invalid option
+ if(!opt) continue;
+ // Set, non-pre-parse options will be ignored
+ r = m_config_set_option(config,arg,
+ i+1 < argc ? argv[i+1] : NULL);
+ if(r < 0) ret = r;
+ else i += r;
+ }
+
+ mp_msg_levels[MSGT_CFGPARSER] = msg_lvl;
+
+ return ret;
+}
+
///@}
diff --git a/parser-cfg.h b/parser-cfg.h
index 852a68f697..d69f77106a 100644
--- a/parser-cfg.h
+++ b/parser-cfg.h
@@ -5,4 +5,6 @@
int m_config_parse_config_file(m_config_t* config, char *conffile);
+int m_config_preparse_command_line(m_config_t *config, int argc, char **argv);
+
#endif /* MPLAYER_PARSER_CFG_H */