aboutsummaryrefslogtreecommitdiff
path: root/surf/patches/surf-git-20170323-webkit2-searchengines.diff
blob: a8de97c57110481499fa521025f91848c3f81b1d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
diff --git a/surf.c b/surf.c
index 93a1629..eb2af97 100644
--- a/surf.c
+++ b/surf.c
@@ -129,6 +129,11 @@ typedef struct {
 } Button;
 
 typedef struct {
+	char *token;
+	char *uri;
+} SearchEngine;
+
+typedef struct {
 	const char *uri;
 	Parameter config[ParameterLast];
 	regex_t re;
@@ -202,6 +207,7 @@ static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
 static void download(Client *c, WebKitURIResponse *r);
 static void closeview(WebKitWebView *v, Client *c);
 static void destroywin(GtkWidget* w, Client *c);
+static gchar *parseuri(const gchar *uri);
 
 /* Hotkeys */
 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
@@ -477,7 +483,7 @@ loaduri(Client *c, const Arg *a)
 		url = g_strdup_printf("file://%s", path);
 		free(path);
 	} else {
-		url = g_strdup_printf("http://%s", uri);
+		url = parseuri(uri);
 	}
 
 	setatom(c, AtomUri, url);
@@ -1461,6 +1467,22 @@ destroywin(GtkWidget* w, Client *c)
 		gtk_main_quit();
 }
 
+gchar *
+parseuri(const gchar *uri) {
+	guint i;
+
+	for (i = 0; i < LENGTH(searchengines); i++) {
+		if (searchengines[i].token == NULL || searchengines[i].uri == NULL ||
+		    *(uri + strlen(searchengines[i].token)) != ' ')
+			continue;
+		if (g_str_has_prefix(uri, searchengines[i].token))
+			return g_strdup_printf(searchengines[i].uri,
+					       uri + strlen(searchengines[i].token) + 1);
+	}
+
+	return g_strdup_printf("http://%s", uri);
+}
+
 void
 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
 {