[dahdi-commits] rmeyerriecks: branch linux/rmeyerriecks/dahdi-tools-maintmodes r7564 - /linux...
SVN commits to the DAHDI project
dahdi-commits at lists.digium.com
Wed Nov 11 11:13:24 CST 2009
Author: rmeyerriecks
Date: Wed Nov 11 11:13:20 2009
New Revision: 7564
URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=7564
Log:
Renamed h and j flags, integrated exit codes for the help function, dynamically
use the utility's name in the fprintf of the help function as per angler's
patch on DAHDI-301. Plus various checkpatch style conformities
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=7564&r1=7563&r2=7564
==============================================================================
--- linux/team/rmeyerriecks/dahdi-tools-maintmodes/dahdi_maint.c (original)
+++ linux/team/rmeyerriecks/dahdi-tools-maintmodes/dahdi_maint.c Wed Nov 11 11:13:20 2009
@@ -8,15 +8,24 @@
#include <stdlib.h>
#include <dahdi/user.h>
+#include "dahdi_tools_version.h"
#define DAHDI_CTL "/dev/dahdi/ctl"
extern char *optarg;
extern int optind;
-void display_help(void)
+void display_help(char *argv0, int exitcode)
{
- fprintf(stderr, "Usage: dahdi_maint -s <span num> [-h|--help] <-j|--local [on|off]>\n");
+ char *c;
+ c = strrchr(argv0, '/');
+ if (!c)
+ c = argv0;
+ else
+ c++;
+ fprintf(stderr, "%s\n\n", dahdi_tools_version);
+ fprintf(stderr, "Usage: %s -s <span num> [-h|--help] <-j|--local "\
+ "[on|off]>\n", c);
fprintf(stderr, "Options:\n");
fprintf(stderr, " -h, --help display help\n");
fprintf(stderr, " -s, --span <span num> specify the span\n");
@@ -30,6 +39,8 @@
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\n");
+
+ exit(exitcode);
}
int main(int argc, char *argv[]) {
@@ -37,7 +48,7 @@
int res;
int localhostloopback = 0;
- char *harg = NULL;
+ char *jarg = NULL;
int networklineloopback= 0;
char *larg = NULL;
int networkpayloadloopback= 0;
@@ -45,7 +56,7 @@
int sflag = 0;
int span = 1;
int iflag = 0;
- char *darg = NULL;
+ char *iarg = NULL;
int gflag = 0;
int c;
int rflag = 0;
@@ -67,18 +78,16 @@
int option_index = 0;
if (argc < 2) { /* no options */
- display_help();
- exit(1);
+ display_help(argv[0], 1);
}
while((c = getopt_long(argc, argv, "hj:l:p:s:i:g:r", long_options, &option_index)) != -1) {
switch(c) {
case 'h': /* local host loopback */
- display_help();
- exit(1);
+ display_help(argv[0], 0);
break;
case 'j': /* local host loopback */
- harg = optarg;
+ jarg = optarg;
localhostloopback = 1;
break;
case 'l': /* network line loopback */
@@ -94,7 +103,7 @@
sflag = 1;
break;
case 'i': /* insert an error */
- darg = optarg;
+ iarg = optarg;
iflag = 1;
break;
case 'g': /* generate psuedo random sequence */
@@ -116,94 +125,90 @@
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);
+ 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;
}
m.spanno = span;
- if(localhostloopback) {
- if(!strcasecmp(harg, "on")) {
- printf("span %d: local host loopback ON\n", span);
+ if (localhostloopback) {
+ if (!strcasecmp(jarg, "on")) {
+ printf("Span %d: local host loopback ON\n", span);
m.command = DAHDI_MAINT_LOCALLOOP;
- } else if (!strcasecmp(harg, "off")) {
- printf("span %d: local host loopback OFF\n", span);
+ } else if (!strcasecmp(jarg, "off")) {
+ printf("Span %d: local host loopback OFF\n", span);
m.command = DAHDI_MAINT_NONE;
} else {
- display_help();
- exit(1);
- }
-
- res = ioctl(ctl, DAHDI_MAINT, &m);
- }
-
- if(networklineloopback) {
- if(!strcasecmp(larg, "on")) {
- printf("span %d: network line loopback ON\n", span);
+ display_help(argv[0], 1);
+ }
+
+ res = ioctl(ctl, DAHDI_MAINT, &m);
+ }
+
+ if (networklineloopback) {
+ if (!strcasecmp(larg, "on")) {
+ printf("Span %d: network line loopback ON\n", span);
m.command = DAHDI_MAINT_NETWORKLINELOOP;
} else if (!strcasecmp(larg, "off")) {
- printf("span %d: network line loopback OFF\n", span);
+ printf("Span %d: network line loopback OFF\n", span);
m.command = DAHDI_MAINT_NONE;
} else {
- display_help();
- exit(1);
- }
- res = ioctl(ctl, DAHDI_MAINT, &m);
- }
-
- if(networkpayloadloopback) {
- if(!strcasecmp(parg, "on")) {
- printf("span %d: network payload loopback ON\n", span);
+ display_help(argv[0], 1);
+ }
+ res = ioctl(ctl, DAHDI_MAINT, &m);
+ }
+
+ if (networkpayloadloopback) {
+ if (!strcasecmp(parg, "on")) {
+ printf("Span %d: network payload loopback ON\n", span);
m.command = DAHDI_MAINT_NETWORKPAYLOADLOOP;
} else if (!strcasecmp(parg, "off")) {
- printf("span %d: network payload loopback OFF\n", span);
+ printf("Span %d: network payload loopback OFF\n", span);
m.command = DAHDI_MAINT_NONE;
} else {
- display_help();
- exit(1);
- }
- res = ioctl(ctl, DAHDI_MAINT, &m);
- }
-
- if(iflag) {
- if(!strcasecmp(darg, "fas")) {
+ display_help(argv[0], 1);
+ }
+ res = ioctl(ctl, DAHDI_MAINT, &m);
+ }
+
+ if (iflag) {
+ if (!strcasecmp(iarg, "fas")) {
m.command = DAHDI_MAINT_FAS_DEFECT;
printf("Inserting a single FAS defect\n");
- } else if (!strcasecmp(darg, "multi")) {
+ } else if (!strcasecmp(iarg, "multi")) {
m.command = DAHDI_MAINT_MULTI_DEFECT;
printf("Inserting a single multiframe defect\n");
- } else if (!strcasecmp(darg, "crc")) {
+ } else if (!strcasecmp(iarg, "crc")) {
m.command = DAHDI_MAINT_CRC_DEFECT;
printf("Inserting a single CRC defect\n");
- } else if (!strcasecmp(darg, "cas")) {
+ } else if (!strcasecmp(iarg, "cas")) {
m.command = DAHDI_MAINT_CAS_DEFECT;
printf("Inserting a single CAS defect\n");
- } else if (!strcasecmp(darg, "prbs")) {
+ } else if (!strcasecmp(iarg, "prbs")) {
m.command = DAHDI_MAINT_PRBS_DEFECT;
printf("Inserting a single PRBS defect\n");
- } else if (!strcasecmp(darg, "bipolar")) {
+ } else if (!strcasecmp(iarg, "bipolar")) {
m.command = DAHDI_MAINT_BIPOLAR_DEFECT;
printf("Inserting a single bipolar defect\n");
} else {
- display_help();
- exit(1);
- }
- res = ioctl(ctl, DAHDI_MAINT, &m);
- }
-
- if(gflag) {
+ display_help(argv[0], 1);
+ }
+ res = ioctl(ctl, DAHDI_MAINT, &m);
+ }
+
+ if (gflag) {
printf("Enabled the Pseudo-Random Binary Sequence Generation and Monitor\n");
m.command = DAHDI_MAINT_PRBS;
res = ioctl(ctl, DAHDI_MAINT, &m);
}
- if(rflag) {
+ if (rflag) {
printf("Resetting error counters for span %d\n", span);
m.command = DAHDI_RESET_COUNTERS;
res = ioctl(ctl, DAHDI_MAINT, &m);
More information about the dahdi-commits
mailing list