summaryrefslogtreecommitdiffstats
path: root/parser-cfg.c
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 /parser-cfg.c
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
Diffstat (limited to 'parser-cfg.c')
-rw-r--r--parser-cfg.c38
1 files changed, 38 insertions, 0 deletions
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;
+}
+
///@}