From 6ac6d7448aa0a976e7347daf8b48d6e56216af85 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 5 May 2014 15:38:33 +0000 Subject: Fix use of lv2info -m and -p options to write plugin data. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@5401 a436a847-0d15-0410-975c-d299462d15a1 --- NEWS | 7 +++++-- lilv/lilv.h | 13 +++++++++++++ src/node.c | 14 ++++++++++++++ test/lilv_test.c | 10 ++++++++++ utils/lv2info.c | 22 +++++++++++++++------- wscript | 2 +- 6 files changed, 58 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index ccecf36..ba8c527 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -lilv (0.18.1) unstable; +lilv (0.19.0) unstable; * Don't load files multiple times if they are listed as rdfs:seeAlso for several plugins @@ -6,8 +6,11 @@ lilv (0.18.1) unstable; * Call lv2_lib_descriptor separately for different bundle paths (fix loading several dynamic plugins like Ingen at once) * Tolerate calling lilv_node_as_uri or lilv_node_as_blank on NULL + * Add convenient lilv_new_file_uri for creating file URIs. + * Fix use of lv2info -m and -p options to write plugin data + (useful for porting plugins bridges with NASPRO). - -- David Robillard Sat, 26 Apr 2014 20:29:27 -0400 + -- David Robillard Mon, 05 May 2014 17:00:36 +0200 lilv (0.18.0) stable; diff --git a/lilv/lilv.h b/lilv/lilv.h index bdf70dc..8c60132 100644 --- a/lilv/lilv.h +++ b/lilv/lilv.h @@ -118,6 +118,19 @@ LILV_API LilvNode* lilv_new_uri(LilvWorld* world, const char* uri); +/** + Create a new file URI value. + @param host Host name, or NULL. + @param path Path on host. + @return A new node that must be freed by caller. + + Relative paths are resolved against the current working directory. Note + that this may yield unexpected results if @p host is another machine. +*/ +LILV_API +LilvNode* +lilv_new_file_uri(LilvWorld* world, const char* host, const char* path); + /** Create a new string value (with no language). Returned value must be freed by caller with lilv_node_free. diff --git a/src/node.c b/src/node.c index e8756ac..3d074a4 100644 --- a/src/node.c +++ b/src/node.c @@ -154,6 +154,20 @@ lilv_new_uri(LilvWorld* world, const char* uri) return lilv_node_new(world, LILV_VALUE_URI, uri); } +LILV_API +LilvNode* +lilv_new_file_uri(LilvWorld* world, const char* host, const char* path) +{ + char* abs_path = lilv_path_absolute(path); + SerdNode s = serd_node_new_file_uri( + (const uint8_t*)abs_path, (const uint8_t*)host, NULL, true); + + LilvNode* ret = lilv_node_new(world, LILV_VALUE_URI, (const char*)s.buf); + serd_node_free(&s); + free(abs_path); + return ret; +} + LILV_API LilvNode* lilv_new_string(LilvWorld* world, const char* str) diff --git a/test/lilv_test.c b/test/lilv_test.c index 998ffb0..102ffc6 100644 --- a/test/lilv_test.c +++ b/test/lilv_test.c @@ -259,6 +259,16 @@ test_value(void) TEST_ASSERT(lilv_node_as_int(ival) == 42); TEST_ASSERT(fabs(lilv_node_as_float(fval) - 1.6180) < FLT_EPSILON); + LilvNode* loc_abs = lilv_new_file_uri(world, NULL, "/foo/bar"); + LilvNode* loc_rel = lilv_new_file_uri(world, NULL, "foo"); + LilvNode* host_abs = lilv_new_file_uri(world, "host", "/foo/bar"); + LilvNode* host_rel = lilv_new_file_uri(world, "host", "foo"); + + TEST_ASSERT(!strcmp(lilv_node_as_uri(loc_abs), "file:///foo/bar")); + TEST_ASSERT(!strncmp(lilv_node_as_uri(loc_rel), "file:///", 8)); + TEST_ASSERT(!strcmp(lilv_node_as_uri(host_abs), "file://host/foo/bar")); + TEST_ASSERT(!strncmp(lilv_node_as_uri(host_rel), "file://host/", 12)); + char* tok = lilv_node_get_turtle_token(uval); TEST_ASSERT(!strcmp(tok, "")); free(tok); diff --git a/utils/lv2info.c b/utils/lv2info.c index d20789e..3bd79f4 100644 --- a/utils/lv2info.c +++ b/utils/lv2info.c @@ -1,5 +1,5 @@ /* - Copyright 2007-2011 David Robillard + Copyright 2007-2014 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -399,17 +399,25 @@ main(int argc, char** argv) const LilvPlugin* p = lilv_plugins_get_by_uri(plugins, uri); if (p && plugin_file) { - LilvNode* base = lilv_new_uri(world, plugin_file); + LilvNode* base = lilv_new_file_uri(world, NULL, plugin_file); FILE* plugin_fd = fopen(plugin_file, "a"); - lilv_plugin_write_description(world, p, base, plugin_fd); - fclose(plugin_fd); + if (plugin_fd) { + lilv_plugin_write_description(world, p, base, plugin_fd); + fclose(plugin_fd); + } else { + fprintf(stderr, "error: Failed to open %s\n", plugin_file); + } if (manifest_file) { FILE* manifest_fd = fopen(manifest_file, "a"); - lilv_plugin_write_manifest_entry( - world, p, base, manifest_fd, plugin_file); - fclose(manifest_fd); + if (manifest_fd) { + lilv_plugin_write_manifest_entry( + world, p, base, manifest_fd, plugin_file); + fclose(manifest_fd); + } else { + fprintf(stderr, "error: Failed to open %s\n", manifest_file); + } } lilv_node_free(base); } else if (p) { diff --git a/wscript b/wscript index 194a987..5af7efb 100644 --- a/wscript +++ b/wscript @@ -12,7 +12,7 @@ import waflib.Logs as Logs # major increment <=> incompatible changes # minor increment <=> compatible changes (additions) # micro increment <=> no interface changes -LILV_VERSION = '0.18.1' +LILV_VERSION = '0.19.0' LILV_MAJOR_VERSION = '0' # Mandatory waf variables -- cgit v1.2.1