Mercurial > hg > nnchat
changeset 99:0313fabd8049
Added varargs versions of some functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 17 Nov 2009 23:08:15 +0200 |
parents | b7c981e27b66 |
children | ed4067c10a8a |
files | th_util.c th_util.h |
diffstat | 2 files changed, 48 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/th_util.c Tue Nov 17 19:21:35 2009 +0200 +++ b/th_util.c Tue Nov 17 23:08:15 2009 +0200 @@ -48,44 +48,66 @@ /* Print formatted error, warning and information messages * TODO: Implement th_vfprintf() and friends? */ -void THERR(const char *pcFormat, ...) +void THERR_V(const char *fmt, va_list ap) +{ + assert(th_initialized == TRUE); + + fprintf(stderr, "%s: ", th_prog_name); + vfprintf(stderr, fmt, ap); +} + + +void THMSG_V(int level, const char *fmt, va_list ap) +{ + assert(th_initialized == TRUE); + + if (th_verbosityLevel >= level) { + fprintf(stderr, "%s: ", th_prog_name); + vfprintf(stderr, fmt, ap); + } +} + + +void THPRINT_V(int level, const char *fmt, va_list ap) +{ + assert(th_initialized == TRUE); + + if (th_verbosityLevel >= level) { + vfprintf(stderr, fmt, ap); + } +} + + +void THERR(const char *fmt, ...) { va_list ap; - assert(th_initialized); + assert(th_initialized == TRUE); - va_start(ap, pcFormat); - fprintf(stderr, "%s: ", th_prog_name); - vfprintf(stderr, pcFormat, ap); + va_start(ap, fmt); + THERR_V(fmt, ap); va_end(ap); } -void THMSG(int verbLevel, const char *pcFormat, ...) +void THMSG(int level, const char *fmt, ...) { va_list ap; - assert(th_initialized); + assert(th_initialized == TRUE); - /* Check if the current verbosity level is enough */ - if (th_verbosityLevel >= verbLevel) { - va_start(ap, pcFormat); - fprintf(stderr, "%s: ", th_prog_name); - vfprintf(stderr, pcFormat, ap); - va_end(ap); - } + va_start(ap, fmt); + THMSG_V(level, fmt, ap); + va_end(ap); } -void THPRINT(int verbLevel, const char *pcFormat, ...) +void THPRINT(int level, const char *fmt, ...) { va_list ap; - assert(th_initialized); + assert(th_initialized == TRUE); - /* Check if the current verbosity level is enough */ - if (th_verbosityLevel >= verbLevel) { - va_start(ap, pcFormat); - vfprintf(stderr, pcFormat, ap); - va_end(ap); - } + va_start(ap, fmt); + THPRINT_V(level, fmt, ap); + va_end(ap); }
--- a/th_util.h Tue Nov 17 19:21:35 2009 +0200 +++ b/th_util.h Tue Nov 17 23:08:15 2009 +0200 @@ -68,6 +68,10 @@ void THMSG(int, const char *, ...); void THPRINT(int, const char *, ...); +void THERR_V(const char *, va_list); +void THMSG_V(int, const char *, va_list); +void THPRINT_V(int, const char *, va_list); + void *th_malloc(size_t); void *th_calloc(size_t, size_t); void *th_realloc(void *, size_t);