From 29af4f9fa833a1f73f50bf68a3b5c02759a85464 Mon Sep 17 00:00:00 2001 From: Matteo Bruni Date: Tue, 29 Sep 2009 12:34:17 +0200 Subject: [PATCH] wpp: Add error management callbacks. --- include/wine/wpp.h | 9 +++++++++ libs/wpp/preproc.c | 25 ++++++++++++++++++++++--- libs/wpp/wpp.c | 5 +++++ libs/wpp/wpp_private.h | 2 ++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/include/wine/wpp.h b/include/wine/wpp.h index 86575b16121..dd341bdee96 100644 --- a/include/wine/wpp.h +++ b/include/wine/wpp.h @@ -22,6 +22,14 @@ #define __WINE_WPP_H #include +#include + +struct wpp_callbacks +{ + /* Error callbacks */ + void (*error)( const char *file, int line, int col, const char *near, const char *msg, va_list ap ); + void (*warning)( const char *file, int line, int col, const char *near, const char *msg, va_list ap ); +}; /* Return value == 0 means successful execution */ extern int wpp_add_define( const char *name, const char *value ); @@ -33,5 +41,6 @@ extern int wpp_add_include_path( const char *path ); extern char *wpp_find_include( const char *name, const char *parent_name ); extern int wpp_parse( const char *input, FILE *output ); extern int wpp_parse_temp( const char *input, const char *output_base, char **output_name ); +extern void wpp_set_callbacks( const struct wpp_callbacks *callbacks ); #endif /* __WINE_WPP_H */ diff --git a/libs/wpp/preproc.c b/libs/wpp/preproc.c index cd46fc25e06..874e54cd244 100644 --- a/libs/wpp/preproc.c +++ b/libs/wpp/preproc.c @@ -674,13 +674,32 @@ end: fprintf(stderr, "\n"); } +static void wpp_default_error(const char *file, int line, int col, const char *near, const char *msg, va_list ap) +{ + generic_msg(msg, "Error", near, ap); + exit(1); +} + +static void wpp_default_warning(const char *file, int line, int col, const char *near, const char *msg, va_list ap) +{ + generic_msg(msg, "Warning", near, ap); +} + +static const struct wpp_callbacks default_callbacks = +{ + wpp_default_error, + wpp_default_warning, +}; + +const struct wpp_callbacks *wpp_callbacks = &default_callbacks; + int ppy_error(const char *s, ...) { va_list ap; va_start(ap, s); - generic_msg(s, "Error", ppy_text, ap); + wpp_callbacks->error(pp_status.input, pp_status.line_number, pp_status.char_number, ppy_text, s, ap); va_end(ap); - exit(1); + pp_status.state = 1; return 1; } @@ -688,7 +707,7 @@ int ppy_warning(const char *s, ...) { va_list ap; va_start(ap, s); - generic_msg(s, "Warning", ppy_text, ap); + wpp_callbacks->warning(pp_status.input, pp_status.line_number, pp_status.char_number, ppy_text, s, ap); va_end(ap); return 0; } diff --git a/libs/wpp/wpp.c b/libs/wpp/wpp.c index e3541fe880a..e6a1a831503 100644 --- a/libs/wpp/wpp.c +++ b/libs/wpp/wpp.c @@ -230,3 +230,8 @@ int wpp_parse_temp( const char *input, const char *output_base, char **output_na fclose( output ); return ret; } + +void wpp_set_callbacks( const struct wpp_callbacks *callbacks ) +{ + wpp_callbacks = callbacks; +} diff --git a/libs/wpp/wpp_private.h b/libs/wpp/wpp_private.h index c0b95a48fbe..e08221351bb 100644 --- a/libs/wpp/wpp_private.h +++ b/libs/wpp/wpp_private.h @@ -218,6 +218,8 @@ int pp_get_if_depth(void); #define __attribute__(x) /*nothing*/ #endif +extern const struct wpp_callbacks *wpp_callbacks; + int ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2))); int ppy_warning(const char *s, ...) __attribute__((format (printf, 1, 2))); void pp_internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4)));