aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-07-05 21:01:12 +0200
committerDavid Robillard <d@drobilla.net>2018-11-25 22:12:47 +0100
commit4e7bf77fd35a76ef6b3e97e6182c58698d86421f (patch)
tree0ed50145173d5161332104d0899ce8c994ef10b6
parentf591a377441dd4ac32c389bd4ef19def580ca267 (diff)
downloadserd-4e7bf77fd35a76ef6b3e97e6182c58698d86421f.tar.gz
serd-4e7bf77fd35a76ef6b3e97e6182c58698d86421f.tar.bz2
serd-4e7bf77fd35a76ef6b3e97e6182c58698d86421f.zip
Simplify writer style options
-rw-r--r--doc/serdi.14
-rw-r--r--serd/serd.h7
-rw-r--r--src/serdi.c25
-rw-r--r--src/writer.c4
-rw-r--r--wscript15
5 files changed, 16 insertions, 39 deletions
diff --git a/doc/serdi.1 b/doc/serdi.1
index 921de461..66d845c6 100644
--- a/doc/serdi.1
+++ b/doc/serdi.1
@@ -29,10 +29,6 @@ page of input has arrived. With this option serdi uses one page less memory,
but will likely be significantly slower.
.TP
-\fB\-f\fR
-Keep full URIs in input (don't qualify).
-
-.TP
\fB\-h\fR
Print the command line options.
diff --git a/serd/serd.h b/serd/serd.h
index cf079842..3b6fa3e3 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -304,11 +304,8 @@ typedef struct {
always ASCII).
*/
typedef enum {
- SERD_STYLE_ABBREVIATED = 1, /**< Abbreviate triples when possible. */
- SERD_STYLE_ASCII = 1 << 1, /**< Escape all non-ASCII characters. */
- SERD_STYLE_RESOLVED = 1 << 2, /**< Resolve URIs against base URI. */
- SERD_STYLE_CURIED = 1 << 3, /**< Shorten URIs into CURIEs. */
- SERD_STYLE_BULK = 1 << 4 /**< Write output in pages. */
+ SERD_STYLE_ASCII = 1 << 0, /**< Escape all non-ASCII characters. */
+ SERD_STYLE_BULK = 1 << 1 /**< Write output in pages. */
} SerdStyle;
/**
diff --git a/src/serdi.c b/src/serdi.c
index 0b9f46d5..13438725 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -51,7 +51,6 @@ print_usage(const char* name, bool error)
fprintf(os, " -b Fast bulk output for large serialisations.\n");
fprintf(os, " -c PREFIX Chop PREFIX from matching blank node IDs.\n");
fprintf(os, " -e Eat input one character at a time.\n");
- fprintf(os, " -f Keep full URIs in input (don't qualify).\n");
fprintf(os, " -h Display this help and exit.\n");
fprintf(os, " -i SYNTAX Input syntax: turtle/ntriples/trig/nquads.\n");
fprintf(os, " -k BYTES Parser stack size.\n");
@@ -92,7 +91,6 @@ main(int argc, char** argv)
bool ascii = false;
bool bulk_read = true;
bool bulk_write = false;
- bool full_uris = false;
bool lax = false;
bool quiet = false;
long stack_size = 4194304;
@@ -110,8 +108,6 @@ main(int argc, char** argv)
bulk_write = true;
} else if (argv[a][1] == 'e') {
bulk_read = false;
- } else if (argv[a][1] == 'f') {
- full_uris = true;
} else if (argv[a][1] == 'h') {
return print_usage(argv[0], false);
} else if (argv[a][1] == 'l') {
@@ -193,25 +189,8 @@ main(int argc, char** argv)
SerdWorld* world = serd_world_new();
SerdEnv* env = serd_env_new(base);
- SerdStyleFlags output_style = 0;
- if (output_syntax == SERD_NTRIPLES || ascii) {
- output_style |= SERD_STYLE_ASCII;
- } else if (output_syntax == SERD_TURTLE) {
- output_style |= SERD_STYLE_ABBREVIATED;
- if (!full_uris) {
- output_style |= SERD_STYLE_CURIED;
- }
- }
-
- if ((input_syntax == SERD_TURTLE || input_syntax == SERD_TRIG) ||
- (output_style & SERD_STYLE_CURIED)) {
- // Base URI may change and/or we're abbreviating URIs, so must resolve
- output_style |= SERD_STYLE_RESOLVED;
- }
-
- if (bulk_write) {
- output_style |= SERD_STYLE_BULK;
- }
+ const SerdStyleFlags output_style = ((ascii ? SERD_STYLE_ASCII : 0) |
+ (bulk_write ? SERD_STYLE_BULK : 0));
SerdWriter* writer = serd_writer_new(world,
output_syntax,
diff --git a/src/writer.c b/src/writer.c
index 2a886718..274e2b20 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -511,7 +511,7 @@ write_uri_node(SerdWriter* const writer,
return sink("a", 1, writer) == 1;
} else if (supports_abbrev(writer) && !strcmp(node_str, NS_RDF "nil")) {
return sink("()", 2, writer) == 2;
- } else if (has_scheme && (writer->style & SERD_STYLE_CURIED) &&
+ } else if (has_scheme && supports_abbrev(writer) &&
serd_env_qualify_in_place(writer->env, node, &prefix, &suffix) &&
is_name(suffix.buf, suffix.len)) {
write_uri_from_node(writer, prefix);
@@ -521,7 +521,7 @@ write_uri_node(SerdWriter* const writer,
}
write_sep(writer, SEP_URI_BEGIN);
- if (writer->style & SERD_STYLE_RESOLVED) {
+ if (serd_env_get_base_uri(writer->env)) {
const SerdURI* base_uri = serd_env_get_parsed_base_uri(writer->env);
SerdURI uri, abs_uri;
serd_uri_parse(node_str, &uri);
diff --git a/wscript b/wscript
index b552b62b..165a81a7 100644
--- a/wscript
+++ b/wscript
@@ -296,6 +296,11 @@ def check_output(out_filename, check_filename, subst_from='', subst_to=''):
return False
+def test_osyntax_options(osyntax):
+ if osyntax.lower() == 'ntriples' or osyntax.lower() == 'nquads':
+ return ' -a'
+ return ''
+
def test_thru(ctx, base, path, check_filename, flags, isyntax, osyntax,
options='', quiet=False):
in_filename = os.path.join(ctx.path.abspath(), path)
@@ -303,9 +308,9 @@ def test_thru(ctx, base, path, check_filename, flags, isyntax, osyntax,
command = ('serdi_static %s %s -i %s -o %s -p foo "%s" "%s" | '
'serdi_static %s -i %s -o %s -c foo - "%s" > %s') % (
- options, flags.ljust(5),
+ options + test_osyntax_options(isyntax), flags.ljust(5),
isyntax, isyntax, in_filename, base,
- options, isyntax, osyntax, base, out_filename)
+ options + test_osyntax_options(osyntax), isyntax, osyntax, base, out_filename)
if autowaf.run_test(ctx, APPNAME, command, 0, name=' to ' + out_filename, quiet=quiet):
autowaf.run_test(
@@ -372,7 +377,7 @@ def test_suite(ctx, base_uri, testdir, report, isyntax, osyntax, options=''):
if len(tests) == 0:
return
- thru_flags = ['-e', '-f', '-b', '-r http://example.org/']
+ thru_flags = ['-e', '-b', '-r http://example.org/']
thru_options = []
for n in range(len(thru_flags) + 1):
thru_options += list(itertools.combinations(thru_flags, n))
@@ -387,7 +392,7 @@ def test_suite(ctx, base_uri, testdir, report, isyntax, osyntax, options=''):
rel_action = os.path.join(os.path.relpath(srcdir), action)
abs_action = os.path.join(srcdir, action)
uri = base_uri + os.path.basename(action)
- command = 'serdi_static %s -f %s "%s" > %s' % (
+ command = 'serdi_static -a %s %s "%s" > %s' % (
options, rel_action, uri, action + '.out')
# Run strict test
@@ -526,7 +531,7 @@ def test(ctx):
test_suite(ctx, w3c_base + 'NQuadsTests/',
'NQuadsTests', report, 'NQuads', 'NQuads')
test_suite(ctx, w3c_base + 'TriGTests/',
- 'TriGTests', report, 'TriG', 'NQuads', '-a')
+ 'TriGTests', report, 'TriG', 'NQuads')
autowaf.post_test(ctx, APPNAME)