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

Function whatdoes_cond

src/pager.c:2457–2573  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2455staticfn boolean whatdoes_cond(char *, struct wd_stack_frame *, int *, int);
2456
2457staticfn boolean
2458whatdoes_cond(char *buf, struct wd_stack_frame *stack, int *depth, int lnum)
2459{
2460 const char badstackfmt[] = "cmdhlp: too many &%c directives at line %d.";
2461 boolean newcond, neg, gotopt;
2462 char *p, *q, act = buf[1];
2463 int np = 0;
2464
2465 newcond = (act == '?' || !stack[*depth].been_true);
2466 buf += 2;
2467 mungspaces(buf);
2468 if (act == '#' || *buf == '#' || !*buf || !newcond) {
2469 gotopt = (*buf && *buf != '#');
2470 *buf = '\0';
2471 neg = FALSE; /* lint suppression */
2472 p = q = (char *) 0;
2473 } else {
2474 gotopt = TRUE;
2475 if ((neg = (*buf == '!')) != 0)
2476 if (*++buf == ' ')
2477 ++buf;
2478 p = strchr(buf, '='), q = strchr(buf, ':');
2479 if (!p || (q && q < p))
2480 p = q;
2481 if (p) { /* we have a value specified */
2482 /* handle a space before or after (or both) '=' (or ':') */
2483 if (p > buf && p[-1] == ' ')
2484 p[-1] = '\0'; /* end of keyword in buf[] */
2485 *p++ = '\0'; /* terminate keyword, advance to start of value */
2486 if (*p == ' ')
2487 p++;
2488 }
2489 }
2490 if (*buf && (act == '?' || act == ':')) {
2491 if (!strcmpi(buf, "number_pad")) {
2492 if (!p) {
2493 newcond = iflags.num_pad;
2494 } else {
2495 /* convert internal encoding (separate yes/no and 0..3)
2496 back to user-visible one (-1..4) */
2497 np = iflags.num_pad ? (1 + iflags.num_pad_mode) /* 1..4 */
2498 : (-1 * iflags.num_pad_mode); /* -1..0 */
2499 newcond = FALSE;
2500 for (; p; p = q) {
2501 q = strchr(p, ',');
2502 if (q)
2503 *q++ = '\0';
2504 if (atoi(p) == np) {
2505 newcond = TRUE;
2506 break;
2507 }
2508 }
2509 }
2510 } else if (!strcmpi(buf, "rest_on_space")) {
2511 newcond = flags.rest_on_space;
2512 } else if (!strcmpi(buf, "debug") || !strcmpi(buf, "wizard")) {
2513 newcond = flags.debug; /* == wizard */
2514 } else if (!strcmpi(buf, "shell")) {

Callers 1

dowhatdoes_coreFunction · 0.85

Calls 2

mungspacesFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected