aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-12-02 17:11:23 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commitb13ad41a4d65b577b4db67660a9edf3056bdf7af (patch)
treee89535f6098a1b860f38ec8a7a1b698b30a72545 /tools
parent0db18e483f11ac2f9518d96e137d217040ed1339 (diff)
downloadserd-b13ad41a4d65b577b4db67660a9edf3056bdf7af.tar.gz
serd-b13ad41a4d65b577b4db67660a9edf3056bdf7af.tar.bz2
serd-b13ad41a4d65b577b4db67660a9edf3056bdf7af.zip
Use SerdNodes instead of manual memory management in tests
Diffstat (limited to 'tools')
-rw-r--r--tools/console.c68
-rw-r--r--tools/console.h3
2 files changed, 19 insertions, 52 deletions
diff --git a/tools/console.c b/tools/console.c
index 94d9a0c5..89223eaf 100644
--- a/tools/console.c
+++ b/tools/console.c
@@ -10,9 +10,7 @@
#include "serd/syntax.h"
#include "serd/uri.h"
#include "serd/version.h"
-#include "zix/allocator.h"
#include "zix/attributes.h"
-#include "zix/filesystem.h"
#ifdef _WIN32
# ifdef _MSC_VER
@@ -197,39 +195,6 @@ serd_get_size_argument(OptionIter* const iter, size_t* const argument)
return SERD_SUCCESS;
}
-SerdStatus
-serd_set_base_uri_from_path(SerdEnv* const env, const char* const path)
-{
- const size_t path_len = strlen(path);
- char* const real_path = zix_canonical_path(NULL, path);
- if (!real_path) {
- return SERD_BAD_ARG;
- }
-
- const size_t real_path_len = strlen(real_path);
- SerdNode* base_node = NULL;
- if (path[path_len - 1] == '/' || path[path_len - 1] == '\\') {
- char* const base_path = (char*)calloc(real_path_len + 2, 1);
-
- memcpy(base_path, real_path, real_path_len + 1);
- base_path[real_path_len] = path[path_len - 1];
-
- base_node = serd_node_new(
- NULL, serd_a_file_uri(serd_string(base_path), serd_empty_string()));
-
- free(base_path);
- } else {
- base_node = serd_node_new(
- NULL, serd_a_file_uri(serd_string(real_path), serd_empty_string()));
- }
-
- serd_env_set_base_uri(env, serd_node_string_view(base_node));
- serd_node_free(NULL, base_node);
- zix_free(NULL, real_path);
-
- return SERD_SUCCESS;
-}
-
SerdSyntax
serd_choose_syntax(SerdWorld* const world,
const SerdSyntaxOptions options,
@@ -431,24 +396,29 @@ serd_create_env(SerdAllocator* const allocator,
const char* const base_string,
const char* const out_filename)
{
- const bool is_rebase = base_string && !strcmp(base_string, "rebase");
- if (is_rebase && !out_filename) {
- fprintf(stderr, "%s: rebase requires an output filename\n", program);
- return NULL;
- }
-
- if (base_string && serd_uri_string_has_scheme(base_string)) {
+ if (serd_uri_string_has_scheme(base_string)) {
return serd_env_new(allocator, serd_string(base_string));
}
- SerdEnv* const env = serd_env_new(allocator, serd_empty_string());
- if (base_string && base_string[0]) {
- const SerdStatus st = serd_set_base_uri_from_path(env, base_string);
- if (st) {
- fprintf(stderr, "%s: invalid base URI \"%s\"\n", program, base_string);
- serd_env_free(env);
+ const bool is_rebase = !strcmp(base_string, "rebase");
+ if (is_rebase) {
+ if (!out_filename) {
+ fprintf(stderr, "%s: rebase requires an output filename\n", program);
return NULL;
}
+
+ SerdEnv* const env = serd_env_new(allocator, serd_empty_string());
+ serd_env_set_base_path(env, serd_string(out_filename));
+ return env;
+ }
+
+ SerdEnv* const env = serd_env_new(allocator, serd_empty_string());
+ const SerdStringView base = serd_string(base_string);
+ const SerdStatus st = serd_env_set_base_path(env, base);
+ if (st) {
+ fprintf(stderr, "%s: invalid base URI \"%s\"\n", program, base_string);
+ serd_env_free(env);
+ return NULL;
}
return env;
@@ -536,7 +506,7 @@ serd_read_inputs(SerdWorld* const world,
// Use the filename as the base URI if possible if user didn't override it
const char* const in_path = inputs[i];
if (!opts.base_uri[0] && !!strcmp(in_path, "-")) {
- serd_set_base_uri_from_path(env, in_path);
+ serd_env_set_base_path(env, serd_string(in_path));
}
// Open the input stream
diff --git a/tools/console.h b/tools/console.h
index c8c68411..ed59264a 100644
--- a/tools/console.h
+++ b/tools/console.h
@@ -76,9 +76,6 @@ serd_set_stream_utf8_mode(FILE* stream);
SerdStatus
serd_print_version(const char* program);
-SerdStatus
-serd_set_base_uri_from_path(SerdEnv* env, const char* path);
-
SerdSyntax
serd_choose_syntax(SerdWorld* world,
SerdSyntaxOptions options,