From be24979e1393e94290ae783e52579c5209e37ca6 Mon Sep 17 00:00:00 2001 From: sebastid Date: Sat, 23 Sep 2006 08:05:23 +0000 Subject: [PATCH] Return immediatly on error. SVN revision: 26037 --- .../src/lib/ecore_desktop/ecore_desktop.c | 182 +++++++++--------- 1 file changed, 90 insertions(+), 92 deletions(-) diff --git a/legacy/ecore/src/lib/ecore_desktop/ecore_desktop.c b/legacy/ecore/src/lib/ecore_desktop/ecore_desktop.c index 2d23b00969..f2831f48a9 100644 --- a/legacy/ecore/src/lib/ecore_desktop/ecore_desktop.c +++ b/legacy/ecore/src/lib/ecore_desktop/ecore_desktop.c @@ -46,102 +46,100 @@ Ecore_Hash * ecore_desktop_ini_get(const char *file) { Ecore_Hash *result; + FILE *f; + char buffer[PATH_MAX]; + Ecore_Hash *current = NULL; result = ecore_hash_new(ecore_str_hash, ecore_str_compare); - if (result) + if (!result) NULL; + + f = fopen(file, "r"); + if (!f) { - FILE *f; - char buffer[PATH_MAX]; - Ecore_Hash *current = NULL; - - f = fopen(file, "r"); - if (!f) - { - fprintf(stderr, "ERROR: Cannot Open File %s\n", file); - ecore_hash_destroy(result); - return NULL; - } - ecore_hash_set_free_key(result, free); - ecore_hash_set_free_value(result, (Ecore_Free_Cb) ecore_hash_destroy); - *buffer = '\0'; -#ifdef DEBUG - fprintf(stdout, "PARSING INI %s\n", file); -#endif - while (fgets(buffer, sizeof(buffer), f) != NULL) - { - char *c; - char *key; - char *value; - - c = buffer; - /* Strip preceeding blanks. */ - while (((*c == ' ') || (*c == '\t')) && (*c != '\n') - && (*c != '\0')) - c++; - /* Skip blank lines and comments */ - if ((*c == '\0') || (*c == '\n') || (*c == '#')) - continue; - if (*c == '[') /* New group. */ - { - key = c + 1; - while ((*c != ']') && (*c != '\n') && (*c != '\0')) - c++; - *c++ = '\0'; - current = ecore_hash_new(ecore_str_hash, ecore_str_compare); - if (current) - { - ecore_hash_set_free_key(current, free); - ecore_hash_set_free_value(current, free); - ecore_hash_set(result, strdup(key), current); -#ifdef DEBUG - fprintf(stdout, " GROUP [%s]\n", key); -#endif - } - } - else if (current) /* key=value pair of current group. */ - { - char *tv; - - key = c; - /* Find trailing blanks or =. */ - while ((*c != '=') && (*c != ' ') && (*c != '\t') - && (*c != '\n') && (*c != '\0')) - c++; - if (*c != '=') /* Find equals. */ - { - *c++ = '\0'; - while ((*c != '=') && (*c != '\n') && (*c != '\0')) - c++; - } - if (*c == '=') /* Equals found. */ - { - *c++ = '\0'; - /* Strip preceeding blanks. */ - while (((*c == ' ') || (*c == '\t')) && (*c != '\n') - && (*c != '\0')) - c++; - value = c; - /* Find end. */ - while ((*c != '\n') && (*c != '\0')) - c++; - *c++ = '\0'; - /* FIXME: should strip space at end, then unescape value. */ - tv = ecore_hash_remove(current, key); - if (tv) - free(tv); - if (value[0] != '\0') - ecore_hash_set(current, strdup(key), strdup(value)); -#ifdef DEBUG - fprintf(stdout, " %s=%s\n", key, value); -#endif - } - } - - } - buffer[0] = (char)0; - - fclose(f); + fprintf(stderr, "ERROR: Cannot Open File %s\n", file); + ecore_hash_destroy(result); + return NULL; } + ecore_hash_set_free_key(result, free); + ecore_hash_set_free_value(result, (Ecore_Free_Cb) ecore_hash_destroy); + *buffer = '\0'; +#ifdef DEBUG + fprintf(stdout, "PARSING INI %s\n", file); +#endif + while (fgets(buffer, sizeof(buffer), f) != NULL) + { + char *c; + char *key; + char *value; + + c = buffer; + /* Strip preceeding blanks. */ + while (((*c == ' ') || (*c == '\t')) && (*c != '\n') + && (*c != '\0')) + c++; + /* Skip blank lines and comments */ + if ((*c == '\0') || (*c == '\n') || (*c == '#')) + continue; + if (*c == '[') /* New group. */ + { + key = c + 1; + while ((*c != ']') && (*c != '\n') && (*c != '\0')) + c++; + *c++ = '\0'; + current = ecore_hash_new(ecore_str_hash, ecore_str_compare); + if (current) + { + ecore_hash_set_free_key(current, free); + ecore_hash_set_free_value(current, free); + ecore_hash_set(result, strdup(key), current); +#ifdef DEBUG + fprintf(stdout, " GROUP [%s]\n", key); +#endif + } + } + else if (current) /* key=value pair of current group. */ + { + char *tv; + + key = c; + /* Find trailing blanks or =. */ + while ((*c != '=') && (*c != ' ') && (*c != '\t') + && (*c != '\n') && (*c != '\0')) + c++; + if (*c != '=') /* Find equals. */ + { + *c++ = '\0'; + while ((*c != '=') && (*c != '\n') && (*c != '\0')) + c++; + } + if (*c == '=') /* Equals found. */ + { + *c++ = '\0'; + /* Strip preceeding blanks. */ + while (((*c == ' ') || (*c == '\t')) && (*c != '\n') + && (*c != '\0')) + c++; + value = c; + /* Find end. */ + while ((*c != '\n') && (*c != '\0')) + c++; + *c++ = '\0'; + /* FIXME: should strip space at end, then unescape value. */ + tv = ecore_hash_remove(current, key); + if (tv) + free(tv); + if (value[0] != '\0') + ecore_hash_set(current, strdup(key), strdup(value)); +#ifdef DEBUG + fprintf(stdout, " %s=%s\n", key, value); +#endif + } + } + + } + buffer[0] = (char)0; + + fclose(f); return result; }