aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/serdi.c73
-rw-r--r--src/writer.c7
2 files changed, 21 insertions, 59 deletions
diff --git a/src/serdi.c b/src/serdi.c
index 0932348c..01e2e764 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -92,61 +92,24 @@ quiet_error_func(void* const handle, const SerdError* const e)
return SERD_SUCCESS;
}
-static SerdWriterFlags
-choose_style(const SerdSyntax input_syntax,
- const SerdSyntax output_syntax,
- const bool ascii,
- const bool bulk_write,
- const bool full_uris,
- const bool lax)
-{
- SerdWriterFlags writer_flags = 0U;
- if (output_syntax == SERD_NTRIPLES || ascii) {
- writer_flags |= SERD_WRITE_ASCII;
- } else if (output_syntax == SERD_TURTLE) {
- writer_flags |= SERD_WRITE_ABBREVIATED;
- if (!full_uris) {
- writer_flags |= SERD_WRITE_CURIED;
- }
- }
-
- if ((input_syntax == SERD_TURTLE || input_syntax == SERD_TRIG) ||
- (writer_flags & SERD_WRITE_CURIED)) {
- // Base URI may change and/or we're abbreviating URIs, so must resolve
- writer_flags |= SERD_WRITE_RESOLVED;
- }
-
- if (bulk_write) {
- writer_flags |= SERD_WRITE_BULK;
- }
-
- if (!lax) {
- writer_flags |= SERD_WRITE_STRICT;
- }
-
- return writer_flags;
-}
-
int
main(int argc, char** argv)
{
const char* const prog = argv[0];
- SerdSyntax input_syntax = (SerdSyntax)0;
- SerdSyntax output_syntax = (SerdSyntax)0;
- bool from_string = false;
- bool from_stdin = false;
- bool ascii = false;
- bool bulk_read = true;
- bool bulk_write = false;
- bool full_uris = false;
- bool lax = false;
- bool quiet = false;
- size_t stack_size = 1048576U;
- const char* add_prefix = NULL;
- const char* chop_prefix = NULL;
- const char* root_uri = NULL;
- int a = 1;
+ SerdSyntax input_syntax = (SerdSyntax)0;
+ SerdSyntax output_syntax = (SerdSyntax)0;
+ SerdWriterFlags writer_flags = SERD_WRITE_STRICT;
+ bool from_string = false;
+ bool from_stdin = false;
+ bool bulk_read = true;
+ bool lax = false;
+ bool quiet = false;
+ size_t stack_size = 1048576U;
+ const char* add_prefix = NULL;
+ const char* chop_prefix = NULL;
+ const char* root_uri = NULL;
+ int a = 1;
for (; a < argc && !from_string && argv[a][0] == '-'; ++a) {
if (argv[a][1] == '\0') {
from_stdin = true;
@@ -165,17 +128,18 @@ main(int argc, char** argv)
const char opt = argv[a][o];
if (opt == 'a') {
- ascii = true;
+ writer_flags |= SERD_WRITE_ASCII;
} else if (opt == 'b') {
- bulk_write = true;
+ writer_flags |= SERD_WRITE_BULK;
} else if (opt == 'e') {
bulk_read = false;
} else if (opt == 'f') {
- full_uris = true;
+ writer_flags |= (SERD_WRITE_UNQUALIFIED | SERD_WRITE_UNRESOLVED);
} else if (opt == 'h') {
return print_usage(prog, false);
} else if (opt == 'l') {
lax = true;
+ writer_flags &= ~(SerdWriterFlags)SERD_WRITE_STRICT;
} else if (opt == 'q') {
quiet = true;
} else if (opt == 'v') {
@@ -263,9 +227,6 @@ main(int argc, char** argv)
output_syntax = input_has_graphs ? SERD_NQUADS : SERD_NTRIPLES;
}
- const SerdWriterFlags writer_flags = choose_style(
- input_syntax, output_syntax, ascii, bulk_write, full_uris, lax);
-
SerdNode* base = NULL;
if (a < argc) { // Base URI given on command line
base = serd_new_uri(serd_string(argv[a]));
diff --git a/src/writer.c b/src/writer.c
index 376becf1..37263010 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -762,7 +762,7 @@ write_uri_node(SerdWriter* const writer,
return esink("()", 2, writer);
}
- if (has_scheme && (writer->flags & SERD_WRITE_CURIED) &&
+ if (has_scheme && !(writer->flags & SERD_WRITE_UNQUALIFIED) &&
serd_env_qualify(writer->env, node, &prefix, &suffix) &&
is_name(serd_node_string(prefix), serd_node_length(prefix)) &&
is_name(suffix.data, suffix.length)) {
@@ -782,7 +782,8 @@ write_uri_node(SerdWriter* const writer,
TRY(st, esink("<", 1, writer));
- if ((writer->flags & SERD_WRITE_RESOLVED) && serd_env_base_uri(writer->env)) {
+ if (!(writer->flags & SERD_WRITE_UNRESOLVED) &&
+ serd_env_base_uri(writer->env)) {
const SerdURIView base_uri = serd_env_base_uri_view(writer->env);
SerdURIView uri = serd_parse_uri(node_str);
SerdURIView abs_uri = serd_resolve_uri(uri, base_uri);
@@ -812,7 +813,7 @@ write_curie(SerdWriter* const writer, const SerdNode* const node)
// In fast-and-loose Turtle/TriG mode CURIEs are simply passed through
const bool fast =
- !(writer->flags & (SERD_WRITE_CURIED | SERD_WRITE_RESOLVED));
+ (writer->flags & (SERD_WRITE_UNQUALIFIED | SERD_WRITE_UNRESOLVED));
if (!supports_abbrev(writer) || !fast) {
if ((st = serd_env_expand(writer->env, node, &prefix, &suffix))) {