Mercurial > mplayer.hg
changeset 29561:82ff5f35918a
Factor out code to try and load a config file only if it exists.
author | reimar |
---|---|
date | Mon, 31 Aug 2009 09:48:25 +0000 |
parents | 61b1e80faf63 |
children | 647445e4999e |
files | mplayer.c |
diffstat | 1 files changed, 16 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mplayer.c Mon Aug 31 09:41:27 2009 +0000 +++ b/mplayer.c Mon Aug 31 09:48:25 2009 +0000 @@ -913,21 +913,30 @@ } } +/** + * Tries to load a config file + * @return 0 if file was not found, 1 otherwise + */ +static int try_load_config(m_config_t *conf, const char *file) +{ + struct stat st; + if (stat(file, &st)) + return 0; + mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, file); + m_config_parse_config_file (conf, file); + return 1; +} + static void load_per_file_config (m_config_t* conf, const char *const file) { char *confpath; char cfg[strlen(file)+10]; - struct stat st; char *name; sprintf (cfg, "%s.conf", file); - if (use_filedir_conf && !stat (cfg, &st)) - { - mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg); - m_config_parse_config_file (conf, cfg); + if (use_filedir_conf && try_load_config(conf, cfg)) return; - } if ((name = strrchr (cfg, '/')) == NULL) name = cfg; @@ -936,11 +945,7 @@ if ((confpath = get_path (name)) != NULL) { - if (!stat (confpath, &st)) - { - mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath); - m_config_parse_config_file (conf, confpath); - } + try_load_config(conf, confpath); free (confpath); }