| 418 | } |
| 419 | |
| 420 | int parse_options(void *optctx, int argc, char **argv, const OptionDef *options, |
| 421 | int (*parse_arg_function)(void *, const char*)) |
| 422 | { |
| 423 | const char *opt; |
| 424 | int optindex, handleoptions = 1, ret; |
| 425 | |
| 426 | /* perform system-dependent conversions for arguments list */ |
| 427 | prepare_app_arguments(&argc, &argv); |
| 428 | |
| 429 | /* parse options */ |
| 430 | optindex = 1; |
| 431 | while (optindex < argc) { |
| 432 | opt = argv[optindex++]; |
| 433 | |
| 434 | if (handleoptions && opt[0] == '-' && opt[1] != '\0') { |
| 435 | if (opt[1] == '-' && opt[2] == '\0') { |
| 436 | handleoptions = 0; |
| 437 | continue; |
| 438 | } |
| 439 | opt++; |
| 440 | |
| 441 | if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0) |
| 442 | return ret; |
| 443 | optindex += ret; |
| 444 | } else { |
| 445 | if (parse_arg_function) { |
| 446 | ret = parse_arg_function(optctx, opt); |
| 447 | if (ret < 0) |
| 448 | return ret; |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | int parse_optgroup(void *optctx, OptionGroup *g, const OptionDef *defs) |
| 457 | { |
no test coverage detected