Index: mplayer.c =================================================================== --- mplayer.c (revision 29565) +++ mplayer.c (working copy) @@ -48,6 +48,7 @@ #include "cfg-mplayer-def.h" #include "libavutil/intreadwrite.h" +#include "libavutil/avstring.h" #include "subreader.h" @@ -913,36 +914,46 @@ } } +static int check_and_load_config (m_config_t* conf, const char* file) +{ + struct stat st; + + if (!stat(file, &st)) { + mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingConfig, file); + return m_config_parse_config_file(conf, file); + } + return 0; +} + 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 dircfg[strlen(file)+14]; 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); - return; + sprintf(cfg, "%s.conf", file); + if ((name = strrchr(cfg, '/'))) { + name++; + } else { + name = cfg; } - if ((name = strrchr (cfg, '/')) == NULL) - name = cfg; - else - name++; + if (use_filedir_conf) { + /* First search for mplayer.conf in the file's directory */ + av_strlcpy (dircfg, cfg, name-cfg+1); + strcat(dircfg, "mplayer.conf"); + check_and_load_config(conf, dircfg); - 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); - } + /* Then look up a file specific config file in the file's directory */ + if (check_and_load_config(conf, cfg) > 0) + return; + } - free (confpath); + /* Look up a file specific config file in mplayer's config directory */ + if ((confpath = get_path(name))) { + check_and_load_config(conf, confpath); + free(confpath); } }