[MPlayer-dev-eng] [PATCH] Use the normal option parser for command line preparsing
Andrew Savchenko
Bircoph at list.ru
Sun Apr 13 18:33:42 CEST 2008
Hi,
On Sunday 13 April 2008 18:52, Alban Bedel wrote:
> with regard to the -noconfig patch I fixed the command line
> preparsing to allow using options normally. I put the preparser
> code with the config file parser together bcs this code is also
> used by both mplayer and mencoder.
Good, I'll wait with my patch until yours one will be applied.
> --- parser-cfg.c (revision 26439)
> +++ parser-cfg.c (working copy)
> @@ -245,4 +245,42 @@
> 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;
> +}
> +
> ///@}
Why this is needed to be implemented as separate function instead
of reusing m_config_parse_*_commandline()?
Perhaps it will be better just to shut up parser errors, set
appropriate config mode and run normal
m_config_parse_mp_commandline() or m_config_parse_me_commandline()
respectively?
> Index: m_config.c
> ================================================================
>=== --- m_config.c (revision 26439)
> +++ m_config.c (working copy)
> @@ -308,6 +308,13 @@
> mp_msg(MSGT_CFGPARSER,
> MSGL_ERR,MSGTR_InvalidCmdlineOption,arg); return M_OPT_INVALID;
> }
> + // During pre-parse don't set non-pre-parse options
> + // Otherwise don't set pre-parse options
> + 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)))
The problem is here. Just imagine that option is marked as
CONF_PRE_PARSE and is not specified in the command line, but is
specified in the config file. It such case option just will be
ignored.
I suggest to add another flag (e.g. M_OPT_PREPARSE_DONE) and toggle
it while preparsing, and only skip option at the main parse if
this flag is set.
> + set = 0;
Why not exit from m_config_parse_option() immediately?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20080413/196a5e5a/attachment.pgp>
More information about the MPlayer-dev-eng
mailing list