aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/console.c20
-rw-r--r--tools/console.h5
-rw-r--r--tools/serd-pipe.c13
3 files changed, 27 insertions, 11 deletions
diff --git a/tools/console.c b/tools/console.c
index f6a15ecb..c187f500 100644
--- a/tools/console.c
+++ b/tools/console.c
@@ -4,6 +4,8 @@
#include "console.h"
#include "serd/serd.h"
+#include "zix/allocator.h"
+#include "zix/filesystem.h"
#ifdef _WIN32
# ifdef _MSC_VER
@@ -43,6 +45,24 @@ serd_print_version(const char* const program)
return 0;
}
+SerdStatus
+serd_set_base_uri_from_path(SerdEnv* const env, const char* const path)
+{
+ char* const input_path = zix_canonical_path(NULL, path);
+ if (!input_path) {
+ return SERD_BAD_ARG;
+ }
+
+ SerdNode* const file_uri =
+ serd_new_file_uri(serd_string(input_path), serd_empty_string());
+
+ serd_env_set_base_uri(env, serd_node_string_view(file_uri));
+ serd_node_free(file_uri);
+ zix_free(NULL, input_path);
+
+ return SERD_SUCCESS;
+}
+
/// Wrapper for getc that is compatible with SerdReadFunc but faster than fread
static size_t
serd_file_read_byte(void* buf, size_t size, size_t nmemb, void* stream)
diff --git a/tools/console.h b/tools/console.h
index ef0fb1d1..763ff215 100644
--- a/tools/console.h
+++ b/tools/console.h
@@ -4,7 +4,9 @@
#ifndef SERD_TOOLS_CONSOLE_H
#define SERD_TOOLS_CONSOLE_H
+#include "serd/env.h"
#include "serd/input_stream.h"
+#include "serd/status.h"
#include <stdio.h>
@@ -14,6 +16,9 @@ serd_set_stream_utf8_mode(FILE* stream);
int
serd_print_version(const char* program);
+SerdStatus
+serd_set_base_uri_from_path(SerdEnv* env, const char* path);
+
SerdInputStream
serd_open_tool_input(const char* filename);
diff --git a/tools/serd-pipe.c b/tools/serd-pipe.c
index 894a422b..1ad07719 100644
--- a/tools/serd-pipe.c
+++ b/tools/serd-pipe.c
@@ -340,19 +340,10 @@ main(int argc, char** argv)
for (int i = 0; !st && i < n_inputs; ++i) {
if (!base && !!strcmp(inputs[i], "-")) {
- char* const input_path = zix_canonical_path(NULL, inputs[i]);
- if (!input_path) {
- SERDI_ERRORF("failed to resolve path %s\n", inputs[i]);
- st = SERD_BAD_ARG;
+ if ((st = serd_set_base_uri_from_path(env, inputs[i]))) {
+ SERDI_ERRORF("failed to set base URI from path %s\n", inputs[i]);
break;
}
-
- SerdNode* const file_uri =
- serd_new_file_uri(serd_string(input_path), serd_empty_string());
-
- serd_env_set_base_uri(env, serd_node_string_view(file_uri));
- serd_node_free(file_uri);
- zix_free(NULL, input_path);
}
if (n_inputs > 1) {