aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/console.c18
-rw-r--r--src/console.h3
-rw-r--r--src/serdi.c13
3 files changed, 23 insertions, 11 deletions
diff --git a/src/console.c b/src/console.c
index 3d2c110a..2cc908ef 100644
--- a/src/console.c
+++ b/src/console.c
@@ -91,3 +91,21 @@ serd_open_output(const char* const filename, const size_t page_size)
return serd_byte_sink_new_filename(filename, page_size);
}
+
+SerdStatus
+serd_set_base_uri_from_path(SerdEnv* const env, const char* const path)
+{
+ char* const input_path = serd_canonical_path(path);
+ if (!input_path) {
+ return SERD_ERR_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);
+ serd_free(input_path);
+
+ return SERD_SUCCESS;
+}
diff --git a/src/console.h b/src/console.h
index f1d11f8e..57170a94 100644
--- a/src/console.h
+++ b/src/console.h
@@ -29,3 +29,6 @@ serd_open_input(const char* filename, size_t page_size);
SerdByteSink*
serd_open_output(const char* filename, size_t page_size);
+
+SerdStatus
+serd_set_base_uri_from_path(SerdEnv* env, const char* path);
diff --git a/src/serdi.c b/src/serdi.c
index b1771fec..88ccacd9 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -480,19 +480,10 @@ main(int argc, char** argv)
for (int i = 0; !st && i < n_inputs; ++i) {
if (!base && strcmp(inputs[i], "-")) {
- char* const input_path = serd_canonical_path(inputs[i]);
- if (!input_path) {
- SERDI_ERRORF("failed to resolve path %s\n", inputs[i]);
- st = SERD_ERR_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);
- serd_free(input_path);
}
if (n_inputs > 1) {