From ffcf4ece6e69764dde0ee6a4e796e97151259cd9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 22 Dec 2013 23:08:31 +0100 Subject: [PATCH] player: move code around The only thing that used mp_load_per_file_config() was inside configfiles.c too, so remove the declaration from core.h and move the function before its use. --- player/configfiles.c | 88 +++++++++++++++++++++----------------------- player/core.h | 1 - 2 files changed, 42 insertions(+), 47 deletions(-) diff --git a/player/configfiles.c b/player/configfiles.c index 04dc631701..b3804c0bd0 100644 --- a/player/configfiles.c +++ b/player/configfiles.c @@ -72,10 +72,52 @@ bool mp_parse_cfgfiles(struct MPContext *mpctx) return true; } +static int try_load_config(struct MPContext *mpctx, const char *file, int flags) +{ + if (!mp_path_exists(file)) + return 0; + MP_INFO(mpctx, "Loading config '%s'\n", file); + m_config_parse_config_file(mpctx->mconfig, file, flags); + return 1; +} + // Set options file-local, and don't set them if the user set them via the // command line. #define FILE_LOCAL_FLAGS (M_SETOPT_BACKUP | M_SETOPT_PRESERVE_CMDLINE) +static void mp_load_per_file_config(struct MPContext *mpctx) +{ + struct MPOpts *opts = mpctx->opts; + char *confpath; + char cfg[MP_PATH_MAX]; + const char *name; + const char *file = mpctx->filename; + + if (strlen(file) > MP_PATH_MAX - 14) { + MP_WARN(mpctx, "Filename is too long, " + "can not load file or directory specific config files\n"); + return; + } + sprintf(cfg, "%s.conf", file); + + name = mp_basename(cfg); + if (opts->use_filedir_conf) { + char dircfg[MP_PATH_MAX]; + strcpy(dircfg, cfg); + strcpy(dircfg + (name - cfg), "mpv.conf"); + try_load_config(mpctx, dircfg, FILE_LOCAL_FLAGS); + + if (try_load_config(mpctx, cfg, FILE_LOCAL_FLAGS)) + return; + } + + if ((confpath = mp_find_user_config_file(NULL, mpctx->global, name))) { + try_load_config(mpctx, confpath, FILE_LOCAL_FLAGS); + + talloc_free(confpath); + } +} + static void mp_auto_load_profile(struct MPContext *mpctx, char *category, bstr item) { @@ -108,52 +150,6 @@ void mp_load_auto_profiles(struct MPContext *mpctx) mp_auto_load_profile(mpctx, "ao", bstr0(opts->audio_driver_list[0].name)); } -/** - * Tries to load a config file (in file local mode) - * @return 0 if file was not found, 1 otherwise - */ -static int try_load_config(struct MPContext *mpctx, const char *file, int flags) -{ - if (!mp_path_exists(file)) - return 0; - MP_INFO(mpctx, "Loading config '%s'\n", file); - m_config_parse_config_file(mpctx->mconfig, file, flags); - return 1; -} - -void mp_load_per_file_config(struct MPContext *mpctx) -{ - struct MPOpts *opts = mpctx->opts; - char *confpath; - char cfg[MP_PATH_MAX]; - const char *name; - const char *file = mpctx->filename; - - if (strlen(file) > MP_PATH_MAX - 14) { - MP_WARN(mpctx, "Filename is too long, " - "can not load file or directory specific config files\n"); - return; - } - sprintf(cfg, "%s.conf", file); - - name = mp_basename(cfg); - if (opts->use_filedir_conf) { - char dircfg[MP_PATH_MAX]; - strcpy(dircfg, cfg); - strcpy(dircfg + (name - cfg), "mpv.conf"); - try_load_config(mpctx, dircfg, FILE_LOCAL_FLAGS); - - if (try_load_config(mpctx, cfg, FILE_LOCAL_FLAGS)) - return; - } - - if ((confpath = mp_find_user_config_file(NULL, mpctx->global, name))) { - try_load_config(mpctx, confpath, FILE_LOCAL_FLAGS); - - talloc_free(confpath); - } -} - #define MP_WATCH_LATER_CONF "watch_later" static char *mp_get_playback_resume_config_filename(struct mpv_global *global, diff --git a/player/core.h b/player/core.h index 711c99840b..5b4cc738e5 100644 --- a/player/core.h +++ b/player/core.h @@ -350,7 +350,6 @@ void clear_audio_decode_buffers(struct MPContext *mpctx); // configfiles.c bool mp_parse_cfgfiles(struct MPContext *mpctx); void mp_load_auto_profiles(struct MPContext *mpctx); -void mp_load_per_file_config(struct MPContext *mpctx); void mp_load_playback_resume(struct MPContext *mpctx, const char *file); void mp_write_watch_later_conf(struct MPContext *mpctx); struct playlist_entry *mp_check_playlist_resume(struct MPContext *mpctx,