[zaptel-commits] tzafrir: branch tzafrir/ztscan r4004 - /team/tzafrir/ztscan/ztscan.c

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Sun Mar 16 14:42:19 CDT 2008


Author: tzafrir
Date: Sun Mar 16 14:42:18 2008
New Revision: 4004

URL: http://svn.digium.com/view/zaptel?view=rev&rev=4004
Log:
Allow ztscan to accept a list of span numbers. The default remains to
print them all.

Modified:
    team/tzafrir/ztscan/ztscan.c

Modified: team/tzafrir/ztscan/ztscan.c
URL: http://svn.digium.com/view/zaptel/team/tzafrir/ztscan/ztscan.c?view=diff&rev=4004&r1=4003&r2=4004
==============================================================================
--- team/tzafrir/ztscan/ztscan.c (original)
+++ team/tzafrir/ztscan/ztscan.c Sun Mar 16 14:42:18 2008
@@ -164,16 +164,31 @@
 int main(int argc, char *argv[])
 {
 	int ctl;
-	int x;
+	int x, spanno;
 
 	if ((ctl = open("/dev/zap/ctl", O_RDWR)) < 0) {
 		fprintf(stderr, "Unable to open /dev/zap/ctl: %s\n", strerror(errno));
 		exit(1);
 	}
 	
-	for (x = 1; x < ZT_MAX_SPANS; x++) {
-		print_span(x, ctl);
+	/* If no parameters: loop over all spans */
+	if (argc == 1) {
+		for (spanno = 1; spanno < ZT_MAX_SPANS; spanno++)
+			print_span(spanno, ctl);
+		return 0;
 	}
 
-	exit(0);
+	/* Parameters provided: use them as span numbers */
+	for (x=1; argv[x]; x++) {
+		/* We can use atoi because span numbers must be > 0 */
+		int spanno = atoi(argv[x]);
+		if (spanno <= 0) {
+			fprintf(stderr, "%s: Error: Invalid span number %d (%s). Aborting\n",
+					argv[0], spanno, argv[x]);
+			exit(2);
+		}
+		print_span(spanno, ctl);
+	}
+
+	return 0;
 }




More information about the zaptel-commits mailing list