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

Function parseoptions

src/options.c:488–691  ·  view source on GitHub ↗

********************************** * * parseoptions * ********************************** */

Source from the content-addressed store, hash-verified

486 **********************************
487 */
488boolean
489parseoptions(
490 char *opts,
491 boolean tinitial,
492 boolean tfrom_file)
493{
494 char *op;
495 boolean negated, got_match = FALSE, pfx_match = FALSE;
496#if 0
497 boolean has_val = FALSE;
498#endif
499 int i, matchidx = -1, optresult = optn_err, optlen, optlen_wo_val;
500 boolean retval = TRUE;
501
502 duplicate = FALSE;
503 using_alias = FALSE;
504 go.opt_initial = tinitial;
505 go.opt_from_file = tfrom_file;
506 /*
507 * Process elements of comma-separated list in right to left order.
508 * When some options are set interactively--notably various compound
509 * options that issue a prompt for a value--they use parseoptions()
510 * to handle setting the new value. For those, 'tinitial' is False
511 * and if user tries to supply a comma-separated list, it will be
512 * treated as part of the current option, probably failing to parse.
513 */
514 if (tinitial && (op = strchr(opts, ',')) != 0) {
515 *op++ = 0;
516 /* current element remains pending while the rest of the line gets
517 handled recursively; if the rest of line contains any commas,
518 then the process will recurse deeper as it is processed */
519 if (!parseoptions(op, go.opt_initial, go.opt_from_file))
520 retval = FALSE;
521 }
522 if (strlen(opts) > BUFSZ / 2) {
523 config_error_add("Option too long, max length is %i characters",
524 (BUFSZ / 2));
525 return FALSE;
526 }
527
528 /* strip leading and trailing white space */
529 while (isspace((uchar) *opts))
530 opts++;
531 op = eos(opts);
532 while (--op >= opts && isspace((uchar) *op))
533 *op = '\0';
534
535 if (!*opts) {
536 config_error_add("Empty statement");
537 return FALSE;
538 }
539 negated = FALSE;
540 while ((*opts == '!') || !strncmpi(opts, "no", 2)) {
541 opts += (*opts == '!') ? 1 : (opts[2] != '-') ? 2 : 3;
542 negated = !negated;
543 }
544 optlen = (int) strlen(opts);
545 optlen_wo_val = length_without_val(opts, optlen);

Callers 6

handler_pickup_typesFunction · 0.85
doset_simple_menuFunction · 0.85
dosetFunction · 0.85
toggle_bool_optionFunction · 0.85
cnf_line_OPTIONSFunction · 0.85
rcfileFunction · 0.85

Calls 15

config_error_addFunction · 0.85
isspaceFunction · 0.85
eosFunction · 0.85
str_start_isFunction · 0.85
duplicate_opt_detectionFunction · 0.85
complain_about_duplicateFunction · 0.85
bad_negationFunction · 0.85
string_for_optFunction · 0.85
check_misc_menu_commandFunction · 0.85
spcfn_misc_menu_cmdFunction · 0.85
parsesymbolsFunction · 0.85
switch_symbolsFunction · 0.85

Tested by

no test coverage detected