options: change -v parsing

Handle -v flags as a special case in command line preparsing stage,
and change the option entry into a dummy one. Specifying "v" in config
file no longer works (and the dummy entry shows an error in this
case); "msglevel" can still be used for that purpose. Because the flag
is now interpreted at an earlier parsing stage, it now affects the
printing of some early messages that were only affected by the
MPLAYER_VERBOSE environment variable before.

The main motivation for this change is to get rid of the last
CONF_TYPE_FUNC option.
This commit is contained in:
Uoti Urpala 2012-05-07 23:51:58 +03:00
parent c02d0ee703
commit 9fbfac25da
4 changed files with 12 additions and 10 deletions

View File

@ -373,7 +373,8 @@ const m_option_t common_opts[] = {
// ------------------------- common options --------------------
OPT_MAKE_FLAGS("quiet", quiet, CONF_GLOBAL),
{"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},
// -v is handled in command line preparser
{"v", NULL, CONF_TYPE_FLAG, CONF_NOCFG, 0, 0, NULL},
{"msglevel", (void *) msgl_config, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
{"msgcolor", &mp_msg_color, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
{"nomsgcolor", &mp_msg_color, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL},

View File

@ -149,12 +149,6 @@ char *heartbeat_cmd;
// Config file
//**************************************************************************//
static int cfg_inc_verbose(m_option_t *conf)
{
++verbose;
return 0;
}
#include "path.h"
//**************************************************************************//
@ -3952,7 +3946,7 @@ int main(int argc, char *argv[])
mp_input_register_options(mpctx->mconfig);
// Preparse the command line
m_config_preparse_command_line(mpctx->mconfig, argc, argv);
m_config_preparse_command_line(mpctx->mconfig, argc, argv, &verbose);
#if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
set_path_env();

View File

@ -308,7 +308,8 @@ extern int mp_msg_levels[];
* command line parsing), and --really-quiet suppresses messages printed
* during normal options parsing.
*/
int m_config_preparse_command_line(m_config_t *config, int argc, char **argv)
int m_config_preparse_command_line(m_config_t *config, int argc, char **argv,
int *verbose)
{
int ret = 0;
@ -330,6 +331,11 @@ int m_config_preparse_command_line(m_config_t *config, int argc, char **argv)
// Ignore invalid options
if (map_to_option(config, old_syntax, NULL, &opt, &param) < 0)
continue;
// "-v" is handled here
if (!bstrcmp0(opt, "v")) {
(*verbose)++;
continue;
}
// Set, non-pre-parse options will be ignored
int r = m_config_set_option(config, opt, param, old_syntax);
if (r < 0)

View File

@ -24,6 +24,7 @@
play_tree_t *m_config_parse_mp_command_line(m_config_t *config, int argc,
char **argv);
int m_config_preparse_command_line(m_config_t *config, int argc, char **argv);
int m_config_preparse_command_line(m_config_t *config, int argc, char **argv,
int *verbose);
#endif /* MPLAYER_PARSER_MPCMD_H */