* Returns: * 0 = no match * 1 = found and skip past this argument * 2 = found and trigger immediate exit */
| 447 | * 2 = found and trigger immediate exit |
| 448 | */ |
| 449 | int |
| 450 | argcheck(int argc, char *argv[], enum earlyarg e_arg) |
| 451 | { |
| 452 | int i, idx; |
| 453 | boolean match = FALSE; |
| 454 | char *userea = (char *) 0; |
| 455 | const char *dashdash = ""; |
| 456 | |
| 457 | for (idx = 0; idx < SIZE(earlyopts); idx++) { |
| 458 | if (earlyopts[idx].e == e_arg){ |
| 459 | break; |
| 460 | } |
| 461 | } |
| 462 | if (idx >= SIZE(earlyopts) || argc < 1) |
| 463 | return 0; |
| 464 | |
| 465 | for (i = 0; i < argc; ++i) { |
| 466 | if (argv[i][0] != '-') |
| 467 | continue; |
| 468 | if (argv[i][1] == '-') { |
| 469 | userea = &argv[i][2]; |
| 470 | dashdash = "-"; |
| 471 | } else { |
| 472 | userea = &argv[i][1]; |
| 473 | } |
| 474 | match = match_optname(userea, earlyopts[idx].name, |
| 475 | earlyopts[idx].minlength, |
| 476 | earlyopts[idx].valallowed); |
| 477 | if (match) |
| 478 | break; |
| 479 | } |
| 480 | |
| 481 | if (match) { |
| 482 | const char *extended_opt = strchr(userea, ':'); |
| 483 | |
| 484 | if (!extended_opt) |
| 485 | extended_opt = strchr(userea, '='); |
| 486 | switch(e_arg) { |
| 487 | case ARG_DEBUG: |
| 488 | if (extended_opt) { |
| 489 | char *cpy_extended_opt; |
| 490 | |
| 491 | cpy_extended_opt = dupstr(extended_opt); |
| 492 | debug_fields(cpy_extended_opt + 1); |
| 493 | free((genericptr_t) cpy_extended_opt); |
| 494 | } |
| 495 | return 1; |
| 496 | case ARG_VERSION: { |
| 497 | boolean insert_into_pastebuf = FALSE; |
| 498 | |
| 499 | if (extended_opt) { |
| 500 | extended_opt++; |
| 501 | /* Deprecated in favor of "copy" - remove no later |
| 502 | than next major version */ |
| 503 | if (match_optname(extended_opt, "paste", 5, FALSE)) { |
| 504 | insert_into_pastebuf = TRUE; |
| 505 | } else if (match_optname(extended_opt, "copy", 4, FALSE)) { |
| 506 | insert_into_pastebuf = TRUE; |
no test coverage detected