From 86751029a3aef417b65e25dab11180411ddec628 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 4 Nov 2002 08:17:44 +0000 Subject: [PATCH] Add va_list versions of error and warning errwarn functions. Required adding stdarg to util.h. svn path=/trunk/yasm/; revision=798 --- libyasm/errwarn.c | 61 +++++++++++++++++++++++++++++++---------------- libyasm/errwarn.h | 5 ++++ libyasm/util.h | 1 + src/errwarn.c | 61 +++++++++++++++++++++++++++++++---------------- src/errwarn.h | 5 ++++ src/util.h | 1 + util.h | 1 + 7 files changed, 95 insertions(+), 40 deletions(-) diff --git a/libyasm/errwarn.c b/libyasm/errwarn.c index 6278a3e1..525baf13 100644 --- a/libyasm/errwarn.c +++ b/libyasm/errwarn.c @@ -219,24 +219,58 @@ errwarn_data_new(unsigned long lindex, int replace_parser_error) * for output_all() to print. */ static void -yasm_errwarn_error(unsigned long lindex, const char *fmt, ...) +yasm_errwarn_error_va(unsigned long lindex, const char *fmt, va_list va) { - va_list va; errwarn_data *we = errwarn_data_new(lindex, 1); we->type = WE_ERROR; - va_start(va, fmt); #ifdef HAVE_VSNPRINTF vsnprintf(we->msg, MSG_MAXSIZE, gettext(fmt), va); #else vsprintf(we->msg, gettext(fmt), va); #endif - va_end(va); error_count++; } +/* Register an warning at line lindex. Does not print the warning, only stores + * it for output_all() to print. + */ +static void +yasm_errwarn_warning_va(warn_class_num num, unsigned long lindex, + const char *fmt, va_list va) +{ + errwarn_data *we; + + if (!(warn_class_enabled & (1UL<type = WE_WARNING; + +#ifdef HAVE_VSNPRINTF + vsnprintf(we->msg, MSG_MAXSIZE, gettext(fmt), va); +#else + vsprintf(we->msg, gettext(fmt), va); +#endif + + warning_count++; +} + +/* Register an error at line lindex. Does not print the error, only stores it + * for output_all() to print. + */ +static void +yasm_errwarn_error(unsigned long lindex, const char *fmt, ...) +{ + va_list va; + va_start(va, fmt); + yasm_errwarn_error_va(lindex, fmt, va); + va_end(va); +} + /* Register an warning at line lindex. Does not print the warning, only stores * it for output_all() to print. */ @@ -245,24 +279,9 @@ yasm_errwarn_warning(warn_class_num num, unsigned long lindex, const char *fmt, ...) { va_list va; - errwarn_data *we; - - if (!(warn_class_enabled & (1UL<type = WE_WARNING; - va_start(va, fmt); -#ifdef HAVE_VSNPRINTF - vsnprintf(we->msg, MSG_MAXSIZE, gettext(fmt), va); -#else - vsprintf(we->msg, gettext(fmt), va); -#endif + yasm_errwarn_warning_va(num, lindex, fmt, va); va_end(va); - - warning_count++; } /* Parser error handler. Moves YACC-style error into our error handling @@ -336,6 +355,8 @@ errwarn yasm_errwarn = { yasm_errwarn_cleanup, yasm_errwarn_internal_error_, yasm_errwarn_fatal, + yasm_errwarn_error_va, + yasm_errwarn_warning_va, yasm_errwarn_error, yasm_errwarn_warning, yasm_errwarn_parser_error, diff --git a/libyasm/errwarn.h b/libyasm/errwarn.h index e3c3014e..cbc88dfc 100644 --- a/libyasm/errwarn.h +++ b/libyasm/errwarn.h @@ -58,6 +58,11 @@ struct errwarn { */ /*@exits@*/ void (*fatal) (fatal_num); + /* va_list versions of the below two functions */ + void (*error_va) (unsigned long lindex, const char *, va_list va); + void (*warning_va) (warn_class_num, unsigned long lindex, const char *, + va_list va); + void (*error) (unsigned long lindex, const char *, ...) /*@printflike@*/; void (*warning) (warn_class_num, unsigned long lindex, const char *, ...) /*@printflike@*/; diff --git a/libyasm/util.h b/libyasm/util.h index 89fa46c8..55068c86 100644 --- a/libyasm/util.h +++ b/libyasm/util.h @@ -47,6 +47,7 @@ # include # include # include +# include #endif #if defined(lint) diff --git a/src/errwarn.c b/src/errwarn.c index 6278a3e1..525baf13 100644 --- a/src/errwarn.c +++ b/src/errwarn.c @@ -219,24 +219,58 @@ errwarn_data_new(unsigned long lindex, int replace_parser_error) * for output_all() to print. */ static void -yasm_errwarn_error(unsigned long lindex, const char *fmt, ...) +yasm_errwarn_error_va(unsigned long lindex, const char *fmt, va_list va) { - va_list va; errwarn_data *we = errwarn_data_new(lindex, 1); we->type = WE_ERROR; - va_start(va, fmt); #ifdef HAVE_VSNPRINTF vsnprintf(we->msg, MSG_MAXSIZE, gettext(fmt), va); #else vsprintf(we->msg, gettext(fmt), va); #endif - va_end(va); error_count++; } +/* Register an warning at line lindex. Does not print the warning, only stores + * it for output_all() to print. + */ +static void +yasm_errwarn_warning_va(warn_class_num num, unsigned long lindex, + const char *fmt, va_list va) +{ + errwarn_data *we; + + if (!(warn_class_enabled & (1UL<type = WE_WARNING; + +#ifdef HAVE_VSNPRINTF + vsnprintf(we->msg, MSG_MAXSIZE, gettext(fmt), va); +#else + vsprintf(we->msg, gettext(fmt), va); +#endif + + warning_count++; +} + +/* Register an error at line lindex. Does not print the error, only stores it + * for output_all() to print. + */ +static void +yasm_errwarn_error(unsigned long lindex, const char *fmt, ...) +{ + va_list va; + va_start(va, fmt); + yasm_errwarn_error_va(lindex, fmt, va); + va_end(va); +} + /* Register an warning at line lindex. Does not print the warning, only stores * it for output_all() to print. */ @@ -245,24 +279,9 @@ yasm_errwarn_warning(warn_class_num num, unsigned long lindex, const char *fmt, ...) { va_list va; - errwarn_data *we; - - if (!(warn_class_enabled & (1UL<type = WE_WARNING; - va_start(va, fmt); -#ifdef HAVE_VSNPRINTF - vsnprintf(we->msg, MSG_MAXSIZE, gettext(fmt), va); -#else - vsprintf(we->msg, gettext(fmt), va); -#endif + yasm_errwarn_warning_va(num, lindex, fmt, va); va_end(va); - - warning_count++; } /* Parser error handler. Moves YACC-style error into our error handling @@ -336,6 +355,8 @@ errwarn yasm_errwarn = { yasm_errwarn_cleanup, yasm_errwarn_internal_error_, yasm_errwarn_fatal, + yasm_errwarn_error_va, + yasm_errwarn_warning_va, yasm_errwarn_error, yasm_errwarn_warning, yasm_errwarn_parser_error, diff --git a/src/errwarn.h b/src/errwarn.h index e3c3014e..cbc88dfc 100644 --- a/src/errwarn.h +++ b/src/errwarn.h @@ -58,6 +58,11 @@ struct errwarn { */ /*@exits@*/ void (*fatal) (fatal_num); + /* va_list versions of the below two functions */ + void (*error_va) (unsigned long lindex, const char *, va_list va); + void (*warning_va) (warn_class_num, unsigned long lindex, const char *, + va_list va); + void (*error) (unsigned long lindex, const char *, ...) /*@printflike@*/; void (*warning) (warn_class_num, unsigned long lindex, const char *, ...) /*@printflike@*/; diff --git a/src/util.h b/src/util.h index 89fa46c8..55068c86 100644 --- a/src/util.h +++ b/src/util.h @@ -47,6 +47,7 @@ # include # include # include +# include #endif #if defined(lint) diff --git a/util.h b/util.h index 89fa46c8..55068c86 100644 --- a/util.h +++ b/util.h @@ -47,6 +47,7 @@ # include # include # include +# include #endif #if defined(lint)