slackbuilds_ponce/network/surf/patches/searchengines.diff
B. Watson 3a2d309b99
network/surf: Updated for version 2.1.
Signed-off-by: B. Watson <yalhcru@gmail.com>

Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
2021-10-29 17:07:19 +07:00

72 lines
2.2 KiB
Diff

diff -Naur surf-2.1/config.def.h surf-2.1.patched/config.def.h
--- surf-2.1/config.def.h 2021-05-09 18:34:33.000000000 -0400
+++ surf-2.1.patched/config.def.h 2021-10-20 02:51:08.497221512 -0400
@@ -179,6 +179,13 @@
{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, toggle, { .i = Style } },
};
+static SearchEngine searchengines[] = {
+ { "d", "https://duckduckgo.com/html/?q=%s" },
+ { "g", "https://www.google.com/search?q=%s" },
+ { "dict", "https://www.thefreedictionary.com/%s" },
+ { "sb", "https://slackbuilds.org/result/?search=%s&sv=@SLACKVER@" },
+};
+
/* button definitions */
/* target can be OnDoc, OnLink, OnImg, OnMedia, OnEdit, OnBar, OnSel, OnAny */
static Button buttons[] = {
diff -Naur surf-2.1/surf.c surf-2.1.patched/surf.c
--- surf-2.1/surf.c 2021-05-09 18:34:33.000000000 -0400
+++ surf-2.1.patched/surf.c 2021-10-20 02:53:48.600206958 -0400
@@ -130,6 +130,11 @@
} Button;
typedef struct {
+ char *token;
+ char *uri;
+} SearchEngine;
+
+typedef struct {
const char *uri;
Parameter config[ParameterLast];
regex_t re;
@@ -216,6 +221,7 @@
Client *c);
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);
@@ -576,7 +582,7 @@
url = g_strdup_printf("file://%s", path);
free(path);
} else {
- url = g_strdup_printf("http://%s", uri);
+ url = parseuri(uri);
}
if (apath != uri)
free(apath);
@@ -1776,6 +1782,22 @@
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)
{