-/* NetHack 3.6 sp_lev.h $NHDT-Date: 1470212260 2016/08/03 08:17:40 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.17 $ */
+/* NetHack 3.6 sp_lev.h $NHDT-Date: 1501723399 2017/08/03 01:23:19 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.20 $ */
/* Copyright (c) 1989 by Jean-Christophe Collet */
/* NetHack may be freely redistributed. See license for details. */
#ifdef SPEC_LEV
/* compiling lev_comp rather than nethack */
#ifdef USE_OLDARGS
-#undef VA_ARGS
-#undef VA_DECL
-#undef VA_DECL2
-#undef VA_SHIFT
+#ifndef VA_TYPE
+typedef const char *vA;
+#define VA_TYPE
+#endif
+#undef VA_ARGS /* redefine with the maximum number actually used */
+#undef VA_SHIFT /* ditto */
#define VA_ARGS \
arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, \
arg12, arg13, arg14
-#define VA_DECL(typ1, var1) \
- (var1, VA_ARGS) typ1 var1; \
- char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8, *arg9, \
- *arg10, *arg11, *arg12, *arg13, *arg14; \
- {
-#define VA_DECL2(typ1, var1, typ2, var2) \
- (var1, var2, VA_ARGS) typ1 var1; \
- typ2 var2; \
- char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8, *arg9, \
- *arg10, *arg11, *arg12, *arg13, *arg14; \
- {
-/* unlike in the core, lev_comp's VA_SHIFT is completely safe,
- because callers always pass all these arguments */
+/* Unlike in the core, lev_comp's VA_SHIFT should be completely safe,
+ because callers always pass all these arguments. */
#define VA_SHIFT() \
(arg1 = arg2, arg2 = arg3, arg3 = arg4, arg4 = arg5, arg5 = arg6, \
arg6 = arg7, arg7 = arg8, arg8 = arg9, arg9 = arg10, arg10 = arg11, \
arg11 = arg12, arg12 = arg13, arg13 = arg14, arg14 = 0)
/* standard NULL may be either (void *)0 or plain 0, both of
which would need to be explicitly cast to (char *) here */
-typedef char *Va;
#define VA_PASS1(a1) \
- (Va) a1, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, \
- (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
+ (vA) a1, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, \
+ (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0
#define VA_PASS2(a1, a2) \
- (Va) a1, (Va) a2, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, \
- (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
+ (vA) a1, (vA) a2, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, \
+ (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0
#define VA_PASS3(a1, a2, a3) \
- (Va) a1, (Va) a2, (Va) a3, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, \
- (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
+ (vA) a1, (vA) a2, (vA) a3, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, \
+ (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0
#define VA_PASS4(a1, a2, a3, a4) \
- (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) 0, (Va) 0, (Va) 0, (Va) 0, \
- (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
+ (vA) a1, (vA) a2, (vA) a3, (vA) a4, (vA) 0, (vA) 0, (vA) 0, (vA) 0, \
+ (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0
#define VA_PASS5(a1, a2, a3, a4, a5) \
- (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) a5, (Va) 0, (Va) 0, (Va) 0, \
- (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
+ (vA) a1, (vA) a2, (vA) a3, (vA) a4, (vA) a5, (vA) 0, (vA) 0, (vA) 0, \
+ (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0
#define VA_PASS7(a1, a2, a3, a4, a5, a6, a7) \
- (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) a5, (Va) a6, (Va) a7, (Va) 0, \
- (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
+ (vA) a1, (vA) a2, (vA) a3, (vA) a4, (vA) a5, (vA) a6, (vA) a7, (vA) 0, \
+ (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0
#define VA_PASS8(a1, a2, a3, a4, a5, a6, a7, a8) \
- (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) a5, (Va) a6, (Va) a7, (Va) a8, \
- (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
+ (vA) a1, (vA) a2, (vA) a3, (vA) a4, (vA) a5, (vA) a6, (vA) a7, (vA) a8, \
+ (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0
#define VA_PASS9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \
- (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) a5, (Va) a6, (Va) a7, (Va) a8, \
- (Va) a9, (Va) 0, (Va) 0, (Va) 0, (Va) 0, (Va) 0
+ (vA) a1, (vA) a2, (vA) a3, (vA) a4, (vA) a5, (vA) a6, (vA) a7, (vA) a8, \
+ (vA) a9, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0
#define VA_PASS14(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, \
a14) \
- (Va) a1, (Va) a2, (Va) a3, (Va) a4, (Va) a5, (Va) a6, (Va) a7, (Va) a8, \
- (Va) a9, (Va) a10, (Va) a11, (Va) a12, (Va) a13, (Va) a14
+ (vA) a1, (vA) a2, (vA) a3, (vA) a4, (vA) a5, (vA) a6, (vA) a7, (vA) a8, \
+ (vA) a9, (vA) a10, (vA) a11, (vA) a12, (vA) a13, (vA) a14
#else /*!USE_OLDARGS*/
/* USE_STDARG and USE_VARARGS don't need to pass dummy arguments
or cast real ones */
-/* NetHack 3.6 system.h $NHDT-Date: 1449269772 2015/12/04 22:56:12 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.12 $ */
+/* NetHack 3.6 system.h $NHDT-Date: 1501723401 2017/08/03 01:23:21 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.13 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
#endif
#endif
#else
+#ifdef vprintf
+#undef vprintf
+#endif
#define vprintf printf
+#ifdef vfprintf
+#undef vfprintf
+#endif
#define vfprintf fprintf
+#ifdef vsprintf
+#undef vsprintf
+#endif
#define vsprintf sprintf
#endif
#endif /* NEED_VARARGS */
-/* NetHack 3.6 tradstdc.h $NHDT-Date: 1448210011 2015/11/22 16:33:31 $ $NHDT-Branch: master $:$NHDT-Revision: 1.27 $ */
+/* NetHack 3.6 tradstdc.h $NHDT-Date: 1501723401 2017/08/03 01:23:21 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.28 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
#else
/*USE_OLDARGS*/
+/*
+ * CAVEAT: passing double (including float promoted to double) will
+ * almost certainly break this, as would any integer type bigger than
+ * sizeof (char *).
+ * NetHack avoids floating point, and any configuration able to use
+ * 'long long int' or I64P32 or the like should be using USE_STDARG.
+ */
+#ifndef VA_TYPE
+typedef const char *vA;
+#define VA_TYPE
+#endif
#define VA_ARGS arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
#define VA_DECL(typ1, var1) \
- (var1, VA_ARGS) typ1 var1; \
- char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8, *arg9; \
+ (var1, VA_ARGS) typ1 var1; vA VA_ARGS; \
{
#define VA_DECL2(typ1, var1, typ2, var2) \
- (var1, var2, VA_ARGS) typ1 var1; \
- typ2 var2; \
- char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8, *arg9; \
+ (var1, var2, VA_ARGS) typ1 var1; typ2 var2; vA VA_ARGS; \
{
#define VA_START(x)
#define VA_INIT(var1, typ1)
*/
#define VA_SHIFT() \
(arg1 = arg2, arg2 = arg3, arg3 = arg4, arg4 = arg5, arg5 = arg6, \
- arg6 = arg7, arg7 = arg8, arg8 = arg9)
+ arg6 = arg7, arg7 = arg8, arg8 = arg9, arg9 = 0)
#define VA_NEXT(var1, typ1) ((var1 = (typ1) arg1), VA_SHIFT(), var1)
#define VA_END() }
#endif
* append this to a prototype declaration (see pline() in extern.h).
*/
#ifdef __GNUC__
-#if __GNUC__ >= 2
+#if (__GNUC__ >= 2) && !defined(USE_OLDARGS)
#define PRINTF_F(f, v) __attribute__((format(printf, f, v)))
#endif
#if __GNUC__ >= 3
-/* NetHack 3.6 lev_main.c $NHDT-Date: 1501461281 2017/07/31 00:34:41 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.46 $ */
+/* NetHack 3.6 lev_main.c $NHDT-Date: 1501723418 2017/08/03 01:23:38 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.47 $ */
/* Copyright (c) 1989 by Jean-Christophe Collet */
/* NetHack may be freely redistributed. See license for details. */
}
fin = freopen(fname, "r", stdin);
if (!fin) {
- lc_pline("Can't open \"%s\" for input.\n", fname);
+ lc_pline("Can't open \"%s\" for input.\n", VA_PASS1(fname));
perror(fname);
errors_encountered = TRUE;
} else {
case 'i': /* integer */
{
struct opvar *ov = New(struct opvar);
- set_opvar_int(ov, VA_NEXT(la, long) );
+ set_opvar_int(ov, VA_NEXT(la, long));
add_opcode(sp, SPO_PUSH, ov);
break;
}
case 'c': /* coordinate */
{
struct opvar *ov = New(struct opvar);
- set_opvar_coord(ov, VA_NEXT(la, long) );
+ set_opvar_coord(ov, VA_NEXT(la, long));
add_opcode(sp, SPO_PUSH, ov);
break;
}
case 'r': /* region */
{
struct opvar *ov = New(struct opvar);
- set_opvar_region(ov, VA_NEXT(la, long) );
+ set_opvar_region(ov, VA_NEXT(la, long));
add_opcode(sp, SPO_PUSH, ov);
break;
}
case 'm': /* mapchar */
{
struct opvar *ov = New(struct opvar);
- set_opvar_mapchar(ov, VA_NEXT(la, long) );
+ set_opvar_mapchar(ov, VA_NEXT(la, long));
add_opcode(sp, SPO_PUSH, ov);
break;
}
case 'M': /* monster */
{
struct opvar *ov = New(struct opvar);
- set_opvar_monst(ov, VA_NEXT(la, long) );
+ set_opvar_monst(ov, VA_NEXT(la, long));
add_opcode(sp, SPO_PUSH, ov);
break;
}
case 'O': /* object */
{
struct opvar *ov = New(struct opvar);
- set_opvar_obj(ov, VA_NEXT(la, long) );
+ set_opvar_obj(ov, VA_NEXT(la, long));
add_opcode(sp, SPO_PUSH, ov);
break;
}
case 's': /* string */
{
struct opvar *ov = New(struct opvar);
- set_opvar_str(ov, VA_NEXT(lp, const char *) );
+ set_opvar_str(ov, VA_NEXT(lp, const char *));
add_opcode(sp, SPO_PUSH, ov);
break;
}
case 'v': /* variable */
{
struct opvar *ov = New(struct opvar);
- set_opvar_var(ov, VA_NEXT(lp, const char *) );
+ set_opvar_var(ov, VA_NEXT(lp, const char *));
add_opcode(sp, SPO_PUSH, ov);
break;
}
{
long i = VA_NEXT(la, int);
if (i < 0 || i >= MAX_SP_OPCODES)
- lc_pline("add_opvars: unknown opcode '%ld'.", i);
+ lc_pline("add_opvars: unknown opcode '%ld'.", VA_PASS1(i));
add_opcode(sp, i, NULL);
break;
}
default:
- lc_pline("add_opvars: illegal format character '%c'.", *p);
+ lc_pline("add_opvars: illegal format character '%ld'.",
+ VA_PASS1((long) *p));
break;
}
}
struct lc_funcdefs *f = New(struct lc_funcdefs);
if (!f) {
- lc_error("Could not alloc function definition for '%s'.", name);
+ lc_error("Could not alloc function definition for '%s'.",
+ VA_PASS1(name));
return NULL;
}
f->next = NULL;
struct lc_vardefs *f = New(struct lc_vardefs);
if (!f) {
- lc_error("Could not alloc variable definition for '%s'.", name);
+ lc_error("Could not alloc variable definition for '%s'.",
+ VA_PASS1(name));
return NULL;
}
f->next = NULL;
while (tmp) {
if (be_verbose && (tmp->n_used == 0))
- lc_warning("Unused variable '%s'", tmp->name);
+ lc_warning("Unused variable '%s'", VA_PASS1(tmp->name));
nxt = tmp->next;
Free(tmp->name);
Free(tmp);
spovar &= ~SPOVAR_ARRAY;
switch (spovar) {
default:
- lc_error("spovar2str(%ld)", spovar);
+ lc_error("spovar2str(%ld)", VA_PASS1(spovar));
break;
case SPOVAR_INT:
n = "integer";
if ((tmp = vardef_defined(vd, varname, 1)) != 0) {
if (tmp->var_type != vartype)
lc_error("Trying to use variable '%s' as %s, when it is %s.",
- varname, spovar2str(vartype), spovar2str(tmp->var_type));
+ VA_PASS3(varname,
+ spovar2str(vartype),
+ spovar2str(tmp->var_type)));
} else
- lc_error("Variable '%s' not defined.", varname);
+ lc_error("Variable '%s' not defined.", VA_PASS1(varname));
}
struct lc_vardefs *
if ((tmp = vardef_defined(vd, varname, 1)) != 0) {
if (tmp->var_type != vartype)
lc_error("Trying to redefine variable '%s' as %s, when it is %s.",
- varname, spovar2str(vartype), spovar2str(tmp->var_type));
+ VA_PASS3(varname,
+ spovar2str(vartype),
+ spovar2str(tmp->var_type)));
} else {
tmp = vardef_new(vartype, varname);
tmp->next = vd;
case SPO_JGE:
return SPO_JL;
default:
- lc_error("Cannot reverse comparison jmp opcode %d.", opcode);
+ lc_error("Cannot reverse comparison jmp opcode %ld.",
+ VA_PASS1((long) opcode));
return SPO_NULL;
}
}
tmpov->vardata.str[len] = '\0';
} break;
default: {
- lc_error("Unknown opvar_clone value type (%d)!", ov->spovartyp);
+ lc_error("Unknown opvar_clone value type (%ld)!",
+ VA_PASS1((long) ov->spovartyp));
} /* default */
} /* switch */
return tmpov;
struct lc_funcdefs *f;
if (index(ldfname, '.'))
- lc_error("Invalid dot ('.') in level name '%s'.", ldfname);
+ lc_error("Invalid dot ('.') in level name '%s'.", VA_PASS1(ldfname));
if ((int) strlen(ldfname) > 14)
- lc_error("Level names limited to 14 characters ('%s').", ldfname);
+ lc_error("Level names limited to 14 characters ('%s').",
+ VA_PASS1(ldfname));
f = function_definitions;
while (f) {
f->n_called = 0;
if (!class || class == mons[i].mlet)
if (!case_insensitive_comp(s, mons[i].mname)) {
if (be_verbose)
- lc_warning("Monster type \"%s\" matches \"%s\".", s,
- mons[i].mname);
+ lc_warning("Monster type \"%s\" matches \"%s\".",
+ VA_PASS2(s, mons[i].mname));
return i;
}
return ERR;
objname = obj_descr[i].oc_name;
if (objname && !case_insensitive_comp(s, objname)) {
if (be_verbose)
- lc_warning("Object type \"%s\" matches \"%s\".", s, objname);
+ lc_warning("Object type \"%s\" matches \"%s\".",
+ VA_PASS2(s, objname));
return i;
}
}
_opcode *tmp;
if ((opc < 0) || (opc >= MAX_SP_OPCODES))
- lc_error("Unknown opcode '%d'", opc);
+ lc_error("Unknown opcode '%ld'", VA_PASS1((long) opc));
tmp = (_opcode *) alloc(sizeof(_opcode) * (nop + 1));
if (!tmp) { /* lint suppression */
/*NOTREACHED*/
#if 0
/* not possible; alloc() never returns Null */
- lc_error("Could not alloc opcode space");
+ lc_error("%s", VA_PASS1("Could not alloc opcode space"));
#endif
return;
}
for (i = 0; i < len; i++)
if ((tmpmap[max_hig][i] = what_map_char(map[i]))
== INVALID_TYPE) {
- lc_warning("Invalid character '%c' @ (%d, %d) - replacing "
- "with stone",
- map[i], max_hig, i);
+ lc_warning(
+ "Invalid character '%ld' @ (%ld, %ld) - replacing with stone",
+ VA_PASS3((long) map[i], (long) max_hig, (long) i));
tmpmap[max_hig][i] = STONE;
}
while (i < max_len)
max_y_map = max_hig - 1;
if (max_len > MAP_X_LIM || max_hig > MAP_Y_LIM) {
- lc_error("Map too large at (%d x %d), max is (%d x %d)", max_len,
- max_hig, MAP_X_LIM, MAP_Y_LIM);
+ lc_error("Map too large at (%ld x %ld), max is (%ld x %ld)",
+ VA_PASS4((long) max_len, (long) max_hig,
+ (long) MAP_X_LIM, (long) MAP_Y_LIM));
}
mbuf = (char *) alloc(((max_hig - 1) * max_len) + (max_len - 1) + 2);
mbuf[((max_hig - 1) * max_len) + (max_len - 1) + 1] = '\0';
- add_opvars(sp, "siio", VA_PASS4(mbuf, max_hig, max_len, SPO_MAP));
+ add_opvars(sp, "siio", VA_PASS4(mbuf, (long) max_hig, (long) max_len,
+ SPO_MAP));
for (dy = 0; dy < max_hig; dy++)
Free(tmpmap[dy]);