[dahdi-commits] mspiceland: branch linux/rmeyerriecks/dahdi-tools-maintmodes r7453 - /linux/t...

SVN commits to the DAHDI project dahdi-commits at lists.digium.com
Fri Oct 30 15:33:57 CDT 2009


Author: mspiceland
Date: Fri Oct 30 15:33:54 2009
New Revision: 7453

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=7453
Log:
Use getopts long so that we can use things like --help instead of just -h.

Print a help/usage screen for quick reference.

Modified:
    linux/team/rmeyerriecks/dahdi-tools-maintmodes/dahdi_maint.c

Modified: linux/team/rmeyerriecks/dahdi-tools-maintmodes/dahdi_maint.c
URL: http://svnview.digium.com/svn/dahdi/linux/team/rmeyerriecks/dahdi-tools-maintmodes/dahdi_maint.c?view=diff&rev=7453&r1=7452&r2=7453
==============================================================================
--- linux/team/rmeyerriecks/dahdi-tools-maintmodes/dahdi_maint.c (original)
+++ linux/team/rmeyerriecks/dahdi-tools-maintmodes/dahdi_maint.c Fri Oct 30 15:33:54 2009
@@ -14,6 +14,23 @@
 extern char *optarg;
 extern int optind;
 
+void display_help(void)
+{
+	fprintf(stderr, "Usage: dahdi_maint -s <span num> [-h|--help] <-j|--local [on|off]>\n");
+	fprintf(stderr, "Options:\n");
+	fprintf(stderr, "        -h, --help		display help\n");
+	fprintf(stderr, "        -s, --span <span num>	specify the span\n");
+	fprintf(stderr, "        -j, --host <on|off>	turn on/off local host looopback\n");
+	fprintf(stderr, "        -l, --line <on|off>	turn on/off network line looopback\n");
+	fprintf(stderr, "        -p, --payload <on|off>	turn on/off network payload looopback\n");
+	fprintf(stderr, "        -i, --insert <fas|multi|crc|cas|prbs|bipolar>	insert an error of a specific type\n");
+	fprintf(stderr, "Examples: \n");
+	fprintf(stderr, "Enable local host loopback (virtual loopback plug)\n");
+	fprintf(stderr, "	dahdi_maint -s 1 --local on\n");
+	fprintf(stderr, "Disable local host loopback (virtual loopback plug)\n");
+	fprintf(stderr, "	dahdi_maint -s 1 --local off\n");
+}
+
 int main(int argc, char *argv[]) {
 	static int ctl = -1;
 	int res;
@@ -25,8 +42,8 @@
 	int networkpayloadloopback= 0;
 	char *parg = NULL;
 	int sflag = 0;
-	int span = 0;
-	int dflag = 0;
+	int span = 1;
+	int iflag = 0;
 	char *darg = NULL;
 	int gflag = 0;
 	int c;
@@ -34,9 +51,30 @@
 	struct dahdi_maintinfo m;
 	struct dahdi_spaninfo s;
 
-	while((c = getopt(argc, argv, "h:l:p:s:d:g")) != -1) {
+	static struct option long_options[] =
+	{
+		{"help",    no_argument,       0, 'h'},
+		{"host",    required_argument, 0, 'j'},
+		{"line",    required_argument, 0, 'l'},
+		{"payload", required_argument, 0, 'p'},
+		{"span",    required_argument, 0, 's'},
+		{"insert",  required_argument, 0, 'd'},
+		{0,0,0,0}
+	};
+	int option_index = 0;
+
+	if (argc < 2) { /* no options */
+		display_help();
+		exit(1);
+	}
+
+	while((c = getopt_long(argc, argv, "hj:l:p:s:i:g", long_options, &option_index)) != -1) {
 			switch(c) {
 			case 'h': /* local host loopback */
+				display_help();
+				exit(1);
+				break;
+			case 'j': /* local host loopback */
 				harg = optarg;
 				localhostloopback = 1;
 				break;
@@ -52,9 +90,9 @@
 				span = atoi(optarg);
 				sflag = 1;
 				break;
-			case 'd': /* insert an error */
+			case 'i': /* insert an error */
 				darg = optarg;
-				dflag = 1;
+				iflag = 1;
 				break;
 			case 'g': /* generate psuedo random sequence */
 				gflag = 1;
@@ -68,20 +106,17 @@
 		return -1;
 	}
 
-	if(!sflag) {
-		// Eventually Figure out how many spans are active
-		int i;
-		for(i = 1; i < 3; i++) {
-			s.spanno = i;
-			res = ioctl(ctl, DAHDI_SPANSTAT, &s);	
-			printf("Span %d:\n", i);
-			printf(">FEC : %d:\n", s.fecount);
-			printf(">CEC : %d:\n", s.crc4count);
-			printf(">CVC : %d:\n", s.cvcount);
-			printf(">EBC : %d:\n", s.ebitcount);
-			printf(">BEC : %d:\n", s.becount);
-			printf(">PRBS: %d:\n", s.prbscount);
-		}
+	if(!(localhostloopback || networklineloopback || networkpayloadloopback || gflag)) {
+		s.spanno = span;
+		res = ioctl(ctl, DAHDI_SPANSTAT, &s);	
+		printf("Span %d:\n", span);
+		printf(">FEC : %d:\n", s.fecount);
+		printf(">CEC : %d:\n", s.crc4count);
+		printf(">CVC : %d:\n", s.cvcount);
+		printf(">EBC : %d:\n", s.ebitcount);
+		printf(">BEC : %d:\n", s.becount);
+		printf(">PRBS: %d:\n", s.prbscount);
+	
 		return 0;
 	}
 
@@ -127,7 +162,7 @@
 		res = ioctl(ctl, DAHDI_MAINT, &m);
 	}
 
-	if(dflag) {
+	if(iflag) {
 		if(!strcasecmp(darg, "fas")) {
 			m.command = DAHDI_MAINT_FAS_DEFECT;
 			printf("Inserting a single FAS defect\n");




More information about the dahdi-commits mailing list