mirror of
https://github.com/mpv-player/mpv
synced 2025-02-16 20:27:23 +00:00
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:
parent
ae33ec2c5b
commit
dcabceb626
@ -41,7 +41,6 @@
|
|||||||
|
|
||||||
struct parse_state {
|
struct parse_state {
|
||||||
struct m_config *config;
|
struct m_config *config;
|
||||||
int argc;
|
|
||||||
char **argv;
|
char **argv;
|
||||||
|
|
||||||
bool no_more_opts;
|
bool no_more_opts;
|
||||||
@ -57,14 +56,13 @@ static int split_opt_silent(struct parse_state *p)
|
|||||||
{
|
{
|
||||||
assert(!p->error);
|
assert(!p->error);
|
||||||
|
|
||||||
if (p->argc < 1)
|
if (!p->argv || !p->argv[0])
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
p->is_opt = false;
|
p->is_opt = false;
|
||||||
p->arg = bstr0(p->argv[0]);
|
p->arg = bstr0(p->argv[0]);
|
||||||
p->param = bstr0(NULL);
|
p->param = bstr0(NULL);
|
||||||
|
|
||||||
p->argc--;
|
|
||||||
p->argv++;
|
p->argv++;
|
||||||
|
|
||||||
if (p->no_more_opts || !bstr_startswith0(p->arg, "-") || p->arg.len == 1)
|
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;
|
bool need_param = m_config_option_requires_param(p->config, p->arg) > 0;
|
||||||
|
|
||||||
if (ambiguous && need_param) {
|
if (ambiguous && need_param) {
|
||||||
if (p->argc < 1)
|
if (!p->argv[0])
|
||||||
return M_OPT_MISSING_PARAM;
|
return M_OPT_MISSING_PARAM;
|
||||||
p->param = bstr0(p->argv[0]);
|
p->param = bstr0(p->argv[0]);
|
||||||
p->argc--;
|
|
||||||
p->argv++;
|
p->argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,8 +129,7 @@ static void process_non_option(struct playlist *files, const char *arg)
|
|||||||
|
|
||||||
// returns M_OPT_... error code
|
// returns M_OPT_... error code
|
||||||
int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
|
int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
|
||||||
struct mpv_global *global,
|
struct mpv_global *global, char **argv)
|
||||||
int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
int ret = M_OPT_UNKNOWN;
|
int ret = M_OPT_UNKNOWN;
|
||||||
int mode = 0;
|
int mode = 0;
|
||||||
@ -146,7 +142,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
|
|||||||
|
|
||||||
mode = GLOBAL;
|
mode = GLOBAL;
|
||||||
|
|
||||||
struct parse_state p = {config, argc - 1, argv + 1};
|
struct parse_state p = {config, argv + 1};
|
||||||
while (split_opt(&p)) {
|
while (split_opt(&p)) {
|
||||||
if (p.is_opt) {
|
if (p.is_opt) {
|
||||||
int flags = M_SETOPT_FROM_CMDLINE;
|
int flags = M_SETOPT_FROM_CMDLINE;
|
||||||
@ -283,14 +279,14 @@ err_out:
|
|||||||
* during normal options parsing.
|
* during normal options parsing.
|
||||||
*/
|
*/
|
||||||
void m_config_preparse_command_line(m_config_t *config, struct mpv_global *global,
|
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;
|
struct MPOpts *opts = global->opts;
|
||||||
|
|
||||||
// Hack to shut up parser error messages
|
// Hack to shut up parser error messages
|
||||||
mp_msg_mute(global, true);
|
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) {
|
while (split_opt_silent(&p) == 0) {
|
||||||
if (p.is_opt) {
|
if (p.is_opt) {
|
||||||
// Ignore non-pre-parse options. They will be set later.
|
// Ignore non-pre-parse options. They will be set later.
|
||||||
|
@ -26,9 +26,8 @@ struct m_config;
|
|||||||
struct mpv_global;
|
struct mpv_global;
|
||||||
|
|
||||||
int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
|
int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
|
||||||
struct mpv_global *global,
|
struct mpv_global *global, char **argv);
|
||||||
int argc, char **argv);
|
|
||||||
void m_config_preparse_command_line(m_config_t *config, struct mpv_global *global,
|
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 */
|
#endif /* MPLAYER_PARSER_MPCMD_H */
|
||||||
|
@ -476,7 +476,7 @@ int mpv_main(int argc, char *argv[])
|
|||||||
opts->verbose = atoi(verbose_env);
|
opts->verbose = atoi(verbose_env);
|
||||||
|
|
||||||
// Preparse the command line
|
// 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))
|
if (mpctx->opts->use_terminal && cas_terminal_owner(NULL, mpctx))
|
||||||
terminal_init();
|
terminal_init();
|
||||||
@ -484,7 +484,7 @@ int mpv_main(int argc, char *argv[])
|
|||||||
mp_msg_update_msglevels(mpctx->global);
|
mp_msg_update_msglevels(mpctx->global);
|
||||||
|
|
||||||
MP_VERBOSE(mpctx, "Command line:");
|
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, " '%s'", argv[i]);
|
||||||
MP_VERBOSE(mpctx, "\n");
|
MP_VERBOSE(mpctx, "\n");
|
||||||
|
|
||||||
@ -493,7 +493,7 @@ int mpv_main(int argc, char *argv[])
|
|||||||
mp_parse_cfgfiles(mpctx);
|
mp_parse_cfgfiles(mpctx);
|
||||||
|
|
||||||
int r = m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist,
|
int r = m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist,
|
||||||
mpctx->global, argc, argv);
|
mpctx->global, argv);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
if (r <= M_OPT_EXIT) {
|
if (r <= M_OPT_EXIT) {
|
||||||
return prepare_exit_cplayer(mpctx, EXIT_NONE);
|
return prepare_exit_cplayer(mpctx, EXIT_NONE);
|
||||||
|
Loading…
Reference in New Issue
Block a user