more tty extmenu option
Change extcmd_via_menu() so that the code which guards against overflow when gathering menu entries is always present. Now only the explanatory message when overflow is discovered remains conditional upon DEBUG || BETA. And make MAX_EXT_CMD actually be the maximum number of extended commands supported by the menu, instead of MAX_EXT_CMD-2 (which was an off-by-one bug; capacity for MAX_EXT_CMD-1 was available, but the last slot was always left unused except if/when unchecked overflow occured).
This commit is contained in:
@@ -357,7 +357,9 @@ doextlist(VOID_ARGS) /* here after #? - now list all full-word commands */
|
|||||||
#define MAX_EXT_CMD 50 /* Change if we ever have > 50 ext cmds */
|
#define MAX_EXT_CMD 50 /* Change if we ever have > 50 ext cmds */
|
||||||
/*
|
/*
|
||||||
* This is currently used only by the tty port and is
|
* This is currently used only by the tty port and is
|
||||||
* controlled via runtime option 'extmenu'
|
* controlled via runtime option 'extmenu'.
|
||||||
|
* ``# ?'' is counted towards the limit of the number of commands,
|
||||||
|
* so we actually support MAX_EXT_CMD-1 "real" extended commands.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
extcmd_via_menu() /* here after # - now show pick-list of possible commands */
|
extcmd_via_menu() /* here after # - now show pick-list of possible commands */
|
||||||
@@ -366,7 +368,7 @@ extcmd_via_menu() /* here after # - now show pick-list of possible commands */
|
|||||||
menu_item *pick_list = (menu_item *)0;
|
menu_item *pick_list = (menu_item *)0;
|
||||||
winid win;
|
winid win;
|
||||||
anything any;
|
anything any;
|
||||||
const struct ext_func_tab *choices[MAX_EXT_CMD];
|
const struct ext_func_tab *choices[MAX_EXT_CMD + 1];
|
||||||
char buf[BUFSZ];
|
char buf[BUFSZ];
|
||||||
char cbuf[QBUFSZ], prompt[QBUFSZ], fmtstr[20];
|
char cbuf[QBUFSZ], prompt[QBUFSZ], fmtstr[20];
|
||||||
int i, n, nchoices, acount;
|
int i, n, nchoices, acount;
|
||||||
@@ -384,20 +386,20 @@ extcmd_via_menu() /* here after # - now show pick-list of possible commands */
|
|||||||
/* populate choices */
|
/* populate choices */
|
||||||
for (efp = extcmdlist; efp->ef_txt; efp++) {
|
for (efp = extcmdlist; efp->ef_txt; efp++) {
|
||||||
if (!matchlevel || !strncmp(efp->ef_txt, cbuf, matchlevel)) {
|
if (!matchlevel || !strncmp(efp->ef_txt, cbuf, matchlevel)) {
|
||||||
choices[i++] = efp;
|
choices[i] = efp;
|
||||||
if ((int)strlen(efp->ef_desc) > biggest) {
|
if ((int)strlen(efp->ef_desc) > biggest) {
|
||||||
biggest = strlen(efp->ef_desc);
|
biggest = strlen(efp->ef_desc);
|
||||||
Sprintf(fmtstr, "%%-%ds", biggest + 15);
|
Sprintf(fmtstr, "%%-%ds", biggest + 15);
|
||||||
}
|
}
|
||||||
|
if (++i > MAX_EXT_CMD) {
|
||||||
# if defined(DEBUG) || defined(BETA)
|
# if defined(DEBUG) || defined(BETA)
|
||||||
if (i >= MAX_EXT_CMD - 2) {
|
|
||||||
impossible(
|
impossible(
|
||||||
"Exceeded %d extended commands in doextcmd() menu; 'extmenu' disabled.",
|
"Exceeded %d extended commands in doextcmd() menu; 'extmenu' disabled.",
|
||||||
MAX_EXT_CMD - 2);
|
MAX_EXT_CMD);
|
||||||
|
# endif /* DEBUG || BETA */
|
||||||
iflags.extmenu = 0;
|
iflags.extmenu = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
# endif /* DEBUG || BETA */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
choices[i] = (struct ext_func_tab *)0;
|
choices[i] = (struct ext_func_tab *)0;
|
||||||
|
|||||||
Reference in New Issue
Block a user