From 2e1c423dff651761a1da433fadef50ca57fd0946 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 22 Dec 2013 23:06:41 +0100 Subject: player: remove code duplication for auto-loaded config profiles Code for loading "[vo.vdpau]" profiles and similar. The messages printed on loading change, but other than that, everything should behave about the same. --- player/configfiles.c | 74 ++++++++++------------------------------------------ 1 file changed, 14 insertions(+), 60 deletions(-) diff --git a/player/configfiles.c b/player/configfiles.c index 87da9d9260..04dc631701 100644 --- a/player/configfiles.c +++ b/player/configfiles.c @@ -76,66 +76,17 @@ bool mp_parse_cfgfiles(struct MPContext *mpctx) // command line. #define FILE_LOCAL_FLAGS (M_SETOPT_BACKUP | M_SETOPT_PRESERVE_CMDLINE) -#define PROFILE_CFG_PROTOCOL "protocol." - -static void mp_load_per_protocol_config(struct MPContext *mpctx) +static void mp_auto_load_profile(struct MPContext *mpctx, char *category, + bstr item) { - char *str; - const char *file = mpctx->filename; - char protocol[strlen(PROFILE_CFG_PROTOCOL) + strlen(file) + 1]; - m_profile_t *p; - - /* does filename actually uses a protocol ? */ - if (!mp_is_url(bstr0(file))) - return; - str = strstr(file, "://"); - if (!str) + if (!item.len) return; - sprintf(protocol, "%s%s", PROFILE_CFG_PROTOCOL, file); - protocol[strlen(PROFILE_CFG_PROTOCOL) + strlen(file) - strlen(str)] = '\0'; - p = m_config_get_profile0(mpctx->mconfig, protocol); + char t[512]; + snprintf(t, sizeof(t), "%s.%.*s", category, BSTR_P(item)); + m_profile_t *p = m_config_get_profile0(mpctx->mconfig, t); if (p) { - MP_INFO(mpctx, "Loading protocol-related profile '%s'\n", protocol); - m_config_set_profile(mpctx->mconfig, p, FILE_LOCAL_FLAGS); - } -} - -#define PROFILE_CFG_EXTENSION "extension." - -static void mp_load_per_extension_config(struct MPContext *mpctx) -{ - char *str; - const char *file = mpctx->filename; - char extension[strlen(PROFILE_CFG_EXTENSION) + 8]; - m_profile_t *p; - - /* does filename actually have an extension ? */ - str = strrchr(file, '.'); - if (!str) - return; - - sprintf(extension, PROFILE_CFG_EXTENSION); - strncat(extension, ++str, 7); - p = m_config_get_profile0(mpctx->mconfig, extension); - if (p) { - MP_INFO(mpctx, "Loading extension-related profile '%s'\n", extension); - m_config_set_profile(mpctx->mconfig, p, FILE_LOCAL_FLAGS); - } -} - -static void mp_load_per_output_config(struct MPContext *mpctx, char *cfg, char *out) -{ - char profile[strlen(cfg) + strlen(out) + 1]; - m_profile_t *p; - - if (!out && !out[0]) - return; - - sprintf(profile, "%s%s", cfg, out); - p = m_config_get_profile0(mpctx->mconfig, profile); - if (p) { - MP_INFO(mpctx, "Loading extension-related profile '%s'\n", profile); + MP_INFO(mpctx, "Auto-loading profile '%s'\n", t); m_config_set_profile(mpctx->mconfig, p, FILE_LOCAL_FLAGS); } } @@ -144,14 +95,17 @@ void mp_load_auto_profiles(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; - mp_load_per_protocol_config(mpctx); - mp_load_per_extension_config(mpctx); + mp_auto_load_profile(mpctx, "protocol", + mp_split_proto(bstr0(mpctx->filename), NULL)); + mp_auto_load_profile(mpctx, "extension", + bstr0(mp_splitext(mpctx->filename, NULL))); + mp_load_per_file_config(mpctx); if (opts->vo.video_driver_list) - mp_load_per_output_config(mpctx, "vo.", opts->vo.video_driver_list[0].name); + mp_auto_load_profile(mpctx, "vo", bstr0(opts->vo.video_driver_list[0].name)); if (opts->audio_driver_list) - mp_load_per_output_config(mpctx, "ao.", opts->audio_driver_list[0].name); + mp_auto_load_profile(mpctx, "ao", bstr0(opts->audio_driver_list[0].name)); } /** -- cgit v1.2.3