From dcabceb6268d64a16c370504de265d0dcc657301 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 5 Mar 2015 10:57:38 +0100 Subject: 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. --- options/parse_commandline.c | 16 ++++++---------- options/parse_commandline.h | 5 ++--- player/main.c | 6 +++--- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/options/parse_commandline.c b/options/parse_commandline.c index 90675c7e01..06a6cb639b 100644 --- a/options/parse_commandline.c +++ b/options/parse_commandline.c @@ -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. diff --git a/options/parse_commandline.h b/options/parse_commandline.h index 39512ca51a..fde1329995 100644 --- a/options/parse_commandline.h +++ b/options/parse_commandline.h @@ -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 */ diff --git a/player/main.c b/player/main.c index dbd969ecef..bf684cbae0 100644 --- a/player/main.c +++ b/player/main.c @@ -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); -- cgit v1.2.3