diff options
-rw-r--r-- | src/reader.c | 3 | ||||
-rw-r--r-- | src/serd_internal.h | 24 | ||||
-rw-r--r-- | src/world.c | 49 | ||||
-rw-r--r-- | src/world.h | 16 | ||||
-rw-r--r-- | src/writer.c | 7 |
5 files changed, 69 insertions, 30 deletions
diff --git a/src/reader.c b/src/reader.c index c2c20b82..83f13e8c 100644 --- a/src/reader.c +++ b/src/reader.c @@ -8,6 +8,7 @@ #include "serd_internal.h" #include "stack.h" #include "system.h" +#include "world.h" #include "serd/stream.h" #include "serd/uri.h" @@ -28,7 +29,7 @@ r_err(SerdReader* const reader, const SerdStatus st, const char* const fmt, ...) va_start(args, fmt); const Cursor* const cur = &reader->source.cur; const SerdError e = {st, cur->filename, cur->line, cur->col, fmt, &args}; - serd_error(reader->world, &e); + serd_world_error(reader->world, &e); va_end(args); return st; } diff --git a/src/serd_internal.h b/src/serd_internal.h index 0c9d4609..49a1cd93 100644 --- a/src/serd_internal.h +++ b/src/serd_internal.h @@ -4,13 +4,6 @@ #ifndef SERD_SRC_SERD_INTERNAL_H #define SERD_SRC_SERD_INTERNAL_H -#include "world.h" - -#include "serd/error.h" -#include "serd/world.h" - -#include <stdio.h> - #define NS_XSD "http://www.w3.org/2001/XMLSchema#" #define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" @@ -20,21 +13,4 @@ # define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif -/* Error reporting */ - -static inline void -serd_error(const SerdWorld* world, const SerdError* e) -{ - if (world->error_func) { - world->error_func(world->error_handle, e); - } else { - if (e->filename) { - fprintf(stderr, "error: %s:%u:%u: ", e->filename, e->line, e->col); - } else { - fprintf(stderr, "error: "); - } - vfprintf(stderr, e->fmt, *e->args); - } -} - #endif // SERD_SRC_SERD_INTERNAL_H diff --git a/src/world.c b/src/world.c index eef70a14..4d2e175a 100644 --- a/src/world.c +++ b/src/world.c @@ -3,10 +3,55 @@ #include "world.h" -#include "serd/world.h" - +#include <stdarg.h> +#include <stdio.h> #include <stdlib.h> +SerdStatus +serd_world_error(const SerdWorld* const world, const SerdError* const e) +{ + if (world->error_func) { + world->error_func(world->error_handle, e); + } else { + if (e->filename) { + fprintf(stderr, "error: %s:%u:%u: ", e->filename, e->line, e->col); + } else { + fprintf(stderr, "error: "); + } + vfprintf(stderr, e->fmt, *e->args); + } + return e->status; +} + +SerdStatus +serd_world_verrorf(const SerdWorld* const world, + const SerdStatus st, + const char* const fmt, + va_list args) +{ + va_list args_copy; + va_copy(args_copy, args); + + const SerdError e = {st, NULL, 0, 0, fmt, &args_copy}; + serd_world_error(world, &e); + va_end(args_copy); + return st; +} + +SerdStatus +serd_world_errorf(const SerdWorld* const world, + const SerdStatus st, + const char* const fmt, + ...) +{ + va_list args; // NOLINT(cppcoreguidelines-init-variables) + va_start(args, fmt); + const SerdError e = {st, NULL, 0, 0, fmt, &args}; + serd_world_error(world, &e); + va_end(args); + return st; +} + SerdWorld* serd_world_new(void) { diff --git a/src/world.h b/src/world.h index 39fdf5e0..8281bb5e 100644 --- a/src/world.h +++ b/src/world.h @@ -5,10 +5,26 @@ #define SERD_SRC_WORLD_H #include "serd/error.h" +#include "serd/status.h" +#include "serd/world.h" + +#include <stdarg.h> struct SerdWorldImpl { SerdErrorFunc error_func; void* error_handle; }; +SerdStatus +serd_world_error(const SerdWorld* world, const SerdError* e); + +SerdStatus +serd_world_errorf(const SerdWorld* world, SerdStatus st, const char* fmt, ...); + +SerdStatus +serd_world_verrorf(const SerdWorld* world, + SerdStatus st, + const char* fmt, + va_list args); + #endif // SERD_SRC_WORLD_H diff --git a/src/writer.c b/src/writer.c index f39363aa..9c076c11 100644 --- a/src/writer.c +++ b/src/writer.c @@ -10,11 +10,11 @@ #include "string_utils.h" #include "try.h" #include "uri_utils.h" +#include "world.h" #include "serd/attributes.h" #include "serd/buffer.h" #include "serd/env.h" -#include "serd/error.h" #include "serd/node.h" #include "serd/sink.h" #include "serd/statement.h" @@ -192,8 +192,9 @@ w_err(SerdWriter* writer, SerdStatus st, const char* fmt, ...) va_list args; // NOLINT(cppcoreguidelines-init-variables) va_start(args, fmt); - const SerdError e = {st, NULL, 0, 0, fmt, &args}; - serd_error(writer->world, &e); + + serd_world_verrorf(writer->world, st, fmt, args); + va_end(args); return st; } |