[asterisk-commits] murf: trunk r81519 - in /trunk: include/asterisk/config.h main/config.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 5 09:47:46 CDT 2007


Author: murf
Date: Wed Sep  5 09:47:45 2007
New Revision: 81519

URL: http://svn.digium.com/view/asterisk?view=rev&rev=81519
Log:
this set of changes fixes issue # 10643 by keeping track of the last object defined in a file, and attaching any accumulated comments to that object (category header or variable declaration). The file_save routine also had to be upgraded to output these trailing comments. Config.h was modified to include the trailing comment list on categories and variables.

Modified:
    trunk/include/asterisk/config.h
    trunk/main/config.c

Modified: trunk/include/asterisk/config.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/config.h?view=diff&rev=81519&r1=81518&r2=81519
==============================================================================
--- trunk/include/asterisk/config.h (original)
+++ trunk/include/asterisk/config.h Wed Sep  5 09:47:45 2007
@@ -58,6 +58,7 @@
 	int blanklines; 	/*!< Number of blanklines following entry */
 	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 *next;
 	char stuff[0];
 };

Modified: trunk/main/config.c
URL: http://svn.digium.com/view/asterisk/trunk/main/config.c?view=diff&rev=81519&r1=81518&r2=81519
==============================================================================
--- trunk/main/config.c (original)
+++ trunk/main/config.c Wed Sep  5 09:47:45 2007
@@ -185,6 +185,7 @@
 	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;
@@ -797,7 +798,7 @@
 }
 
 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;
@@ -825,6 +826,8 @@
 			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] ) {
@@ -967,6 +970,8 @@
 			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);
@@ -1003,6 +1008,8 @@
 	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 */
@@ -1210,7 +1217,7 @@
 				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;
 						}
@@ -1218,6 +1225,23 @@
 				}
 			}
 		}
+		/* 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) {
@@ -1385,6 +1409,10 @@
 			}
 			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;
@@ -1419,6 +1447,10 @@
 					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--)




More information about the asterisk-commits mailing list