| 737 | #define MAX_EXT_CMD 200 /* Change if we ever have more ext cmds */ |
| 738 | |
| 739 | DISABLE_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 | */ |
| 751 | int |
| 752 | extcmd_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; |
no test coverage detected