aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-08-02 11:56:54 -0400
committerDavid Robillard <d@drobilla.net>2022-01-28 21:57:07 -0500
commitc6124f291118ae8270da43560d84dc5903118400 (patch)
tree7ac054e481c2f187a436c31a528b611904519a01
parent44846374476986dbff7ac6f576ec02eecc2e2902 (diff)
downloadserd-c6124f291118ae8270da43560d84dc5903118400.tar.gz
serd-c6124f291118ae8270da43560d84dc5903118400.tar.bz2
serd-c6124f291118ae8270da43560d84dc5903118400.zip
Factor out setting base URI from a path
-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) {