Mercurial > mplayer.hg
comparison mplayer.c @ 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 | 47808d1fca5a |
children | 647445e4999e |
comparison
equal
deleted
inserted
replaced
29560:61b1e80faf63 | 29561:82ff5f35918a |
---|---|
911 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingExtensionProfile, profile); | 911 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingExtensionProfile, profile); |
912 m_config_set_profile(conf,p); | 912 m_config_set_profile(conf,p); |
913 } | 913 } |
914 } | 914 } |
915 | 915 |
916 /** | |
917 * Tries to load a config file | |
918 * @return 0 if file was not found, 1 otherwise | |
919 */ | |
920 static int try_load_config(m_config_t *conf, const char *file) | |
921 { | |
922 struct stat st; | |
923 if (stat(file, &st)) | |
924 return 0; | |
925 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, file); | |
926 m_config_parse_config_file (conf, file); | |
927 return 1; | |
928 } | |
929 | |
916 static void load_per_file_config (m_config_t* conf, const char *const file) | 930 static void load_per_file_config (m_config_t* conf, const char *const file) |
917 { | 931 { |
918 char *confpath; | 932 char *confpath; |
919 char cfg[strlen(file)+10]; | 933 char cfg[strlen(file)+10]; |
920 struct stat st; | |
921 char *name; | 934 char *name; |
922 | 935 |
923 sprintf (cfg, "%s.conf", file); | 936 sprintf (cfg, "%s.conf", file); |
924 | 937 |
925 if (use_filedir_conf && !stat (cfg, &st)) | 938 if (use_filedir_conf && try_load_config(conf, cfg)) |
926 { | |
927 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg); | |
928 m_config_parse_config_file (conf, cfg); | |
929 return; | 939 return; |
930 } | |
931 | 940 |
932 if ((name = strrchr (cfg, '/')) == NULL) | 941 if ((name = strrchr (cfg, '/')) == NULL) |
933 name = cfg; | 942 name = cfg; |
934 else | 943 else |
935 name++; | 944 name++; |
936 | 945 |
937 if ((confpath = get_path (name)) != NULL) | 946 if ((confpath = get_path (name)) != NULL) |
938 { | 947 { |
939 if (!stat (confpath, &st)) | 948 try_load_config(conf, confpath); |
940 { | |
941 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath); | |
942 m_config_parse_config_file (conf, confpath); | |
943 } | |
944 | 949 |
945 free (confpath); | 950 free (confpath); |
946 } | 951 } |
947 } | 952 } |
948 | 953 |