config: Fix indentation and missing curlies in config_text_file_load().

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@415288 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2014-06-05 19:04:02 +00:00
parent 61b0be0600
commit b0abea6028

View File

@@ -1687,9 +1687,14 @@ static struct ast_config *config_text_file_load(const char *database, const char
/*! Growable string buffer */
struct ast_str *comment_buffer = NULL; /*!< this will be a comment collector.*/
struct ast_str *lline_buffer = NULL; /*!< A buffer for stuff behind the ; */
#ifdef AST_INCLUDE_GLOB
int glob_ret;
glob_t globbuf;
#endif
if (cfg)
if (cfg) {
cat = ast_config_get_current_category(cfg);
}
if (filename[0] == '/') {
ast_copy_string(fn, filename, sizeof(fn));
@@ -1699,8 +1704,9 @@ static struct ast_config *config_text_file_load(const char *database, const char
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
comment_buffer = ast_str_create(CB_SIZE);
if (comment_buffer)
if (comment_buffer) {
lline_buffer = ast_str_create(CB_SIZE);
}
if (!lline_buffer) {
ast_free(comment_buffer);
ast_log(LOG_ERROR, "Failed to initialize the comment buffer!\n");
@@ -1708,10 +1714,6 @@ static struct ast_config *config_text_file_load(const char *database, const char
}
}
#ifdef AST_INCLUDE_GLOB
{
int glob_ret;
glob_t globbuf;
globbuf.gl_offs = 0; /* initialize it to silence gcc */
glob_ret = glob(fn, MY_GLOB_FLAGS, NULL, &globbuf);
if (glob_ret == GLOB_NOSPACE) {
@@ -1765,9 +1767,10 @@ static struct ast_config *config_text_file_load(const char *database, const char
/* Find our cached entry for this configuration file */
AST_LIST_LOCK(&cfmtime_head);
AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
if (!strcmp(cfmtime->filename, fn) && !strcmp(cfmtime->who_asked, who_asked))
if (!strcmp(cfmtime->filename, fn) && !strcmp(cfmtime->who_asked, who_asked)) {
break;
}
}
if (!cfmtime) {
cfmtime = cfmtime_new(fn, who_asked);
if (!cfmtime) {
@@ -1847,18 +1850,24 @@ static struct ast_config *config_text_file_load(const char *database, const char
continue;
}
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && lline_buffer && ast_str_strlen(lline_buffer)) {
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)
&& lline_buffer
&& ast_str_strlen(lline_buffer)) {
CB_ADD(&comment_buffer, ast_str_buffer(lline_buffer)); /* add the current lline buffer to the comment buffer */
ast_str_reset(lline_buffer); /* erase the lline buffer */
}
new_buf = buf;
if (comment)
if (comment) {
process_buf = NULL;
else
} else {
process_buf = buf;
}
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment_buffer && ast_str_strlen(comment_buffer) && (ast_strlen_zero(buf) || strlen(buf) == strspn(buf," \t\n\r"))) {
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)
&& comment_buffer
&& ast_str_strlen(comment_buffer)
&& (ast_strlen_zero(buf) || strlen(buf) == strspn(buf," \t\n\r"))) {
/* blank line? really? Can we add it to an existing comment and maybe preserve inter- and post- comment spacing? */
CB_ADD(&comment_buffer, "\n"); /* add a newline to the comment buffer */
continue; /* go get a new line, then */
@@ -1891,6 +1900,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
if (process_buf) {
/* Actually have to move what's left over the top, then continue */
char *oldptr;
oldptr = process_buf + strlen(process_buf);
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
CB_ADD(&comment_buffer, ";");
@@ -1899,9 +1909,10 @@ static struct ast_config *config_text_file_load(const char *database, const char
memmove(oldptr, new_buf, strlen(new_buf) + 1);
new_buf = oldptr;
} else
} else {
process_buf = new_buf;
}
}
} else {
if (!comment) {
/* If ; is found, and we are not nested in a comment,
@@ -1911,18 +1922,23 @@ static struct ast_config *config_text_file_load(const char *database, const char
}
*comment_p = '\0';
new_buf = comment_p;
} else
} else {
new_buf = comment_p + 1;
}
}
}
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment && !process_buf ) {
CB_ADD(&comment_buffer, buf); /* the whole line is a comment, store it */
}
if (process_buf) {
char *buffer = ast_strip(process_buf);
if (!ast_strlen_zero(buffer)) {
if (process_text_line(cfg, &cat, buffer, lineno, fn, flags, comment_buffer, lline_buffer, suggested_include_file, &last_cat, &last_var, who_asked)) {
if (process_text_line(cfg, &cat, buffer, lineno, fn,
flags, comment_buffer, lline_buffer,
suggested_include_file, &last_cat, &last_var,
who_asked)) {
cfg = CONFIG_STATUS_FILEINVALID;
break;
}
@@ -1952,8 +1968,9 @@ static struct ast_config *config_text_file_load(const char *database, const char
ast_debug(1, "Nothing to attach comments to, discarded: %s\n", ast_str_buffer(comment_buffer));
}
}
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS))
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
CB_RESET(comment_buffer, lline_buffer);
}
fclose(f);
} while (0);
@@ -1967,14 +1984,14 @@ static struct ast_config *config_text_file_load(const char *database, const char
}
globfree(&globbuf);
}
}
#endif
ast_free(comment_buffer);
ast_free(lline_buffer);
if (count == 0)
if (count == 0) {
return NULL;
}
return cfg;
}