aboutsummaryrefslogtreecommitdiffstats
path: root/serd/serd.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-07-05 17:35:14 +0000
committerDavid Robillard <d@drobilla.net>2012-07-05 17:35:14 +0000
commit02a41f39b216ca43056fc2e8183351c077b5dd9c (patch)
tree1224e6ba637bc4879213786228a1b4d1e7516ea2 /serd/serd.h
parent1c7fb2461a581a501f62a7c72a444147da39787e (diff)
downloadserd-02a41f39b216ca43056fc2e8183351c077b5dd9c.tar.gz
serd-02a41f39b216ca43056fc2e8183351c077b5dd9c.tar.bz2
serd-02a41f39b216ca43056fc2e8183351c077b5dd9c.zip
Add error callback to reader and writer for custom error reporting.
Add -q option to serdi to suppress all non-data output, e.g. errors. Resolves #815. git-svn-id: http://svn.drobilla.net/serd/trunk@354 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'serd/serd.h')
-rw-r--r--serd/serd.h51
1 files changed, 50 insertions, 1 deletions
diff --git a/serd/serd.h b/serd/serd.h
index cc2365f4..1cd54df8 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -21,6 +21,7 @@
#ifndef SERD_SERD_H
#define SERD_SERD_H
+#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@@ -89,7 +90,10 @@ typedef enum {
SERD_ERR_UNKNOWN, /**< Unknown error */
SERD_ERR_BAD_SYNTAX, /**< Invalid syntax */
SERD_ERR_BAD_ARG, /**< Invalid argument */
- SERD_ERR_NOT_FOUND /**< Not found */
+ SERD_ERR_NOT_FOUND, /**< Not found */
+ SERD_ERR_ID_CLASH, /**< Encountered clashing blank node IDs */
+ SERD_ERR_BAD_CURIE, /**< Invalid CURIE (e.g. prefix does not exist) */
+ SERD_ERR_INTERNAL /**< Unexpected internal error (should not happen) */
} SerdStatus;
/**
@@ -216,6 +220,18 @@ typedef struct {
} SerdChunk;
/**
+ An error description.
+*/
+typedef struct {
+ SerdStatus status; /**< Error code */
+ const uint8_t* filename; /**< File where error was encountered, or NULL */
+ unsigned line; /**< Line where error was encountered, or 0 */
+ unsigned col; /**< Column where error was encountered */
+ const char* fmt; /**< Message format string (printf style) */
+ va_list* args; /**< Arguments for fmt */
+} SerdError;
+
+/**
A parsed URI.
This struct directly refers to chunks in other strings, it does not own any
@@ -513,6 +529,15 @@ serd_node_free(SerdNode* node);
*/
/**
+ Sink (callback) for errors.
+
+ @param handle Handle for user data.
+ @param error Error description.
+*/
+typedef SerdStatus (*SerdErrorSink)(void* handle,
+ const SerdError* error);
+
+/**
Sink (callback) for base URI changes.
Called whenever the base URI of the serialisation changes.
@@ -664,6 +689,18 @@ serd_reader_new(SerdSyntax syntax,
SerdEndSink end_sink);
/**
+ Set a function to be called when errors occur during reading.
+
+ The @p error_sink will be called with @p 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* reader,
+ SerdErrorSink error_sink,
+ void* handle);
+
+/**
Return the @c handle passed to @ref serd_reader_new.
*/
SERD_API
@@ -826,6 +863,18 @@ uint8_t*
serd_chunk_sink_finish(SerdChunk* stream);
/**
+ Set a function to be called when errors occur during writing.
+
+ The @p error_sink will be called with @p 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* writer,
+ SerdErrorSink error_sink,
+ void* handle);
+
+/**
Set a prefix to be removed from matching blank node identifiers.
*/
SERD_API