1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-22 06:42:03 +00:00

options: some more mp_msg conversions

This commit is contained in:
wm4 2013-12-21 20:08:34 +01:00
parent d57eaa7e30
commit 09e588662e
4 changed files with 31 additions and 42 deletions

View File

@ -104,14 +104,14 @@ static bool split_opt(struct parse_state *p)
return r == 0;
p->error = true;
mp_msg(MSGT_CFGPARSER, MSGL_FATAL,
"Error parsing commandline option %.*s: %s\n",
BSTR_P(p->arg), m_option_strerror(r));
MP_FATAL(p->config, "Error parsing commandline option %.*s: %s\n",
BSTR_P(p->arg), m_option_strerror(r));
return false;
}
// 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 MPOpts *opts = config->optstruct;
@ -138,9 +138,8 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
goto err_out;
}
if (r < 0) {
mp_msg(MSGT_CFGPARSER, MSGL_FATAL,
"Setting commandline option --%.*s=%.*s failed.\n",
BSTR_P(p.arg), BSTR_P(p.param));
MP_FATAL(config, "Setting commandline option --%.*s=%.*s failed.\n",
BSTR_P(p.arg), BSTR_P(p.param));
goto err_out;
}
@ -148,8 +147,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
if (!bstrcmp0(p.arg, "{")) {
if (mode != GLOBAL) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"'--{' can not be nested.\n");
MP_ERR(config, "'--{' can not be nested.\n");
goto err_out;
}
mode = LOCAL;
@ -160,8 +158,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
if (!bstrcmp0(p.arg, "}")) {
if (mode != LOCAL) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"Too many closing '--}'.\n");
MP_ERR(config, "Too many closing '--}'.\n");
goto err_out;
}
if (local_params_count) {
@ -172,7 +169,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
struct playlist_entry *cur
= local_start ? local_start->next : files->first;
if (!cur)
mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Ignored options!\n");
MP_WARN(config, "Ignored options!\n");
while (cur) {
playlist_entry_add_params(cur, local_params,
local_params_count);
@ -192,8 +189,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
struct playlist *pl = playlist_parse_file(param0, opts);
talloc_free(param0);
if (!pl) {
mp_msg(MSGT_CFGPARSER, MSGL_FATAL,
"Error reading playlist '%.*s'", BSTR_P(p.param));
MP_FATAL(config, "Error reading playlist '%.*s'", BSTR_P(p.param));
goto err_out;
}
playlist_transfer_entries(files, pl);
@ -233,8 +229,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
playlist_add_file(files, f);
}
} else
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"Invalid play entry %s\n", file0);
MP_ERR(config, "Invalid play entry %s\n", file0);
} else // dvd:// or dvd://x entry
playlist_add_file(files, file0);
@ -252,8 +247,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
goto err_out;
if (mode != GLOBAL) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"Missing closing --} on command line.\n");
MP_ERR(config, "Missing closing --} on command line.\n");
goto err_out;
}

View File

@ -23,9 +23,10 @@
struct playlist;
struct m_config;
struct mpv_global;
int m_config_parse_mp_command_line(struct m_config *config,
struct playlist *files,
int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
struct mpv_global *global,
int argc, char **argv);
void m_config_preparse_command_line(struct m_config *config,
int argc, char **argv);

View File

