标签:
int main(int argc, char *argv[]) {
int opt_exit = 0; //标示 MPlayer 在没有播放视频时是否应该退出
int profile_config_loaded; //配置文件加载标示
profile_config_loaded = load_profile_config(mconfig, filename);
static int load_profile_config(m_config_t *conf, const char *const file) {
if (file) {
load_per_protocol_config(conf, file);
load_per_extension_config(conf, file);
load_per_file_config(conf, file);
}
return file != NULL;
}
static void load_per_protocol_config(m_config_t *conf, const char *const file) {
char *str;
char protocol[strlen(PROFILE_CFG_PROTOCOL) + strlen(file) + 1];
m_profile_t *p;
/* does filename actually uses a protocol ? */
str = strstr(file, "://");
if (!str)
return;
sprintf(protocol, "%s%s", PROFILE_CFG_PROTOCOL, file);
protocol[strlen(PROFILE_CFG_PROTOCOL) + strlen(file) - strlen(str)] = ‘\0‘;
p = m_config_get_profile(conf, protocol);
if (p) {
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingProtocolProfile, protocol);
m_config_set_profile(conf, p);
}
}
static void load_per_extension_config(m_config_t *conf, const char *const file) {
char *str;
char extension[strlen(PROFILE_CFG_EXTENSION) + 8];
m_profile_t *p;
/* does filename actually have an extension ? */
str = strrchr(filename, ‘.‘);
if (!str)
return;
sprintf(extension, PROFILE_CFG_EXTENSION);
strncat(extension, ++str, 7);
p = m_config_get_profile(conf, extension);
if (p) {
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingExtensionProfile, extension);
m_config_set_profile(conf, p);
}
}
static void load_per_file_config(m_config_t *conf, const char *const file) {
char *confpath;
char cfg[PATH_MAX];
const char *name;
if (strlen(file) > PATH_MAX - 14) {
mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_FilenameTooLong);
return;
}
sprintf(cfg, "%s.conf", file);
name = mp_basename(cfg);
if (use_filedir_conf) {
char dircfg[PATH_MAX];
strcpy(dircfg, cfg);
strcpy(dircfg + (name - cfg), "mplayer.conf");
try_load_config(conf, dircfg);
if (try_load_config(conf, cfg))
return;
}
if ((confpath = get_path(name)) != NULL) {
try_load_config(conf, confpath);
free(confpath);
}
}
标签:
原文地址:http://my.oschina.net/fonddream/blog/528872