aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-03-31 14:20:03 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:07 -0500
commit09bf03fd6e522d6e421fed85d010057f87486544 (patch)
tree837adc1381f0e19e7cbab246be81de5fb6f1bf50 /src
parent2f490c80f9623ac2deaeb37a29fc98d01eb20e7e (diff)
downloadserd-09bf03fd6e522d6e421fed85d010057f87486544.tar.gz
serd-09bf03fd6e522d6e421fed85d010057f87486544.tar.bz2
serd-09bf03fd6e522d6e421fed85d010057f87486544.zip
Add empty syntax type for suppressing output
Diffstat (limited to 'src')
-rw-r--r--src/serdi.c16
-rw-r--r--src/syntax.c8
-rw-r--r--src/writer.c6
3 files changed, 19 insertions, 11 deletions
diff --git a/src/serdi.c b/src/serdi.c
index 75599ac7..8a4a52cf 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -65,7 +65,7 @@ print_usage(const char* const name, const bool error)
" -i SYNTAX Input syntax: turtle/ntriples/trig/nquads.\n"
" -k BYTES Parser stack size.\n"
" -l Lax (non-strict) parsing.\n"
- " -o SYNTAX Output syntax: turtle/ntriples/nquads.\n"
+ " -o SYNTAX Output syntax: empty/turtle/ntriples/nquads.\n"
" -p PREFIX Add PREFIX to blank node IDs.\n"
" -q Suppress all output except data.\n"
" -r ROOT_URI Keep relative URIs within ROOT_URI.\n"
@@ -100,13 +100,14 @@ main(int argc, char** argv)
{
const char* const prog = argv[0];
- SerdSyntax input_syntax = (SerdSyntax)0;
- SerdSyntax output_syntax = (SerdSyntax)0;
+ SerdSyntax input_syntax = SERD_SYNTAX_EMPTY;
+ SerdSyntax output_syntax = SERD_SYNTAX_EMPTY;
SerdWriterFlags writer_flags = 0;
bool from_string = false;
bool from_stdin = false;
bool bulk_read = true;
bool lax = false;
+ bool osyntax_set = false;
bool quiet = false;
size_t stack_size = 1048576U;
const char* add_prefix = NULL;
@@ -182,12 +183,15 @@ main(int argc, char** argv)
stack_size = (size_t)size;
break;
} else if (opt == 'o') {
+ osyntax_set = true;
if (argv[a][o + 1] || ++a == argc) {
return missing_arg(prog, 'o');
}
- if (!(output_syntax = serd_syntax_by_name(argv[a]))) {
- return print_usage(prog, true);
+ 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);
}
break;
} else if (opt == 'p') {
@@ -228,7 +232,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 1599df08..d75865b1 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -19,7 +19,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
@@ -33,7 +33,7 @@ serd_syntax_by_name(const char* const name)
}
}
}
- return (SerdSyntax)0;
+ return SERD_SYNTAX_EMPTY;
}
SerdSyntax
@@ -43,12 +43,12 @@ serd_guess_syntax(const char* const filename)
if (ext && ext[1]) {
const size_t ext_len = strlen(ext);
for (const Syntax* s = syntaxes; s->name; ++s) {
- if (!serd_strncasecmp(s->extension, ext, ext_len)) {
+ if (s->extension && !serd_strncasecmp(s->extension, ext, ext_len)) {
return s->syntax;
}
}
}
- return (SerdSyntax)0;
+ return SERD_SYNTAX_EMPTY;
}
bool
diff --git a/src/writer.c b/src/writer.c
index 5603e9ca..a1d91ff8 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -1003,6 +1003,10 @@ serd_writer_write_statement(SerdWriter* const writer,
assert(!((flags & SERD_ANON_O) && (flags & SERD_LIST_O)));
assert(!((flags & SERD_EMPTY_O) && (flags & SERD_LIST_O)));
+ if (writer->syntax == SERD_SYNTAX_EMPTY) {
+ return SERD_SUCCESS;
+ }
+
SerdStatus st = SERD_SUCCESS;
const SerdNode* const subject = serd_statement_subject(statement);
const SerdNode* const predicate = serd_statement_predicate(statement);
@@ -1149,7 +1153,7 @@ serd_writer_end_anon(SerdWriter* writer, const SerdNode* node)
{
SerdStatus st = SERD_SUCCESS;
- if (writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS) {
+ if (writer->syntax != SERD_TURTLE && writer->syntax != SERD_TRIG) {
return SERD_SUCCESS;
}