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

Function extcmds_match

src/cmd.c:2522–2558  ·  view source on GitHub ↗

find extended command entries matching findstr. if findstr is NULL, returns all available entries. returns: number of matching extended commands, and the entry indexes in matchlist. for windowport use. */

Source from the content-addressed store, hash-verified

2520 and the entry indexes in matchlist.
2521 for windowport use. */
2522int
2523extcmds_match(const char *findstr, int ecmflags, int **matchlist)
2524{
2525 static int retmatchlist[SIZE(extcmdlist)] = DUMMY;
2526 int i, mi = 0;
2527 int fslen = findstr ? Strlen(findstr) : 0;
2528 boolean ignoreac = (ecmflags & ECM_IGNOREAC) != 0;
2529 boolean exactmatch = (ecmflags & ECM_EXACTMATCH) != 0;
2530 boolean no1charcmd = (ecmflags & ECM_NO1CHARCMD) != 0;
2531
2532 for (i = 0; extcmdlist[i].ef_txt; i++) {
2533 if (extcmdlist[i].flags & (CMD_NOT_AVAILABLE|INTERNALCMD))
2534 continue;
2535 if (!wizard && (extcmdlist[i].flags & WIZMODECMD))
2536 continue;
2537 if (!ignoreac && !(extcmdlist[i].flags & AUTOCOMPLETE))
2538 continue;
2539 if (no1charcmd && (strlen(extcmdlist[i].ef_txt) == 1))
2540 continue;
2541 if (!findstr) {
2542 retmatchlist[mi++] = i;
2543 } else if (exactmatch) {
2544 if (!strcmpi(findstr, extcmdlist[i].ef_txt)) {
2545 retmatchlist[mi++] = i;
2546 }
2547 } else {
2548 if (!strncmpi(findstr, extcmdlist[i].ef_txt, fslen)) {
2549 retmatchlist[mi++] = i;
2550 }
2551 }
2552 }
2553
2554 if (matchlist)
2555 *matchlist = retmatchlist;
2556
2557 return mi;
2558}
2559
2560const char *
2561key2extcmddesc(uchar key)

Callers 4

ext_cmd_getlin_hookFunction · 0.85
tty_get_ext_cmdFunction · 0.85
curses_ext_cmdFunction · 0.85

Calls 1

strncmpiFunction · 0.70

Tested by

no test coverage detected