[asterisk-commits] qwell: trunk r39965 - in /trunk: frame.c translate.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Aug 15 20:48:37 MST 2006


Author: qwell
Date: Tue Aug 15 22:48:36 2006
New Revision: 39965

URL: http://svn.digium.com/view/asterisk?rev=39965&view=rev
Log:
Fix formatting of "show codecs" CLI command.
Make "show translations" CLI command have dynamic widths.

Also display g726 codec in both commands.
There are probably other places where "11" is hardcoded...

Modified:
    trunk/frame.c
    trunk/translate.c

Modified: trunk/frame.c
URL: http://svn.digium.com/view/asterisk/trunk/frame.c?rev=39965&r1=39964&r2=39965&view=diff
==============================================================================
--- trunk/frame.c (original)
+++ trunk/frame.c Tue Aug 15 22:48:36 2006
@@ -615,13 +615,13 @@
 		ast_cli(fd, "Disclaimer: this command is for informational purposes only.\n"
 				"\tIt does not indicate anything about your configuration.\n");
 
-	ast_cli(fd, "%11s %9s %10s   TYPE   %5s   %s\n","INT","BINARY","HEX","NAME","DESC");
+	ast_cli(fd, "%11s %9s %10s   TYPE   %8s   %s\n","INT","BINARY","HEX","NAME","DESC");
 	ast_cli(fd, "--------------------------------------------------------------------------------\n");
 	if ((argc == 2) || (!strcasecmp(argv[1],"audio"))) {
 		found = 1;
-		for (i=0;i<11;i++) {
+		for (i=0;i<12;i++) {
 			snprintf(hex,25,"(0x%x)",1<<i);
-			ast_cli(fd, "%11u (1 << %2d) %10s  audio   %5s   (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
+			ast_cli(fd, "%11u (1 << %2d) %10s  audio   %8s   (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
 		}
 	}
 
@@ -629,7 +629,7 @@
 		found = 1;
 		for (i=16;i<18;i++) {
 			snprintf(hex,25,"(0x%x)",1<<i);
-			ast_cli(fd, "%11u (1 << %2d) %10s  image   %5s   (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
+			ast_cli(fd, "%11u (1 << %2d) %10s  image   %8s   (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
 		}
 	}
 
@@ -637,7 +637,7 @@
 		found = 1;
 		for (i=18;i<22;i++) {
 			snprintf(hex,25,"(0x%x)",1<<i);
-			ast_cli(fd, "%11u (1 << %2d) %10s  video   %5s   (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
+			ast_cli(fd, "%11u (1 << %2d) %10s  video   %8s   (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i));
 		}
 	}
 

Modified: trunk/translate.c
URL: http://svn.digium.com/view/asterisk/trunk/translate.c?rev=39965&r1=39964&r2=39965&view=diff
==============================================================================
--- trunk/translate.c (original)
+++ trunk/translate.c Tue Aug 15 22:48:36 2006
@@ -482,8 +482,9 @@
 /*! \brief CLI "show translation" command handler */
 static int show_translation(int fd, int argc, char *argv[])
 {
-#define SHOW_TRANS 11
+#define SHOW_TRANS 12
 	int x, y, z;
+	int curlen = 0, longest = 0;
 
 	if (argc > 4) 
 		return RESULT_SHOWUSAGE;
@@ -507,7 +508,13 @@
 	}
 
 	ast_cli(fd, "         Translation times between formats (in milliseconds)\n");
-	ast_cli(fd, "          Source Format (Rows) Destination Format(Columns)\n\n");
+	ast_cli(fd, "          Source Format (Rows) Destination Format (Columns)\n\n");
+	/* Get the length of the longest (usable?) codec name, so we know how wide the left side should be */
+	for (x = 0; x < SHOW_TRANS; x++) {
+		curlen = strlen(ast_getformatname(1 << (x + 1)));
+		if (curlen > longest)
+			longest = curlen;
+	}
 	for (x = -1; x < SHOW_TRANS; x++) {
 		char line[80];
 		char *buf = line;
@@ -516,14 +523,23 @@
 		*buf++ = ' ';
 		*buf = '\0';
 		for (y = -1; y < SHOW_TRANS; y++) {
-			if (x >= 0 && y >= 0 && tr_matrix[x][y].step)    /* XXX what is 99999 ? */
-				ast_build_string(&buf, &left, " %5d", tr_matrix[x][y].cost >= 99999 ? 0 : tr_matrix[x][y].cost);
-			else if (((x == -1 && y >= 0) || (y == -1 && x >= 0))) {
-				ast_build_string(&buf, &left, " %5s", ast_getformatname(1 << (x + y + 1)) );
-			} else if (x != -1 && y != -1) {
-				ast_build_string(&buf, &left, "     -");
+			curlen = strlen(ast_getformatname(1 << (y)));
+
+			if (x >= 0 && y >= 0 && tr_matrix[x][y].step) {
+				/* XXX 999 is a little hackish
+				   We don't want this number being larger than the shortest (or current) codec
+				   For now, that is "gsm" */
+				ast_build_string(&buf, &left, "%*d", curlen + 1, tr_matrix[x][y].cost > 999 ? 0 : tr_matrix[x][y].cost);
+			} else if (x == -1 && y >= 0) {
+				/* Top row - use a dynamic size */
+				ast_build_string(&buf, &left, "%*s", curlen + 1, ast_getformatname(1 << (x + y + 1)) );
+			} else if (y == -1 && x >= 0) {
+				/* Left column - use a static size. */
+				ast_build_string(&buf, &left, "%*s", longest, ast_getformatname(1 << (x + y + 1)) );
+			} else if (x >= 0 && y >= 0) {
+				ast_build_string(&buf, &left, "%*s", curlen + 1, "-");
 			} else {
-				ast_build_string(&buf, &left, "      ");
+				ast_build_string(&buf, &left, "%*s", longest, "");
 			}
 		}
 		ast_build_string(&buf, &left, "\n");



More information about the asterisk-commits mailing list