aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/serdi.c17
-rw-r--r--src/syntax.c8
-rw-r--r--src/writer.c21
3 files changed, 25 insertions, 21 deletions
diff --git a/src/serdi.c b/src/serdi.c
index 155e570a..74b8cad4 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -31,6 +31,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__)
@@ -63,7 +64,7 @@ print_usage(const char* const name, const bool error)
fprintf(os, " -i SYNTAX Input syntax: turtle/ntriples/trig/nquads.\n");
fprintf(os, " -k BYTES Parser stack size.\n");
fprintf(os, " -l Lax (non-strict) parsing.\n");
- fprintf(os, " -o SYNTAX Output syntax: turtle/ntriples/nquads.\n");
+ fprintf(os, " -o SYNTAX Output syntax: empty/turtle/ntriples/nquads.\n");
fprintf(os, " -p PREFIX Add PREFIX to blank node IDs.\n");
fprintf(os, " -q Suppress all output except data.\n");
fprintf(os, " -r ROOT_URI Keep relative URIs within ROOT_URI.\n");
@@ -96,14 +97,15 @@ main(int argc, char** argv)
return print_usage(prog, true);
}
- 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 bulk_write = false;
bool lax = false;
+ bool osyntax_set = false;
bool quiet = false;
size_t stack_size = 4194304;
const char* add_prefix = NULL;
@@ -171,12 +173,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') {
@@ -217,7 +222,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 61814709..59453bca 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,12 @@ 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 cd6ce613..3e0faa1e 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -792,9 +792,8 @@ write_curie(SerdWriter* const writer, const SerdNode* const node)
SerdStringView prefix = {NULL, 0};
SerdStringView suffix = {NULL, 0};
SerdStatus st = SERD_SUCCESS;
- switch (writer->syntax) {
- case SERD_NTRIPLES:
- case SERD_NQUADS:
+
+ if (writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS) {
if ((st = serd_env_expand_in_place(writer->env, node, &prefix, &suffix))) {
serd_world_errorf(writer->world,
st,
@@ -802,18 +801,14 @@ write_curie(SerdWriter* const writer, const SerdNode* const node)
serd_node_string(node));
return st;
}
+
TRY(st, esink("<", 1, writer));
TRY(st, ewrite_uri(writer, prefix.buf, prefix.len));
TRY(st, ewrite_uri(writer, suffix.buf, suffix.len));
- TRY(st, esink(">", 1, writer));
- break;
- case SERD_TURTLE:
- case SERD_TRIG:
- TRY(st, write_lname(writer, serd_node_string(node), node->length));
- break;
+ return esink(">", 1, writer);
}
- return st;
+ return write_lname(writer, serd_node_string(node), node->length);
}
SERD_WARN_UNUSED_RESULT static SerdStatus
@@ -922,6 +917,10 @@ serd_writer_write_statement(SerdWriter* const 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;
+ }
+
SerdStatus st = SERD_SUCCESS;
const SerdNode* const subject = serd_statement_subject(statement);
const SerdNode* const predicate = serd_statement_predicate(statement);
@@ -1064,7 +1063,7 @@ serd_writer_write_statement(SerdWriter* const writer,
SERD_WARN_UNUSED_RESULT static SerdStatus
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;
}