diff options
author | David Robillard <d@drobilla.net> | 2018-12-13 08:46:06 -0800 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-12-13 08:46:06 -0800 |
commit | 073c84386c0bba0d9d5b9a1e5fb16b9af6d1b48a (patch) | |
tree | 48cd3d42426d73c8de8e5d1ed6ea8256cb8ad388 | |
parent | 7d663f4cd217b91809c6b279873520192383b614 (diff) | |
download | serd-073c84386c0bba0d9d5b9a1e5fb16b9af6d1b48a.tar.gz serd-073c84386c0bba0d9d5b9a1e5fb16b9af6d1b48a.tar.bz2 serd-073c84386c0bba0d9d5b9a1e5fb16b9af6d1b48a.zip |
WIP: Validator logserd1-world-log
-rw-r--r-- | src/serd_validate.c | 52 | ||||
-rw-r--r-- | src/world.c | 4 | ||||
-rw-r--r-- | src/world.h | 3 |
3 files changed, 39 insertions, 20 deletions
diff --git a/src/serd_validate.c b/src/serd_validate.c index f84344b1..168b9f03 100644 --- a/src/serd_validate.c +++ b/src/serd_validate.c @@ -45,14 +45,16 @@ #define CERRORF(fmt, ...) fprintf(stderr, "serd_validate: " fmt, __VA_ARGS__); #define VERRORF(model, statement, fmt, ...) \ - report(model, statement, "error", fmt, __VA_ARGS__); + report(model, statement, SERD_LOG_LEVEL_ERROR, fmt, __VA_ARGS__); -#define VERROR(model, statement, fmt) report(model, statement, "error", fmt); +#define VERROR(model, statement, fmt) \ + report(model, statement, SERD_LOG_LEVEL_ERROR, fmt); #define VNOTEF(model, statement, fmt, ...) \ - report(model, statement, "note", fmt, __VA_ARGS__); + report(model, statement, SERD_LOG_LEVEL_INFO, fmt, __VA_ARGS__); -#define VNOTE(model, statement, fmt) report(model, statement, "note", fmt); +#define VNOTE(model, statement, fmt) \ + report(model, statement, SERD_LOG_LEVEL_INFO, fmt); #define SERD_FOREACH(name, range) \ for (const SerdStatement* name = NULL; \ @@ -155,29 +157,43 @@ absolute_path(const char* path) #endif } +/* static const char* level_strings[] = { "note", "warning", "error" }; */ + static int report(const SerdModel* model, const SerdStatement* statement, - const char* type, + const SerdLogLevel level, const char* fmt, ...) { va_list args; va_start(args, fmt); - - serd_world_errorf(model->world, SERD_ERR_INVALID, "%s: ", type); - - const SerdCursor* cursor = serd_statement_get_cursor(statement); - if (cursor) { - fprintf(stderr, - "%s:%u:%u: ", - serd_node_get_string(serd_cursor_get_name(cursor)), - serd_cursor_get_line(cursor), - serd_cursor_get_column(cursor)); - } - - vfprintf(stderr, fmt, args); + const SerdMessage msg = { SERD_ERR_INVALID, + level, + serd_statement_get_cursor(statement), + fmt, + &args }; + serd_world_error(model->world, &msg); va_end(args); + /* return st; */ + + /* va_list args; */ + /* va_start(args, fmt); */ + + /* serd_world_errorf( */ + /* model->world, SERD_ERR_INVALID, "%s: ", level_strings[level]); */ + + /* const SerdCursor* cursor = serd_statement_get_cursor(statement); */ + /* if (cursor) { */ + /* fprintf(stderr, */ + /* "%s:%u:%u: ", */ + /* serd_node_get_string(serd_cursor_get_name(cursor)), */ + /* serd_cursor_get_line(cursor), */ + /* serd_cursor_get_column(cursor)); */ + /* } */ + + /* vfprintf(stderr, fmt, args); */ + /* va_end(args); */ ++n_errors; return 1; diff --git a/src/world.c b/src/world.c index 3140066e..03fb1d29 100644 --- a/src/world.c +++ b/src/world.c @@ -53,10 +53,12 @@ serd_world_fopen(SerdWorld* world, const char* path, const char* mode) SerdStatus serd_world_error(const SerdWorld* world, const SerdMessage* msg) { + static const char* level_strings[] = { "note", "warning", "error" }; + if (world->msg_sink) { world->msg_sink(world->msg_handle, msg); } else { - fprintf(stderr, "error: "); + fprintf(stderr, "%s: ", level_strings[msg->level]); if (msg->cursor) { fprintf(stderr, "%s:%u:%u: ", diff --git a/src/world.h b/src/world.h index 724bd038..23fcdf61 100644 --- a/src/world.h +++ b/src/world.h @@ -38,7 +38,8 @@ struct SerdWorldImpl { FILE* serd_world_fopen(SerdWorld* world, const char* path, const char* mode); -SerdStatus serd_world_error(const SerdWorld* world, const SerdMessage* msg); +// FIXME +SERD_API SerdStatus serd_world_error(const SerdWorld* world, const SerdMessage* msg); SerdStatus serd_world_errorf(const SerdWorld* world, SerdStatus st, const char* fmt, ...); |