Commit 29af4f9f authored by Matteo Bruni's avatar Matteo Bruni Committed by Alexandre Julliard

wpp: Add error management callbacks.

parent 28fb6a24
...@@ -22,6 +22,14 @@ ...@@ -22,6 +22,14 @@
#define __WINE_WPP_H #define __WINE_WPP_H
#include <stdio.h> #include <stdio.h>
#include <stdarg.h>
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 */ /* Return value == 0 means successful execution */
extern int wpp_add_define( const char *name, const char *value ); extern int wpp_add_define( const char *name, const char *value );
...@@ -33,5 +41,6 @@ extern int wpp_add_include_path( const char *path ); ...@@ -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 char *wpp_find_include( const char *name, const char *parent_name );
extern int wpp_parse( const char *input, FILE *output ); 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 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 */ #endif /* __WINE_WPP_H */
...@@ -674,13 +674,32 @@ end: ...@@ -674,13 +674,32 @@ end:
fprintf(stderr, "\n"); 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, ...) int ppy_error(const char *s, ...)
{ {
va_list ap; va_list ap;
va_start(ap, s); 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); va_end(ap);
exit(1); pp_status.state = 1;
return 1; return 1;
} }
...@@ -688,7 +707,7 @@ int ppy_warning(const char *s, ...) ...@@ -688,7 +707,7 @@ int ppy_warning(const char *s, ...)
{ {
va_list ap; va_list ap;
va_start(ap, s); 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); va_end(ap);
return 0; return 0;
} }
......
...@@ -230,3 +230,8 @@ int wpp_parse_temp( const char *input, const char *output_base, char **output_na ...@@ -230,3 +230,8 @@ int wpp_parse_temp( const char *input, const char *output_base, char **output_na
fclose( output ); fclose( output );
return ret; return ret;
} }
void wpp_set_callbacks( const struct wpp_callbacks *callbacks )
{
wpp_callbacks = callbacks;
}
...@@ -218,6 +218,8 @@ int pp_get_if_depth(void); ...@@ -218,6 +218,8 @@ int pp_get_if_depth(void);
#define __attribute__(x) /*nothing*/ #define __attribute__(x) /*nothing*/
#endif #endif
extern const struct wpp_callbacks *wpp_callbacks;
int ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2))); int ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
int ppy_warning(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))); void pp_internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment