summaryrefslogtreecommitdiff
path: root/network/surf/patches/searchengines.diff
blob: 97aa6a49221cc1f381d41404b4e59d459673052d (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
diff -Naur surf-0.6/config.def.h surf-0.6.patched/config.def.h
--- surf-0.6/config.def.h	2013-02-10 13:40:14.000000000 -0500
+++ surf-0.6.patched/config.def.h	2013-07-03 16:40:14.000000000 -0400
@@ -93,3 +93,10 @@
     { MODKEY|GDK_SHIFT_MASK,GDK_v,      toggle,     { .v = "enable-plugins" } },
 };
 
+static SearchEngine searchengines[] = {
+  { "d",        "https://duckduckgo.com/html/?q=%s"   },
+  { "g",        "https://www.google.com/search?q=%s"   },
+  { "dict",     "http://www.thefreedictionary.com/%s" },
+  { "sb",       "http://slackbuilds.org/result/?search=%s&sv=@SLACKVER@" },
+  { "sw",       "http://search.slackware.eu/cgi-bin/search.cgi?rm=search&needle=%s&haystack=2&sver=@SVER@&button-search=Search" },
+};
diff -Naur surf-0.6/surf.c surf-0.6.patched/surf.c
--- surf-0.6/surf.c	2013-02-10 13:40:14.000000000 -0500
+++ surf-0.6.patched/surf.c	2013-07-03 15:25:44.000000000 -0400
@@ -76,6 +76,11 @@
 
 G_DEFINE_TYPE(CookieJar, cookiejar, SOUP_TYPE_COOKIE_JAR_TEXT)
 
+typedef struct {
+	char *token;
+	char *uri;
+} SearchEngine;
+
 static Display *dpy;
 static Atom atoms[AtomLast];
 static Client *clients = NULL;
@@ -139,6 +144,7 @@
 static void navigate(Client *c, const Arg *arg);
 static Client *newclient(void);
 static void newwindow(Client *c, const Arg *arg, gboolean noembed);
+static gchar *parseuri(const gchar *uri);
 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
 static void populatepopup(WebKitWebView *web, GtkMenu *menu, Client *c);
 static void popupactivate(GtkMenuItem *menu, Client *);
@@ -627,8 +633,8 @@
 		u = g_strdup_printf("file://%s", rp);
 		free(rp);
 	} else {
-		u = g_strrstr(uri, "://") ? g_strdup(uri)
-			: g_strdup_printf("http://%s", uri);
+		u = parseuri(uri);
+
 	}
 
 	/* prevents endless loop */
@@ -893,6 +899,20 @@
 	}
 }
 
+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_strrstr(uri, "://") ? g_strdup(uri) : g_strdup_printf("http://%s", uri);
+}
+
 static void
 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) {
 	Arg arg = {.v = text };