summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugin.c15
-rw-r--r--src/port.c13
-rw-r--r--src/query.c15
-rw-r--r--src/util.c49
-rw-r--r--src/util.h2
5 files changed, 47 insertions, 47 deletions
diff --git a/src/plugin.c b/src/plugin.c
index 0ffd760..a6b2344 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -149,16 +149,18 @@ slv2_plugin_get_property(const SLV2Plugin* p,
rasqal_init();
- rasqal_query_results* results = slv2_plugin_run_query(p,
+ char* query = strjoin(
"SELECT DISTINCT ?value FROM data: WHERE { \n"
- "plugin: ", property, " ?value . \n"
- "} \n", NULL);
+ "plugin: ", property, " ?value . \n"
+ "} \n", NULL);
+
+ rasqal_query_results* results = slv2_plugin_run_query(p, query);
struct _Property* result = slv2_query_get_results(results);
- //free(query_string);
rasqal_free_query_results(results);
rasqal_finish();
+ free(query);
return result;
}
@@ -171,10 +173,12 @@ slv2_plugin_get_num_ports(const SLV2Plugin* p)
rasqal_init();
- rasqal_query_results* results = slv2_plugin_run_query(p,
+ char* query = strjoin(
"SELECT DISTINCT ?value FROM data: WHERE { \n"
"plugin: lv2:port ?value . \n"
"} \n", NULL);
+
+ rasqal_query_results* results = slv2_plugin_run_query(p, query);
while (!rasqal_query_results_finished(results)) {
++result;
@@ -183,6 +187,7 @@ slv2_plugin_get_num_ports(const SLV2Plugin* p)
rasqal_free_query_results(results);
rasqal_finish();
+ free(query);
return result;
}
diff --git a/src/port.c b/src/port.c
index 329e63c..db18ab8 100644
--- a/src/port.c
+++ b/src/port.c
@@ -79,17 +79,20 @@ slv2_port_get_property(SLV2Plugin* p,
rasqal_init();
- rasqal_query_results* results = slv2_plugin_run_query(p,
+ char* query = strjoin(
"SELECT DISTINCT ?value FROM data: WHERE { \n"
- "plugin: lv2:port ?port \n"
- "?port lv2:index ", index_str, " \n"
- "?port ", property, " ?value . \n}\n", NULL);
+ "plugin: lv2:port ?port . \n"
+ "?port lv2:index ", index_str, " . \n"
+ "?port ", property, " ?value . \n}\n", NULL);
+
+ rasqal_query_results* results = slv2_plugin_run_query(p, query);
SLV2Property result = slv2_query_get_results(results);
rasqal_free_query_results(results);
rasqal_finish();
-
+ free(query);
+
return result;
}
diff --git a/src/query.c b/src/query.c
index b8d279f..0517331 100644
--- a/src/query.c
+++ b/src/query.c
@@ -60,18 +60,10 @@ slv2_query_lang_filter(const char* variable)
rasqal_query_results*
slv2_plugin_run_query(const SLV2Plugin* p,
- const char* first, ...)
+ const char* query)
{
-
- /* FIXME: Too much unecessary allocation */
- char* header = slv2_query_header(p);
-
- va_list args_list;
- va_start(args_list, first);
-
- char* args_str = vstrjoin(first, args_list);
- char* query_str = strjoin(header, args_str, NULL);
- va_end(args_list);
+ char* header = slv2_query_header(p);
+ char* query_str = strjoin(header, query, NULL);
assert(p);
assert(query_str);
@@ -86,7 +78,6 @@ slv2_plugin_run_query(const SLV2Plugin* p,
rasqal_free_query(rq);
free(query_str);
- free(args_str);
free(header);
return results;
diff --git a/src/util.c b/src/util.c
index 99564eb..4f08e20 100644
--- a/src/util.c
+++ b/src/util.c
@@ -42,36 +42,37 @@ strappend(char** dst, const char* suffix)
char*
strjoin(const char* first, ...)
{
- va_list args_list;
- va_start(args_list, first);
-
- char* result = vstrjoin(first, args_list);
-
- va_end(args_list);
-
- return result;
-}
-
-
-char*
-vstrjoin(const char* first, va_list args_list)
-{
- // FIXME: this is horribly, awfully, disgracefully slow.
- // so I'm lazy.
-
- const char* arg = NULL;
- char* result = strdup(first);
+ size_t len = strlen(first);
+ char* result = NULL;
+ va_list args;
+
+ va_start(args, first);
+ while (1) {
+ const char* const s = va_arg(args, const char *);
+ if (s == NULL)
+ break;
+ len += strlen(s);
+ }
+ va_end(args);
+
+ result = malloc(len + 1);
+ if (!result)
+ return NULL;
- while ((arg = va_arg(args_list, const char*)) != NULL)
- strappend(&result, arg);
-
- //va_end(args_list);
+ strcpy(result, first);
+ va_start(args, first);
+ while (1) {
+ const char* const s = va_arg(args, const char *);
+ if (s == NULL)
+ break;
+ strcat(result, s);
+ }
+ va_end(args);
return result;
}
-
/** Convert a URL to a local filesystem path (ie by chopping off the
* leading "file://".
*
diff --git a/src/util.h b/src/util.h
index f4bdd7f..f3331b6 100644
--- a/src/util.h
+++ b/src/util.h
@@ -43,7 +43,7 @@ char*
strjoin(const char* first, ...);
char*
-vstrjoin(const char* first, va_list args_list);
+vstrjoin(const char** first, va_list args_list);
const char*
url2path(const char* const url);