diff options
-rw-r--r-- | include/serd/serd.h | 44 | ||||
-rw-r--r-- | src/env.c | 2 | ||||
-rw-r--r-- | src/n3.c | 12 | ||||
-rw-r--r-- | src/reader.c | 26 | ||||
-rw-r--r-- | src/reader.h | 10 | ||||
-rw-r--r-- | src/serd_internal.h | 6 | ||||
-rw-r--r-- | src/serdi.c | 8 | ||||
-rw-r--r-- | src/writer.c | 8 | ||||
-rw-r--r-- | test/test_reader_writer.c | 8 |
9 files changed, 62 insertions, 62 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h index c7ff1358..3486cc95 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -523,37 +523,37 @@ typedef struct { } SerdError; /** - Sink (callback) for errors. + Callback function for errors. @param handle Handle for user data. @param error Error description. */ -typedef SerdStatus (*SerdErrorSink)(void* SERD_NULLABLE handle, +typedef SerdStatus (*SerdErrorFunc)(void* SERD_NULLABLE handle, const SerdError* SERD_NONNULL error); /** - Sink (callback) for base URI changes. + Sink function for base URI changes. Called whenever the base URI of the serialisation changes. */ -typedef SerdStatus (*SerdBaseSink)(void* SERD_NULLABLE handle, +typedef SerdStatus (*SerdBaseFunc)(void* SERD_NULLABLE handle, const SerdNode* SERD_NONNULL uri); /** - Sink (callback) for namespace definitions. + Sink function for namespace definitions. Called whenever a prefix is defined in the serialisation. */ -typedef SerdStatus (*SerdPrefixSink)(void* SERD_NULLABLE handle, +typedef SerdStatus (*SerdPrefixFunc)(void* SERD_NULLABLE handle, const SerdNode* SERD_NONNULL name, const SerdNode* SERD_NONNULL uri); /** - Sink (callback) for statements. + Sink function for statements. Called for every RDF statement in the serialisation. */ -typedef SerdStatus (*SerdStatementSink)( +typedef SerdStatus (*SerdStatementFunc)( void* SERD_NULLABLE handle, SerdStatementFlags flags, const SerdNode* SERD_NULLABLE graph, @@ -564,13 +564,13 @@ typedef SerdStatus (*SerdStatementSink)( const SerdNode* SERD_NULLABLE object_lang); /** - Sink (callback) for anonymous node end markers. + Sink function for anonymous node end markers. - This is called to indicate that the anonymous node with the given - `value` will no longer be referred to by any future statements - (i.e. the anonymous serialisation of the node is finished). + This is called to indicate that the anonymous node with the given `value` + will no longer be referred to by any future statements (so the anonymous + node is finished). */ -typedef SerdStatus (*SerdEndSink)(void* SERD_NULLABLE handle, +typedef SerdStatus (*SerdEndFunc)(void* SERD_NULLABLE handle, const SerdNode* SERD_NONNULL node); /** @@ -649,7 +649,7 @@ serd_env_expand_node(const SerdEnv* SERD_NULLABLE env, /// Call `func` for each prefix defined in `env` SERD_API void serd_env_foreach(const SerdEnv* SERD_NONNULL env, - SerdPrefixSink SERD_NONNULL func, + SerdPrefixFunc SERD_NONNULL func, void* SERD_NULLABLE handle); /** @@ -666,10 +666,10 @@ SERD_API SerdReader* SERD_ALLOCATED serd_reader_new(SerdSyntax syntax, void* SERD_NULLABLE handle, void (*SERD_NULLABLE free_handle)(void* SERD_NULLABLE), - SerdBaseSink SERD_NULLABLE base_sink, - SerdPrefixSink SERD_NULLABLE prefix_sink, - SerdStatementSink SERD_NULLABLE statement_sink, - SerdEndSink SERD_NULLABLE end_sink); + SerdBaseFunc SERD_NULLABLE base_func, + SerdPrefixFunc SERD_NULLABLE prefix_func, + SerdStatementFunc SERD_NULLABLE statement_func, + SerdEndFunc SERD_NULLABLE end_func); /** Enable or disable strict parsing. @@ -684,12 +684,12 @@ serd_reader_set_strict(SerdReader* SERD_NONNULL reader, bool strict); /** Set a function to be called when errors occur during reading. - The `error_sink` will be called with `handle` as its first argument. If + The `error_func` will be called with `handle` as its first argument. If no error function is set, errors are printed to stderr in GCC style. */ SERD_API void serd_reader_set_error_sink(SerdReader* SERD_NONNULL reader, - SerdErrorSink SERD_NULLABLE error_sink, + SerdErrorFunc SERD_NULLABLE error_func, void* SERD_NULLABLE error_handle); /// Return the `handle` passed to serd_reader_new() @@ -887,12 +887,12 @@ serd_buffer_sink_finish(SerdBuffer* SERD_NONNULL stream); /** Set a function to be called when errors occur during writing. - The `error_sink` will be called with `handle` as its first argument. If + The `error_func` will be called with `handle` as its first argument. If no error function is set, errors are printed to stderr. */ SERD_API void serd_writer_set_error_sink(SerdWriter* SERD_NONNULL writer, - SerdErrorSink SERD_NONNULL error_sink, + SerdErrorFunc SERD_NONNULL error_func, void* SERD_NULLABLE error_handle); /** @@ -252,7 +252,7 @@ serd_env_expand_node(const SerdEnv* const env, const SerdNode* const node) void serd_env_foreach(const SerdEnv* const env, - const SerdPrefixSink func, + const SerdPrefixFunc func, void* const handle) { for (size_t i = 0; i < env->n_prefixes; ++i) { @@ -1094,8 +1094,8 @@ read_anon(SerdReader* const reader, } read_ws_star(reader); - if (reader->end_sink) { - reader->end_sink(reader->handle, deref(reader, *dest)); + if (reader->end_func) { + reader->end_func(reader->handle, deref(reader, *dest)); } *ctx.flags = old_flags; @@ -1447,8 +1447,8 @@ read_base(SerdReader* const reader, const bool sparql, const bool token) Ref uri = 0; TRY(st, read_IRIREF(reader, &uri)); - if (reader->base_sink) { - TRY(st, reader->base_sink(reader->handle, deref(reader, uri))); + if (reader->base_func) { + TRY(st, reader->base_func(reader->handle, deref(reader, uri))); } pop_node(reader, uri); @@ -1485,8 +1485,8 @@ read_prefixID(SerdReader* const reader, const bool sparql, const bool token) Ref uri = 0; TRY(st, read_IRIREF(reader, &uri)); - if (reader->prefix_sink) { - st = reader->prefix_sink( + if (reader->prefix_func) { + st = reader->prefix_func( reader->handle, deref(reader, name), deref(reader, uri)); } diff --git a/src/reader.c b/src/reader.c index 8bd80d37..8a376b28 100644 --- a/src/reader.c +++ b/src/reader.c @@ -23,7 +23,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->error_sink, reader->error_handle, &e); + serd_error(reader->error_func, reader->error_handle, &e); va_end(args); return st; } @@ -145,9 +145,9 @@ emit_statement(SerdReader* const reader, graph = &reader->default_graph; } - const SerdStatus st = !reader->statement_sink + const SerdStatus st = !reader->statement_func ? SERD_SUCCESS - : reader->statement_sink(reader->handle, + : reader->statement_func(reader->handle, *ctx.flags, graph, deref(reader, ctx.subject), @@ -171,18 +171,18 @@ SerdReader* serd_reader_new(const SerdSyntax syntax, void* const handle, void (*const free_handle)(void*), - const SerdBaseSink base_sink, - const SerdPrefixSink prefix_sink, - const SerdStatementSink statement_sink, - const SerdEndSink end_sink) + const SerdBaseFunc base_func, + const SerdPrefixFunc prefix_func, + const SerdStatementFunc statement_func, + const SerdEndFunc end_func) { SerdReader* me = (SerdReader*)calloc(1, sizeof(SerdReader)); me->handle = handle; me->free_handle = free_handle; - me->base_sink = base_sink; - me->prefix_sink = prefix_sink; - me->statement_sink = statement_sink; - me->end_sink = end_sink; + me->base_func = base_func; + me->prefix_func = prefix_func; + me->statement_func = statement_func; + me->end_func = end_func; me->default_graph = SERD_NODE_NULL; me->stack = serd_stack_new(SERD_PAGE_SIZE); me->syntax = syntax; @@ -204,10 +204,10 @@ serd_reader_set_strict(SerdReader* const reader, const bool strict) void serd_reader_set_error_sink(SerdReader* const reader, - const SerdErrorSink error_sink, + const SerdErrorFunc error_func, void* const error_handle) { - reader->error_sink = error_sink; + reader->error_func = error_func; reader->error_handle = error_handle; } diff --git a/src/reader.h b/src/reader.h index ce2d1a59..c0bf3765 100644 --- a/src/reader.h +++ b/src/reader.h @@ -40,11 +40,11 @@ typedef struct { struct SerdReaderImpl { void* handle; void (*free_handle)(void* ptr); - SerdBaseSink base_sink; - SerdPrefixSink prefix_sink; - SerdStatementSink statement_sink; - SerdEndSink end_sink; - SerdErrorSink error_sink; + SerdBaseFunc base_func; + SerdPrefixFunc prefix_func; + SerdStatementFunc statement_func; + SerdEndFunc end_func; + SerdErrorFunc error_func; void* error_handle; Ref rdf_first; Ref rdf_rest; diff --git a/src/serd_internal.h b/src/serd_internal.h index 388c12ec..7fcae691 100644 --- a/src/serd_internal.h +++ b/src/serd_internal.h @@ -20,10 +20,10 @@ /* Error reporting */ static inline void -serd_error(SerdErrorSink error_sink, void* handle, const SerdError* e) +serd_error(SerdErrorFunc error_func, void* handle, const SerdError* e) { - if (error_sink) { - error_sink(handle, e); + if (error_func) { + error_func(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 0a7cfc56..421e5df8 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -334,10 +334,10 @@ main(int argc, char** argv) serd_reader_new(input_syntax, writer, NULL, - (SerdBaseSink)serd_writer_set_base_uri, - (SerdPrefixSink)serd_writer_set_prefix, - (SerdStatementSink)serd_writer_write_statement, - (SerdEndSink)serd_writer_end_anon); + (SerdBaseFunc)serd_writer_set_base_uri, + (SerdPrefixFunc)serd_writer_set_prefix, + (SerdStatementFunc)serd_writer_write_statement, + (SerdEndFunc)serd_writer_end_anon); serd_reader_set_strict(reader, !lax); if (quiet) { diff --git a/src/writer.c b/src/writer.c index e8225a41..6bc69c78 100644 --- a/src/writer.c +++ b/src/writer.c @@ -122,7 +122,7 @@ struct SerdWriterImpl { SerdURIView base_uri; SerdStack anon_stack; SerdByteSink byte_sink; - SerdErrorSink error_sink; + SerdErrorFunc error_func; void* error_handle; WriteContext context; char* bprefix; @@ -179,7 +179,7 @@ w_err(SerdWriter* writer, SerdStatus st, const char* fmt, ...) va_list args; // NOLINT(cppcoreguidelines-init-variables) va_start(args, fmt); const SerdError e = {st, "", 0, 0, fmt, &args}; - serd_error(writer->error_sink, writer->error_handle, &e); + serd_error(writer->error_func, writer->error_handle, &e); va_end(args); return st; } @@ -1144,10 +1144,10 @@ serd_writer_new(SerdSyntax syntax, void serd_writer_set_error_sink(SerdWriter* writer, - SerdErrorSink error_sink, + SerdErrorFunc error_func, void* error_handle) { - writer->error_sink = error_sink; + writer->error_func = error_func; writer->error_handle = error_handle; } diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 6c759d8d..d6752d4b 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -415,10 +415,10 @@ test_write_errors(void) serd_reader_new(SERD_TRIG, writer, NULL, - (SerdBaseSink)serd_writer_set_base_uri, - (SerdPrefixSink)serd_writer_set_prefix, - (SerdStatementSink)serd_writer_write_statement, - (SerdEndSink)serd_writer_end_anon); + (SerdBaseFunc)serd_writer_set_base_uri, + (SerdPrefixFunc)serd_writer_set_prefix, + (SerdStatementFunc)serd_writer_write_statement, + (SerdEndFunc)serd_writer_end_anon); serd_reader_set_error_sink(reader, quiet_error_sink, NULL); serd_writer_set_error_sink(writer, quiet_error_sink, NULL); |