From c52e6bfc2a9df4ee17d10664e78850f4378629cf Mon Sep 17 00:00:00 2001 From: tsxv478 Date: Tue, 27 Sep 2022 11:43:58 +0300 Subject: search engines --- config.def.h | 5 +++++ surf.c | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 93cfeeb..a9fed5c 100644 --- a/config.def.h +++ b/config.def.h @@ -7,6 +7,11 @@ static char *certdir = "~/.surf/certificates/"; static char *cachedir = "~/.surf/cache/"; static char *cookiefile = "~/.surf/cookies.txt"; +static SearchEngine searchengines[] = { + { " ", "https://duckduckgo.com/?q=%s" }, + { "osrs ", "https://oldschool.runescape.wiki/?search=%s" }, +}; + /* Webkit default features */ /* Highest priority value will be used. * Default parameters are priority 0 diff --git a/surf.c b/surf.c index 474c01b..2c67a2e 100644 --- a/surf.c +++ b/surf.c @@ -132,6 +132,11 @@ typedef struct { unsigned int stopevent; } Button; +typedef struct { + char *token; + char *uri; +} SearchEngine; + typedef struct { const char *uri; Parameter config[ParameterLast]; @@ -219,6 +224,7 @@ static void webprocessterminated(WebKitWebView *v, 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); @@ -581,7 +587,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); } if (apath != uri) free(apath); @@ -1792,6 +1798,20 @@ destroywin(GtkWidget* w, Client *c) gtk_main_quit(); } +gchar * +parseuri(const gchar *uri) +{ + guint i; + + for (i = 0; i < LENGTH(searchengines); i++) { + if (g_str_has_prefix(uri, searchengines[i].token)) + return g_strdup_printf(searchengines[i].uri, + uri + strlen(searchengines[i].token)); + } + + return g_strdup_printf("http://%s", uri); +} + void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) { -- cgit v1.2.3