aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-03-27 19:14:40 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commit959a0db69fa0a61b8a131ee49f9a553f0e01f3e1 (patch)
treec57d91a0bee4ab8ae998ec355d612a583e8d6512 /tools
parent0e9169e24fcfc4599a62f85991f407f257fec520 (diff)
downloadserd-959a0db69fa0a61b8a131ee49f9a553f0e01f3e1.tar.gz
serd-959a0db69fa0a61b8a131ee49f9a553f0e01f3e1.tar.bz2
serd-959a0db69fa0a61b8a131ee49f9a553f0e01f3e1.zip
Add base URI command-line option
Diffstat (limited to 'tools')
-rw-r--r--tools/serd-pipe.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/tools/serd-pipe.c b/tools/serd-pipe.c
index 26a4a26a..a5f2a1b2 100644
--- a/tools/serd-pipe.c
+++ b/tools/serd-pipe.c
@@ -33,6 +33,7 @@ print_usage(const char* const name, const bool error)
static const char* const description =
"Read and write RDF syntax.\n"
"Use - for INPUT to read from standard input.\n\n"
+ " -B BASE_URI Base URI.\n"
" -a Write ASCII output.\n"
" -b Write output in blocks for performance.\n"
" -c PREFIX Chop PREFIX from matching blank node IDs.\n"
@@ -52,7 +53,7 @@ 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, "%s", description);
return error ? 1 : 0;
}
@@ -77,6 +78,7 @@ main(int argc, char** argv)
{
const char* const prog = argv[0];
+ SerdNode* base = NULL;
SerdSyntax input_syntax = SERD_SYNTAX_EMPTY;
SerdSyntax output_syntax = SERD_SYNTAX_EMPTY;
SerdReaderFlags reader_flags = 0;
@@ -131,6 +133,13 @@ main(int argc, char** argv)
} else if (opt == 's') {
from_string = true;
break;
+ } else if (argv[a][1] == 'B') {
+ if (++a == argc) {
+ return missing_arg(prog, 'B');
+ }
+
+ 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');
@@ -212,10 +221,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());
}