MCPcopy Index your code
hub / github.com/NetHack/NetHack / argcheck

Function argcheck

src/earlyarg.c:449–560  ·  view source on GitHub ↗

* Returns: * 0 = no match * 1 = found and skip past this argument * 2 = found and trigger immediate exit */

Source from the content-addressed store, hash-verified

447 * 2 = found and trigger immediate exit
448 */
449int
450argcheck(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;

Callers 5

libnhmain.cFile · 0.85
early_optionsFunction · 0.85
mainFunction · 0.85
pcmainFunction · 0.85
early_optionsFunction · 0.85

Calls 12

dupstrFunction · 0.85
debug_fieldsFunction · 0.85
dump_version_infoFunction · 0.85
early_version_infoFunction · 0.85
dump_enumsFunction · 0.85
dump_glyphidsFunction · 0.85
dump_mongenFunction · 0.85
dump_weightsFunction · 0.85
crashreport_bidshowFunction · 0.85
windows_early_optionsFunction · 0.85
match_optnameFunction · 0.70
raw_printfFunction · 0.70

Tested by

no test coverage detected