gboolean vb_load_uri(const Arg* arg)
{
char* uri;
- char* part;
char* path = arg->s;
struct stat st;
if (stat(path, &st) == 0) {
char* rp = realpath(path, NULL);
uri = g_strdup_printf("file://%s", rp);
- } else if (!strchr(path, '.') && (part = strchr(path, ' '))) {
- /* look up for a searchengine */
- *part = '\0';
- char* search_uri = searchengine_get_uri(path);
- char* term = soup_uri_encode(part + 1, "&");
-
- if (search_uri) {
- uri = g_strdup_printf(search_uri, term);
+ } else if (!strchr(path, '.')) {
+ char* part = NULL;
+ char* tmpl = NULL;
+ char* query = NULL;
+
+ /* look up for a searchengine with handle */
+ if ((part = strchr(path, ' '))) {
+ *part = '\0';
+ tmpl = searchengine_get_uri(path);
+ query = soup_uri_encode(part + 1, "&");
+ } else {
+ tmpl = searchengine_get_uri(NULL);
+ query = soup_uri_encode(path, "&");
+ }
+
+ if (tmpl) {
+ uri = g_strdup_printf(tmpl, query);
} else {
uri = g_strrstr(path, "://") ? g_strdup(path) : g_strdup_printf("http://%s", path);
}
- g_free(term);
+ g_free(query);
} else {
uri = g_strrstr(path, "://") ? g_strdup(path) : g_strdup_printf("http://%s", path);
}
char* searchengine_get_uri(const char* handle)
{
- char* def = vb.behave.searchengine_default;
- GSList* l = searchengine_find(handle);
+ const char* def = vb.behave.searchengine_default;
+ GSList* l = NULL;
- if (l) {
+ if (handle && (l = searchengine_find(handle))) {
return ((Searchengine*)l->data)->uri;
} else if (def && (l = searchengine_find(def))) {
return ((Searchengine*)l->data)->uri;