aboutsummaryrefslogtreecommitdiffstats
path: root/src/serdi.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-05-03 20:18:43 +0200
committerDavid Robillard <d@drobilla.net>2019-12-20 10:26:55 -0500
commitb9554abeb93b7c39db5beaa34c35bd0b2b332b03 (patch)
treefd1eb889abe26fbf695b2817d09ff88cea622e1c /src/serdi.c
parent27411951c2949ab08f9dee5b4a1e0870d005a427 (diff)
downloadserd-b9554abeb93b7c39db5beaa34c35bd0b2b332b03.tar.gz
serd-b9554abeb93b7c39db5beaa34c35bd0b2b332b03.tar.bz2
serd-b9554abeb93b7c39db5beaa34c35bd0b2b332b03.zip
Add input base URI option
Diffstat (limited to 'src/serdi.c')
-rw-r--r--src/serdi.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/serdi.c b/src/serdi.c
index cbd03a7b..30280280 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -49,9 +49,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");
@@ -94,6 +95,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;
@@ -114,6 +116,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') {
@@ -204,10 +211,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);
}