From 02a41f39b216ca43056fc2e8183351c077b5dd9c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 5 Jul 2012 17:35:14 +0000 Subject: 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 --- serd/serd.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'serd') 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 #include #include #include @@ -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; /** @@ -215,6 +219,18 @@ typedef struct { size_t len; /**< Length of chunk in bytes */ } 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. @@ -512,6 +528,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. @@ -663,6 +688,18 @@ serd_reader_new(SerdSyntax syntax, SerdStatementSink statement_sink, 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. */ @@ -825,6 +862,18 @@ SERD_API 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. */ -- cgit v1.2.1