--- mencoder.c_bak 2007-11-26 13:50:15.000000000 -0500 +++ mencoder.c 2007-11-26 15:00:45.000000000 -0500 @@ -46,6 +46,7 @@ #include "codec-cfg.h" #include "m_option.h" #include "m_config.h" +#include "parser-cfg.h" #include "parser-mecmd.h" #include "get_path.h" @@ -316,18 +314,6 @@ exit(level); } -static void parse_cfgfiles( m_config_t* conf ) -{ - char *conffile; - if ((conffile = get_path("mencoder.conf")) == NULL) { - mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem); - } else { - if (m_config_parse_config_file(conf, conffile) < 0) - mencoder_exit(1,MSGTR_ConfigFileError); - free(conffile); - } -} - //--------------------------------------------------------------------------- @@ -473,7 +459,8 @@ mconfig = m_config_new(); m_config_register_options(mconfig,mencoder_opts); - parse_cfgfiles(mconfig); + if(parse_cfgfiles(mconfig, "mencoder.conf") < 0) + mencoder_exit(1,MSGTR_ConfigFileError); filelist = m_config_parse_me_command_line(mconfig, argc, argv); if(!filelist) mencoder_exit(1, MSGTR_ErrorParsingCommandLine); --- mplayer.c_bak 2007-11-26 13:50:26.000000000 -0500 +++ mplayer.c 2007-11-26 14:59:44.000000000 -0500 @@ -14,7 +14,6 @@ #include // #include -#include #ifndef __MINGW32__ #include #include @@ -31,7 +30,6 @@ #include #include -#include #include #include @@ -47,8 +45,6 @@ #include "m_config.h" #include "m_property.h" -#include "cfg-mplayer-def.h" - #include "subreader.h" #include "libvo/video_out.h" @@ -798,36 +792,6 @@ #include "cfg-mplayer.h" -static void parse_cfgfiles( m_config_t* conf ) -{ -char *conffile; -int conffile_fd; -if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0) - exit_player(NULL); -if ((conffile = get_path("")) == NULL) { - mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir); -} else { -#ifdef __MINGW32__ - mkdir(conffile); -#else - mkdir(conffile, 0777); -#endif - free(conffile); - if ((conffile = get_path("config")) == NULL) { - mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem); - } else { - if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) { - mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile); - write(conffile_fd, default_config, strlen(default_config)); - close(conffile_fd); - } - if (m_config_parse_config_file(conf, conffile) < 0) - exit_player(NULL); - free(conffile); - } -} -} - void load_per_file_config (m_config_t* conf, const char *const file) { char *confpath; @@ -2337,7 +2301,8 @@ m_config_register_options(mconfig,mplayer_opts); // TODO : add something to let modules register their options mp_input_register_options(mconfig); - parse_cfgfiles(mconfig); + if(parse_cfgfiles(mconfig, "mplayer.conf") < 0) + exit_player(NULL); #ifdef HAVE_NEW_GUI if ( use_gui ) cfg_read(); --- parser-cfg.h_bak 2007-11-26 13:54:37.000000000 -0500 +++ parser-cfg.h 2007-11-26 13:55:01.000000000 -0500 @@ -2,5 +2,6 @@ #define _parser_cfg_h extern int m_config_parse_config_file(m_config_t* config, char *conffile); +extern int parse_cfgfiles(m_config_t* config, const char* confname); #endif --- parser-cfg.c_bak 2007-11-26 13:50:39.000000000 -0500 +++ parser-cfg.c 2007-11-26 15:00:29.000000000 -0500 @@ -9,9 +9,12 @@ #include "config.h" +#include #include #include #include +#include +#include #include #include @@ -19,9 +22,13 @@ #include #endif +#include "avstring.h" +#include "cfg-mplayer-def.h" +#include "help_mp.h" #include "mp_msg.h" #include "m_option.h" #include "m_config.h" +#include "get_path.h" /// Maximal include depth. #define MAX_RECURSION_DEPTH 8 @@ -244,4 +251,51 @@ return ret; } +/// Parse the config file for mplayer or mencoder. +/** \param config The config object. + * \param confname Name of the config file. + * \return 1 on sucess, -1 on error. + */ +int parse_cfgfiles(m_config_t* config, const char* confname) +{ + char *conffile; + int pathlen = strlen(confname)+sizeof(MPLAYER_CONFDIR)+2; + char confpath[pathlen]; + int conffile_fd; + + //first try parsing the confname from MPLAYER_CONFDIR + av_strlcpy(confpath, MPLAYER_CONFDIR, pathlen); + av_strlcat(confpath, "/", pathlen); + av_strlcat(confpath, confname, pathlen); + if (m_config_parse_config_file(config, confpath) < 0) + return -1; + if ((conffile = get_path("")) == NULL) { + mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir); + } else { +#ifdef __MINGW32__ + mkdir(conffile); +#else + mkdir(conffile, 0777); +#endif + free(conffile); + //the mplayer config file in the user directory is named "config" + if (!strcmp(confname, "mplayer.conf")) + confname = "config"; + //next try parsing the confname from the user directory + if ((conffile = get_path(confname)) == NULL) { + mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem); + } else { + if ((conffile_fd = open(conffile, O_CREAT|O_EXCL|O_WRONLY, 0666)) != -1) { + mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile); + write(conffile_fd, default_config, strlen(default_config)); + close(conffile_fd); + } + if (m_config_parse_config_file(config, conffile) < 0) + return -1; + free(conffile); + } + } + return 1; +} + ///@}