aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-10 20:14:24 +0200
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:07 -0500
commita14effc37415540b7b8a1dc6238b350566f273e1 (patch)
tree5291df350a08771824718a108a81060546f1bc2b /src/world.c
parent6eb1fa15a06ab7de08e33add1540a45b83c5f0d8 (diff)
downloadserd-a14effc37415540b7b8a1dc6238b350566f273e1.tar.gz
serd-a14effc37415540b7b8a1dc6238b350566f273e1.tar.bz2
serd-a14effc37415540b7b8a1dc6238b350566f273e1.zip
Move error handling to world
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c49
1 files changed, 47 insertions, 2 deletions
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)
{