diff options
-rw-r--r-- | dillorc | 2 | ||||
-rw-r--r-- | src/uicmd.cc | 33 |
2 files changed, 34 insertions, 1 deletions
@@ -146,7 +146,7 @@ # Format: search_url="[<label> ]<url>" # You can enable multiple search_url strings at once and select from among # them at runtime, with the first being the default. -search_url="http://duckduckgo.com/lite/?kp=-1&q=%s" +search_url="DuckDuckGo http://duckduckgo.com/lite/?kp=-1&q=%s" search_url="Wikipedia http://www.wikipedia.org/w/index.php?search=%s&go=Go" search_url="Free Dictionary http://www.thefreedictionary.com/%s" search_url="Google http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=%s" diff --git a/src/uicmd.cc b/src/uicmd.cc index e286ee9c..84e7e4cd 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -70,6 +70,7 @@ static const char *save_dir = ""; */ static BrowserWindow *UIcmd_tab_new(CustTabs *tabs, UI *old_ui, int focus); static void close_tab_btn_cb (Fl_Widget *w, void *cb_data); +static char *UIcmd_make_search_str(const char *str); //---------------------------------------------------------------------------- @@ -649,6 +650,33 @@ void a_UIcmd_close_all_bw(void *) } /* + * Return a search string of the suffix if str starts with a + * prefix of a search engine name and a blank + */ +static char *UIcmd_find_search_str(const char *str) +{ + int p; + char *url = NULL; + int len = strcspn(str, " "); + + if (len > 0 && str[len] != '\0') { + /* we found a ' ' in str, check whether the first part of str + * is a prefix of a search_url label + */ + for (p = 0; p < dList_length(prefs.search_urls); p++) { + const char *search = + (const char *)dList_nth_data(prefs.search_urls, p); + if (strncasecmp(str, search, len) == 0) { + prefs.search_url_idx = p; + url = UIcmd_make_search_str(str + len + 1); + break; + } + } + } + return url; +} + +/* * Open a new URL in the given browser window. * * our custom "file:" URIs are normalized here too. @@ -656,10 +684,14 @@ void a_UIcmd_close_all_bw(void *) void a_UIcmd_open_urlstr(void *vbw, const char *urlstr) { char *new_urlstr; + char *search_urlstr = NULL; DilloUrl *url; int ch; BrowserWindow *bw = (BrowserWindow*)vbw; + if ((search_urlstr = UIcmd_find_search_str(urlstr))) { + urlstr = search_urlstr; + } if (urlstr && *urlstr) { /* Filter URL string */ new_urlstr = a_Url_string_strip_delimiters(urlstr); @@ -686,6 +718,7 @@ void a_UIcmd_open_urlstr(void *vbw, const char *urlstr) a_Url_free(url); } } + dFree(search_urlstr); } /* |