]> granicus.if.org Git - nethack/commitdiff
debugpline() fix
authorPatR <rankin@nethack.org>
Sun, 19 Jun 2022 09:30:45 +0000 (02:30 -0700)
committerPatR <rankin@nethack.org>
Sun, 19 Jun 2022 09:30:45 +0000 (02:30 -0700)
Something which occurred to me when looking at the magic whistle code.
It's behavior can vary depending upon whether pline()/You()/&c has
been called and that is detected by checking whether pline() has reset
iflags.last_msg.  Change the debugpline() mechanism to prevent it from
interfering with that.

include/lint.h

index d812117fbd62c7c1c026ab29d5db8357e7261334..76d9aee7a5b32325472b04fd3d972564f4f48c4f 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 lint.h  $NHDT-Date: 1596498539 2020/08/03 23:48:59 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.6 $ */
+/* NetHack 3.7 lint.h  $NHDT-Date: 1655631029 2022/06/19 09:30:29 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.8 $ */
 /*      Copyright (c) 2016 by Robert Patrick Rankin               */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -15,7 +15,7 @@
    (also caller's responsibility to ensure it isn't actually modified!) */
 #define nhStr(str) ((char *) str)
 
-#define nhUse(arg) (void)(arg)
+#define nhUse(arg) ((void) (arg))
 
 /*
  * This stuff isn't related to lint suppression but lives here to
 #ifdef DEBUG
 #define showdebug(file) debugcore(file, TRUE)
 #define explicitdebug(file) debugcore(file, FALSE)
-#define ifdebug(stmt)                   \
-    do {                                \
-        if (showdebug(__FILE__)) {      \
-            stmt;                       \
-        }                               \
+    /* in case 'stmt' is pline() or something which calls pline(),
+       save and restore previous plnmsg code so that use of debugpline()
+       doesn't change message semantics */
+#define ifdebug(stmt) \
+    do {                                       \
+        if (showdebug(__FILE__)) {             \
+            int save_plnmsg = iflags.last_msg; \
+            stmt;                              \
+            iflags.last_msg = save_plnmsg;     \
+        }                                      \
     } while (0)
 #ifdef _MSC_VER
 /* if we have microsoft's C runtime we can use these instead */
 #include <crtdbg.h>
-#define crtdebug(stmt)                  \
-    do {                                \
-        if (showdebug(__FILE__)) {      \
-            stmt;                       \
-        }                               \
-        _RPT0(_CRT_WARN, "\n");         \
+#define crtdebug(stmt) \
+    do {                                       \
+        if (showdebug(__FILE__)) {             \
+            int save_plnmsg = iflags.last_msg; \
+            stmt;                              \
+            iflags.last_msg = save_plnmsg;     \
+        }                                      \
+        _RPT0(_CRT_WARN, "\n");                \
     } while (0)
 #define debugpline0(str) crtdebug(_RPT0(_CRT_WARN, str))
 #define debugpline1(fmt, arg) crtdebug(_RPT1(_CRT_WARN, fmt, arg))