Index: main/config.c =================================================================== --- main/config.c (revision 191559) +++ main/config.c (working copy) @@ -747,9 +747,17 @@ if (!(newer = ast_variable_new(variable, value, cur->file))) return -1; - + newer->next = cur->next; newer->object = cur->object || object; + + /* Preserve everything */ + newer->lineno = cur->lineno; + newer->blanklines = cur->blanklines; + newer->precomments = cur->precomments; cur->precomments = NULL; + newer->sameline = cur->sameline; cur->sameline = NULL; + newer->trailing = cur->trailing; cur->trailing = NULL; + if (prev) prev->next = newer; else @@ -1565,16 +1573,30 @@ int i; /* I don't have to worry about those ;! comments, they are - stored in the precomments, but not printed back out. - I did have to make sure that comments following - the ;! header comments were not also deleted in the process */ - if (lineno - precomment_lines - fi->lineno < 0) { /* insertions can mess up the line numbering and produce negative numbers that mess things up */ + * stored in the precomments, but not printed back out. + * I did have to make sure that comments following + * the ;! header comments were not also deleted in the process. + */ + if (lineno - precomment_lines - fi->lineno < 0) { + /* insertions can mess up the line numbering and produce negative + * numbers that mess things up */ return; + } else if (lineno == 0) { + /* Line replacements also mess things up */ + return; + } else if (lineno - precomment_lines - fi->lineno < 5) { + /* Only insert less than 5 blank lines; if anything more occurs, + * it's probably due to context deletion. */ + for (i = fi->lineno; i < lineno - precomment_lines; i++) { + fprintf(fp, "\n"); + } + } else { + /* Deletion occurred - insert a single blank line, for separation of + * contexts. */ + fprintf(fp, "\n"); } - for (i=fi->lineno; ilineno = lineno+1; /* Advance the file lineno */ + + fi->lineno = lineno + 1; /* Advance the file lineno */ } int config_text_file_save(const char *configfile, const struct ast_config *cfg, const char *generator)