diff options
author | bbryant <bbryant@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2008-05-29 19:55:14 +0000 |
---|---|---|
committer | bbryant <bbryant@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2008-05-29 19:55:14 +0000 |
commit | 7503cd45d9bd7dca2165f5bdac972bfe7d5a66ea (patch) | |
tree | cc7033262b50bb38067f8cf4d7b70db7fd57e8d4 /ztmonitor.c | |
parent | d923382136c4427299d9f0247a300febbfb2a2fe (diff) |
Change argument parsing for ztmonitor to use getopt. This adds more compatibility for loosely formatted arguments.
(closes issue #12732)
git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.4@4333 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'ztmonitor.c')
-rw-r--r-- | ztmonitor.c | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/ztmonitor.c b/ztmonitor.c index 3c8b5ff..3f00c62 100644 --- a/ztmonitor.c +++ b/ztmonitor.c @@ -282,8 +282,10 @@ int main(int argc, char *argv[]) int stereo_output = 0; int limit = 0; int readcount = 0; - int x, i, chan; + int x = MON_BRX, i, chan; struct zt_confinfo zc; + char opt, *output_file; + extern char *optarg; if ((argc < 2) || (atoi(argv[1]) < 1)) { fprintf(stderr, "Usage: ztmonitor <channel num> [-v[v]] [-m] [-o] [-p] [-l limit] [-f FILE | -s FILE | -r FILE1 -t FILE2] [-F FILE | -S FILE | -R FILE1 -T FILE2]\n"); @@ -318,81 +320,79 @@ int main(int argc, char *argv[]) chan = atoi(argv[1]); - for (i = 2; i < argc; ++i) { - if (!strcmp(argv[i], "-v")) { + while ((opt = getopt(argc, argv, ":vl:f:r:t:F:R:T:mop"))) { + switch (opt) { + case 'v': if (visual) verbose = 1; - visual = 1; - multichannel = 1; - } else if (!strcmp(argv[i], "-vv")) { visual = 1; - verbose = 1; multichannel = 1; - } else if ((!strcmp(argv[i], "-f") || !strcmp(argv[i], "-r") || !strcmp(argv[i], "-t") - || !strcmp(argv[i], "-F") || !strcmp(argv[i], "-R") || !strcmp(argv[i], "-T") - || !strcmp(argv[i], "-s") || !strcmp(argv[i], "-S")) - && (i+1) < argc) { - char *output_file; - - /* Set which file descriptor to use */ - if (!strcmp(argv[i], "-f")) { - savefile = 1; + break; + + case 'm': + multichannel = 1; + break; + + case 'o': + ossoutput = 1; + break; + + case 'p': + preecho = 1; + break; + case 'l': + if (sscanf(optarg, "%d", &limit) != 1 || limit < 0) + limit = 0; + printf("limit: %d\n", limit); + break; + default: + if (!strchr("frstFRST", opt)) + break; + + savefile = 1; + + if (opt == 'f') { x = MON_BRX; - } else if (!strcmp(argv[i], "-r")) { - savefile = 1; + } else if (opt == 'r') { multichannel = 1; x = MON_BRX; - } else if (!strcmp(argv[i], "-t")) { - savefile = 1; - multichannel = 1; - x = MON_TX; - } else if (!strcmp(argv[i], "-s")) { - savefile = 1; - stereo_output = 1; + } else if (opt == 's') { multichannel = 1; x = MON_STEREO; - } else if (!strcmp(argv[i], "-F")) { - savefile = 1; - preecho = 1; - x = MON_PRE_BRX; - } else if (!strcmp(argv[i], "-R")) { - savefile = 1; + } else if (opt == 't') { multichannel = 1; + x = MON_TX; + } else if (opt == 'F') { preecho = 1; x = MON_PRE_BRX; - } else if (!strcmp(argv[i], "-T")) { - savefile = 1; + } else if (opt == 'R') { multichannel = 1; preecho = 1; - x = MON_PRE_TX; - } else if (!strcmp(argv[i], "-S")) { - savefile = 1; + x = MON_PRE_BRX; + } else if (opt == 'S') { preecho = 1; stereo_output = 1; multichannel = 1; x = MON_PRE_STEREO; - } else - x = MON_BRX; + } else if (opt == 'T') { + multichannel = 1; + preecho = 1; + x = MON_PRE_TX; + } + + output_file = optarg; - ++i; /* we care about the file name */ - output_file = argv[i]; fprintf(stderr, "Output to %s\n", output_file); - if ((ofh[x] = fopen(output_file, "w"))<0) { + + if ((ofh[x] = fopen(output_file, "w")) < 0) { fprintf(stderr, "Could not open %s for writing: %s\n", - output_file, strerror(errno)); - exit(1); + output_file, strerror(errno)); + exit(EXIT_FAILURE); } + fprintf(stderr, "Run e.g., 'sox -r 8000 -s -w -c 1 %s %s.wav' to convert.\n", output_file, output_file); - } else if (!strcmp(argv[i], "-m")) { - multichannel = 1; - } else if (!strcmp(argv[i], "-o")) { - ossoutput = 1; - } else if (!strcmp(argv[i], "-p")) { - preecho = 1; - } else if (!strcmp(argv[i], "-l") && isdigit(argv[i+1][0])) { - limit = atoi(argv[i+1]); - i++; + break; } } |