From e2c880006bf0569634760a70462a5f3bcb728efc Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Tue, 25 Mar 2014 14:55:22 +0900 Subject: [PATCH] code cleanup - don't repeat profile loading code if possible --- src/lib/elm_config.c | 65 +++++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/src/lib/elm_config.c b/src/lib/elm_config.c index 754a9b9..28a5a80 100644 --- a/src/lib/elm_config.c +++ b/src/lib/elm_config.c @@ -1197,7 +1197,7 @@ _profile_fetch_from_conf(void) { char buf[PATH_MAX], *p, *s; Eet_File *ef = NULL; - int len = 0; + int len = 0, i; // if env var - use profile without question s = getenv("ELM_PROFILE"); @@ -1212,52 +1212,35 @@ _profile_fetch_from_conf(void) return; } - // user profile - _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg"); - ef = eet_open(buf, EET_FILE_MODE_READ); - if (ef) - { - p = eet_read(ef, "config", &len); - if (p) - { - _elm_profile = malloc(len + 1); - if (_elm_profile) - { - memcpy(_elm_profile, p, len); - _elm_profile[len] = 0; - free(p); - } - else free(p); - eet_close(ef); - p = strchr(_elm_profile, '/'); - if (p) *p = 0; - return; - } - eet_close(ef); - } - - // system profile - _elm_data_dir_snprintf(buf, sizeof(buf), "config/profile.cfg"); - ef = eet_open(buf, EET_FILE_MODE_READ); - if (ef) + for (i = 0; i < 2; i++) { - p = eet_read(ef, "config", &len); - if (p) + // user profile + if (i == 0) + _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg"); + // system profile + else if (i == 1) + _elm_data_dir_snprintf(buf, sizeof(buf), "config/profile.cfg"); + ef = eet_open(buf, EET_FILE_MODE_READ); + if (ef) { - _elm_profile = malloc(len + 1); - if (_elm_profile) + p = eet_read(ef, "config", &len); + if (p) { - memcpy(_elm_profile, p, len); - _elm_profile[len] = 0; - free(p); + _elm_profile = malloc(len + 1); + if (_elm_profile) + { + memcpy(_elm_profile, p, len); + _elm_profile[len] = 0; + free(p); + } + else free(p); + eet_close(ef); + p = strchr(_elm_profile, '/'); + if (p) *p = 0; + return; } - else free(p); eet_close(ef); - p = strchr(_elm_profile, '/'); - if (p) *p = 0; - return; } - eet_close(ef); } _elm_profile = strdup("default"); -- 2.7.4