surf-0.7-webkit2-searchengines.diff (1749B)
1 diff --git a/surf.c b/surf.c 2 index 9b4dbb9..bf54d84 100644 3 --- a/surf.c 4 +++ b/surf.c 5 @@ -92,6 +92,12 @@ typedef struct { 6 } Button; 7 8 typedef struct { 9 + char *token; 10 + char *uri; 11 +} SearchEngine; 12 + 13 + 14 +typedef struct { 15 char *regex; 16 char *style; 17 regex_t re; 18 @@ -124,6 +130,7 @@ static void newwindow(Client *c, const Arg *a, int noembed); 19 static void spawn(Client *c, const Arg *a); 20 static void destroyclient(Client *c); 21 static void cleanup(void); 22 +static gchar *parseuri(const gchar *uri); 23 24 /* GTK/WebKit */ 25 static WebKitWebView *newview(Client *c, WebKitWebView *rv); 26 @@ -350,13 +357,13 @@ loaduri(Client *c, const Arg *a) 27 if (g_strcmp0(uri, "") == 0) 28 return; 29 30 - if (g_strrstr(uri, "://") || g_str_has_prefix(uri, "about:")) { 31 + if (g_str_has_prefix(uri, "about:")) { 32 url = g_strdup(uri); 33 } else if (!stat(uri, &st) && (path = realpath(uri, NULL))) { 34 url = g_strdup_printf("file://%s", path); 35 free(path); 36 } else { 37 - url = g_strdup_printf("http://%s", uri); 38 + url = parseuri(uri); 39 } 40 41 setatom(c, AtomUri, url); 42 @@ -1205,6 +1212,21 @@ destroywin(GtkWidget* w, Client *c) 43 gtk_main_quit(); 44 } 45 46 +static gchar * 47 +parseuri(const gchar *uri) { 48 + guint i; 49 + 50 + for (i = 0; i < LENGTH(searchengines); i++) { 51 + if (searchengines[i].token == NULL || searchengines[i].uri == NULL || \ 52 + *(uri + strlen(searchengines[i].token)) != ' ') 53 + continue; 54 + if (g_str_has_prefix(uri, searchengines[i].token)) 55 + return g_strdup_printf(searchengines[i].uri, uri + strlen(searchengines[i].token) + 1); 56 + } 57 + 58 + return g_strrstr(uri, "://") ? g_strdup(uri) : g_strdup_printf("http://%s", uri); 59 +} 60 + 61 void 62 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) 63 {