Cleanup config_file.c
This commit is contained in:
parent
b4173ee0b4
commit
8fbcf34e02
|
@ -124,10 +124,11 @@ static char *strip_comment(char *str)
|
||||||
char *comment = NULL;
|
char *comment = NULL;
|
||||||
char *literal = strchr(str, '\"');
|
char *literal = strchr(str, '\"');
|
||||||
if (!literal)
|
if (!literal)
|
||||||
literal = string_end;
|
literal = string_end;
|
||||||
comment = (char*)strchr(str, '#');
|
comment = (char*)strchr(str, '#');
|
||||||
|
|
||||||
if (!comment)
|
if (!comment)
|
||||||
comment = string_end;
|
comment = string_end;
|
||||||
|
|
||||||
if (cut_comment && literal < comment)
|
if (cut_comment && literal < comment)
|
||||||
{
|
{
|
||||||
|
@ -139,13 +140,11 @@ static char *strip_comment(char *str)
|
||||||
cut_comment = true;
|
cut_comment = true;
|
||||||
str = literal + 1;
|
str = literal + 1;
|
||||||
}
|
}
|
||||||
else if (comment)
|
else
|
||||||
{
|
{
|
||||||
*comment = '\0';
|
*comment = '\0';
|
||||||
str = comment;
|
str = comment;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
str = string_end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
@ -313,12 +312,6 @@ static bool parse_line(config_file_t *conf,
|
||||||
if (!key)
|
if (!key)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!line || !*line)
|
|
||||||
{
|
|
||||||
free(key);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
comment = strip_comment(line);
|
comment = strip_comment(line);
|
||||||
|
|
||||||
/* Starting line with # and include includes config files. */
|
/* Starting line with # and include includes config files. */
|
||||||
|
@ -328,8 +321,7 @@ static bool parse_line(config_file_t *conf,
|
||||||
if (strstr(comment, "include ") == comment)
|
if (strstr(comment, "include ") == comment)
|
||||||
{
|
{
|
||||||
add_sub_conf(conf, comment + strlen("include "));
|
add_sub_conf(conf, comment + strlen("include "));
|
||||||
free(key);
|
goto error;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (conf->include_depth >= MAX_INCLUDE_DEPTH)
|
else if (conf->include_depth >= MAX_INCLUDE_DEPTH)
|
||||||
|
@ -349,10 +341,7 @@ static bool parse_line(config_file_t *conf,
|
||||||
key_tmp = (char*)realloc(key, cur_size + 1);
|
key_tmp = (char*)realloc(key, cur_size + 1);
|
||||||
|
|
||||||
if (!key_tmp)
|
if (!key_tmp)
|
||||||
{
|
goto error;
|
||||||
free(key);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
key = key_tmp;
|
key = key_tmp;
|
||||||
}
|
}
|
||||||
|
@ -367,11 +356,14 @@ static bool parse_line(config_file_t *conf,
|
||||||
if (!list->value)
|
if (!list->value)
|
||||||
{
|
{
|
||||||
list->key = NULL;
|
list->key = NULL;
|
||||||
free(key);
|
goto error;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
error:
|
||||||
|
free(key);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static config_file_t *config_file_new_internal(
|
static config_file_t *config_file_new_internal(
|
||||||
|
@ -423,7 +415,7 @@ static config_file_t *config_file_new_internal(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parse_line(conf, list, line))
|
if (*line && parse_line(conf, list, line))
|
||||||
{
|
{
|
||||||
if (conf->entries)
|
if (conf->entries)
|
||||||
conf->tail->next = list;
|
conf->tail->next = list;
|
||||||
|
@ -541,7 +533,7 @@ config_file_t *config_file_new_from_string(const char *from_string)
|
||||||
|
|
||||||
if (line && conf)
|
if (line && conf)
|
||||||
{
|
{
|
||||||
if (parse_line(conf, list, line))
|
if (*line && parse_line(conf, list, line))
|
||||||
{
|
{
|
||||||
if (conf->entries)
|
if (conf->entries)
|
||||||
conf->tail->next = list;
|
conf->tail->next = list;
|
||||||
|
|
Loading…
Reference in New Issue