player: minor simplification

argv is always terminated with a NULL, so we don't need to drag argc
along. Simplifies the following commit a little bit.
This commit is contained in:
wm4 2015-03-05 10:57:38 +01:00
parent ae33ec2c5b
commit dcabceb626
3 changed files with 11 additions and 16 deletions

View File

@ -41,7 +41,6 @@
struct parse_state {
struct m_config *config;
int argc;
char **argv;
bool no_more_opts;
@ -57,14 +56,13 @@ static int split_opt_silent(struct parse_state *p)
{
assert(!p->error);
if (p->argc < 1)
if (!p->argv || !p->argv[0])
return 1;
p->is_opt = false;
p->arg = bstr0(p->argv[0]);
p->param = bstr0(NULL);
p->argc--;
p->argv++;
if (p->no_more_opts || !bstr_startswith0(p->arg, "-") || p->arg.len == 1)
@ -85,10 +83,9 @@ static int split_opt_silent(struct parse_state *p)
bool need_param = m_config_option_requires_param(p->config, p->arg) > 0;
if (ambiguous && need_param) {
if (p->argc < 1)
if (!p->argv[0])
return M_OPT_MISSING_PARAM;
p->param = bstr0(p->argv[0]);
p->argc--;
p->argv++;
}
@ -132,8 +129,7 @@ static void process_non_option(struct playlist *files, const char *arg)
// returns M_OPT_... error code
int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
struct mpv_global *global,
int argc, char **argv)
struct mpv_global *global, char **argv)
{
int ret = M_OPT_UNKNOWN;
int mode = 0;
@ -146,7 +142,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
mode = GLOBAL;
struct parse_state p = {config, argc - 1, argv + 1};
struct parse_state p = {config, argv + 1};
while (split_opt(&p)) {
if (p.is_opt) {
int flags = M_SETOPT_FROM_CMDLINE;
@ -283,14 +279,14 @@ err_out:
* during normal options parsing.
*/
void m_config_preparse_command_line(m_config_t *config, struct mpv_global *global,
int argc, char **argv)
char **argv)
{
struct MPOpts *opts = global->opts;
// Hack to shut up parser error messages
mp_msg_mute(global, true);
struct parse_state p = {config, argc - 1, argv + 1};
struct parse_state p = {config, argv + 1};
while (split_opt_silent(&p) == 0) {
if (p.is_opt) {
// Ignore non-pre-parse options. They will be set later.

View File

@ -26,9 +26,8 @@ struct m_config;
struct mpv_global;
int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
struct mpv_global *global,
int argc, char **argv);
struct mpv_global *global, char **argv);
void m_config_preparse_command_line(m_config_t *config, struct mpv_global *global,
int argc, char **argv);
char **argv);
#endif /* MPLAYER_PARSER_MPCMD_H */

View File

@ -476,7 +476,7 @@ int mpv_main(int argc, char *argv[])
opts->verbose = atoi(verbose_env);
// Preparse the command line
m_config_preparse_command_line(mpctx->mconfig, mpctx->global, argc, argv);
m_config_preparse_command_line(mpctx->mconfig, mpctx->global, argv);
if (mpctx->opts->use_terminal && cas_terminal_owner(NULL, mpctx))
terminal_init();
@ -484,7 +484,7 @@ int mpv_main(int argc, char *argv[])
mp_msg_update_msglevels(mpctx->global);
MP_VERBOSE(mpctx, "Command line:");
for (int i = 0; i < argc; i++)
for (int i = 0; argv[i]; i++)
MP_VERBOSE(mpctx, " '%s'", argv[i]);
MP_VERBOSE(mpctx, "\n");
@ -493,7 +493,7 @@ int mpv_main(int argc, char *argv[])
mp_parse_cfgfiles(mpctx);
int r = m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist,
mpctx->global, argc, argv);
mpctx->global, argv);
if (r < 0) {
if (r <= M_OPT_EXIT) {
return prepare_exit_cplayer(mpctx, EXIT_NONE);