@ -47,7 +47,7 @@ static int recursion_depth = 0;
int m_config_parse_config_file(m_config_t *config, const char *conffile,
int flags)
{
#define PRINT_LINENUM mp_msg(MSGT_CFGPARSER, MSGL_ERR, "%s:%d: ", conffile, line_num)
#define PRINT_LINENUM MP_ERR(config, "%s:%d: ", conffile, line_num)
#define MAX_LINE_LEN 10000
#define MAX_OPT_LEN 1000
#define MAX_PARAM_LEN 1500
@ -67,33 +67,31 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile,
flags = flags | M_SETOPT_FROM_CONFIG_FILE;
mp_msg(MSGT_CFGPARSER, MSGL_V, "Reading config file %s", conffile);
MP_VERBOSE(config, "Reading config file %s", conffile);
if (recursion_depth > MAX_RECURSION_DEPTH) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
": too deep 'include'. check your configfiles\n");
MP_ERR(config, ": too deep 'include'. check your configfiles\n");
ret = -1;
goto out;
}
if ((line = malloc(MAX_LINE_LEN + 1)) == NULL) {
mp_msg(MSGT_CFGPARSER, MSGL_FATAL,
"\ncan't get memory for 'line': %s", strerror(errno));
MP_FATAL(config, "\ncan't get memory for 'line': %s", strerror(errno));
ret = -1;
goto out;
} else
mp_msg(MSGT_CFGPARSER, MSGL_V, "\n");
MP_VERBOSE(config, "\n");
if ((fp = fopen(conffile, "r")) == NULL) {
mp_msg(MSGT_CFGPARSER, MSGL_V, ": %s\n", strerror(errno));
MP_VERBOSE(config, ": %s\n", strerror(errno));
ret = 0;
goto out;
}
while (fgets(line, MAX_LINE_LEN, fp)) {
if (errors >= 16) {
mp_msg(MSGT_CFGPARSER, MSGL_FATAL, "too many errors\n");
MP_FATAL(config, "too many errors\n");
goto out;
}
@ -116,7 +114,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile,
opt[opt_pos++] = line[line_pos++];
if (opt_pos >= MAX_OPT_LEN) {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too long option\n");
MP_ERR(config, "too long option\n");
errors++;
ret = -1;
goto nextline;
@ -124,7 +122,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile,
}
if (opt_pos == 0) {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parse error\n");
MP_ERR(config, "parse error\n");
ret = -1;
errors++;
continue;
@ -165,8 +163,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile,
param[param_pos++] = line[line_pos++];
if (param_pos >= MAX_PARAM_LEN) {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"option %s has a too long parameter\n", opt);
MP_ERR(config, "option %s has a too long parameter\n", opt);
ret = -1;
errors++;
goto nextline;
@ -185,7 +182,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile,
strlen(end + 1) < len)
{
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "bogus %% length\n");
MP_ERR(config, "bogus %% length\n");
ret = -1;
errors++;
goto nextline;
@ -203,7 +200,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile,
param[param_pos++] = line[line_pos++];
if (param_pos >= MAX_PARAM_LEN) {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too long parameter\n");
MP_ERR(config, "too long parameter\n");
ret = -1;
errors++;
goto nextline;
@ -220,8 +217,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile,
/* EOL / comment */
if (line[line_pos] != '\0' && line[line_pos] != '#') {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"extra characters: %s\n", line + line_pos);
MP_ERR(config, "extra characters: %s\n", line + line_pos);
ret = -1;
}
@ -241,8 +237,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile,
tmp = M_OPT_MISSING_PARAM;
if (tmp < 0) {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"error parsing option %.*s=%.*s: %s\n",
MP_ERR(config, "error parsing option %.*s=%.*s: %s\n",
BSTR_P(bopt), BSTR_P(bparam), m_option_strerror(tmp));
continue;
}
@ -254,8 +249,7 @@ int m_config_parse_config_file(m_config_t *config, const char *conffile,
}
if (tmp < 0) {
PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"setting option %.*s='%.*s' failed.\n",
MP_ERR(config, "setting option %.*s='%.*s' failed.\n",
BSTR_P(bopt), BSTR_P(bparam));
continue;
/* break */
@ -270,7 +264,7 @@ out:
fclose(fp);
--recursion_depth;
if (ret < 0) {
mp_msg(MSGT_CFGPARSER, MSGL_FATAL, "Error loading config file %s.\n",
MP_FATAL(config, "Error loading config file %s.\n",
conffile);
}
return ret;

View File

@ -327,7 +327,7 @@ static int mpv_main(int argc, char *argv[])
exit_player(mpctx, EXIT_ERROR);
int r = m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist,
argc, argv);
mpctx->global, argc, argv);
if (r < 0) {
if (r <= M_OPT_EXIT) {
exit_player(mpctx, EXIT_NONE);