VA_DECL/VA_END usage
Make the variadic functions look more like ordinary code rather than
have the function opening brace be hidden inside the VA_DECL() macro.
That brace is still there, but VA_DECL() now needs to be followed by
a visible brace (which introduces a nested block rather than the
start of the funciton). VA_END() now provides a hidden closing brace
to end the nested block, and the existing closing brace still matches
the one in VA_DECL().
Sample usage:
void foo VA_DECL(int, arg) --macro expansion has a hidden opening brace
{ --new, explicit opening brace (actually introduces a nested block)
VA_START(bar);
...code for foo...
VA_END(); --expansion now provides a closing brace for the nested block
} --existing closing brace, still pairs with the hidden one in VA_DECL()
This should help if/when another round of reformatting ever takes place,
and also with editors or other tools that do brace/bracket/parenthesis
matching.
I had forgotten that there were variadic functions in sys/* and ended
up modifying a lot more files than intended. The majority of changes
to those just inserted a new '{' line so that revised VA_END()'s '}'
won't introduce a syntax error. A couple of them needed VA_END() moved
so that local variables wouldn't go out of scope too soon. Only the
Unix ones have been tested.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 lev_main.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.38 $ */
|
||||
/* NetHack 3.6 lev_main.c $NHDT-Date: 1431737057 2015/05/16 00:44:17 $ $NHDT-Branch: master $:$NHDT-Revision: 1.39 $ */
|
||||
/* NetHack 3.6 lev_main.c $Date: 2012/01/12 04:48:12 $ $Revision: 1.20 $ */
|
||||
/* SCCS Id: @(#)lev_main.c 3.5 2007/01/17 */
|
||||
/* Copyright (c) 1989 by Jean-Christophe Collet */
|
||||
@@ -365,6 +365,7 @@ static void FDECL(lc_vpline, (const char *, va_list));
|
||||
|
||||
void lc_pline
|
||||
VA_DECL(const char *, line)
|
||||
{
|
||||
VA_START(line);
|
||||
VA_INIT(line, char *);
|
||||
lc_vpline(line, VA_ARGS);
|
||||
@@ -374,13 +375,11 @@ VA_DECL(const char *, line)
|
||||
#ifdef USE_STDARG
|
||||
static void
|
||||
lc_vpline(const char *line, va_list the_args)
|
||||
{
|
||||
#else
|
||||
static void
|
||||
lc_vpline(line, the_args)
|
||||
const char *line;
|
||||
va_list the_args;
|
||||
{
|
||||
#endif
|
||||
|
||||
#else /* USE_STDARG | USE_VARARG */
|
||||
@@ -390,6 +389,7 @@ va_list the_args;
|
||||
void lc_pline
|
||||
VA_DECL(const char *, line)
|
||||
#endif /* USE_STDARG | USE_VARARG */
|
||||
{ /* opening brace for lc_vpline, nested block for USE_OLDARGS lc_pline */
|
||||
|
||||
char pbuf[3 * BUFSZ];
|
||||
static char nomsg[] = "(no message)";
|
||||
@@ -415,11 +415,15 @@ VA_DECL(const char *, line)
|
||||
}
|
||||
lc_pline_mode = LC_PLINE_MESSAGE; /* reset to default */
|
||||
return;
|
||||
#if !(defined(USE_STDARG) || defined(USE_VARARGS))
|
||||
VA_END(); /* closing brace ofr USE_OLDARGS's nested block */
|
||||
#endif
|
||||
}
|
||||
|
||||
/*VARARGS1*/
|
||||
void lc_error
|
||||
VA_DECL(const char *, line)
|
||||
{
|
||||
VA_START(line);
|
||||
VA_INIT(line, const char *);
|
||||
lc_pline_mode = LC_PLINE_ERROR;
|
||||
@@ -431,6 +435,7 @@ VA_DECL(const char *, line)
|
||||
/*VARARGS1*/
|
||||
void lc_warning
|
||||
VA_DECL(const char *, line)
|
||||
{
|
||||
VA_START(line);
|
||||
VA_INIT(line, const char *);
|
||||
lc_pline_mode = LC_PLINE_WARNING;
|
||||
@@ -598,6 +603,7 @@ static void FDECL(vadd_opvars, (sp_lev *, const char *, va_list));
|
||||
|
||||
void add_opvars
|
||||
VA_DECL2(sp_lev *, sp, const char *, fmt)
|
||||
{
|
||||
VA_START(fmt);
|
||||
VA_INIT(fmt, char *);
|
||||
vadd_opvars(sp, fmt, VA_ARGS);
|
||||
|
||||
8238
util/lev_main.i
Normal file
8238
util/lev_main.i
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 panic.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
|
||||
/* NetHack 3.6 panic.c $NHDT-Date: 1431737058 2015/05/16 00:44:18 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
|
||||
/* NetHack 3.6 panic.c $Date: 2009/05/06 10:54:39 $ $Revision: 1.4 $ */
|
||||
/* SCCS Id: @(#)panic.c 3.5 1994/03/02 */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
@@ -25,6 +25,7 @@ void VDECL(panic, (char *, ...));
|
||||
|
||||
void panic
|
||||
VA_DECL(char *, str)
|
||||
{
|
||||
VA_START(str);
|
||||
VA_INIT(str, char *);
|
||||
if (panicking++)
|
||||
|
||||
Reference in New Issue
Block a user