diff options
author | David Robillard <d@drobilla.net> | 2006-07-26 03:25:08 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2006-07-26 03:25:08 +0000 |
commit | 2cd84e4209633e59439c445f821bed8410347bab (patch) | |
tree | ba34505505795cff5cf35c2958ed21933b822e12 /src | |
parent | deca2cc89850dffc051d0a0aafc9d681af838934 (diff) | |
download | lilv-2cd84e4209633e59439c445f821bed8410347bab.tar.gz lilv-2cd84e4209633e59439c445f821bed8410347bab.tar.bz2 lilv-2cd84e4209633e59439c445f821bed8410347bab.zip |
- Removed all the unsigned char garbage from the API
- Updated types in lv2.h to be non-machine-dependant (removed unsigned long in favour of uint32_t)
- Updated schema
- Updated example plugin to work with the above (partially)
git-svn-id: http://svn.drobilla.net/lad/libslv2@101 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin.c | 42 | ||||
-rw-r--r-- | src/plugininstance.c | 10 | ||||
-rw-r--r-- | src/pluginlist.c | 57 | ||||
-rw-r--r-- | src/port.c | 58 | ||||
-rw-r--r-- | src/query.c | 50 | ||||
-rw-r--r-- | src/util.c | 30 | ||||
-rw-r--r-- | src/util.h | 19 |
7 files changed, 127 insertions, 139 deletions
diff --git a/src/plugin.c b/src/plugin.c index b44eb56..0ffd760 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -40,7 +40,7 @@ slv2_plugin_duplicate(const SLV2Plugin* p) } -const unsigned char* +const char* slv2_plugin_get_uri(const SLV2Plugin* p) { assert(p); @@ -48,7 +48,7 @@ slv2_plugin_get_uri(const SLV2Plugin* p) } -const unsigned char* +const char* slv2_plugin_get_data_url(const SLV2Plugin* p) { assert(p); @@ -56,7 +56,7 @@ slv2_plugin_get_data_url(const SLV2Plugin* p) } -const unsigned char* +const char* slv2_plugin_get_data_path(const SLV2Plugin* p) { assert(p); @@ -67,7 +67,7 @@ slv2_plugin_get_data_path(const SLV2Plugin* p) } -const unsigned char* +const char* slv2_plugin_get_library_url(const SLV2Plugin* p) { assert(p); @@ -75,7 +75,7 @@ slv2_plugin_get_library_url(const SLV2Plugin* p) } -const unsigned char* +const char* slv2_plugin_get_library_path(const SLV2Plugin* p) { assert(p); @@ -111,11 +111,11 @@ slv2_plugin_verify(const SLV2Plugin* plugin) } -unsigned char* +char* slv2_plugin_get_name(const SLV2Plugin* plugin) { // FIXME: leak - unsigned char* result = NULL; + char* result = NULL; struct _Property* prop = slv2_plugin_get_property(plugin, "doap:name"); // FIXME: guaranteed to be the untagged one? @@ -134,14 +134,14 @@ slv2_plugin_get_property(const SLV2Plugin* p, assert(property); /* - uchar* header = slv2_query_header(p); - uchar* lang_filter = slv2_query_lang_filter(U("?value")); + char* header = slv2_query_header(p); + char* lang_filter = slv2_query_lang_filter("?value"); - uchar* query_string = ustrjoin( + char* query_string = strjoin( header, - U("SELECT DISTINCT ?value FROM data: WHERE { \n"), - U("plugin: "), property, U(" ?value . \n"), - ((lang_filter != NULL) ? lang_filter : U("")), + "SELECT DISTINCT ?value FROM data: WHERE { \n", + "plugin: ", property, " ?value . \n", + ((lang_filter != NULL) ? lang_filter : ""), "}", 0); free(header); @@ -150,9 +150,9 @@ slv2_plugin_get_property(const SLV2Plugin* p, rasqal_init(); rasqal_query_results* results = slv2_plugin_run_query(p, - U("SELECT DISTINCT ?value FROM data: WHERE { \n" - "plugin: "), property, U(" ?value . \n" - "} \n"), NULL); + "SELECT DISTINCT ?value FROM data: WHERE { \n" + "plugin: ", property, " ?value . \n" + "} \n", NULL); struct _Property* result = slv2_query_get_results(results); @@ -164,17 +164,17 @@ slv2_plugin_get_property(const SLV2Plugin* p, } -unsigned long +uint32_t slv2_plugin_get_num_ports(const SLV2Plugin* p) { - unsigned long result = 0; + uint32_t result = 0; rasqal_init(); rasqal_query_results* results = slv2_plugin_run_query(p, - U("SELECT DISTINCT ?value FROM data: WHERE { \n" - "plugin: lv2:port ?value . \n" - "} \n"), NULL); + "SELECT DISTINCT ?value FROM data: WHERE { \n" + "plugin: lv2:port ?value . \n" + "} \n", NULL); while (!rasqal_query_results_finished(results)) { ++result; diff --git a/src/plugininstance.c b/src/plugininstance.c index 8ff9e54..6665fd7 100644 --- a/src/plugininstance.c +++ b/src/plugininstance.c @@ -30,12 +30,12 @@ SLV2Instance* slv2_plugin_instantiate(const SLV2Plugin* plugin, - unsigned long sample_rate, + uint32_t sample_rate, const LV2_Host_Feature** host_features) { struct _Instance* result = NULL; - const unsigned char* const lib_path = slv2_plugin_get_library_path(plugin); + const char* const lib_path = slv2_plugin_get_library_path(plugin); if (!lib_path) return NULL; @@ -57,7 +57,7 @@ slv2_plugin_instantiate(const SLV2Plugin* plugin, const char* const bundle_path = url2path(plugin->bundle_url); - for (unsigned long i=0; 1; ++i) { + for (uint32_t i=0; 1; ++i) { const LV2_Descriptor* ld = df(i); if (!ld) { @@ -66,7 +66,7 @@ slv2_plugin_instantiate(const SLV2Plugin* plugin, dlclose(lib); break; // return NULL } else if (!strcmp(ld->URI, (char*)plugin->plugin_uri)) { - printf("Found %s at index %ld in:\n\t%s\n\n", plugin->plugin_uri, i, lib_path); + printf("Found %s at index %u in:\n\t%s\n\n", plugin->plugin_uri, i, lib_path); assert(ld->instantiate); @@ -86,7 +86,7 @@ slv2_plugin_instantiate(const SLV2Plugin* plugin, assert(slv2_plugin_get_num_ports(plugin) > 0); // Connect all ports to NULL (catches bugs) - for (unsigned long i=0; i < slv2_plugin_get_num_ports(plugin); ++i) + for (uint32_t i=0; i < slv2_plugin_get_num_ports(plugin); ++i) result->descriptor->connect_port(result->lv2_handle, i, NULL); return result; diff --git a/src/pluginlist.c b/src/pluginlist.c index 6a1a8c1..cd83629 100644 --- a/src/pluginlist.c +++ b/src/pluginlist.c @@ -70,8 +70,8 @@ slv2_list_load_all(SLV2List list) /* This is the parser for manifest.ttl */ void -slv2_list_load_bundle(SLV2List list, - const unsigned char* bundle_base_uri) +slv2_list_load_bundle(SLV2List list, + const char* bundle_base_uri) { // FIXME: ew unsigned char* manifest_uri = malloc( @@ -85,44 +85,41 @@ slv2_list_load_bundle(SLV2List list, rasqal_init(); rasqal_query_results *results; raptor_uri *base_uri = raptor_new_uri(manifest_uri); - rasqal_query *rq = rasqal_new_query((const char*)"sparql", (const uchar*)base_uri); + rasqal_query *rq = rasqal_new_query("sparql", (unsigned char*)base_uri); - unsigned char* query_string = - U("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" - "PREFIX : <http://lv2plug.in/ontology#> \n\n" - - "SELECT DISTINCT $plugin_uri $data_url $lib_url FROM <> WHERE { \n" - "$plugin_uri :binary $lib_url ; \n" - " rdfs:seeAlso $data_url . \n" - "} \n"); + char* query_string = + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + "PREFIX : <http://lv2plug.in/ontology#> \n\n" + + "SELECT DISTINCT $plugin_uri $data_url $lib_url FROM <> WHERE { \n" + "$plugin_uri :binary $lib_url ; \n" + " rdfs:seeAlso $data_url . \n" + "} \n"; //printf("%s\n\n", query_string); - rasqal_query_prepare(rq, (const uchar*)query_string, base_uri); + rasqal_query_prepare(rq, (unsigned char*)query_string, base_uri); results = rasqal_query_execute(rq); while (!rasqal_query_results_finished(results)) { // Create a new plugin struct _Plugin* new_plugin = malloc(sizeof(struct _Plugin)); - new_plugin->bundle_url = ustrdup(bundle_base_uri); + new_plugin->bundle_url = strdup(bundle_base_uri); rasqal_literal* literal = NULL; - literal = rasqal_query_results_get_binding_value_by_name(results, - U("plugin_uri")); + literal = rasqal_query_results_get_binding_value_by_name(results, "plugin_uri"); if (literal) - new_plugin->plugin_uri = ustrdup(rasqal_literal_as_string(literal)); + new_plugin->plugin_uri = strdup(rasqal_literal_as_string(literal)); - literal = rasqal_query_results_get_binding_value_by_name(results, - U("data_url")); + literal = rasqal_query_results_get_binding_value_by_name(results, "data_url"); if (literal) - new_plugin->data_url = ustrdup(rasqal_literal_as_string(literal)); + new_plugin->data_url = strdup(rasqal_literal_as_string(literal)); - literal = rasqal_query_results_get_binding_value_by_name(results, - U("lib_url")); + literal = rasqal_query_results_get_binding_value_by_name(results, "lib_url"); if (literal) - new_plugin->lib_url = ustrdup(rasqal_literal_as_string(literal)); + new_plugin->lib_url = strdup(rasqal_literal_as_string(literal)); /* Add the plugin if it's valid */ if (new_plugin->lib_url && new_plugin->data_url && new_plugin->plugin_uri @@ -165,14 +162,14 @@ add_plugins_from_dir(SLV2List list, const char* dir) if (!strcmp(pfile->d_name, ".") || !strcmp(pfile->d_name, "..")) continue; - char* bundle_path = (char*)ustrjoin(U(dir), U("/"), U(pfile->d_name), NULL); - char* bundle_url = (char*)ustrjoin(U("file://"), U(dir), U("/"), U(pfile->d_name), NULL); + char* bundle_path = (char*)strjoin(dir, "/", pfile->d_name, NULL); + char* bundle_url = (char*)strjoin("file://", dir, "/", pfile->d_name, NULL); DIR* bundle_dir = opendir(bundle_path); if (bundle_dir != NULL) { closedir(bundle_dir); - slv2_list_load_bundle(list, U(bundle_url)); + slv2_list_load_bundle(list, bundle_url); //printf("Loaded bundle %s\n", bundle_url); } @@ -188,7 +185,7 @@ slv2_list_load_path(SLV2List list, const char* slv2_path) { - char* path = (char*)ustrjoin(U(slv2_path), U(":"), NULL); + char* path = (char*)strjoin(slv2_path, ":", NULL); char* dir = path; // Pointer into path @@ -210,7 +207,7 @@ slv2_list_load_path(SLV2List list, } -unsigned long +size_t slv2_list_get_length(const SLV2List list) { assert(list != NULL); @@ -219,12 +216,12 @@ slv2_list_get_length(const SLV2List list) SLV2Plugin* -slv2_list_get_plugin_by_uri(const SLV2List list, const unsigned char* uri) +slv2_list_get_plugin_by_uri(const SLV2List list, const char* uri) { if (list->num_plugins > 0) { assert(list->plugins != NULL); - for (unsigned long i=0; i < list->num_plugins; ++i) + for (size_t i=0; i < list->num_plugins; ++i) if (!strcmp((char*)list->plugins[i]->plugin_uri, (char*)uri)) return list->plugins[i]; } @@ -234,7 +231,7 @@ slv2_list_get_plugin_by_uri(const SLV2List list, const unsigned char* uri) SLV2Plugin* -slv2_list_get_plugin_by_index(const SLV2List list, unsigned long index) +slv2_list_get_plugin_by_index(const SLV2List list, size_t index) { if (list->num_plugins == 0) return NULL; @@ -26,10 +26,10 @@ #include "util.h" enum SLV2PortClass -slv2_port_get_class(SLV2Plugin* p, - unsigned long index) +slv2_port_get_class(SLV2Plugin* p, + uint32_t index) { - struct _Property* class = slv2_port_get_property(p, index, U("rdf:type")); + struct _Property* class = slv2_port_get_property(p, index, "rdf:type"); assert(class); assert(class->num_values == 1); assert(class->values); @@ -51,39 +51,39 @@ slv2_port_get_class(SLV2Plugin* p, } -uchar* -slv2_port_get_data_type(SLV2Plugin* p, - unsigned long index) +char* +slv2_port_get_data_type(SLV2Plugin* p, + uint32_t index) { - SLV2Property type = slv2_port_get_property(p, index, U("lv2:datatype")); + SLV2Property type = slv2_port_get_property(p, index, "lv2:datatype"); assert(type); assert(type->num_values == 1); assert(type->values); - uchar* ret = type->values[0]; + char* ret = type->values[0]; slv2_property_free(type); return ret; } SLV2Property -slv2_port_get_property(SLV2Plugin* p, - unsigned long index, - const uchar* property) +slv2_port_get_property(SLV2Plugin* p, + uint32_t index, + const char* property) { assert(p); assert(property); char index_str[4]; - snprintf(index_str, (size_t)4, "%lu", index); + snprintf(index_str, (size_t)4, "%u", index); rasqal_init(); rasqal_query_results* results = slv2_plugin_run_query(p, - U("SELECT DISTINCT ?value FROM data: WHERE { \n" + "SELECT DISTINCT ?value FROM data: WHERE { \n" "plugin: lv2:port ?port \n" - "?port lv2:index "), index_str, U(" \n" - "?port "), property, U(" ?value . \n}\n"), NULL); + "?port lv2:index ", index_str, " \n" + "?port ", property, " ?value . \n}\n", NULL); SLV2Property result = slv2_query_get_results(results); @@ -94,18 +94,18 @@ slv2_port_get_property(SLV2Plugin* p, } -uchar* -slv2_port_get_symbol(SLV2Plugin* p, - unsigned long index) +char* +slv2_port_get_symbol(SLV2Plugin* p, + uint32_t index) { // FIXME: leaks - uchar* result = NULL; + char* result = NULL; SLV2Property prop - = slv2_port_get_property(p, index, U("lv2:symbol")); + = slv2_port_get_property(p, index, "lv2:symbol"); if (prop && prop->num_values == 1) - result = (uchar*)strdup((char*)prop->values[0]); + result = strdup(prop->values[0]); slv2_property_free(prop); return result; @@ -114,14 +114,14 @@ slv2_port_get_symbol(SLV2Plugin* p, float slv2_port_get_default_value(SLV2Plugin* p, - unsigned long index) + uint32_t index) { // FIXME: do casting properly in the SPARQL query float result = 0.0f; SLV2Property prop - = slv2_port_get_property(p, index, U("lv2:default")); + = slv2_port_get_property(p, index, "lv2:default"); if (prop && prop->num_values == 1) result = atof((char*)prop->values[0]); @@ -133,15 +133,15 @@ slv2_port_get_default_value(SLV2Plugin* p, float -slv2_port_get_minimum_value(SLV2Plugin* p, - unsigned long index) +slv2_port_get_minimum_value(SLV2Plugin* p, + uint32_t index) { // FIXME: do casting properly in the SPARQL query float result = 0.0f; SLV2Property prop - = slv2_port_get_property(p, index, U("lv2:minimum")); + = slv2_port_get_property(p, index, "lv2:minimum"); if (prop && prop->num_values == 1) result = atof((char*)prop->values[0]); @@ -153,15 +153,15 @@ slv2_port_get_minimum_value(SLV2Plugin* p, float -slv2_port_get_maximum_value(SLV2Plugin* p, - unsigned long index) +slv2_port_get_maximum_value(SLV2Plugin* p, + uint32_t index) { // FIXME: do casting properly in the SPARQL query float result = 0.0f; SLV2Property prop - = slv2_port_get_property(p, index, U("lv2:maximum")); + = slv2_port_get_property(p, index, "lv2:maximum"); if (prop && prop->num_values == 1) result = atof((char*)prop->values[0]); diff --git a/src/query.c b/src/query.c index da9239d..b8d279f 100644 --- a/src/query.c +++ b/src/query.c @@ -23,35 +23,35 @@ #include <slv2/query.h> -unsigned char* +char* slv2_query_header(const SLV2Plugin* p) { - const unsigned char* plugin_uri = slv2_plugin_get_uri(p); - const unsigned char* data_file_url = slv2_plugin_get_data_url(p); + const char* const plugin_uri = slv2_plugin_get_uri(p); + const char* const data_file_url = slv2_plugin_get_data_url(p); - unsigned char* query_string = ustrjoin(U( - "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" - "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" - "PREFIX doap: <http://usefulinc.com/ns/doap#> \n" - "PREFIX lv2: <http://lv2plug.in/ontology#> \n" - "PREFIX plugin: <"), plugin_uri, U("> \n"), - U("PREFIX data: <"), data_file_url, U("> \n\n"), NULL); + char* query_string = strjoin( + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + "PREFIX doap: <http://usefulinc.com/ns/doap#> \n" + "PREFIX lv2: <http://lv2plug.in/ontology#> \n" + "PREFIX plugin: <", plugin_uri, "> \n", + "PREFIX data: <", data_file_url, "> \n\n", NULL); return query_string; } -unsigned char* -slv2_query_lang_filter(const uchar* variable) +char* +slv2_query_lang_filter(const char* variable) { - uchar* result = NULL; - uchar* const lang = (uchar*)getenv("LANG"); + char* result = NULL; + char* const lang = (char*)getenv("LANG"); if (lang) { // FILTER( LANG(?value) = "en" || LANG(?value) = "" ) - result = ustrjoin( - //U("FILTER (lang(?value) = \""), lang, U("\")\n"), 0); - U("FILTER( lang(?"), variable, U(") = \""), lang, - U("\" || lang(?"), variable, U(") = \"\" )\n"), NULL); + result = strjoin( + //"FILTER (lang(?value) = \"", lang, "\"\n"), 0); + "FILTER( lang(?", variable, ") = \"", lang, + "\" || lang(?", variable, ") = \"\" )\n", NULL); } return result; @@ -60,17 +60,17 @@ slv2_query_lang_filter(const uchar* variable) rasqal_query_results* slv2_plugin_run_query(const SLV2Plugin* p, - const uchar* first, ...) + const char* first, ...) { /* FIXME: Too much unecessary allocation */ - uchar* header = slv2_query_header(p); + char* header = slv2_query_header(p); va_list args_list; va_start(args_list, first); - uchar* args_str = vstrjoin(first, args_list); - uchar* query_str = ustrjoin(header, args_str, NULL); + char* args_str = vstrjoin(first, args_list); + char* query_str = strjoin(header, args_str, NULL); va_end(args_list); assert(p); @@ -80,7 +80,7 @@ slv2_plugin_run_query(const SLV2Plugin* p, //printf("Query: \n%s\n\n", query_str); - rasqal_query_prepare(rq, query_str, NULL); + rasqal_query_prepare(rq, (unsigned char*)query_str, NULL); rasqal_query_results* results = rasqal_query_execute(rq); rasqal_free_query(rq); @@ -107,14 +107,14 @@ slv2_query_get_results(rasqal_query_results* results) while (!rasqal_query_results_finished(results)) { rasqal_literal* literal = - rasqal_query_results_get_binding_value_by_name(results, U("value")); + rasqal_query_results_get_binding_value_by_name(results, "value"); assert(literal != NULL); // Add value on to the array. Yes, this is disgusting. result->num_values++; // FIXME LEAK: result->values = realloc(result->values, result->num_values * sizeof(char*)); - result->values[result->num_values-1] = ustrdup(rasqal_literal_as_string(literal)); + result->values[result->num_values-1] = strdup(rasqal_literal_as_string(literal)); rasqal_query_results_next(results); } @@ -26,7 +26,7 @@ void -ustrappend(uchar** dst, const uchar* suffix) +strappend(char** dst, const char* suffix) { assert(dst); assert(*dst); @@ -39,21 +39,13 @@ ustrappend(uchar** dst, const uchar* suffix) } -uchar* -ustrdup(const uchar* src) -{ - assert(src); - return (uchar*)strdup((char*)src); -} - - -uchar* -ustrjoin(const uchar* first, ...) +char* +strjoin(const char* first, ...) { va_list args_list; va_start(args_list, first); - uchar* result = vstrjoin(first, args_list); + char* result = vstrjoin(first, args_list); va_end(args_list); @@ -61,17 +53,17 @@ ustrjoin(const uchar* first, ...) } -uchar* -vstrjoin(const uchar* first, va_list args_list) +char* +vstrjoin(const char* first, va_list args_list) { // FIXME: this is horribly, awfully, disgracefully slow. // so I'm lazy. - const uchar* arg = NULL; - uchar* result = ustrdup(first); + const char* arg = NULL; + char* result = strdup(first); - while ((arg = va_arg(args_list, const uchar*)) != NULL) - ustrappend(&result, arg); + while ((arg = va_arg(args_list, const char*)) != NULL) + strappend(&result, arg); //va_end(args_list); @@ -87,7 +79,7 @@ vstrjoin(const uchar* first, va_list args_list) * Result is simply a pointer in to \a url and must not be free()'d. */ const char* -url2path(const uchar* const url) +url2path(const char* const url) { /*assert(strlen((char*)url) > 8); char* result = calloc(strlen((char*)url)-7+1, sizeof(char)); @@ -19,11 +19,12 @@ #ifndef __UTIL_H #define __UTIL_H +#define _XOPEN_SOURCE 500 +#include <string.h> + #include <stdarg.h> #include <slv2/types.h> -/* Cast a char* to an unsigned char* (Used for string literals) */ -#define U(x) (unsigned char*)(x) /** Append \a suffix to \a *dst, reallocating \a dst as necessary. * @@ -31,23 +32,21 @@ * or NULL. */ void -ustrappend(uchar** dst, const uchar* suffix); +strappend(char** dst, const char* suffix); -uchar* -ustrdup(const uchar* src); /** Join all arguments into one string. * * Arguments are not modified, return value must be free()'d. */ -uchar* -ustrjoin(const uchar* first, ...); +char* +strjoin(const char* first, ...); -uchar* -vstrjoin(const uchar* first, va_list args_list); +char* +vstrjoin(const char* first, va_list args_list); const char* -url2path(const uchar* const url); +url2path(const char* const url); #endif |