surf

Mahdi's build of surf
git clone git://mahdi.pw/surf.git
Log | Files | Refs | README | LICENSE

surf-git-20170323-webkit2-searchengines.diff (1520B)


      1 diff --git a/surf.c b/surf.c
      2 index 93a1629..eb2af97 100644
      3 --- a/surf.c
      4 +++ b/surf.c
      5 @@ -129,6 +129,11 @@ typedef struct {
      6  } Button;
      7  
      8  typedef struct {
      9 +	char *token;
     10 +	char *uri;
     11 +} SearchEngine;
     12 +
     13 +typedef struct {
     14  	const char *uri;
     15  	Parameter config[ParameterLast];
     16  	regex_t re;
     17 @@ -202,6 +207,7 @@ static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
     18  static void download(Client *c, WebKitURIResponse *r);
     19  static void closeview(WebKitWebView *v, Client *c);
     20  static void destroywin(GtkWidget* w, Client *c);
     21 +static gchar *parseuri(const gchar *uri);
     22  
     23  /* Hotkeys */
     24  static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
     25 @@ -477,7 +483,7 @@ loaduri(Client *c, const Arg *a)
     26  		url = g_strdup_printf("file://%s", path);
     27  		free(path);
     28  	} else {
     29 -		url = g_strdup_printf("http://%s", uri);
     30 +		url = parseuri(uri);
     31  	}
     32  
     33  	setatom(c, AtomUri, url);
     34 @@ -1461,6 +1467,22 @@ destroywin(GtkWidget* w, Client *c)
     35  		gtk_main_quit();
     36  }
     37  
     38 +gchar *
     39 +parseuri(const gchar *uri) {
     40 +	guint i;
     41 +
     42 +	for (i = 0; i < LENGTH(searchengines); i++) {
     43 +		if (searchengines[i].token == NULL || searchengines[i].uri == NULL ||
     44 +		    *(uri + strlen(searchengines[i].token)) != ' ')
     45 +			continue;
     46 +		if (g_str_has_prefix(uri, searchengines[i].token))
     47 +			return g_strdup_printf(searchengines[i].uri,
     48 +					       uri + strlen(searchengines[i].token) + 1);
     49 +	}
     50 +
     51 +	return g_strdup_printf("http://%s", uri);
     52 +}
     53 +
     54  void
     55  pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
     56  {