]> granicus.if.org Git - nethack/commitdiff
mon name buffers
authornethack.allison <nethack.allison>
Thu, 6 Nov 2003 02:16:22 +0000 (02:16 +0000)
committernethack.allison <nethack.allison>
Thu, 6 Nov 2003 02:16:22 +0000 (02:16 +0000)
Follow suit with what <Someone> did for the object name buffers,
so that this sort of statement can work correctly:

pline("%s hits %s.", Monnam(mtmp), mon_nam(mtmp2));

doc/fixes35.0
src/do_name.c

index 5087f0fd6bdd1a2c054e248ca7cc8caf96a2d74a..185c6ef9b2641fe113d2ad4272b0312231b8952e 100644 (file)
@@ -48,6 +48,7 @@ make it possible for the code to recognize your starting pet throughout the
 healers notice when a wand of undead turning revives a monster so the
        wand is then identified
 update display if bestowed a spellbook while unable to see invisible self
+use small pool of static buffers for mon_nam() and Monnam()
 
 
 Platform- and/or Interface-Specific Fixes
index 9d3cff73ef5a64bdfda4a83d42bf617973ef3b6c..099d07a3c7ce2b8561b3fbb81b9ef0afeebf1df0 100644 (file)
@@ -6,9 +6,23 @@
 
 STATIC_DCL void FDECL(do_oname, (struct obj *));
 STATIC_DCL void FDECL(getpos_help, (BOOLEAN_P,const char *));
+STATIC_DCL char *NDECL(nextmbuf);
 
 extern const char what_is_an_unknown_object[];         /* from pager.c */
 
+#define NUMMBUF 5
+
+/* manage a pool of BUFSZ buffers, so callers don't have to */
+STATIC_OVL char *
+nextmbuf()
+{
+       static char NEARDATA bufs[NUMMBUF][BUFSZ];
+       static int bufidx = 0;
+
+       bufidx = (bufidx + 1) % NUMMBUF;
+       return bufs[bufidx];
+}
+
 /* the response for '?' help request in getpos() */
 STATIC_OVL void
 getpos_help(force, goal)
@@ -579,11 +593,7 @@ int suppress;
  */
 boolean called;
 {
-#ifdef LINT    /* static char buf[BUFSZ]; */
-       char buf[BUFSZ];
-#else
-       static char buf[BUFSZ];
-#endif
+       char *buf = nextmbuf();
        struct permonst *mdat = mtmp->data;
        boolean do_hallu, do_invis, do_it, do_saddle;
        boolean name_at_start, has_adjectives;
@@ -606,7 +616,7 @@ boolean called;
            !(suppress & SUPPRESS_IT);
        do_saddle = !(suppress & SUPPRESS_SADDLE);
 
-       buf[0] = 0;
+       buf[0] = '\0';
 
        /* unseen monsters, etc.  Use "it" */
        if (do_it) {