From 045ee2a8980a961e83eea649975c0cabbd25ffcf Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Sat, 9 Dec 2017 14:12:40 +0000 Subject: [PATCH] Add an instance flag for being inside parse() Some windowports that are currently being written by third parties need more information about the engine than they currently have. Two specific reported problems: a) needing to know whether a putstr() call relates to a count (so that it can be placed in a different part of the user interface from the message area); b) needing to know whether a request for a character relates to command input (some hangup handling routines need this so that they can determine what behaviour is potentially exploitable). Knowing whether or not you're inside parse() fixes both of them. This would be cleaner to do by changing the windowport API, but that'd break existing windowports, which isn't really ideal. Setting a globalish variable that the windowport can inspect, but can ignore if it prefers, means that existing windowports will continue to work fine, but new windowports will have more information and thus more flexibility in how they handle command entry. --- include/flag.h | 1 + src/cmd.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/flag.h b/include/flag.h index 81630bd27..a8f9172f7 100644 --- a/include/flag.h +++ b/include/flag.h @@ -216,6 +216,7 @@ struct instance_flags { boolean sanity_check; /* run sanity checks */ boolean mon_polycontrol; /* debug: control monster polymorphs */ boolean in_dumplog; /* doing the dumplog right now? */ + boolean in_parse; /* is a command being parsed? */ /* stuff that is related to options and/or user or platform preferences */ diff --git a/src/cmd.c b/src/cmd.c index 0272ec0b9..4da0509d2 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -5125,6 +5125,7 @@ parse() register int foo; boolean prezero = FALSE; + iflags.in_parse = TRUE; multi = 0; context.move = 1; flush_screen(1); /* Flush screen buffer. Put the cursor on the hero. */ @@ -5191,6 +5192,8 @@ parse() clear_nhwindow(WIN_MESSAGE); if (prezero) in_line[0] = Cmd.spkeys[NHKF_ESC]; + + iflags.in_parse = FALSE; return in_line; }