[asterisk-commits] rbrindley: trunk r202753 - /trunk/main/config.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jun 23 16:25:23 CDT 2009


Author: rbrindley
Date: Tue Jun 23 16:25:17 2009
New Revision: 202753

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=202753
Log:
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


Modified:
    trunk/main/config.c

Modified: trunk/main/config.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/main/config.c?view=diff&rev=202753&r1=202752&r2=202753
==============================================================================
--- trunk/main/config.c (original)
+++ trunk/main/config.c Tue Jun 23 16:25:17 2009
@@ -750,6 +750,14 @@
 	
 		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 @@
 	   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)




More information about the asterisk-commits mailing list