[6/6] wpp: Add error management callbacks

Matteo Bruni matteo.mystral at gmail.com
Thu Sep 10 10:41:44 CDT 2009


-------------- next part --------------
From b13e2446562407b0a50773ba0abe1762c9324ccc Mon Sep 17 00:00:00 2001
From: Matteo Bruni <matteo.mystral at gmail.com>
Date: Mon, 7 Sep 2009 02:37:51 +0200
Subject: wpp: Add error management callbacks

---
 include/wine/wpp.h     |    8 ++++++++
 libs/wpp/preproc.c     |   31 ++++++++++++++++++++++++-------
 libs/wpp/wpp.c         |    5 +++++
 libs/wpp/wpp_private.h |    2 ++
 4 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/include/wine/wpp.h b/include/wine/wpp.h
index 525db81..51d6cf1 100644
--- a/include/wine/wpp.h
+++ b/include/wine/wpp.h
@@ -52,4 +52,12 @@ struct wpp_io_callback {
 
 void wpp_set_io_callback( struct wpp_io_callback *callback );
 
+struct wpp_error_callback {
+    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 );
+    void (*internal_error)( const char *file, int line, const char *msg, va_list ap );
+};
+
+void wpp_set_error_callback( struct wpp_error_callback *callback );
+
 #endif  /* __WINE_WPP_H */
diff --git a/libs/wpp/preproc.c b/libs/wpp/preproc.c
index 2eb055d..ad21f29 100644
--- a/libs/wpp/preproc.c
+++ b/libs/wpp/preproc.c
@@ -680,6 +680,8 @@ int pp_get_if_depth(void)
 	return if_stack_idx;
 }
 
+struct wpp_error_callback *err_callback;
+
 /* #define WANT_NEAR_INDICATION */
 
 static void generic_msg(const char *s, const char *t, const char *n, va_list ap)
@@ -709,9 +711,15 @@ int ppy_error(const char *s, ...)
 {
 	va_list ap;
 	va_start(ap, s);
-	generic_msg(s, "Error", ppy_text, ap);
+	if(err_callback)
+		err_callback->error(pp_status.input, pp_status.line_number, pp_status.char_number, ppy_text, s, ap);
+	else
+	{
+		generic_msg(s, "Error", ppy_text, ap);
+		exit(1);
+	}
 	va_end(ap);
-	exit(1);
+	pp_status.state = 1;
 	return 1;
 }
 
@@ -719,7 +727,10 @@ int ppy_warning(const char *s, ...)
 {
 	va_list ap;
 	va_start(ap, s);
-	generic_msg(s, "Warning", ppy_text, ap);
+	if(err_callback)
+		err_callback->warning(pp_status.input, pp_status.line_number, pp_status.char_number, ppy_text, s, ap);
+	else
+		generic_msg(s, "Warning", ppy_text, ap);
 	va_end(ap);
 	return 0;
 }
@@ -728,9 +739,15 @@ void pp_internal_error(const char *file, int line, const char *s, ...)
 {
 	va_list ap;
 	va_start(ap, s);
-	fprintf(stderr, "Internal error (please report) %s %d: ", file, line);
-	vfprintf(stderr, s, ap);
-	fprintf(stderr, "\n");
+	if(err_callback)
+		err_callback->internal_error(file, line, s, ap);
+	else
+	{
+		fprintf(stderr, "Internal error (please report) %s %d: ", file, line);
+		vfprintf(stderr, s, ap);
+		fprintf(stderr, "\n");
+		exit(3);
+	}
 	va_end(ap);
-	exit(3);
+	pp_status.state = 1;
 }
diff --git a/libs/wpp/wpp.c b/libs/wpp/wpp.c
index befdda4..199da41 100644
--- a/libs/wpp/wpp.c
+++ b/libs/wpp/wpp.c
@@ -236,3 +236,8 @@ void wpp_set_io_callback( struct wpp_io_callback *callback )
     }
     else io_callback = callback;
 }
+
+void wpp_set_error_callback( struct wpp_error_callback *callback)
+{
+    err_callback = callback;
+}
diff --git a/libs/wpp/wpp_private.h b/libs/wpp/wpp_private.h
index 75f272b..c25c3d3 100644
--- a/libs/wpp/wpp_private.h
+++ b/libs/wpp/wpp_private.h
@@ -221,6 +221,8 @@ int pp_get_if_depth(void);
 #define __attribute__(x)  /*nothing*/
 #endif
 
+extern struct wpp_error_callback *err_callback;
+
 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)));
-- 
1.6.3.3


More information about the wine-patches mailing list