Index: config.c
===================================================================
RCS file: /usr/cvsroot/asterisk/config.c,v
retrieving revision 1.33
diff -u -r1.33 config.c
--- config.c	23 Nov 2004 17:58:59 -0000	1.33
+++ config.c	23 Nov 2004 19:52:30 -0000
@@ -27,6 +27,9 @@
 #include "asterisk.h"
 #include "astconf.h"
 
+#define MAX_NESTED_COMMENTS 128
+#define COMMENT_START ";--"
+#define COMMENT_END "--;"
 
 static int ast_cust_config=0;
 struct ast_config *(*global_load_func)(const char *dbname, const char *table, const char *, struct ast_config *,struct ast_category **,struct ast_variable **,int);
@@ -476,8 +479,13 @@
 	FILE *f;
 	int lineno=0;
 	int master=0;
+	int pre_comment = 0, comment = 0, x = 0, y = 0, nest[MAX_NESTED_COMMENTS];
+	
 	struct ast_config_reg *reg=NULL;
 	struct ast_config *(*load_func)(const char *database, const char *table, const char *, struct ast_config *,struct ast_category **,struct ast_variable **,int);
+	char *comment_p=NULL, *tmp_p=NULL, *comment_end_p=NULL, *new_buf=NULL;
+	const char marker = (char) 200;
+	size_t len = 0;
 
 	load_func=NULL;
 	if (strcmp(configfile,config_conf_file) && strcmp(configfile,"asterisk.conf") && ast_cust_config_list) {
@@ -496,9 +504,7 @@
 
 		if (load_func) {
 			ast_log(LOG_NOTICE,"Loading Config %s via %s engine\n",configfile,reg && reg->name ? reg->name : "global");
-			tmp = load_func(db, table, configfile,tmp, _tmpc, _last, includelevel);
-	    
-			if (tmp)
+			if((tmp = load_func(db, table, configfile,tmp, _tmpc, _last, includelevel)))
 				return tmp;
 		}
 	}
@@ -515,35 +521,87 @@
 	if ((f = fopen(fn, "r"))) {
 		if (option_debug)
 			ast_log(LOG_DEBUG, "Parsing %s\n", fn);
-		else if (option_verbose > 1)
+		else if (option_verbose > 2)
 			ast_verbose( "Found\n");
 		if (!tmp) {
-			tmp = malloc(sizeof(struct ast_config));
-			if (tmp)
+			if((tmp = malloc(sizeof(struct ast_config)))) {
 				memset(tmp, 0, sizeof(struct ast_config));
-
-			master = 1;
-		}
-		if (!tmp) {
-			ast_log(LOG_WARNING, "Out of memory\n");
-			fclose(f);
-			return NULL;
+				master = 1;
+			}
 		}
-		while(!feof(f)) {
-			lineno++;
-			if (fgets(buf, sizeof(buf), f)) {
-				if (cfg_process(tmp, _tmpc, _last, buf, lineno, configfile, includelevel)) {
-					fclose(f);
-					return NULL;
+		if (tmp) {
+			while(!feof(f)) {
+				lineno++;
+				if (fgets(buf, sizeof(buf), f)) {
+					pre_comment = 0;
+					comment_p = new_buf = NULL;
+					if ((comment_p = strstr(buf, COMMENT_START))) {
+						if (strcmp(comment_p, buf))
+							pre_comment = 1;
+						for(x=0; x < 3; x++) {
+							*comment_p = marker;
+							comment_p++;
+						}
+						if (comment < MAX_NESTED_COMMENTS) {
+							comment++;
+							nest[comment-1] = lineno;
+						} else {
+							ast_log(LOG_ERROR, "Maximum nest limit of %d reached.\n", MAX_NESTED_COMMENTS);
+						}
+					}
+					if (comment && (comment_end_p = strstr(buf, COMMENT_END))) {
+						tmp_p = comment_end_p + 1;
+						while((tmp_p = strstr(tmp_p, COMMENT_END))) {
+							comment_end_p = tmp_p;
+							tmp_p++;
+
+						}
+						tmp_p = comment_p ? comment_p : buf;
+						len = strlen(tmp_p);
+						for (x=0; x < len; x++) {
+							if (!strcmp(tmp_p, comment_end_p)) {
+								for(x=0; x < 3; x++) {
+									*tmp_p++ = marker;
+								}
+								break;
+							}
+							*tmp_p++ = marker;
+						}
+						tmp_p = buf;
+						if(comment)
+							comment--;
+					}
+					if (strchr(buf, marker)) {
+						len = strlen(buf);
+						new_buf = alloca(len);
+						memset(new_buf, 0, len);
+						y = 0;
+						for(x = 0; x < len; x++) {
+							if(buf[x] != marker) {
+								new_buf[y++] = buf[x];
+							}
+						}
+					} else 
+						new_buf = buf;
+					
+					if ((!comment || pre_comment) && cfg_process(tmp, _tmpc, _last, new_buf, lineno, configfile, includelevel)) {
+						tmp = NULL;
+						break;
+					}
 				}
 			}
-		}
+		} else 
+			ast_log(LOG_WARNING, "Out of memory\n");
+		
 		fclose(f);		
-	} else {
+	} else { /* can't open file */
 		if (option_debug)
 			ast_log(LOG_DEBUG, "No file to parse: %s\n", fn);
-		else if (option_verbose > 1)
+		else if (option_verbose > 2)
 			ast_verbose( "Not found (%s)\n", strerror(errno));
+	}
+	if (comment) {
+		ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[comment]);
 	}
 	return tmp;
 }
