fix makedefs

If makedefs.c is compiled with MONITOR_HEAP defined, attempted calls to
free() resulted in link failure.  Since makedefs doesn't use alloc(),
call free() directly instead of redirecting to nhfree().

Also some assorted reformatting....
This commit is contained in:
PatR
2015-11-09 01:47:18 -08:00
parent 26b6bff3d2
commit 9f19b60147
+23 -18
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 makedefs.c $NHDT-Date: 1434151372 2015/06/12 23:22:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.103 $ */ /* NetHack 3.6 makedefs.c $NHDT-Date: 1447062431 2015/11/09 09:47:11 $ $NHDT-Branch: master $:$NHDT-Revision: 1.105 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* Copyright (c) M. Stephenson, 1990, 1991. */ /* Copyright (c) M. Stephenson, 1990, 1991. */
/* Copyright (c) Dean Luick, 1990. */ /* Copyright (c) Dean Luick, 1990. */
@@ -7,6 +7,9 @@
#define MAKEDEFS_C /* use to conditionally include file sections */ #define MAKEDEFS_C /* use to conditionally include file sections */
#include "config.h" #include "config.h"
#ifdef MONITOR_HEAP
#undef free /* makedefs doesn't use the alloc and free in src/alloc.c */
#endif
#include "permonst.h" #include "permonst.h"
#include "objclass.h" #include "objclass.h"
#include "monsym.h" #include "monsym.h"
@@ -891,6 +894,7 @@ unsigned long old_rumor_offset;
we ameliorate the latter by padding the shortest lines, we ameliorate the latter by padding the shortest lines,
increasing the chance of the random seek landing in them */ increasing the chance of the random seek landing in them */
int len = (int) strlen(line); int len = (int) strlen(line);
if (len <= PAD_RUMORS_TO) { if (len <= PAD_RUMORS_TO) {
char *base = index(line, '\n'); char *base = index(line, '\n');
/* this is only safe because fgetline() overallocates */ /* this is only safe because fgetline() overallocates */
@@ -1985,7 +1989,7 @@ register struct permonst *ptr;
return TRUE; return TRUE;
} }
return (FALSE); return FALSE;
} }
/* This routine is designed to return an integer value which represents /* This routine is designed to return an integer value which represents
@@ -2035,9 +2039,8 @@ struct permonst *ptr;
n += ((int) (ptr->mattk[i].damd * ptr->mattk[i].damn) > 23); n += ((int) (ptr->mattk[i].damd * ptr->mattk[i].damn) > 23);
} }
/* Leprechauns are special cases. They have many hit dice so they /* Leprechauns are special cases. They have many hit dice so they can
can hit and are hard to kill, but they don't really do much hit and are hard to kill, but they don't really do much damage. */
damage. */
if (!strcmp(ptr->mname, "leprechaun")) if (!strcmp(ptr->mname, "leprechaun"))
n -= 2; n -= 2;
@@ -2049,7 +2052,7 @@ struct permonst *ptr;
else else
tmp += (n / 3 + 1); tmp += (n / 3 + 1);
return ((tmp >= 0) ? tmp : 0); return (tmp >= 0) ? tmp : 0;
} }
void void
@@ -2151,15 +2154,15 @@ qt_comment(s)
char *s; char *s;
{ {
if (s[0] == '#') if (s[0] == '#')
return (TRUE); return TRUE;
return ((boolean)(!in_msg && strlen(s) == NO_MSG)); return (boolean) (!in_msg && strlen(s) == NO_MSG);
} }
static boolean static boolean
qt_control(s) qt_control(s)
char *s; char *s;
{ {
return ((boolean)(s[0] == '%' && (s[1] == 'C' || s[1] == 'E'))); return (boolean) (s[0] == '%' && (s[1] == 'C' || s[1] == 'E'));
} }
static int static int
@@ -2170,9 +2173,9 @@ char *code;
for (i = 0; i < qt_hdr.n_hdr; i++) for (i = 0; i < qt_hdr.n_hdr; i++)
if (!strncmp(code, qt_hdr.id[i], LEN_HDR)) if (!strncmp(code, qt_hdr.id[i], LEN_HDR))
return (++i); return ++i;
return (0); return 0;
} }
static boolean static boolean
@@ -2181,13 +2184,13 @@ char *code;
{ {
if (qt_hdr.n_hdr >= N_HDR) { if (qt_hdr.n_hdr >= N_HDR) {
Fprintf(stderr, OUT_OF_HEADERS, qt_line); Fprintf(stderr, OUT_OF_HEADERS, qt_line);
return (FALSE); return FALSE;
} }
strncpy(&qt_hdr.id[qt_hdr.n_hdr][0], code, LEN_HDR); strncpy(&qt_hdr.id[qt_hdr.n_hdr][0], code, LEN_HDR);
msg_hdr[qt_hdr.n_hdr].n_msg = 0; msg_hdr[qt_hdr.n_hdr].n_msg = 0;
qt_hdr.offset[qt_hdr.n_hdr++] = 0L; qt_hdr.offset[qt_hdr.n_hdr++] = 0L;
return (TRUE); return TRUE;
} }
static boolean static boolean
@@ -2198,9 +2201,9 @@ int num, id;
for (i = 0; i < msg_hdr[num].n_msg; i++) for (i = 0; i < msg_hdr[num].n_msg; i++)
if (msg_hdr[num].qt_msg[i].msgnum == id) if (msg_hdr[num].qt_msg[i].msgnum == id)
return (TRUE); return TRUE;
return (FALSE); return FALSE;
} }
static void static void
@@ -2392,10 +2395,12 @@ put_qt_hdrs()
sizeof(struct qtmsg), msg_hdr[i].n_msg, ofp); sizeof(struct qtmsg), msg_hdr[i].n_msg, ofp);
if (debug) { if (debug) {
int j; int j;
for (j = 0; j < msg_hdr[i].n_msg; j++) { for (j = 0; j < msg_hdr[i].n_msg; j++) {
Fprintf( Fprintf(stderr, "msg %d @ %ld (%ld)",
stderr, "msg %d @ %ld (%ld)", msg_hdr[i].qt_msg[j].msgnum, msg_hdr[i].qt_msg[j].msgnum,
msg_hdr[i].qt_msg[j].offset, msg_hdr[i].qt_msg[j].size); msg_hdr[i].qt_msg[j].offset,
msg_hdr[i].qt_msg[j].size);
if (msg_hdr[i].qt_msg[j].summary_size) if (msg_hdr[i].qt_msg[j].summary_size)
Fprintf(stderr, " [%ld]", Fprintf(stderr, " [%ld]",
msg_hdr[i].qt_msg[j].summary_size); msg_hdr[i].qt_msg[j].summary_size);