aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-14 17:32:01 +0200
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:58 +0100
commitb81636681210b56caa0b9ad2d84118c8f355a186 (patch)
tree27d90d11c4e0370bb5e47bce3431e249e856a6c4 /src
parentd459c6044e3bfdacded8d21c49315cf447e22d3e (diff)
downloadserd-b81636681210b56caa0b9ad2d84118c8f355a186.tar.gz
serd-b81636681210b56caa0b9ad2d84118c8f355a186.tar.bz2
serd-b81636681210b56caa0b9ad2d84118c8f355a186.zip
Add empty syntax type for suppressing output
Diffstat (limited to 'src')
-rw-r--r--src/serdi.c11
-rw-r--r--src/syntax.c9
-rw-r--r--src/writer.c11
3 files changed, 21 insertions, 10 deletions
diff --git a/src/serdi.c b/src/serdi.c
index 9eaf5eb4..c707f42d 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -27,6 +27,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#define SERDI_ERROR(msg) fprintf(stderr, "serdi: " msg)
#define SERDI_ERRORF(fmt, ...) fprintf(stderr, "serdi: " fmt, __VA_ARGS__)
@@ -87,14 +88,15 @@ main(int argc, char** argv)
}
SerdNode* base = NULL;
- SerdSyntax input_syntax = (SerdSyntax)0;
- SerdSyntax output_syntax = (SerdSyntax)0;
+ SerdSyntax input_syntax = SERD_SYNTAX_EMPTY;
+ SerdSyntax output_syntax = SERD_SYNTAX_EMPTY;
SerdReaderFlags reader_flags = 0;
SerdWriterFlags writer_flags = 0;
bool from_stdin = false;
bool bulk_read = true;
bool bulk_write = false;
bool no_inline = false;
+ bool osyntax_set = false;
bool use_model = false;
bool quiet = false;
size_t stack_size = 4194304;
@@ -158,8 +160,11 @@ main(int argc, char** argv)
}
stack_size = (size_t)size;
} else if (argv[a][1] == 'o') {
+ osyntax_set = true;
if (++a == argc) {
return missing_arg(argv[0], 'o');
+ } else if (!strcmp(argv[a], "empty")) {
+ output_syntax = SERD_SYNTAX_EMPTY;
} else if (!(output_syntax = serd_syntax_by_name(argv[a]))) {
return print_usage(argv[0], true);
}
@@ -202,7 +207,7 @@ main(int argc, char** argv)
}
const bool input_has_graphs = serd_syntax_has_graphs(input_syntax);
- if (!output_syntax) {
+ if (!output_syntax && !osyntax_set) {
output_syntax = input_has_graphs ? SERD_NQUADS : SERD_NTRIPLES;
}
diff --git a/src/syntax.c b/src/syntax.c
index 8f091a1d..98fcefbc 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -32,7 +32,7 @@ static const Syntax syntaxes[] = {
{"ntriples", ".nt", SERD_NTRIPLES},
{"nquads", ".nq", SERD_NQUADS},
{"trig", ".trig", SERD_TRIG},
- {NULL, NULL, (SerdSyntax)0},
+ {NULL, NULL, SERD_SYNTAX_EMPTY},
};
SerdSyntax
@@ -43,7 +43,7 @@ serd_syntax_by_name(const char* const name)
return s->syntax;
}
}
- return (SerdSyntax)0;
+ return SERD_SYNTAX_EMPTY;
}
SerdSyntax
@@ -52,12 +52,13 @@ serd_guess_syntax(const char* const filename)
const char* ext = strrchr(filename, '.');
if (ext) {
for (const Syntax* s = syntaxes; s->name; ++s) {
- if (!serd_strncasecmp(s->extension, ext, strlen(ext))) {
+ if (s->extension &&
+ !serd_strncasecmp(s->extension, ext, strlen(ext))) {
return s->syntax;
}
}
}
- return (SerdSyntax)0;
+ return SERD_SYNTAX_EMPTY;
}
bool
diff --git a/src/writer.c b/src/writer.c
index cd6b8437..4f41b303 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -733,6 +733,8 @@ write_curie(SerdWriter* const writer,
if (is_inline_start(writer, field, flags)) {
TRY(st, esink(" ;", 2, writer));
}
+ case SERD_SYNTAX_EMPTY:
+ break;
}
return st;
}
@@ -831,6 +833,10 @@ serd_writer_write_statement(SerdWriter* writer,
assert(!((flags & SERD_ANON_S) && (flags & SERD_LIST_S)));
assert(!((flags & SERD_ANON_O) && (flags & SERD_LIST_O)));
+ if (writer->syntax == SERD_SYNTAX_EMPTY) {
+ return SERD_SUCCESS;
+ }
+
const SerdNode* const subject = serd_statement_subject(statement);
const SerdNode* const predicate = serd_statement_predicate(statement);
const SerdNode* const object = serd_statement_object(statement);
@@ -969,10 +975,9 @@ serd_writer_write_statement(SerdWriter* writer,
}
SERD_WARN_UNUSED_RESULT static SerdStatus
-serd_writer_end_anon(SerdWriter* writer,
- const SerdNode* node)
+serd_writer_end_anon(SerdWriter* writer, const SerdNode* node)
{
- if (writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS) {
+ if (writer->syntax != SERD_TURTLE && writer->syntax != SERD_TRIG) {
return SERD_SUCCESS;
} else if (serd_stack_is_empty(&writer->anon_stack)) {
return SERD_LOG_ERROR(writer->world, SERD_ERR_UNKNOWN,