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:
PatR
2015-05-15 17:45:21 -07:00
parent dd62a6831f
commit fabf9cd901
16 changed files with 8339 additions and 42 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 nttty.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.62 $ */
/* NetHack 3.6 nttty.c $NHDT-Date: 1431737067 2015/05/16 00:44:27 $ $NHDT-Branch: master $:$NHDT-Revision: 1.63 $ */
/* Copyright (c) NetHack PC Development Team 1993 */
/* NetHack may be freely redistributed. See license for details. */
@@ -1014,11 +1014,11 @@ load_keyboard_handler()
*/
void msmsg
VA_DECL(const char *, fmt)
{
char buf[ROWNO * COLNO]; /* worst case scenario */
VA_START(fmt);
VA_INIT(fmt, const char *);
Vsprintf(buf, fmt, VA_ARGS);
VA_END();
if (redirect_stdout)
fprintf(stdout, "%s", buf);
else {
@@ -1026,6 +1026,7 @@ VA_DECL(const char *, fmt)
if (ttyDisplay)
curs(BASE_WINDOW, cursor.X + 1, cursor.Y);
}
VA_END();
return;
}
@@ -1033,6 +1034,7 @@ VA_DECL(const char *, fmt)
/*VARARGS1*/
void nttty_error
VA_DECL(const char *, s)
{
char buf[BUFSZ];
VA_START(s);
VA_INIT(s, const char *);
@@ -1041,9 +1043,9 @@ VA_DECL(const char *, s)
end_screen();
buf[0] = '\n';
(void) vsprintf(&buf[1], s, VA_ARGS);
VA_END();
msmsg(buf);
really_move_cursor();
VA_END();
exit(EXIT_FAILURE);
}

View File

@@ -138,6 +138,7 @@ load_keyboard_handler()
*/
void msmsg
VA_DECL(const char *, fmt)
{
VA_START(fmt);
VA_INIT(fmt, const char *);
VA_END();
@@ -147,6 +148,7 @@ VA_DECL(const char *, fmt)
/*VARARGS1*/
void nttty_error
VA_DECL(const char *, s)
{
VA_START(s);
VA_INIT(s, const char *);
VA_END();

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 winnt.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.25 $ */
/* NetHack 3.6 winnt.c $NHDT-Date: 1431737068 2015/05/16 00:44:28 $ $NHDT-Branch: master $:$NHDT-Revision: 1.26 $ */
/* Copyright (c) NetHack PC Development Team 1993, 1994 */
/* NetHack may be freely redistributed. See license for details. */
@@ -197,6 +197,7 @@ return &szFullPath[0];
/*VARARGS1*/
void error
VA_DECL(const char *, s)
{
char buf[BUFSZ];
VA_START(s);
VA_INIT(s, const char *);