diff options
author | tzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2007-12-11 09:41:07 +0000 |
---|---|---|
committer | tzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2007-12-11 09:41:07 +0000 |
commit | 46b3cc6d2d0f06aef9990b0856b7cad817fac510 (patch) | |
tree | 75b024e9c26eb7950c12e14abcb1acd6928b7601 /zttest.c | |
parent | c474e0590633eca1d8b3355106be7cfc2e1d92ef (diff) |
Fix and document zttest -c <count> .
git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.4@3421 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'zttest.c')
-rw-r--r-- | zttest.c | 43 |
1 files changed, 41 insertions, 2 deletions
@@ -7,6 +7,7 @@ #include <sys/time.h> #include <sys/signal.h> #include <math.h> +#include <getopt.h> #define SIZE 8000 @@ -24,12 +25,30 @@ void hup_handler(int sig) exit(0); } +static void usage(char *argv0) +{ + char *c; + c = strrchr(argv0, '/'); + if (!c) + c = argv0; + else + c++; + fprintf(stderr, + "Usage: %s [-c COUNT] [-v]\n" + " Valid options are:\n" + " -c COUNT Run just COUNT cycles (otherwise: forever).\n" + " -v More verbose output.\n" + " -h This help text.\n" + ,c); +} + int main(int argc, char *argv[]) { int fd; int res; + int c; int count=0; - int seconds; + int seconds = 0; int curarg = 1; int verbose=0; char buf[8192]; @@ -41,6 +60,25 @@ int main(int argc, char *argv[]) fprintf(stderr, "Unable to open zap interface: %s\n", strerror(errno)); exit(1); } + + while((c = getopt(argc, argv, "c:hv")) != -1) { + switch(c) { + case 'c': + seconds = atoi(optarg); + break; + case 'h': + usage(argv[0]); + exit(0); + break; + case '?': + usage(argv[0]); + exit(1); + break; + case 'v': + verbose++; + break; + } + } while(curarg < argc) { if (!strcasecmp(argv[curarg], "-v")) verbose++; @@ -56,8 +94,9 @@ int main(int argc, char *argv[]) for (count = 0;count < 4; count++) res = read(fd, buf, sizeof(buf)); count = 0; + ms = 0; /* Makes the compiler happy */ if (seconds > 0) - alarm(seconds + 1); + alarm(seconds + 1); /* This will give 'seconds' cycles */ for(;;) { if (count == 0) ms = 0; |