[asterisk-commits] russell: trunk r100565 - /trunk/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 28 08:27:29 CST 2008


Author: russell
Date: Mon Jan 28 08:27:28 2008
New Revision: 100565

URL: http://svn.digium.com/view/asterisk?view=rev&rev=100565
Log:
Clean up some formatting, and simplify a bit of code using ast_str

Modified:
    trunk/main/pbx.c

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=100565&r1=100564&r2=100565
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Mon Jan 28 08:27:28 2008
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 1999 - 2006, Digium, Inc.
+ * Copyright (C) 1999 - 2008, Digium, Inc.
  *
  * Mark Spencer <markster at digium.com>
  *
@@ -856,42 +856,58 @@
 
 void log_match_char_tree(struct match_char *node, char *prefix)
 {
-	char my_prefix[1024];
 	char extenstr[40];
+	struct ast_str *my_prefix = ast_str_alloca(1024); 
+
+	extenstr[0] = '\0';
+
+	if (node && node->exten && node->exten)
+		snprintf(extenstr, sizeof(extenstr), "(%p)", node->exten);
 	
-	extenstr[0] = 0;
-	if (node && node->exten && node->exten)
-		sprintf(extenstr,"(%p)",node->exten);
-	
-	if (strlen(node->x) > 1 )
-		ast_log(LOG_DEBUG,"%s[%s]:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N', node->deleted? 'D':'-', node->specificity, node->exten? "EXTEN:":"", node->exten ? node->exten->exten : "", extenstr);
-	else
-		ast_log(LOG_DEBUG,"%s%s:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N', node->deleted? 'D':'-', node->specificity, node->exten? "EXTEN:":"", node->exten ? node->exten->exten : "", extenstr);
-	strcpy(my_prefix,prefix);
-	strcat(my_prefix,"+       ");
+	if (strlen(node->x) > 1) {
+		ast_debug(1, "%s[%s]:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N', 
+			node->deleted? 'D':'-', node->specificity, node->exten? "EXTEN:":"", 
+			node->exten ? node->exten->exten : "", extenstr);
+	} else {
+		ast_debug(1, "%s%s:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N', 
+			node->deleted? 'D':'-', node->specificity, node->exten? "EXTEN:":"", 
+			node->exten ? node->exten->exten : "", extenstr);
+	}
+
+	ast_str_set(&my_prefix, 0, "%s+       ", prefix);
+
 	if (node->next_char)
-		log_match_char_tree(node->next_char, my_prefix);
+		log_match_char_tree(node->next_char, my_prefix->str);
+
 	if (node->alt_char)
 		log_match_char_tree(node->alt_char, prefix);
 }
 
 static void cli_match_char_tree(struct match_char *node, char *prefix, int fd)
 {
-	char my_prefix[1024];
 	char extenstr[40];
+	struct ast_str *my_prefix = ast_str_alloca(1024);
 	
-	extenstr[0] = 0;
+	extenstr[0] = '\0';
+
 	if (node && node->exten && node->exten)
-		sprintf(extenstr,"(%p)",node->exten);
+		snprintf(extenstr, sizeof(extenstr), "(%p)", node->exten);
 	
-	if (strlen(node->x) > 1)
-		ast_cli(fd, "%s[%s]:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N', node->deleted ? 'D' : '-', node->specificity, node->exten? "EXTEN:":"", node->exten ? node->exten->exten : "", extenstr);
-	else
-		ast_cli(fd, "%s%s:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N', node->deleted ? 'D' : '-', node->specificity, node->exten? "EXTEN:":"", node->exten ? node->exten->exten : "", extenstr);
-	strcpy(my_prefix,prefix);
-	strcat(my_prefix,"+       ");
+	if (strlen(node->x) > 1) {
+		ast_cli(fd, "%s[%s]:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y' : 'N', 
+			node->deleted ? 'D' : '-', node->specificity, node->exten? "EXTEN:" : "", 
+			node->exten ? node->exten->exten : "", extenstr);
+	} else {
+		ast_cli(fd, "%s%s:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y' : 'N', 
+			node->deleted ? 'D' : '-', node->specificity, node->exten? "EXTEN:" : "", 
+			node->exten ? node->exten->exten : "", extenstr);
+	}
+
+	ast_str_set(&my_prefix, 0, "%s+       ", prefix);
+
 	if (node->next_char)
-		cli_match_char_tree(node->next_char, my_prefix, fd);
+		cli_match_char_tree(node->next_char, my_prefix->str, fd);
+
 	if (node->alt_char)
 		cli_match_char_tree(node->alt_char, prefix, fd);
 }
@@ -900,9 +916,12 @@
 {
 	/* find the exten at the end of the rope */
 	struct match_char *node2 = node;
-	for (node2 = node; node2; node2 = node2->next_char)
+
+	for (node2 = node; node2; node2 = node2->next_char) {
 		if (node2->exten)
 			return node2->exten;
+	}
+
 	return 0;
 }
 




More information about the asterisk-commits mailing list