aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/serdi.16
-rw-r--r--src/serdi.c14
-rw-r--r--wscript14
3 files changed, 23 insertions, 11 deletions
diff --git a/doc/serdi.1 b/doc/serdi.1
index 74ddae3b..2d88586c 100644
--- a/doc/serdi.1
+++ b/doc/serdi.1
@@ -4,11 +4,15 @@
.B serdi \- Read and write RDF syntax
.SH SYNOPSIS
-serdi [\fIOPTION\fR]... \fIINPUT\fR \fIBASE_URI\fR
+serdi [\fIOPTION\fR]... \fIINPUT\fR
.SH OPTIONS
.TP
+.BR \-I
+Set input base URI.
+
+.TP
.BR \-a
Write ASCII output if possible.
diff --git a/src/serdi.c b/src/serdi.c
index 14b3e6e5..8e786f45 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -47,9 +47,10 @@ print_usage(const char* name, bool error)
{
FILE* const os = error ? stderr : stdout;
fprintf(os, "%s", error ? "\n" : "");
- fprintf(os, "Usage: %s [OPTION]... INPUT [BASE_URI]\n", name);
+ fprintf(os, "Usage: %s [OPTION]... INPUT...\n", name);
fprintf(os, "Read and write RDF syntax.\n");
fprintf(os, "Use - for INPUT to read from standard input.\n\n");
+ fprintf(os, " -I BASE_URI Input base URI.\n");
fprintf(os, " -a Write ASCII output if possible.\n");
fprintf(os, " -b Fast bulk output for large serialisations.\n");
fprintf(os, " -c PREFIX Chop PREFIX from matching blank node IDs.\n");
@@ -85,6 +86,7 @@ main(int argc, char** argv)
return print_usage(argv[0], true);
}
+ SerdNode* base = NULL;
SerdSyntax input_syntax = (SerdSyntax)0;
SerdSyntax output_syntax = (SerdSyntax)0;
SerdReaderFlags reader_flags = 0;
@@ -105,6 +107,11 @@ main(int argc, char** argv)
if (argv[a][1] == '\0') {
from_stdin = true;
break;
+ } else if (argv[a][1] == 'I') {
+ if (++a == argc) {
+ return missing_arg(argv[0], 'I');
+ }
+ base = serd_new_uri(argv[a]);
} else if (argv[a][1] == 'a') {
writer_flags |= SERD_WRITE_ASCII;
} else if (argv[a][1] == 'b') {
@@ -197,10 +204,7 @@ main(int argc, char** argv)
output_syntax = input_has_graphs ? SERD_NQUADS : SERD_NTRIPLES;
}
- SerdNode* base = NULL;
- if (a < argc) { // Base URI given on command line
- base = serd_new_uri(argv[a]);
- } else if (!from_string && !from_stdin) { // Use input file URI
+ if (!base) {
base = serd_new_file_uri(input, NULL);
}
diff --git a/wscript b/wscript
index a7114137..73625f43 100644
--- a/wscript
+++ b/wscript
@@ -435,7 +435,8 @@ def test_thru(check,
'-i', isyntax,
'-o', isyntax,
'-p', 'foo',
- check.tst.src_path(path), base]
+ '-I', base,
+ check.tst.src_path(path)]
thru_path = path + '.thru'
thru_cmd = [serdi] + opts + osyntax_opts + [
@@ -443,8 +444,8 @@ def test_thru(check,
'-o', osyntax,
'-c', 'foo',
'-a',
- out_path,
- base]
+ '-I', base,
+ out_path]
return (check(out_cmd, stdout=out_path, verbosity=0, name=out_path) and
check(thru_cmd, stdout=thru_path, verbosity=0, name=thru_path) and
@@ -568,8 +569,9 @@ def test_suite(ctx,
rel_action = os.path.join(os.path.relpath(srcdir), action)
uri = base_uri + os.path.basename(action)
command = ([serdi, '-a', '-o', osyntax] +
+ ['-I', uri] +
options +
- [rel_action, uri])
+ [rel_action])
# Run strict test
if expected_return == 0:
@@ -654,7 +656,7 @@ def test(tst):
out_path = in_path + '.io'
check_path = '%s/tests/good/%s' % (srcdir, check_name)
- check([serdi, '-o', lang, '%s/%s' % (srcdir, in_path), in_path],
+ check([serdi, '-o', lang, '-I', in_path, '%s/%s' % (srcdir, in_path)],
stdout=out_path, name=in_name)
check.file_equals(check_path, out_path)
@@ -679,6 +681,7 @@ def test(tst):
check([serdi])
check([serdi, '/no/such/file'])
check([serdi, 'ftp://example.org/unsupported.ttl'])
+ check([serdi, '-I'])
check([serdi, '-c'])
check([serdi, '-i', 'illegal'])
check([serdi, '-i', 'turtle'])
@@ -693,6 +696,7 @@ def test(tst):
check([serdi, '-q', '%s/tests/bad/bad-base.ttl' % srcdir], stderr=None)
check([serdi, '-r'])
check([serdi, '-z'])
+ check([serdi] + ['%s/tests/bad/bad-base.ttl' % srcdir] * 2)
with tst.group('IoErrors', expected=1) as check:
check([serdi, '-e', 'file://%s/' % srcdir], name='Read directory')