diff options
| author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2012-07-04 14:22:28 +0000 | 
|---|---|---|
| committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2012-07-04 14:22:28 +0000 | 
| commit | a1ba2d1ca3a1d6c9c36a79a196dd3ccb83ede353 (patch) | |
| tree | ae20718827f0ca6f869c0f7bdb777816d3bf5f3a /drill/error.c | |
Diffstat (limited to 'drill/error.c')
| -rw-r--r-- | drill/error.c | 115 | 
1 files changed, 115 insertions, 0 deletions
| diff --git a/drill/error.c b/drill/error.c new file mode 100644 index 000000000000..e67b7fca020a --- /dev/null +++ b/drill/error.c @@ -0,0 +1,115 @@ +/** + * error.c + * + * error reporting routines + * basicly wrappers around printf + * + * (c) 2005 NLnet Labs + * + * See the file LICENSE for the license + * + */ + +#include "drill.h" +#include <ldns/ldns.h> + +static void +warning_va_list(const char *fmt, va_list args) +{ +        fprintf(stderr, "Warning: "); +        vfprintf(stderr, fmt, args); +        fprintf(stderr, "\n"); +} + +void +warning(const char *fmt, ...) +{ +	va_list args; +	va_start(args, fmt); +	warning_va_list(fmt, args); +	va_end(args); +} + +static void +error_va_list(const char *fmt, va_list args) +{ +        fprintf(stderr, "Error: "); +        vfprintf(stderr, fmt, args); +        fprintf(stderr, "\n"); +} + +void +error(const char *fmt, ...) +{ +	va_list args; +	va_start(args, fmt); +	error_va_list(fmt, args); +	va_end(args); +	exit(EXIT_FAILURE); +} + +static void +verbose_va_list(const char *fmt, va_list args) +{ +        vfprintf(stdout, fmt, args); +        fprintf(stdout, "\n"); +} + +/* print stuff */ +void +mesg(const char *fmt, ...) +{ +	va_list args; +	if (verbosity == -1) { +		return; +	} +	fprintf(stdout, ";; "); +	va_start(args, fmt); +	verbose_va_list(fmt, args); +	va_end(args); +} + +/* print stuff when in verbose mode (1) */ +void +verbose(const char *fmt, ...) +{ +	va_list args; +	if (verbosity < 1) { +		return; +	} + +	va_start(args, fmt); +	verbose_va_list(fmt, args); +	va_end(args); +} + +/* print stuff when in vverbose mode (2) */ +void +vverbose(const char *fmt, ...) +{ +	va_list args; +	if (verbosity < 2) { +		return; +	} + +	va_start(args, fmt); +	verbose_va_list(fmt, args); +	va_end(args); +} + +static void +debug_va_list(const char *fmt, va_list args) +{ +        vfprintf(stderr, fmt, args); +        fprintf(stderr, "\n"); +} + +void +debug(const char *fmt, ...) +{ +	va_list args; +	fprintf(stderr, "[DEBUG] "); +	va_start(args, fmt); +	debug_va_list(fmt, args); +	va_end(args); +} | 
