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
70
71
72
73
74
|
diff -Naur surf-0.7/config.def.h surf-0.7.patched/config.def.h
--- surf-0.7/config.def.h 2015-12-19 09:59:30.000000000 -0500
+++ surf-0.7.patched/config.def.h 2017-01-21 22:05:50.709360322 -0500
@@ -129,6 +129,14 @@
{ MODKEY|GDK_SHIFT_MASK,GDK_g, togglegeolocation, { 0 } },
};
+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" },
+};
+
/* button definitions */
/* click can be ClkDoc, ClkLink, ClkImg, ClkMedia, ClkSel, ClkEdit, ClkAny */
static Button buttons[] = {
diff -Naur surf-0.7/surf.c surf-0.7.patched/surf.c
--- surf-0.7/surf.c 2015-12-19 09:59:30.000000000 -0500
+++ surf-0.7.patched/surf.c 2017-01-21 22:05:12.304360777 -0500
@@ -91,6 +91,12 @@
G_DEFINE_TYPE(CookieJar, cookiejar, SOUP_TYPE_COOKIE_JAR_TEXT)
typedef struct {
+ char *token;
+ char *uri;
+} SearchEngine;
+
+
+typedef struct {
char *regex;
char *style;
regex_t re;
@@ -178,6 +184,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 gboolean contextmenu(WebKitWebView *view, GtkWidget *menu,
WebKitHitTestResult *target, gboolean keyboard,
@@ -838,8 +845,7 @@
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);
}
setatom(c, AtomUri, uri);
@@ -1172,6 +1178,21 @@
}
}
+static 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);
+}
+
void
pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
{
|