aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/serdi.110
-rw-r--r--src/serdi.c16
-rw-r--r--test/meson.build1
-rwxr-xr-xtest/run_test_suite.py20
4 files changed, 35 insertions, 12 deletions
diff --git a/doc/serdi.1 b/doc/serdi.1
index 7c665aff..61063184 100644
--- a/doc/serdi.1
+++ b/doc/serdi.1
@@ -7,6 +7,7 @@
.Sh SYNOPSIS
.Nm serdi
.Op Fl abefhlqtv
+.Op Fl I Ar base
.Op Fl c Ar prefix
.Op Fl i Ar syntax
.Op Fl k Ar bytes
@@ -16,7 +17,6 @@
.Op Fl s Ar string
.Op Fl w Ar filename
.Ar input
-.Op Ar base_uri
.Sh DESCRIPTION
.Nm
is a fast command-line utility for streaming and processing RDF data.
@@ -35,6 +35,14 @@ or transform URIs and blank node IDs.
The options are as follows:
.Pp
.Bl -tag -compact -width 3n
+.It Fl I Ar base
+Input base URI.
+Relative URI references in the input will be resolved against this.
+When the input is a file,
+the URI of the file is automatically used as the base URI.
+This option can be used to override that,
+or to provide a base URI for input from stdin or a string.
+.Pp
.It Fl a
Write ASCII output.
If this is enabled, all non-ASCII characters will be escaped, even if the output syntax allows them to be written in UTF-8.
diff --git a/src/serdi.c b/src/serdi.c
index 3f3bce06..f935a83e 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -52,9 +52,10 @@ print_usage(const char* const name, const 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");
@@ -98,6 +99,7 @@ main(int argc, char** argv)
return print_usage(prog, true);
}
+ SerdNode* base = NULL;
SerdSyntax input_syntax = SERD_SYNTAX_EMPTY;
SerdSyntax output_syntax = SERD_SYNTAX_EMPTY;
SerdReaderFlags reader_flags = 0;
@@ -145,6 +147,13 @@ main(int argc, char** argv)
} else if (opt == 's') {
from_string = true;
break;
+ } else if (argv[a][1] == 'I') {
+ if (++a == argc) {
+ return missing_arg(prog, 'I');
+ }
+
+ base = serd_new_uri(SERD_STRING(argv[a]));
+ break;
} else if (opt == 'c') {
if (argv[a][o + 1] || ++a == argc) {
return missing_arg(prog, 'c');
@@ -230,10 +239,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(SERD_STRING(argv[a]));
- } else if (!from_string && !from_stdin) { // Use input file URI
+ if (!base && !from_string && !from_stdin) { // Use input file URI
base = serd_new_file_uri(SERD_STRING(input), SERD_EMPTY_STRING());
}
diff --git a/test/meson.build b/test/meson.build
index 676fbcf3..ce3d49f7 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -72,6 +72,7 @@ if get_option('utils')
bad_args = [
['/no/such/file'],
['ftp://unsupported.org'],
+ ['-I'],
['-c'],
['-i', 'unknown'],
['-i', 'turtle'],
diff --git a/test/run_test_suite.py b/test/run_test_suite.py
index 7a3b5e88..f23f29e6 100755
--- a/test/run_test_suite.py
+++ b/test/run_test_suite.py
@@ -85,8 +85,9 @@ def test_thru(
"foo",
"-w",
out_path,
- path,
+ "-I",
base_uri,
+ path,
]
)
@@ -103,8 +104,9 @@ def test_thru(
"-w",
thru_path,
"-a",
- out_path,
+ "-I",
base_uri,
+ out_path,
]
)
@@ -168,7 +170,7 @@ def _load_rdf(filename, base_uri, command_prefix):
model = {}
instances = {}
- cmd = command_prefix + [filename, base_uri]
+ cmd = command_prefix + ["-I", base_uri, filename]
proc = subprocess.run(cmd, capture_output=True, check=True)
for line in proc.stdout.splitlines():
matches = re.match(
@@ -275,9 +277,15 @@ def test_suite(
test_name = os.path.basename(test_uri_path)
test_path = os.path.join(test_dir, test_name)
- command = (
- command_prefix + ["-a", "-o", osyntax] + [test_path, test_uri]
- )
+ command = command_prefix + [
+ "-a",
+ "-o",
+ osyntax,
+ "-I",
+ test_uri,
+ test_path,
+ ]
+
command_string = " ".join(shlex.quote(c) for c in command)
out_filename = os.path.join(out_test_dir, test_name + ".out")