[asterisk-commits] mnicholson: branch mnicholson/asttest r167253 - /team/mnicholson/asttest/astt...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jan 6 13:10:35 CST 2009
Author: mnicholson
Date: Tue Jan 6 13:10:34 2009
New Revision: 167253
URL: http://svn.digium.com/view/asterisk?view=rev&rev=167253
Log:
Use getopt() for option parsing in mkstring.
* asttest/tools/mkstring.c (parse_cmdline): use getopt for option parsing
* asttest/tools/mkstring.c (parse_option): removed
Modified:
team/mnicholson/asttest/asttest/tools/mkstring.c
Modified: team/mnicholson/asttest/asttest/tools/mkstring.c
URL: http://svn.digium.com/view/asterisk/team/mnicholson/asttest/asttest/tools/mkstring.c?view=diff&rev=167253&r1=167252&r2=167253
==============================================================================
--- team/mnicholson/asttest/asttest/tools/mkstring.c (original)
+++ team/mnicholson/asttest/asttest/tools/mkstring.c Tue Jan 6 13:10:34 2009
@@ -19,6 +19,7 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
struct mkstring_options {
char *infile;
@@ -64,38 +65,31 @@
return 0;
}
-char *parse_option(int argc, char *argv[], int i) {
- // option in the form of '-ooption'
- if (strlen(argv[i]) > 2) {
- return argv[i] + 2;
- } else { // option in the form '-o option'
- if (argc > i + 1)
- return argv[i + 1];
+int parse_cmdline(int argc, char *argv[], struct mkstring_options *opts) {
+ char c;
+ int i;
+ while ((c = getopt(argc, argv, "n:o:")) != -1) {
+ switch (c) {
+ case 'n':
+ opts->name = optarg;
+ break;
+ case 'o':
+ opts->outfile = optarg;
+ break;
+ case '?':
+ return 1;
+ break;
+ }
}
- return NULL;
-}
-int parse_cmdline(int argc, char *argv[], struct mkstring_options *opts) {
- int i = 0;
- for (i = 0; i < argc; i++) {
- if (i == 0)
- continue;
-
- if (argv[i][0] == '-' && strlen(argv[i]) >= 2) {
- if (argv[i][1] == 'o') {
- opts->outfile = parse_option(argc, argv, i);
- } else if (argv[i][1] == 'n') {
- opts->name = parse_option(argc, argv, i);
- }
- } else {
- opts->infile = argv[i];
- }
+ for (i = optind; i < argc; i++) {
+ opts->infile = argv[i];
}
if (!opts->infile
|| !opts->outfile
|| !opts->name) {
- fprintf(stderr, "Invalid arguments\n");
+ fprintf(stderr, "Missing arguments\n");
return 1;
}
More information about the asterisk-commits
mailing list