MCPcopy Create free account
hub / github.com/NetHack/NetHack / optfn_autounlock

Function optfn_autounlock

src/options.c:1065–1168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1063}
1064
1065staticfn int
1066optfn_autounlock(
1067 int optidx,
1068 int req,
1069 boolean negated,
1070 char *opts,
1071 char *op)
1072{
1073 if (req == do_init) {
1074 flags.autounlock = AUTOUNLOCK_APPLY_KEY;
1075 return optn_ok;
1076 }
1077 if (req == do_set) {
1078 /* autounlock:none or autounlock:untrap+apply-key+kick+force;
1079 autounlock without a value is same as autounlock:apply-key and
1080 !autounlock is same as autounlock:none; multiple values can be
1081 space separated or plus-sign separated but the same separation
1082 must be used for each element, not mix&match */
1083 char sep, *nxt;
1084 unsigned newflags;
1085 int i;
1086
1087 if ((op = string_for_opt(opts, TRUE)) == empty_optstr) {
1088 flags.autounlock = negated ? 0 : AUTOUNLOCK_APPLY_KEY;
1089 return optn_ok;
1090 }
1091 newflags = 0;
1092 sep = strchr(op, '+') ? '+' : ' ';
1093 while (op) {
1094 boolean matched = FALSE;
1095 op = trimspaces(op); /* might have leading space */
1096 if ((nxt = strchr(op, sep)) != 0) {
1097 *nxt++ = '\0';
1098 op = trimspaces(op); /* might have trailing space after
1099 * plus sign removal */
1100 }
1101 if (str_start_is("none", op, TRUE))
1102 negated = TRUE, matched = TRUE;
1103 for (i = 0; i < SIZE(unlocktypes) && !matched; ++i) {
1104 if (str_start_is(unlocktypes[i][0], op, TRUE)
1105 /* fuzzymatch() doesn't match leading substrings but
1106 this allows "apply_key" and "applykey" to match
1107 "apply-key"; "apply key" too if part of foo+bar */
1108 || fuzzymatch(op, unlocktypes[i][0], " -_", TRUE)) {
1109 matched = TRUE;
1110 switch (*op) {
1111 case 'u':
1112 newflags |= AUTOUNLOCK_UNTRAP;
1113 break;
1114 case 'a':
1115 newflags |= AUTOUNLOCK_APPLY_KEY;
1116 break;
1117 case 'k':
1118 newflags |= AUTOUNLOCK_KICK;
1119 break;
1120 case 'f':
1121 newflags |= AUTOUNLOCK_FORCE;
1122 break;

Callers 1

handler_autounlockFunction · 0.85

Calls 7

string_for_optFunction · 0.85
trimspacesFunction · 0.85
str_start_isFunction · 0.85
fuzzymatchFunction · 0.85
config_error_addFunction · 0.85
eosFunction · 0.85
handler_autounlockFunction · 0.85

Tested by

no test coverage detected