version 1.2, 2014/08/27 14:59:44 |
version 1.3, 2014/08/27 15:51:41 |
|
|
int |
int |
options_parse(int argc, char **argv, struct option *opts, char **unnamed) |
options_parse(int argc, char **argv, struct option *opts, char **unnamed) |
{ |
{ |
|
const char *errstr; |
struct option *opt; |
struct option *opt; |
|
long long val; |
char *arg, *p; |
char *arg, *p; |
int i, j; |
int i, j; |
|
|
|
|
if (strcmp(p, opt->name) != 0) |
if (strcmp(p, opt->name) != 0) |
continue; |
continue; |
|
|
switch (opt->type) { |
if (opt->type == OPTION_ARG || |
case OPTION_ARG: |
opt->type == OPTION_ARG_INT) { |
if (++i >= argc) { |
if (++i >= argc) { |
fprintf(stderr, |
fprintf(stderr, |
"missing %s argument for -%s\n", |
"missing %s argument for -%s\n", |
opt->argname, opt->name); |
opt->argname, opt->name); |
return (1); |
return (1); |
} |
} |
|
} |
|
|
|
switch (opt->type) { |
|
case OPTION_ARG: |
*opt->opt.arg = argv[i]; |
*opt->opt.arg = argv[i]; |
|
break; |
|
|
|
case OPTION_ARG_INT: |
|
val = strtonum(argv[i], 0, INT_MAX, &errstr); |
|
if (errstr != NULL) { |
|
fprintf(stderr, |
|
"%s %s argument for -%s\n", |
|
errstr, opt->argname, opt->name); |
|
return (1); |
|
} |
|
*opt->opt.value = (int)val; |
break; |
break; |
|
|
case OPTION_FLAG: |
case OPTION_FLAG: |