]> granicus.if.org Git - nethack/commitdiff
using prefixes via their extended command names
authorPatR <rankin@nethack.org>
Tue, 8 Feb 2022 00:53:56 +0000 (16:53 -0800)
committerPatR <rankin@nethack.org>
Tue, 8 Feb 2022 00:53:56 +0000 (16:53 -0800)
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.

include/decl.h
src/cmd.c
src/decl.c

index a46b0b8a8ec1c8b7cfe96442db03f2b0a65a3976..dff6387e76d10e53cff584e4cf3855f2937f42a0 100644 (file)
@@ -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];
index 65fd06e9f95c4d2166197860f9fe1711c2fc2260..617084ee564037668876c39fc2b2ba08258688cf 100644 (file)
--- 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 */
index 8859919bcc7f4293b4eba8ae9c5297bc852387f0..56514cd453573953757634a48fd121a833095507 100644 (file)
@@ -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 */