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" @@ -916,33 +917,48 @@ static void load_per_file_config (m_config_t* conf, const char *const file) { char *confpath; - char cfg[strlen(file)+10]; + char cfg[strlen(file)+14]; struct stat st; char *name; - sprintf (cfg, "%s.conf", file); + name = strrchr(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; + if (use_filedir_conf) { + /* First search for mplayer.conf in the file's directory */ + if (name) { + av_strlcpy(cfg, file, name - file + 2); + } else { + cfg[0] = 0; + } + strcat(cfg, "mplayer.conf"); + if (!stat(cfg, &st)) { + mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingConfig, cfg); + m_config_parse_config_file(conf, cfg); + } + + sprintf(cfg, "%s.conf", file); + /* Then look up a file specific config file in the file's directory */ + if (!stat (cfg, &st)) { + mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingConfig, cfg); + m_config_parse_config_file(conf, cfg); + return; + } } - if ((name = strrchr (cfg, '/')) == NULL) - name = cfg; - else - name++; + /* Look up a file specific config file in mplayer's config directory */ + if (name) { + sprintf(cfg, "%s.conf", ++name); + } else if (!use_filedir_conf) { + sprintf(cfg, "%s.conf", file); + } - 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); + if ((confpath = get_path(cfg)) != NULL) { + if (!stat(confpath, &st)) { + mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingConfig, confpath); + m_config_parse_config_file(conf, confpath); } - free (confpath); + free(confpath); } }