summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-03-25 14:55:22 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-03-25 14:55:22 +0900
commite2c880006bf0569634760a70462a5f3bcb728efc (patch)
treee90dc5d99f74e634e7b744602a97007cc1598304
parente49a70ae2685188f9f84ed324733f3b42a37a7bb (diff)
code cleanup - don't repeat profile loading code if possible
-rw-r--r--src/lib/elm_config.c65
1 files changed, 24 insertions, 41 deletions
diff --git a/src/lib/elm_config.c b/src/lib/elm_config.c
index 754a9b9e3..28a5a8021 100644
--- a/src/lib/elm_config.c
+++ b/src/lib/elm_config.c
@@ -1197,7 +1197,7 @@ _profile_fetch_from_conf(void)
1197{ 1197{
1198 char buf[PATH_MAX], *p, *s; 1198 char buf[PATH_MAX], *p, *s;
1199 Eet_File *ef = NULL; 1199 Eet_File *ef = NULL;
1200 int len = 0; 1200 int len = 0, i;
1201 1201
1202 // if env var - use profile without question 1202 // if env var - use profile without question
1203 s = getenv("ELM_PROFILE"); 1203 s = getenv("ELM_PROFILE");
@@ -1212,52 +1212,35 @@ _profile_fetch_from_conf(void)
1212 return; 1212 return;
1213 } 1213 }
1214 1214
1215 // user profile 1215 for (i = 0; i < 2; i++)
1216 _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
1217 ef = eet_open(buf, EET_FILE_MODE_READ);
1218 if (ef)
1219 {
1220 p = eet_read(ef, "config", &len);
1221 if (p)
1222 {
1223 _elm_profile = malloc(len + 1);
1224 if (_elm_profile)
1225 {
1226 memcpy(_elm_profile, p, len);
1227 _elm_profile[len] = 0;
1228 free(p);
1229 }
1230 else free(p);
1231 eet_close(ef);
1232 p = strchr(_elm_profile, '/');
1233 if (p) *p = 0;
1234 return;
1235 }
1236 eet_close(ef);
1237 }
1238
1239 // system profile
1240 _elm_data_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
1241 ef = eet_open(buf, EET_FILE_MODE_READ);
1242 if (ef)
1243 { 1216 {
1244 p = eet_read(ef, "config", &len); 1217 // user profile
1245 if (p) 1218 if (i == 0)
1219 _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
1220 // system profile
1221 else if (i == 1)
1222 _elm_data_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
1223 ef = eet_open(buf, EET_FILE_MODE_READ);
1224 if (ef)
1246 { 1225 {
1247 _elm_profile = malloc(len + 1); 1226 p = eet_read(ef, "config", &len);
1248 if (_elm_profile) 1227 if (p)
1249 { 1228 {
1250 memcpy(_elm_profile, p, len); 1229 _elm_profile = malloc(len + 1);
1251 _elm_profile[len] = 0; 1230 if (_elm_profile)
1252 free(p); 1231 {
1232 memcpy(_elm_profile, p, len);
1233 _elm_profile[len] = 0;
1234 free(p);
1235 }
1236 else free(p);
1237 eet_close(ef);
1238 p = strchr(_elm_profile, '/');
1239 if (p) *p = 0;
1240 return;
1253 } 1241 }
1254 else free(p);
1255 eet_close(ef); 1242 eet_close(ef);
1256 p = strchr(_elm_profile, '/');
1257 if (p) *p = 0;
1258 return;
1259 } 1243 }
1260 eet_close(ef);
1261 } 1244 }
1262 1245
1263 _elm_profile = strdup("default"); 1246 _elm_profile = strdup("default");