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

Function key2extcmddesc

src/cmd.c:2560–2621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2558}
2559
2560const char *
2561key2extcmddesc(uchar key)
2562{
2563 static char key2cmdbuf[QBUFSZ];
2564 const char *txt;
2565 int k, i, j;
2566 uchar M_5 = (uchar) M('5'), M_0 = (uchar) M('0');
2567 struct Cmd_bind *cmdbind;
2568
2569 /* need to check for movement commands before checking the extended
2570 commands table because it contains entries for number_pad commands
2571 that match !number_pad movement (like 'j' for "jump") */
2572 key2cmdbuf[0] = '\0';
2573 if (movecmd(k = key, MV_WALK))
2574 Strcpy(key2cmdbuf, "move"); /* "move or attack"? */
2575 else if (movecmd(k = key, MV_RUSH))
2576 Strcpy(key2cmdbuf, "rush");
2577 else if (movecmd(k = key, MV_RUN))
2578 Strcpy(key2cmdbuf, "run");
2579 if (digit(key) || (gc.Cmd.num_pad && digit(unmeta(key)))) {
2580 key2cmdbuf[0] = '\0';
2581 if (!gc.Cmd.num_pad)
2582 Strcpy(key2cmdbuf, "start of, or continuation of, a count");
2583 else if (key == '5' || key == M_5)
2584 Sprintf(key2cmdbuf, "%s prefix",
2585 (!!gc.Cmd.pcHack_compat ^ (key == M_5)) ? "run" : "rush");
2586 else if (key == '0' || (gc.Cmd.pcHack_compat && key == M_0))
2587 Strcpy(key2cmdbuf, "synonym for 'i'");
2588 if (*key2cmdbuf)
2589 return key2cmdbuf;
2590 }
2591 /* check prefixes before regular commands; includes ^A pseudo-command */
2592 for (i = 0; misc_keys[i].desc; ++i) {
2593 if (misc_keys[i].numpad && !iflags.num_pad)
2594 continue;
2595 j = misc_keys[i].nhkf;
2596 if (key == (uchar) gc.Cmd.spkeys[j])
2597 return misc_keys[i].desc;
2598 }
2599 /* finally, check whether 'key' is a command */
2600 if ((cmdbind = cmdbind_get(key)) != 0
2601 && cmdbind->cmd
2602 && (txt = cmdbind->cmd->ef_txt) != 0) {
2603 Sprintf(key2cmdbuf, "%s (#%s)", cmdbind->cmd->ef_desc, txt);
2604
2605 /* special case: for reqmenu prefix (normally 'm'), replace
2606 "prefix: request menu or modify command (#reqmenu)"
2607 with two-line "movement prefix:...\nnon-movement prefix:..." */
2608 if (!strncmpi(key2cmdbuf, "prefix:", 7) && !strcmpi(txt, "reqmenu"))
2609 (void) strsubst(key2cmdbuf, "prefix:",
2610 /* relies on implicit concatenation of literal strings */
2611 "movement prefix:"
2612 " move without autopickup and without attacking"
2613 "\n"
2614 "non-movement prefix:"); /* and rest of buf */
2615
2616 /* another special case: 'txt' for '#' is "#" and showing that as
2617 "perform an extended command (##)" looks silly; strip "(##)" off */

Callers 1

dowhatdoes_coreFunction · 0.85

Calls 5

movecmdFunction · 0.85
digitFunction · 0.85
cmdbind_getFunction · 0.85
strsubstFunction · 0.85
strncmpiFunction · 0.70

Tested by

no test coverage detected