[svn-commits] rizzo: trunk r47667 - /trunk/main/cli.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Nov 15 10:17:07 MST 2006


Author: rizzo
Date: Wed Nov 15 11:17:07 2006
New Revision: 47667

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47667
Log:
small simplifications and localization of variables.


Modified:
    trunk/main/cli.c

Modified: trunk/main/cli.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cli.c?view=diff&rev=47667&r1=47666&r2=47667
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Wed Nov 15 11:17:07 2006
@@ -539,11 +539,6 @@
 #define VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n"
 
 	struct ast_channel *c = NULL;
-	char durbuf[10] = "-";
-	char locbuf[40];
-	char appdata[40];
-	int duration;
-	int durh, durm, durs;
 	int numchans = 0, concise = 0, verbose = 0;
 	int fd, argc;
 	char **argv;
@@ -586,18 +581,18 @@
 
 	while ((c = ast_channel_walk_locked(c)) != NULL) {
 		struct ast_channel *bc = ast_bridged_channel(c);
+		char durbuf[10] = "-";
+
 		if ((concise || verbose)  && c->cdr && !ast_tvzero(c->cdr->start)) {
-			duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
+			int duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
 			if (verbose) {
-				durh = duration / 3600;
-				durm = (duration % 3600) / 60;
-				durs = duration % 60;
+				int durh = duration / 3600;
+				int durm = (duration % 3600) / 60;
+				int durs = duration % 60;
 				snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs);
 			} else {
 				snprintf(durbuf, sizeof(durbuf), "%d", duration);
 			}				
-		} else {
-			durbuf[0] = '\0';
 		}
 		if (concise) {
 			ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
@@ -617,14 +612,13 @@
 			        S_OR(c->accountcode, ""),
 				bc ? bc->name : "(None)");
 		} else {
+			char locbuf[40] = "(None)";
+			char appdata[40] = "(None)";
+
 			if (!ast_strlen_zero(c->context) && !ast_strlen_zero(c->exten)) 
 				snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority);
-			else
-				strcpy(locbuf, "(None)");
 			if (c->appl)
-				snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, c->data ? c->data : "");
-			else
-				strcpy(appdata, "(None)");
+				snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, S_OR(c->data, ""));
 			ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata);
 		}
 		numchans++;



More information about the svn-commits mailing list