Return immediatly on error.

SVN revision: 26037
This commit is contained in:
sebastid 2006-09-23 08:05:23 +00:00 committed by sebastid
parent f1b46bd67e
commit be24979e13
1 changed files with 90 additions and 92 deletions

View File

@ -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;
}