From 4b512a68903953e1372c3ad3b982eed72a7db681 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 23 Dec 2011 02:43:36 +0000 Subject: Add serd_file_sink for the common case of writing to a FILE* stream. git-svn-id: http://svn.drobilla.net/serd/trunk@262 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- ChangeLog | 1 + serd/serd.h | 10 ++++++++++ src/serdi.c | 9 +-------- src/writer.c | 9 +++++++++ wscript | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5b489eae..72177335 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ serd (UNRELEASED) unstable; urgency=low other tools fail to parse. * Add serd_strtod(), serd_node_new_decimal(), and serd_node_new_integer() for locale-independent numeric node parsing/serialising. + * Add serd_file_sink for the common case of writing to a FILE* stream. -- David Robillard (UNRELEASED) diff --git a/serd/serd.h b/serd/serd.h index eebfa113..3e84c302 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -659,6 +659,16 @@ SERD_API void serd_writer_free(SerdWriter* writer); +/** + A convenience sink function for writing to a FILE*. + + This function can be used as a SerdSink when writing to a FILE*. The + associated @c stream parameter must be a FILE* opened for writing. +*/ +SERD_API +size_t +serd_file_sink(const void* buf, size_t len, void* stream); + /** Set a prefix to be removed from matching blank node identifiers. */ diff --git a/src/serdi.c b/src/serdi.c index 14fe3275..7a3ef301 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -56,13 +56,6 @@ print_usage(const char* name, bool error) return error ? 1 : 0; } -static size_t -file_sink(const void* buf, size_t len, void* stream) -{ - FILE* file = (FILE*)stream; - return fwrite(buf, 1, len, file); -} - bool set_syntax(SerdSyntax* syntax, const char* name) { @@ -202,7 +195,7 @@ main(int argc, char** argv) } SerdWriter* writer = serd_writer_new( - output_syntax, output_style, env, &base_uri, file_sink, out_fd); + output_syntax, output_style, env, &base_uri, serd_file_sink, out_fd); if (chop_prefix) { serd_writer_chop_blank_prefix(writer, chop_prefix); diff --git a/src/writer.c b/src/writer.c index cee0455f..b9d80ce7 100644 --- a/src/writer.c +++ b/src/writer.c @@ -606,3 +606,12 @@ serd_writer_free(SerdWriter* writer) } free(writer); } + +SERD_API +size_t +serd_file_sink(const void* buf, size_t len, void* stream) +{ + FILE* file = (FILE*)stream; + return fwrite(buf, 1, len, file); +} + diff --git a/wscript b/wscript index 1ee9ec83..c0387672 100644 --- a/wscript +++ b/wscript @@ -10,7 +10,7 @@ from waflib.extras import autowaf as autowaf import waflib.Logs as Logs, waflib.Options as Options # Version of this package (even if built as a child) -SERD_VERSION = '0.7.0' +SERD_VERSION = '0.8.0' SERD_MAJOR_VERSION = '0' # Library version (UNIX style major, minor, micro) -- cgit v1.2.1