aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/reader.c14
-rw-r--r--src/reader.h3
-rw-r--r--src/serd_internal.h15
-rw-r--r--src/serdi.c14
-rw-r--r--src/world.c40
-rw-r--r--src/world.h27
-rw-r--r--src/writer.c18
7 files changed, 94 insertions, 37 deletions
diff --git a/src/reader.c b/src/reader.c
index 9a968145..98a46654 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -32,7 +32,7 @@ r_err(SerdReader* reader, SerdStatus st, const char* 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->error_sink, reader->error_handle, &e);
+ serd_error(reader->world, &e);
va_end(args);
return 0;
}
@@ -152,10 +152,11 @@ serd_reader_read_document(SerdReader* reader)
}
SerdReader*
-serd_reader_new(SerdSyntax syntax, const SerdSink* sink)
+serd_reader_new(SerdWorld* world, SerdSyntax syntax, const SerdSink* sink)
{
SerdReader* me = (SerdReader*)calloc(1, sizeof(SerdReader));
+ me->world = world;
me->sink = sink;
me->default_graph = NULL;
me->stack = serd_stack_new(SERD_PAGE_SIZE);
@@ -177,15 +178,6 @@ serd_reader_set_strict(SerdReader* reader, bool strict)
}
void
-serd_reader_set_error_sink(SerdReader* reader,
- SerdErrorSink error_sink,
- void* error_handle)
-{
- reader->error_sink = error_sink;
- reader->error_handle = error_handle;
-}
-
-void
serd_reader_free(SerdReader* reader)
{
pop_node(reader, reader->rdf_nil);
diff --git a/src/reader.h b/src/reader.h
index 85ceaf62..1d08f0e0 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -57,7 +57,8 @@ typedef struct {
} ReadContext;
struct SerdReaderImpl {
- const SerdSink* sink;
+ SerdWorld* world;
+ const SerdSink* sink;
SerdErrorSink error_sink;
void* error_handle;
Ref rdf_first;
diff --git a/src/serd_internal.h b/src/serd_internal.h
index e9985778..64b641ce 100644
--- a/src/serd_internal.h
+++ b/src/serd_internal.h
@@ -20,9 +20,14 @@
#define _POSIX_C_SOURCE 200809L /* for posix_memalign and posix_fadvise */
#include "serd_config.h"
+#include "world.h"
#include "serd/serd.h"
+#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO)
+# include <fcntl.h>
+#endif
+
#include <assert.h>
#include <ctype.h>
#include <errno.h>
@@ -30,10 +35,6 @@
#include <stdlib.h>
#include <string.h>
-#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO)
-# include <fcntl.h>
-#endif
-
#define NS_XSD "http://www.w3.org/2001/XMLSchema#"
#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
@@ -71,10 +72,10 @@ serd_bufalloc(size_t size)
}
static inline void
-serd_error(SerdErrorSink error_sink, void* handle, const SerdError* e)
+serd_error(const SerdWorld* world, const SerdError* e)
{
- if (error_sink) {
- error_sink(handle, e);
+ if (world->error_sink) {
+ world->error_sink(world->error_handle, e);
} else {
fprintf(stderr, "error: %s:%u:%u: ", e->filename, e->line, e->col);
vfprintf(stderr, e->fmt, *e->args);
diff --git a/src/serdi.c b/src/serdi.c
index b0e892f5..70badb52 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -267,8 +267,9 @@ main(int argc, char** argv)
base = serd_node_new_file_uri(input, NULL, &base_uri, true);
}
- FILE* out_fd = stdout;
- SerdEnv* env = serd_env_new(base);
+ FILE* out_fd = stdout;
+ SerdWorld* world = serd_world_new();
+ SerdEnv* env = serd_env_new(base);
int output_style = 0;
if (output_syntax == SERD_NTRIPLES || ascii) {
@@ -290,7 +291,8 @@ main(int argc, char** argv)
output_style |= SERD_STYLE_BULK;
}
- SerdWriter* writer = serd_writer_new(output_syntax,
+ SerdWriter* writer = serd_writer_new(world,
+ output_syntax,
(SerdStyle)output_style,
env,
&base_uri,
@@ -298,12 +300,11 @@ main(int argc, char** argv)
out_fd);
SerdReader* reader =
- serd_reader_new(input_syntax, serd_writer_get_sink(writer));
+ serd_reader_new(world, input_syntax, serd_writer_get_sink(writer));
serd_reader_set_strict(reader, !lax);
if (quiet) {
- serd_reader_set_error_sink(reader, quiet_error_sink, NULL);
- serd_writer_set_error_sink(writer, quiet_error_sink, NULL);
+ serd_world_set_error_sink(world, quiet_error_sink, NULL);
}
SerdNode* root = serd_node_new_string(SERD_URI, root_uri);
@@ -336,6 +337,7 @@ main(int argc, char** argv)
serd_writer_free(writer);
serd_env_free(env);
serd_node_free(base);
+ serd_world_free(world);
free(input_path);
if (from_file) {
diff --git a/src/world.c b/src/world.c
new file mode 100644
index 00000000..483a33af
--- /dev/null
+++ b/src/world.c
@@ -0,0 +1,40 @@
+/*
+ Copyright 2011-2020 David Robillard <http://drobilla.net>
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#include "world.h"
+
+#include <stdlib.h>
+
+SerdWorld*
+serd_world_new(void)
+{
+ return (SerdWorld*)calloc(1, sizeof(SerdWorld));
+}
+
+void
+serd_world_free(SerdWorld* world)
+{
+ free(world);
+}
+
+void
+serd_world_set_error_sink(SerdWorld* world,
+ SerdErrorSink error_sink,
+ void* handle)
+{
+ world->error_sink = error_sink;
+ world->error_handle = handle;
+}
diff --git a/src/world.h b/src/world.h
new file mode 100644
index 00000000..87479eab
--- /dev/null
+++ b/src/world.h
@@ -0,0 +1,27 @@
+/*
+ Copyright 2011-2020 David Robillard <http://drobilla.net>
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#ifndef SERD_WORLD_H
+#define SERD_WORLD_H
+
+#include "serd/serd.h"
+
+struct SerdWorldImpl {
+ SerdErrorSink error_sink;
+ void* error_handle;
+};
+
+#endif // SERD_WORLD_H
diff --git a/src/writer.c b/src/writer.c
index da26d9f6..bee4bf9a 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -93,6 +93,7 @@ static const SepRule rules[] = {
};
struct SerdWriterImpl {
+ SerdWorld* world;
SerdSink iface;
SerdSyntax syntax;
SerdStyle style;
@@ -147,8 +148,8 @@ w_err(SerdWriter* writer, SerdStatus st, const char* fmt, ...)
va_list args;
va_start(args, fmt);
- const SerdError e = { st, "", 0, 0, fmt, &args };
- serd_error(writer->error_sink, writer->error_handle, &e);
+ const SerdError e = { st, NULL, 0, 0, fmt, &args };
+ serd_error(writer->world, &e);
va_end(args);
}
@@ -879,7 +880,8 @@ serd_writer_finish(SerdWriter* writer)
}
SerdWriter*
-serd_writer_new(SerdSyntax syntax,
+serd_writer_new(SerdWorld* world,
+ SerdSyntax syntax,
SerdStyle style,
SerdEnv* env,
const SerdURI* base_uri,
@@ -888,6 +890,7 @@ serd_writer_new(SerdSyntax syntax,
{
const WriteContext context = WRITE_CONTEXT_NULL;
SerdWriter* writer = (SerdWriter*)calloc(1, sizeof(SerdWriter));
+ writer->world = world;
writer->syntax = syntax;
writer->style = style;
writer->env = env;
@@ -911,15 +914,6 @@ serd_writer_new(SerdSyntax syntax,
}
void
-serd_writer_set_error_sink(SerdWriter* writer,
- SerdErrorSink error_sink,
- void* error_handle)
-{
- writer->error_sink = error_sink;
- writer->error_handle = error_handle;
-}
-
-void
serd_writer_chop_blank_prefix(SerdWriter* writer,
const char* prefix)
{