wpp: Add error management callbacks.
This commit is contained in:
parent
28fb6a24b1
commit
29af4f9fa8
|
@ -22,6 +22,14 @@
|
|||
#define __WINE_WPP_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 */
|
||||
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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
|
|
Loading…
Reference in New Issue