# HG changeset patch # User albeu # Date 1208114331 0 # Node ID 7a36d5941fd815f4910c23b290f1c6ee1008bac3 # Parent 7451ffea2efb6a5a806a53ec14170bc58272625e Replace the trivial command line preparser with a more robust version allowing all kind of options to be used. diff -r 7451ffea2efb -r 7a36d5941fd8 cfg-common-opts.h --- a/cfg-common-opts.h Sun Apr 13 11:15:08 2008 +0000 +++ b/cfg-common-opts.h Sun Apr 13 19:18:51 2008 +0000 @@ -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 -r 7451ffea2efb -r 7a36d5941fd8 m_config.c --- a/m_config.c Sun Apr 13 11:15:08 2008 +0000 +++ b/m_config.c Sun Apr 13 19:18:51 2008 +0000 @@ -308,6 +308,13 @@ 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 -r 7451ffea2efb -r 7a36d5941fd8 m_option.h --- a/m_option.h Sun Apr 13 11:15:08 2008 +0000 +++ b/m_option.h Sun Apr 13 19:18:51 2008 +0000 @@ -321,6 +321,9 @@ /// 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 @@ #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 @@ #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 -r 7451ffea2efb -r 7a36d5941fd8 mencoder.c --- a/mencoder.c Sun Apr 13 11:15:08 2008 +0000 +++ b/mencoder.c Sun Apr 13 19:18:51 2008 +0000 @@ -408,9 +408,12 @@ mp_msg_init(); - for(i=1; imode = 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 -r 7451ffea2efb -r 7a36d5941fd8 parser-cfg.h --- a/parser-cfg.h Sun Apr 13 11:15:08 2008 +0000 +++ b/parser-cfg.h Sun Apr 13 19:18:51 2008 +0000 @@ -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 */