sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

surf-0.5-searchengines.diff (1611B)


      1 --- surf.c	2012-10-26 17:58:18.912014914 +0200
      2 +++ surf.c	2012-10-27 15:54:06.332317229 +0200
      3 @@ -68,6 +68,11 @@
      4  
      5  G_DEFINE_TYPE(CookieJar, cookiejar, SOUP_TYPE_COOKIE_JAR_TEXT)
      6  
      7 +typedef struct {
      8 +	char *token;
      9 +	char *uri;
     10 +} SearchEngine;
     11 +
     12  static Display *dpy;
     13  static Atom atoms[AtomLast];
     14  static Client *clients = NULL;
     15 @@ -105,6 +110,7 @@
     16  static void navigate(Client *c, const Arg *arg);
     17  static Client *newclient(void);
     18  static void newwindow(Client *c, const Arg *arg, gboolean noembed);
     19 +static gchar *parseuri(const gchar *uri);
     20  static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
     21  static void populatepopup(WebKitWebView *web, GtkMenu *menu, Client *c);
     22  static void popupactivate(GtkMenuItem *menu, Client *);
     23 @@ -475,8 +481,7 @@
     24  
     25  	if(strcmp(uri, "") == 0)
     26  		return;
     27 -	u = g_strrstr(uri, "://") ? g_strdup(uri)
     28 -		: g_strdup_printf("http://%s", uri);
     29 +	u = parseuri(uri);
     30  	/* prevents endless loop */
     31  	if(c->uri && strcmp(u, c->uri) == 0) {
     32  		reload(c, &a);
     33 @@ -679,6 +684,19 @@
     34  	}
     35  }
     36  
     37 +
     38 +gchar *
     39 +parseuri(const gchar *uri) {
     40 +	guint i;
     41 +	for (i = 0; i < LENGTH(searchengines); i++) {
     42 +		if (searchengines[i].token == NULL || searchengines[i].uri == NULL || *(uri + strlen(searchengines[i].token)) != ' ')
     43 +			continue;
     44 +		if (g_str_has_prefix(uri, searchengines[i].token))
     45 +			return g_strdup_printf(searchengines[i].uri, uri + strlen(searchengines[i].token) + 1);
     46 +	}
     47 +	return g_strrstr(uri, "://") ? g_strdup(uri) : g_strdup_printf("http://%s", uri);
     48 +}
     49 +
     50  void
     51  pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) {
     52  	Arg arg = {.v = text };