diff options
author | David Robillard <d@drobilla.net> | 2018-11-26 22:14:39 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-11-26 22:14:39 +0100 |
commit | af475a0c5ee0f61c3046caa0d9b563c07a14d995 (patch) | |
tree | 6b6db89aa95772dbd60cff12315d535f709d812a | |
parent | 2a1a2522b23122e2428019489df9ddb5b0ec30ea (diff) | |
download | serd-af475a0c5ee0f61c3046caa0d9b563c07a14d995.tar.gz serd-af475a0c5ee0f61c3046caa0d9b563c07a14d995.tar.bz2 serd-af475a0c5ee0f61c3046caa0d9b563c07a14d995.zip |
Rename SerdError to SerdMessage
Towards more general usage for all types of logging.
-rw-r--r-- | serd/serd.h | 28 | ||||
-rw-r--r-- | serd/serd.hpp | 4 | ||||
-rw-r--r-- | src/reader.c | 4 | ||||
-rw-r--r-- | src/reader.h | 2 | ||||
-rw-r--r-- | src/serdi.c | 4 | ||||
-rw-r--r-- | src/world.c | 32 | ||||
-rw-r--r-- | src/world.h | 6 | ||||
-rw-r--r-- | src/writer.c | 36 | ||||
-rw-r--r-- | tests/model_test.c | 18 |
9 files changed, 67 insertions, 67 deletions
diff --git a/serd/serd.h b/serd/serd.h index 29bff936..8aa22f7a 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -349,14 +349,14 @@ typedef struct { } SerdBuffer; /** - An error description. + A message description. */ typedef struct { - SerdStatus status; /**< Error code */ - const SerdCursor* cursor; /**< Origin of error, or NULL */ + SerdStatus status; /**< Status code */ + const SerdCursor* cursor; /**< Origin of message, or NULL */ const char* fmt; /**< Message format string (printf style) */ va_list* args; /**< Arguments for fmt */ -} SerdError; +} SerdMessage; /** A parsed URI. @@ -882,13 +882,13 @@ serd_node_free(SerdNode* node); */ /** - Sink (callback) for errors. + Sink (callback) for log messages. @param handle Handle for user data. - @param error Error description. + @param msg Message description. */ -typedef SerdStatus (*SerdErrorSink)(void* handle, - const SerdError* error); +typedef SerdStatus (*SerdMessageSink)(void* handle, + const SerdMessage* msg); /** Sink (callback) for base URI changes. @@ -960,16 +960,16 @@ const SerdNode* serd_world_get_blank(SerdWorld* world); /** - Set a function to be called when errors occur. + Set a function to be called with log messages (typically errors). - The `error_sink` will be called with `handle` as its first argument. If - no error function is set, errors are printed to stderr. + The `msg_sink` will be called with `handle` as its first argument. If + no sink is set, messages are printed to stderr. */ SERD_API void -serd_world_set_error_sink(SerdWorld* world, - SerdErrorSink error_sink, - void* handle); +serd_world_set_message_sink(SerdWorld* world, + SerdMessageSink msg_sink, + void* handle); /** @} diff --git a/serd/serd.hpp b/serd/serd.hpp index bb2d48a1..85cc4b6a 100644 --- a/serd/serd.hpp +++ b/serd/serd.hpp @@ -529,9 +529,9 @@ public: Node get_blank() { return Node(serd_world_get_blank(c_obj())); } - void set_error_sink(SerdErrorSink error_sink, void* handle) + void set_message_sink(SerdMessageSink msg_sink, void* handle) { - serd_world_set_error_sink(c_obj(), error_sink, handle); + serd_world_set_message_sink(c_obj(), msg_sink, handle); } // operator SerdWorld*() { return c_obj(); } diff --git a/src/reader.c b/src/reader.c index ace6ef7d..0b0c2360 100644 --- a/src/reader.c +++ b/src/reader.c @@ -37,8 +37,8 @@ r_err(SerdReader* reader, SerdStatus st, const char* fmt, ...) { va_list args; va_start(args, fmt); - const SerdError e = { st, &reader->source.cur, fmt, &args }; - serd_world_error(reader->world, &e); + const SerdMessage msg = { st, &reader->source.cur, fmt, &args }; + serd_world_error(reader->world, &msg); va_end(args); return st; } diff --git a/src/reader.h b/src/reader.h index 6e946f60..7e4c9756 100644 --- a/src/reader.h +++ b/src/reader.h @@ -46,7 +46,7 @@ typedef struct { struct SerdReaderImpl { SerdWorld* world; const SerdSink* sink; - SerdErrorSink error_sink; + SerdMessageSink msg_sink; void* error_handle; SerdNode* rdf_first; SerdNode* rdf_rest; diff --git a/src/serdi.c b/src/serdi.c index 2bef5e4a..1a07c3e8 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -74,7 +74,7 @@ missing_arg(const char* name, char opt) } static SerdStatus -quiet_error_sink(void* handle, const SerdError* e) +quiet_error_sink(void* handle, const SerdMessage* msg) { return SERD_SUCCESS; } @@ -228,7 +228,7 @@ main(int argc, char** argv) reader = serd_reader_new(world, input_syntax, sink, stack_size); serd_reader_set_strict(reader, !lax); if (quiet) { - serd_world_set_error_sink(world, quiet_error_sink, NULL); + serd_world_set_message_sink(world, quiet_error_sink, NULL); } SerdNode* root = serd_new_uri(root_uri); diff --git a/src/world.c b/src/world.c index 52ef1bce..01a86dc5 100644 --- a/src/world.c +++ b/src/world.c @@ -51,22 +51,22 @@ serd_world_fopen(SerdWorld* world, const char* path, const char* mode) } SerdStatus -serd_world_error(const SerdWorld* world, const SerdError* e) +serd_world_error(const SerdWorld* world, const SerdMessage* msg) { - if (world->error_sink) { - world->error_sink(world->error_handle, e); + if (world->msg_sink) { + world->msg_sink(world->msg_handle, msg); } else { fprintf(stderr, "error: "); - if (e->cursor) { + if (msg->cursor) { fprintf(stderr, "%s:%u:%u: ", - serd_node_get_string(e->cursor->file), - e->cursor->line, - e->cursor->col); + serd_node_get_string(msg->cursor->file), + msg->cursor->line, + msg->cursor->col); } - vfprintf(stderr, e->fmt, *e->args); + vfprintf(stderr, msg->fmt, *msg->args); } - return e->status; + return msg->status; } SerdStatus @@ -74,8 +74,8 @@ serd_world_errorf(const SerdWorld* world, SerdStatus st, const char* fmt, ...) { va_list args; va_start(args, fmt); - const SerdError e = { st, NULL, fmt, &args }; - serd_world_error(world, &e); + const SerdMessage msg = { st, NULL, fmt, &args }; + serd_world_error(world, &msg); va_end(args); return st; } @@ -119,10 +119,10 @@ serd_world_get_blank(SerdWorld* world) } void -serd_world_set_error_sink(SerdWorld* world, - SerdErrorSink error_sink, - void* handle) +serd_world_set_message_sink(SerdWorld* world, + SerdMessageSink msg_sink, + void* handle) { - world->error_sink = error_sink; - world->error_handle = handle; + world->msg_sink = msg_sink; + world->msg_handle = handle; } diff --git a/src/world.h b/src/world.h index 232d458f..724bd038 100644 --- a/src/world.h +++ b/src/world.h @@ -23,8 +23,8 @@ struct SerdWorldImpl { SerdNodes* nodes; - SerdErrorSink error_sink; - void* error_handle; + SerdMessageSink msg_sink; + void* msg_handle; uint32_t next_blank_id; SerdNode* blank_node; const SerdNode* rdf_first; @@ -38,7 +38,7 @@ struct SerdWorldImpl { FILE* serd_world_fopen(SerdWorld* world, const char* path, const char* mode); -SerdStatus serd_world_error(const SerdWorld* world, const SerdError* e); +SerdStatus serd_world_error(const SerdWorld* world, const SerdMessage* msg); SerdStatus serd_world_errorf(const SerdWorld* world, SerdStatus st, const char* fmt, ...); diff --git a/src/writer.c b/src/writer.c index 446bcb18..ab649ff4 100644 --- a/src/writer.c +++ b/src/writer.c @@ -99,24 +99,24 @@ static const SepRule rules[] = { }; struct SerdWriterImpl { - SerdWorld* world; - SerdSink iface; - SerdSyntax syntax; - SerdStyleFlags style; - SerdEnv* env; - SerdNode* root_node; - SerdURI root_uri; - SerdStack anon_stack; - SerdWriteFunc write_func; - void* stream; - SerdErrorSink error_sink; - void* error_handle; - WriteContext context; - unsigned indent; - char* bprefix; - size_t bprefix_len; - Sep last_sep; - bool empty; + SerdWorld* world; + SerdSink iface; + SerdSyntax syntax; + SerdStyleFlags style; + SerdEnv* env; + SerdNode* root_node; + SerdURI root_uri; + SerdStack anon_stack; + SerdWriteFunc write_func; + void* stream; + SerdMessageSink msg_sink; + void* msg_handle; + WriteContext context; + unsigned indent; + char* bprefix; + size_t bprefix_len; + Sep last_sep; + bool empty; }; typedef enum { diff --git a/tests/model_test.c b/tests/model_test.c index 395da7c3..fb242adf 100644 --- a/tests/model_test.c +++ b/tests/model_test.c @@ -325,18 +325,18 @@ test_read(SerdWorld* world, SerdModel* model, SerdNode* g, const size_t n_quads) } static SerdStatus -unexpected_error(void* handle, const SerdError* error) +unexpected_error(void* handle, const SerdMessage* msg) { fprintf(stderr, "error: "); - vfprintf(stderr, error->fmt, *error->args); + vfprintf(stderr, msg->fmt, *msg->args); return SERD_SUCCESS; } static SerdStatus -expected_error(void* handle, const SerdError* error) +expected_error(void* handle, const SerdMessage* msg) { fprintf(stderr, "expected: "); - vfprintf(stderr, error->fmt, *error->args); + vfprintf(stderr, msg->fmt, *msg->args); return SERD_SUCCESS; } @@ -380,7 +380,7 @@ test_add_null(SerdWorld* world, const size_t n_quads) { SerdModel* model = serd_model_new(world, SERD_SPO, false); - serd_world_set_error_sink(world, expected_error, NULL); + serd_world_set_message_sink(world, expected_error, NULL); if (!serd_model_add(model, 0, 0, 0, 0)) { FAIL("Added NULL tuple\n"); } else if (!serd_model_add(model, uri(world, 1), 0, 0, 0)) { @@ -400,7 +400,7 @@ test_add_with_iterator(SerdWorld* world, const size_t n_quads) { SerdModel* model = serd_model_new(world, SERD_SPO, false); - serd_world_set_error_sink(world, expected_error, NULL); + serd_world_set_message_sink(world, expected_error, NULL); if (serd_model_add(model, uri(world, 1), uri(world, 2), uri(world, 3), 0)) { FAIL("Failed to add statement\n"); } @@ -428,7 +428,7 @@ test_erase_with_iterator(SerdWorld* world, const size_t n_quads) { SerdModel* model = serd_model_new(world, SERD_SPO, false); - serd_world_set_error_sink(world, expected_error, NULL); + serd_world_set_message_sink(world, expected_error, NULL); if (serd_model_add(model, uri(world, 1), uri(world, 2), uri(world, 3), 0) || serd_model_add(model, uri(world, 4), uri(world, 5), uri(world, 6), 0)) { FAIL("Failed to add statements\n"); @@ -604,7 +604,7 @@ test_iter_comparison(SerdWorld* world, const size_t n_quads) { SerdModel* model = serd_model_new(world, SERD_SPO, false); - serd_world_set_error_sink(world, expected_error, NULL); + serd_world_set_message_sink(world, expected_error, NULL); if (serd_model_add(model, uri(world, 1), uri(world, 2), uri(world, 3), 0)) { FAIL("Failed to add statement\n"); } @@ -826,7 +826,7 @@ main(int argc, char** argv) SerdWorld* world = serd_world_new(); for (const TestFunc* t = tests; *t; ++t) { - serd_world_set_error_sink(world, unexpected_error, NULL); + serd_world_set_message_sink(world, unexpected_error, NULL); if ((*t)(world, n_quads)) { return EXIT_FAILURE; } |