From: PatR Date: Tue, 8 Feb 2022 00:53:56 +0000 (-0800) Subject: using prefixes via their extended command names X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a0100dd30014403bb4f71f1b5fcc3ec851acea2f;p=nethack using prefixes via their extended command names Trying to use #reqmenu/#rush/#run/#fight prefixes by their extended command names didn't work because rhack()'s post-processing was stuck dealing with the entry for the '#' key after using doextcmd() to run any command. Use a static variable (actually a global one since I put it into struct g) to notify rhack() of the command that ultimately got executed. --- diff --git a/include/decl.h b/include/decl.h index a46b0b8a8..dff6387e7 100644 --- a/include/decl.h +++ b/include/decl.h @@ -728,6 +728,7 @@ struct instance_globals { winid en_win; boolean en_via_menu; long last_command_count; + struct ext_func_tab *ext_tlist; /* info for rhack() from doextcmd() */ /* dbridge.c */ struct entity occupants[ENTITIES]; diff --git a/src/cmd.c b/src/cmd.c index 65fd06e9f..617084ee5 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -391,6 +391,9 @@ doextcmd(void) extcmdlist[idx].ef_txt); iflags.menu_requested = FALSE; } + /* tell rhack() what command is actually executing */ + g.ext_tlist = &extcmdlist[idx]; + retval = (*func)(); } while (func == doextlist); @@ -3886,7 +3889,14 @@ rhack(char *cmd) func = ((struct ext_func_tab *) tlist)->ef_funct; if (tlist->f_text && !g.occupation && g.multi) set_occupation(func, tlist->f_text, g.multi); + g.ext_tlist = NULL; res = (*func)(); /* perform the command */ + /* if 'func' is doextcmd(), 'tlist' is for Cmd.commands['#'] + rather than for the command that doextcmd() just ran; + doextcmd() notifies us what that was via ext_tlist; + other commands leave it Null */ + if (g.ext_tlist) + tlist = g.ext_tlist; if ((tlist->flags & PREFIXCMD)) { /* it was a prefix command, mark and get another cmd */ diff --git a/src/decl.c b/src/decl.c index 8859919bc..56514cd45 100644 --- a/src/decl.c +++ b/src/decl.c @@ -231,6 +231,7 @@ const struct instance_globals g_init = { WIN_ERR, /* en_win */ FALSE, /* en_via_menu */ UNDEFINED_VALUE, /* last_command_count */ + NULL, /* ext_tlist */ /* dbridge.c */ UNDEFINED_VALUES, /* occupants */