aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--serd/serd.h38
-rw-r--r--src/reader.c6
-rw-r--r--src/reader.h2
-rw-r--r--src/serdi.c6
-rw-r--r--src/world.c32
-rw-r--r--src/world.h6
-rw-r--r--src/writer.c38
7 files changed, 70 insertions, 58 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 90ad210f..e9484ec9 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -279,14 +279,24 @@ typedef struct {
} SerdBuffer;
/**
- An error description.
+ Log message level.
+*/
+typedef enum {
+ SERD_LOG_LEVEL_INFO = 0, /**< Normal informative message */
+ SERD_LOG_LEVEL_WARNING = 1, /**< Warning */
+ SERD_LOG_LEVEL_ERROR = 2, /**< Error */
+} SerdLogLevel;
+
+/**
+ A message description.
*/
typedef struct {
- SerdStatus status; /**< Error code */
- const SerdCursor* cursor; /**< Origin of error, or NULL */
+ SerdStatus status; /**< Status code */
+ SerdLogLevel level; /**< Log level */
+ 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.
@@ -802,13 +812,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.
@@ -880,16 +890,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/src/reader.c b/src/reader.c
index dfa80f06..bc8edd52 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -40,8 +40,10 @@ 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, SERD_LOG_LEVEL_ERROR, &reader->source.cur, fmt, &args
+ };
+ serd_world_log(reader->world, &msg);
va_end(args);
return st;
}
diff --git a/src/reader.h b/src/reader.h
index 506aaff2..7794526b 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 22727c46..379ab1b9 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -76,10 +76,10 @@ 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)
{
(void)handle;
- (void)e;
+ (void)msg;
return SERD_SUCCESS;
}
@@ -219,7 +219,7 @@ main(int argc, char** argv)
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 21bce2f3..0bc4f4bc 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_log(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, SERD_LOG_LEVEL_ERROR, NULL, fmt, &args };
+ serd_world_log(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 9ac13a95..f4e7ee3e 100644
--- a/src/world.h
+++ b/src/world.h
@@ -24,8 +24,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;
@@ -39,7 +39,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_log(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 fd1dc043..09bffeef 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -101,24 +101,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 {
@@ -186,7 +186,7 @@ write_character(SerdWriter* writer, const uint8_t* utf8, size_t* size)
switch (*size) {
case 0:
serd_world_errorf(
- writer->world, SERD_ERR_BAD_ARG, "invalid UTF-8: %X\n", utf8[0]);
+ writer->world, SERD_ERR_BAD_ARG, "invalid UTF-8: %X\n", utf8[0]);
return sink(replacement_char, sizeof(replacement_char), writer);
case 1:
snprintf(escape, sizeof(escape), "\\u%04X", utf8[0]);