]> granicus.if.org Git - nethack/commitdiff
altmeta revisited
authorPatR <rankin@nethack.org>
Tue, 27 Jul 2021 18:03:20 +0000 (11:03 -0700)
committerPatR <rankin@nethack.org>
Tue, 27 Jul 2021 18:03:20 +0000 (11:03 -0700)
Put the flag that parse() uses to tell readchar() that the next
keystroke is a command into the program_state structure instead of
having it be a static variable in cmd.c.  Conceivably an interface
could make use of it, and even if none do, it is program state....

More #558

include/decl.h
src/cmd.c

index ba915f7258c913933cfcde4612172373589fb168..95666d860e859853073dd736efe727847acdde1d 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7  decl.h  $NHDT-Date: 1607641577 2020/12/10 23:06:17 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.248 $ */
+/* NetHack 3.7  decl.h  $NHDT-Date: 1627408982 2021/07/27 18:03:02 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.265 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Michael Allison, 2007. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -105,6 +105,10 @@ struct sinfo {
     int in_paniclog;
 #endif
     int wizkit_wishing;
+    /* getting_a_command:  only used for ALTMETA config to process ESC, but
+       present and updated unconditionally; set by parse() when requesting
+       next command keystroke, reset by readchar() as it returns a key */
+    int getting_a_command;
 };
 
 /* Flags for controlling uptodate */
index 9f58d296975c25f1858d7190dd51868950a69a42..838322c73018c45b0a23486a4e7d2cdea36239a8 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -1,4 +1,4 @@
-/* NetHack 3.7 cmd.c   $NHDT-Date: 1621377703 2021/05/18 22:41:43 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.464 $ */
+/* NetHack 3.7 cmd.c   $NHDT-Date: 1627408993 2021/07/27 18:03:13 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.481 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2013. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -171,9 +171,6 @@ static const char unavailcmd[] = "Unavailable command '%s'.";
 /* for rejecting #if !SHELL, !SUSPEND */
 static const char cmdnotavail[] = "'%s' command not available.";
 
-/* only needed for #if ALTMETA config but present unconditionally */
-static boolean getting_cmd = FALSE; /* True when parse() gets next command */
-
 static int
 doprev_message(void)
 {
@@ -4478,8 +4475,9 @@ parse(void)
     g.context.move = 1;
     flush_screen(1); /* Flush screen buffer. Put the cursor on the hero. */
 
-    getting_cmd = TRUE; /* affects readchar() behavior if the 'altmeta'
-                         * option is On; reset to False by readchar() */
+    g.program_state.getting_a_command = 1; /* affects readchar() behavior for
+                                            * ESC iff 'altmeta' option is On;
+                                            * reset to 0 by readchar() */
     if (!g.Cmd.num_pad || (foo = readchar()) == g.Cmd.spkeys[NHKF_COUNT]) {
         foo = get_count((char *) 0, '\0', LARGEST_INT,
                         &g.command_count, FALSE);
@@ -4627,7 +4625,8 @@ readchar_core(int *x, int *y, int *mod)
 #endif
         sym = '\033';
 #ifdef ALTMETA
-    } else if (sym == '\033' && iflags.altmeta && getting_cmd) {
+    } else if (sym == '\033' && iflags.altmeta
+               && g.program_state.getting_a_command) {
         /* iflags.altmeta: treat two character ``ESC c'' as single `M-c' but
            only when we're called by parse() [possibly via get_count()] */
         sym = *readchar_queue ? *readchar_queue++ : pgetchar();
@@ -4641,8 +4640,9 @@ readchar_core(int *x, int *y, int *mod)
         readchar_queue = click_to_cmd(*x, *y, *mod);
         sym = *readchar_queue++;
     }
-    getting_cmd = FALSE; /* next readchar() will be for an ordinary char
-                          * unless parse() sets this back to True */
+    g.program_state.getting_a_command = 0; /* next readchar() will be for an
+                                            * ordinary char unless parse()
+                                            * sets this back to 1 */
     return (char) sym;
 }