From: Daniel Carl Date: Fri, 29 Mar 2013 11:24:29 +0000 (+0100) Subject: Fixed default search engine lookup without handle. X-Git-Url: https://git.owens.tech/assets/static/git-logo.png/assets/static/git-logo.png/git?a=commitdiff_plain;h=a164f85b3a0adb0fdd760a756ab5f3273db96cf7;p=vimb.git Fixed default search engine lookup without handle. To get the search handle the string after :open was split by space char. If only one term was given we skipped the lookup of the search engine so that it wasn't possible to search for a single term without a given search handle. --- diff --git a/src/main.c b/src/main.c index 4b88bb7..2576190 100644 --- a/src/main.c +++ b/src/main.c @@ -137,7 +137,6 @@ gboolean vb_eval_script(WebKitWebFrame* frame, char* script, char* file, char** gboolean vb_load_uri(const Arg* arg) { char* uri; - char* part; char* path = arg->s; struct stat st; @@ -154,18 +153,27 @@ gboolean vb_load_uri(const Arg* arg) 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); } diff --git a/src/searchengine.c b/src/searchengine.c index 9eb07cb..cabbc76 100644 --- a/src/searchengine.c +++ b/src/searchengine.c @@ -80,10 +80,10 @@ gboolean searchengine_set_default(const char* handle) 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;