int lineno;
struct ast_comment *precomments;
struct ast_comment *sameline;
+ struct ast_comment *trailing; /*!< the last object in the list will get assigned any trailing comments when EOF is hit */
struct ast_variable *root;
struct ast_variable *last;
struct ast_category *next;
}
static int process_text_line(struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile, struct ast_flags flags,
- char **comment_buffer, int *comment_buffer_size, char **lline_buffer, int *lline_buffer_size, const char *suggested_include_file)
+ char **comment_buffer, int *comment_buffer_size, char **lline_buffer, int *lline_buffer_size, const char *suggested_include_file, struct ast_category **last_cat, struct ast_variable **last_var)
{
char *c;
char *cur = buf;
return -1;
}
(*cat)->lineno = lineno;
+ *last_var = 0;
+ *last_cat = newcat;
/* add comments */
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && *comment_buffer && (*comment_buffer)[0] ) {
if ((v = ast_variable_new(ast_strip(cur), ast_strip(c), *suggested_include_file ? suggested_include_file : configfile))) {
v->lineno = lineno;
v->object = object;
+ *last_cat = 0;
+ *last_var = v;
/* Put and reset comments */
v->blanklines = 0;
ast_variable_append(*cat, v);
struct stat statbuf;
struct cache_file_mtime *cfmtime = NULL;
struct cache_file_include *cfinclude;
+ struct ast_variable *last_var = 0;
+ struct ast_category *last_cat = 0;
/*! Growable string buffer */
char *comment_buffer=0; /*!< this will be a comment collector.*/
int comment_buffer_size=0; /*!< the amount of storage so far alloc'd for the comment_buffer */
if (process_buf) {
char *buf = ast_strip(process_buf);
if (!ast_strlen_zero(buf)) {
- if (process_text_line(cfg, &cat, buf, lineno, fn, flags, &comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size, suggested_include_file)) {
+ if (process_text_line(cfg, &cat, buf, lineno, fn, flags, &comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size, suggested_include_file, &last_cat, &last_var)) {
cfg = NULL;
break;
}
}
}
}
+ /* end of file-- anything in a comment buffer? */
+ if (last_cat) {
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment_buffer && comment_buffer[0] ) {
+ last_cat->trailing = ALLOC_COMMENT(comment_buffer);
+ }
+ } else if (last_var) {
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment_buffer && comment_buffer[0] ) {
+ last_var->trailing = ALLOC_COMMENT(comment_buffer);
+ }
+ } else {
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment_buffer && (comment_buffer)[0] ) {
+ ast_debug(1, "Nothing to attach comments to, discarded: %s\n", comment_buffer);
+ }
+ }
+ if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS))
+ CB_RESET(&comment_buffer, &lline_buffer);
+
fclose(f);
} while (0);
if (comment) {
}
if (!cat->sameline)
fprintf(f,"\n");
+ for (cmt = cat->trailing; cmt; cmt=cmt->next) {
+ if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
+ fprintf(f,"%s", cmt->cmt);
+ }
fclose(f);
var = cat->root;
fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
else
fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
+ for (cmt = var->trailing; cmt; cmt=cmt->next) {
+ if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
+ fprintf(f,"%s", cmt->cmt);
+ }
if (var->blanklines) {
blanklines = var->blanklines;
while (blanklines--)