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

Function extcmd_via_menu

src/cmd.c:739–882  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

737#define MAX_EXT_CMD 200 /* Change if we ever have more ext cmds */
738
739DISABLE_WARNING_FORMAT_NONLITERAL
740
741/*
742 * This is currently used only by the tty interface and is
743 * controlled via runtime option 'extmenu'. (Most other interfaces
744 * already use a menu all the time for extended commands.)
745 *
746 * ``# ?'' is counted towards the limit of the number of commands,
747 * so we actually support MAX_EXT_CMD-1 "real" extended commands.
748 *
749 * Here after # - now show pick-list of possible commands.
750 */
751int
752extcmd_via_menu(void)
753{
754 const struct ext_func_tab *efp;
755 menu_item *pick_list = (menu_item *) 0;
756 winid win;
757 anything any;
758 const struct ext_func_tab *choices[MAX_EXT_CMD + 1];
759 char buf[BUFSZ];
760 char cbuf[QBUFSZ], prompt[QBUFSZ], fmtstr[20];
761 int i, n, nchoices, acount;
762 int ret, len, biggest;
763 int accelerator, prevaccelerator;
764 int matchlevel = 0;
765 boolean wastoolong, one_per_line;
766 int clr = NO_COLOR;
767
768 ret = 0;
769 cbuf[0] = '\0';
770 biggest = 0;
771 while (!ret) {
772 i = n = 0;
773 any = cg.zeroany;
774 /* populate choices */
775 for (efp = extcmdlist; efp->ef_txt; efp++) {
776 if ((efp->flags & (CMD_NOT_AVAILABLE|INTERNALCMD))
777 || !(efp->flags & AUTOCOMPLETE)
778 || (!wizard && (efp->flags & WIZMODECMD)))
779 continue;
780 if (!matchlevel || !strncmp(efp->ef_txt, cbuf, matchlevel)) {
781 choices[i] = efp;
782 if ((len = (int) strlen(efp->ef_desc)) > biggest)
783 biggest = len;
784 if (++i > MAX_EXT_CMD) {
785#if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
786 impossible(
787 "Exceeded %d extended commands in doextcmd() menu; 'extmenu' disabled.",
788 MAX_EXT_CMD);
789#endif /* NH_DEVEL_STATUS != NH_STATUS_RELEASED */
790 iflags.extmenu = FALSE;
791 return -1;
792 }
793 }
794 }
795 choices[i] = (struct ext_func_tab *) 0;
796 nchoices = i;

Callers 3

tty_get_ext_cmdFunction · 0.85
curses_ext_cmdFunction · 0.85
mac_get_ext_cmdFunction · 0.85

Calls 3

add_menuFunction · 0.85
select_menuFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected