aboutsummaryrefslogtreecommitdiffstats
path: root/src/serdi.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-20 19:44:06 +0000
committerDavid Robillard <d@drobilla.net>2011-01-20 19:44:06 +0000
commit3433e155c739f6a081209ea7422b9fdc7f87a555 (patch)
tree1d193a947ecbac65c3aefc38e00b4d73f5d01146 /src/serdi.c
parent57683c8352e4a545171f28047617df88a6d4c917 (diff)
downloadserd-3433e155c739f6a081209ea7422b9fdc7f87a555.tar.gz
serd-3433e155c739f6a081209ea7422b9fdc7f87a555.tar.bz2
serd-3433e155c739f6a081209ea7422b9fdc7f87a555.zip
Add writer API.
git-svn-id: http://svn.drobilla.net/serd/trunk@14 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/serdi.c')
-rw-r--r--src/serdi.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/serdi.c b/src/serdi.c
index 13fdb2af..abac1010 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -22,7 +22,7 @@
#include "serd/serd.h"
typedef struct {
- FILE* out_fd;
+ SerdWriter writer;
SerdNamespaces ns;
SerdString* base_uri_str;
SerdURI base_uri;
@@ -61,8 +61,9 @@ event_base(void* handle,
// Replace the old base URI
serd_string_free(state->base_uri_str);
- state->base_uri_str = base_uri_str;
- state->base_uri = base_uri;
+ state->base_uri_str = base_uri_str;
+ state->base_uri = base_uri;
+ serd_writer_set_base_uri(state->writer, &base_uri);
return true;
}
@@ -105,17 +106,12 @@ event_statement(void* handle,
const SerdString* object_lang)
{
State* const state = (State*)handle;
- FILE* const fd = state->out_fd;
- serd_write_node(fd, &state->base_uri, state->ns,
- subject_type, subject, NULL, NULL);
- fwrite(" ", 1, 1, fd);
- serd_write_node(fd, &state->base_uri, state->ns,
- predicate_type, predicate, NULL, NULL);
- fwrite(" ", 1, 1, fd);
- serd_write_node(fd, &state->base_uri, state->ns,
- object_type, object, object_datatype, object_lang);
- fwrite(" .\n", 1, 3, fd);
- return true;
+ return serd_writer_write_statement(
+ state->writer,
+ graph,
+ subject, subject_type,
+ predicate, predicate_type,
+ object, object_type, object_datatype, object_lang);
}
int
@@ -146,7 +142,11 @@ main(int argc, char** argv)
return 1;
}
- State state = { out_fd, serd_namespaces_new(), serd_string_new(base_uri_str), base_uri };
+ SerdNamespaces ns = serd_namespaces_new();
+ State state = { serd_writer_new(SERD_NTRIPLES, ns, out_fd, &base_uri),
+ ns,
+ serd_string_new(base_uri_str),
+ base_uri };
SerdReader reader = serd_reader_new(
SERD_TURTLE, &state, event_base, event_prefix, event_statement);
@@ -155,6 +155,7 @@ main(int argc, char** argv)
serd_reader_free(reader);
fclose(in_fd);
serd_namespaces_free(state.ns);
+ serd_writer_free(state.writer);
serd_string_free(state.base_uri_str);
if (success) {