mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-27 06:10:06 +08:00
Add error_func and error_opaque getters to libtcc
This commit is contained in:
parent
944c4003bd
commit
491773ac58
13
libtcc.c
13
libtcc.c
@ -518,13 +518,22 @@ static void error1(TCCState *s1, int is_warning, const char *fmt, va_list ap)
|
||||
s1->nb_errors++;
|
||||
}
|
||||
|
||||
LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
|
||||
void (*error_func)(void *opaque, const char *msg))
|
||||
LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc error_func)
|
||||
{
|
||||
s->error_opaque = error_opaque;
|
||||
s->error_func = error_func;
|
||||
}
|
||||
|
||||
LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s)
|
||||
{
|
||||
return s->error_func;
|
||||
}
|
||||
|
||||
LIBTCCAPI void *tcc_get_error_opaque(TCCState *s)
|
||||
{
|
||||
return s->error_opaque;
|
||||
}
|
||||
|
||||
/* error without aborting current compilation */
|
||||
PUB_FUNC void tcc_error_noabort(const char *fmt, ...)
|
||||
{
|
||||
|
11
libtcc.h
11
libtcc.h
@ -13,6 +13,8 @@ struct TCCState;
|
||||
|
||||
typedef struct TCCState TCCState;
|
||||
|
||||
typedef void (*TCCErrorFunc)(void *opaque, const char *msg);
|
||||
|
||||
/* create a new TCC compilation context */
|
||||
LIBTCCAPI TCCState *tcc_new(void);
|
||||
|
||||
@ -23,8 +25,13 @@ LIBTCCAPI void tcc_delete(TCCState *s);
|
||||
LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
|
||||
|
||||
/* set error/warning display callback */
|
||||
LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
|
||||
void (*error_func)(void *opaque, const char *msg));
|
||||
LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc error_func);
|
||||
|
||||
/* return error/warning callback */
|
||||
LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s);
|
||||
|
||||
/* return error/warning callback opaque pointer */
|
||||
LIBTCCAPI void *tcc_get_error_opaque(TCCState *s);
|
||||
|
||||
/* set options as from command line (multiple supported) */
|
||||
LIBTCCAPI void tcc_set_options(TCCState *s, const char *str);
|
||||
|
@ -6,9 +6,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "libtcc.h"
|
||||
|
||||
void handle_error(void *opaque, const char *msg)
|
||||
{
|
||||
fprintf(opaque, "%s\n", msg);
|
||||
}
|
||||
|
||||
/* this function is called by the generated code */
|
||||
int add(int a, int b)
|
||||
{
|
||||
@ -53,6 +59,14 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
assert(tcc_get_error_func(s) == NULL);
|
||||
assert(tcc_get_error_opaque(s) == NULL);
|
||||
|
||||
tcc_set_error_func(s, stderr, handle_error);
|
||||
|
||||
assert(tcc_get_error_func(s) == handle_error);
|
||||
assert(tcc_get_error_opaque(s) == stderr);
|
||||
|
||||
/* if tcclib.h and libtcc1.a are not installed, where can we find them */
|
||||
for (i = 1; i < argc; ++i) {
|
||||
char *a = argv[i];
|
||||
|
Loading…
Reference in New Issue
Block a user