Removed vstrjoin

git-svn-id: http://svn.drobilla.net/lad@105 a436a847-0d15-0410-975c-d299462d15a1
This commit is contained in:
dave 2006-07-26 18:53:15 +00:00
parent c587ccc926
commit 61768889c1
6 changed files with 49 additions and 50 deletions

View File

@ -76,16 +76,15 @@ slv2_query_lang_filter(const char* variable);
/** Run a SPARQL query on a plugin's data file.
*
* String arguments will be concatenated, allowing for variable substitution
* etc. (without having to define a token syntax and search the string for
* tokens, which would be slow).
* Header from slv2query_header will be prepended to passed query string (so
* the default prefixes will be already defined, you don't need to add them
* yourself).
*
* Header from slv2query_header will be prepended to passed query string.
* rasqal_init() must be called by the caller before calling this function.
*/
rasqal_query_results*
slv2_plugin_run_query(const SLV2Plugin* p,
const char* query_string, ...);
const char* query_string);
SLV2Property
slv2_query_get_results(rasqal_query_results* results);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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);
size_t len = strlen(first);
char* result = NULL;
va_list args;
va_end(args_list);
return result;
}
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;
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);
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://".
*

View File

@ -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);