diff options
author | David Robillard <d@drobilla.net> | 2020-08-15 18:22:12 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-08-15 22:53:00 +0200 |
commit | 7221394ae12f87533261ecaae725821fab6db40d (patch) | |
tree | b19440b7ce7552c1ecc94c9f02bc99ec128dc65e /src/reader.c | |
parent | 8cfbb485d367c861f20aa51261f4b41e78b144b6 (diff) | |
download | serd-7221394ae12f87533261ecaae725821fab6db40d.tar.gz serd-7221394ae12f87533261ecaae725821fab6db40d.tar.bz2 serd-7221394ae12f87533261ecaae725821fab6db40d.zip |
Clean up reader error handling
Diffstat (limited to 'src/reader.c')
-rw-r--r-- | src/reader.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/reader.c b/src/reader.c index 4d281af7..4710caac 100644 --- a/src/reader.c +++ b/src/reader.c @@ -134,29 +134,37 @@ pop_node(SerdReader* reader, Ref ref) return 0; } -bool +SerdStatus emit_statement(SerdReader* reader, ReadContext ctx, Ref o, Ref d, Ref l) { SerdNode* graph = deref(reader, ctx.graph); if (!graph && reader->default_graph.buf) { graph = &reader->default_graph; } - bool ret = !reader->statement_sink || - !reader->statement_sink( - reader->handle, *ctx.flags, graph, - deref(reader, ctx.subject), deref(reader, ctx.predicate), - deref(reader, o), deref(reader, d), deref(reader, l)); + + const SerdStatus st = + !reader->statement_sink + ? SERD_SUCCESS + : reader->statement_sink(reader->handle, + *ctx.flags, + graph, + deref(reader, ctx.subject), + deref(reader, ctx.predicate), + deref(reader, o), + deref(reader, d), + deref(reader, l)); + *ctx.flags &= SERD_ANON_CONT|SERD_LIST_CONT; // Preserve only cont flags - return ret; + return st; } -static bool +static SerdStatus read_statement(SerdReader* reader) { return read_n3_statement(reader); } -static bool +static SerdStatus read_doc(SerdReader* reader) { return ((reader->syntax == SERD_NQUADS) ? read_nquadsDoc(reader) @@ -322,15 +330,15 @@ serd_reader_start_source_stream(SerdReader* reader, static SerdStatus serd_reader_prepare(SerdReader* reader) { - reader->status = serd_byte_source_prepare(&reader->source); - if (reader->status == SERD_SUCCESS) { - reader->status = skip_bom(reader); - } else if (reader->status == SERD_FAILURE) { + SerdStatus st = serd_byte_source_prepare(&reader->source); + if (st == SERD_SUCCESS) { + st = skip_bom(reader); + } else if (st == SERD_FAILURE) { reader->source.eof = true; } else { - r_err(reader, reader->status, "read error: %s\n", strerror(errno)); + r_err(reader, st, "read error: %s\n", strerror(errno)); } - return reader->status; + return st; } SerdStatus @@ -348,7 +356,7 @@ serd_reader_read_chunk(SerdReader* reader) eat_byte_safe(reader, 0); } - return st ? st : read_statement(reader) ? SERD_SUCCESS : SERD_FAILURE; + return st ? st : read_statement(reader); } SerdStatus @@ -381,9 +389,9 @@ serd_reader_read_source(SerdReader* reader, if (st || (st = serd_reader_prepare(reader))) { serd_reader_end_stream(reader); return st; - } else if (!read_doc(reader)) { + } else if ((st = read_doc(reader))) { serd_reader_end_stream(reader); - return SERD_ERR_UNKNOWN; + return st; } return serd_reader_end_stream(reader); @@ -396,7 +404,7 @@ serd_reader_read_string(SerdReader* reader, const uint8_t* utf8) SerdStatus st = serd_reader_prepare(reader); if (!st) { - st = read_doc(reader) ? SERD_SUCCESS : SERD_ERR_UNKNOWN; + st = read_doc(reader); } serd_byte_source_close(&reader->source); |