From c63378d41cdb004bac8e400bef8f3e73c5123de7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 26 Jun 2014 17:56:47 +0200 Subject: [PATCH] player: remove some minor code duplication in config loader code It's better to keep the logic in one place. Also drop that a broken config file aborts loading of the player. I don't see much reason for this, and it inflates the code slightly. --- player/configfiles.c | 32 ++++++++++++++------------------ player/core.h | 2 +- player/main.c | 3 +-- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/player/configfiles.c b/player/configfiles.c index a295d7d9f2..a44bc93437 100644 --- a/player/configfiles.c +++ b/player/configfiles.c @@ -46,17 +46,26 @@ #include "core.h" #include "command.h" +static void load_all_cfgfiles(struct MPContext *mpctx, char *section, + char *filename) +{ + void *tmp = talloc_new(NULL); + char **cf = mp_find_all_config_files(tmp, mpctx->global, filename); + for (int i = 0; cf && cf[i]; i++) + m_config_parse_config_file(mpctx->mconfig, cf[i], section, 0); + talloc_free(tmp); +} + #define SECT_ENCODE "encoding" -bool mp_parse_cfgfiles(struct MPContext *mpctx) +void mp_parse_cfgfiles(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; if (!opts->load_config) - return true; + return; m_config_t *conf = mpctx->mconfig; void *tmp = talloc_new(NULL); - bool r = true; char *conffile; char *section = NULL; bool encoding = opts->encode_opts && @@ -75,26 +84,13 @@ bool mp_parse_cfgfiles(struct MPContext *mpctx) m_config_parse_config_file(mpctx->mconfig, conffile, SECT_ENCODE, 0); #endif - // Maintain compatibility with /config - for (char** cf = mp_find_all_config_files(tmp, mpctx->global, "config"); *cf; cf++) { - if (m_config_parse_config_file(conf, *cf, section, 0) < 0) { - r = false; - goto done; - } - } - for (char** cf = mp_find_all_config_files(tmp, mpctx->global, "mpv.conf"); *cf; cf++) { - if (m_config_parse_config_file(conf, *cf, section, 0) < 0) { - r = false; - goto done; - } - } + load_all_cfgfiles(mpctx, section, "config"); + load_all_cfgfiles(mpctx, section, "mpv.conf"); if (encoding) m_config_set_profile(conf, m_config_add_profile(conf, SECT_ENCODE), 0); -done: talloc_free(tmp); - return r; } static int try_load_config(struct MPContext *mpctx, const char *file, int flags) diff --git a/player/core.h b/player/core.h index e3d84f4ed9..4a52424ca9 100644 --- a/player/core.h +++ b/player/core.h @@ -363,7 +363,7 @@ void clear_audio_output_buffers(struct MPContext *mpctx); void clear_audio_decode_buffers(struct MPContext *mpctx); // configfiles.c -bool mp_parse_cfgfiles(struct MPContext *mpctx); +void mp_parse_cfgfiles(struct MPContext *mpctx); void mp_load_auto_profiles(struct MPContext *mpctx); void mp_get_resume_defaults(struct MPContext *mpctx); void mp_load_playback_resume(struct MPContext *mpctx, const char *file); diff --git a/player/main.c b/player/main.c index e2b15f6dbc..0a18df1a4e 100644 --- a/player/main.c +++ b/player/main.c @@ -491,8 +491,7 @@ int mpv_main(int argc, char *argv[]) mp_print_version(mpctx->log, false); - if (!mp_parse_cfgfiles(mpctx)) - exit_player(mpctx, EXIT_ERROR); + mp_parse_cfgfiles(mpctx); int r = m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist, mpctx->global, argc, argv);