From: Eric S. Raymond Date: Sat, 24 Aug 2013 15:43:05 +0000 (-0400) Subject: Refactor topmsg functions to use a varags helper. X-Git-Tag: 1.11~31 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=8145c5da0492a9123ec31a13b1756aefb5fc4dc9;p=vms-empire.git Refactor topmsg functions to use a varags helper. --- diff --git a/extern.h b/extern.h index 3a704f6..81cea50 100644 --- a/extern.h +++ b/extern.h @@ -212,9 +212,9 @@ void set_prod (city_info_t *cityp); void pdebug (char *s, int a, int b, int c, int d, int e, int f, int g, int h); void topini (void); void clreol (int linep, int colp); -void topmsg (int linep, char *buf, int a, int b, int c, int d, int e, int f, int g, int h); -void topmsg1 (int linep, char *buf, char *a, int b, int c, int d, int e, int f, int g, int h); -void topmsg2 (int linep, char *buf, char *a, int b, int c, int d, char *e, char *f, int g, int h); +void topmsg (int linep, char *buf, ...); +void topmsg1 (int linep, char *buf, ...); +void topmsg2 (int linep, char *buf, ...); void prompt (char *buf, int a, int b, int c, int d, int e, int f, int g, int h); void prompt1 (char *buf, char *a, int b, int c, int d, int e, int f, int g, int h); void prompt2 (char *buf, char *a, int b, int c, int d, char *e, char *f, int g, int h); diff --git a/term.c b/term.c index 0e95db9..654c5a7 100644 --- a/term.c +++ b/term.c @@ -32,6 +32,7 @@ to read the lines. The new information is then displayed, and the #include #include #include +#include #include "empire.h" #include "extern.h" @@ -63,47 +64,47 @@ topini(void) Write a message to one of the top lines. */ -void -/* VARARGS2 */ -topmsg(int linep, char *buf, - int a, int b, int c, int d, int e, int f, int g, int h) +static void vtopmsg(int line, const char *fmt, va_list varglist) +/* assemble command in printf(3) style, print to a top line */ { - if (linep < 1 || linep > NUMTOPS) - linep = 1; - (void) move (linep - 1, 0); + char junkbuf[STRSIZE]; - if (buf != NULL && strlen (buf) > 0) - addprintf (buf, a, b, c, d, e, f, g, h); - - (void) clrtoeol (); + if (line < 1 || line > NUMTOPS) + line = 1; + (void) move (line - 1, 0); + vsprintf(junkbuf, fmt, varglist); + (void) addstr (junkbuf); + (void) clrtoeol(); } void -topmsg1(int linep, char *buf, char *a, - int b, int c, int d, int e, int f, int g, int h) +topmsg(int line, char *fmt, ...) { - if (linep < 1 || linep > NUMTOPS) - linep = 1; - (void) move (linep - 1, 0); - - if (buf != NULL && strlen (buf) > 0) - addprintf1 (buf, a, b, c, d, e, f, g, h); - - (void) clrtoeol (); + va_list ap; + + va_start(ap, fmt); + vtopmsg(line, fmt, ap); + va_end(ap); } void -topmsg2(int linep, char *buf, - char *a, int b, int c, int d, char *e, char *f, int g, int h) +topmsg1(int line, char *fmt, ...) { - if (linep < 1 || linep > NUMTOPS) - linep = 1; - (void) move (linep - 1, 0); - - if (buf != NULL && strlen (buf) > 0) - addprintf2 (buf, a, b, c, d, e, f, g, h); - - (void) clrtoeol (); + va_list ap; + + va_start(ap, fmt); + vtopmsg(line, fmt, ap); + va_end(ap); +} + +void +topmsg2(int line, char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vtopmsg(line, fmt, ap); + va_end(ap); } /*