applied search engine patch
authorDaniel Liu <mr.picklepinosaur@gmail.com>
Tue, 4 Aug 2020 02:18:51 +0000 (22:18 -0400)
committerDaniel Liu <mr.picklepinosaur@gmail.com>
Tue, 4 Aug 2020 02:18:51 +0000 (22:18 -0400)
surf.c

diff --git a/surf.c b/surf.c
index 2b54e3c..5ff13f0 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -128,6 +128,12 @@ typedef struct {
        unsigned int stopevent;
 } Button;
 
+
+typedef struct {
+   char *token;
+   char *uri;
+} SearchEngine;
+
 typedef struct {
        const char *uri;
        Parameter config[ParameterLast];
@@ -214,6 +220,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);
@@ -559,7 +566,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);
@@ -1765,6 +1772,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)
 {