MCPcopy Create free account
hub / github.com/DFHack/dfhack / collectargs

Function collectargs

depends/lua/src/lua.c:465–507  ·  view source on GitHub ↗

** Traverses all arguments from 'argv', returning a mask with those ** needed before running any Lua code (or an error code if it finds ** any invalid argument). 'first' returns the first not-handled argument ** (either the script name or a bad argument in case of error). */

Source from the content-addressed store, hash-verified

463** (either the script name or a bad argument in case of error).
464*/
465static int collectargs (char **argv, int *first) {
466 int args = 0;
467 int i;
468 for (i = 1; argv[i] != NULL; i++) {
469 *first = i;
470 if (argv[i][0] != '-') /* not an option? */
471 return args; /* stop handling options */
472 switch (argv[i][1]) { /* else check option */
473 case '-': /* '--' */
474 if (argv[i][2] != '\0') /* extra characters after '--'? */
475 return has_error; /* invalid option */
476 *first = i + 1;
477 return args;
478 case '\0': /* '-' */
479 return args; /* script "name" is '-' */
480 case 'E':
481 if (argv[i][2] != '\0') /* extra characters after 1st? */
482 return has_error; /* invalid option */
483 args |= has_E;
484 break;
485 case 'i':
486 args |= has_i; /* (-i implies -v) *//* FALLTHROUGH */
487 case 'v':
488 if (argv[i][2] != '\0') /* extra characters after 1st? */
489 return has_error; /* invalid option */
490 args |= has_v;
491 break;
492 case 'e':
493 args |= has_e; /* FALLTHROUGH */
494 case 'l': /* both options need an argument */
495 if (argv[i][2] == '\0') { /* no concatenated argument? */
496 i++; /* try next 'argv' */
497 if (argv[i] == NULL || argv[i][0] == '-')
498 return has_error; /* no next argument or it is another option */
499 }
500 break;
501 default: /* invalid option */
502 return has_error;
503 }
504 }
505 *first = i; /* no script name */
506 return args;
507}
508
509
510/*

Callers 1

pmainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected