summaryrefslogtreecommitdiff
path: root/main/config.c
diff options
context:
space:
mode:
authorRyan Brindley <rbrindley@digium.com>2009-06-23 21:25:17 +0000
committerRyan Brindley <rbrindley@digium.com>2009-06-23 21:25:17 +0000
commitef667f2f82a5ec651934aacdafd2693d457ba865 (patch)
tree4d175f7c929e60acbc1b8a25a6eecb3a9873ea44 /main/config.c
parent5f73ab9f4e52a786b18629ac945564a11749de1a (diff)
If we delete the info, lets also delete the lines
(closes issue #14509) Reported by: timeshell Patches: 20090504__bug14509.diff.txt uploaded by tilghman (license 14) Tested by: awk, timeshell git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@202753 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/config.c')
-rw-r--r--main/config.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/main/config.c b/main/config.c
index 83adee0a4..c1805956e 100644
--- a/main/config.c
+++ b/main/config.c
@@ -750,6 +750,14 @@ int ast_variable_update(struct ast_category *category, const char *variable,
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
@@ -1570,11 +1578,22 @@ static void insert_leading_blank_lines(FILE *fp, struct inclfile *fi, struct ast
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;
- }
- for (i=fi->lineno; i<lineno - precomment_lines; i++) {
- fprintf(fp,"\n");
- }
- fi->lineno = lineno+1; /* Advance the file lineno */
+ } 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");
+ }
+
+ fi->lineno = lineno + 1; /* Advance the file lineno */
}
int config_text_file_save(const char *configfile, const struct ast_config *cfg, const char *generator)