sites

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

surf-0.3-searchengines.diff (2107B)


      1 diff -up surf-0.3/config.def.h surf-0.3-modified/config.def.h
      2 --- surf-0.3/config.def.h	2009-10-30 08:41:02.000000000 -0400
      3 +++ surf-0.3-modified/config.def.h	2009-12-04 10:44:48.000000000 -0500
      4 @@ -45,3 +45,7 @@ static Item items[] = {
      5      { "Copy URI",       clipboard, { .b = FALSE } },
      6      { "Download",       download,  { 0 } },
      7  };
      8 +
      9 +static SearchEngine searchengines[] = {
     10 +    { NULL, NULL },
     11 +};
     12 diff -up surf-0.3/surf.c surf-0.3-modified/surf.c
     13 --- surf-0.3/surf.c	2009-10-30 08:41:02.000000000 -0400
     14 +++ surf-0.3-modified/surf.c	2009-12-04 10:46:18.000000000 -0500
     15 @@ -54,6 +54,11 @@ typedef struct {
     16  	const Arg arg;
     17  } Key;
     18  
     19 +typedef struct {
     20 +	char *token;
     21 +	char *uri;
     22 +} SearchEngine;
     23 +
     24  static Display *dpy;
     25  static Atom uriprop, findprop;
     26  static SoupCookieJar *cookies;
     27 @@ -90,6 +95,7 @@ static gboolean keypress(GtkWidget *w, G
     28  static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c);
     29  static void loadcommit(WebKitWebView *v, WebKitWebFrame *f, Client *c);
     30  static void loadstart(WebKitWebView *v, WebKitWebFrame *f, Client *c);
     31 +static gchar *parseuri(const gchar *uri);
     32  static void loaduri(Client *c, const Arg *arg);
     33  static void navigate(Client *c, const Arg *arg);
     34  static Client *newclient(void);
     35 @@ -431,13 +437,24 @@ loadstart(WebKitWebView *view, WebKitWeb
     36  	reloadcookies();
     37  }
     38  
     39 +gchar *
     40 +parseuri(const gchar *uri) {
     41 +	guint i;
     42 +	for (i = 0; i < LENGTH(searchengines); i++) {
     43 +		if (searchengines[i].token == NULL || searchengines[i].uri == NULL || *(uri + strlen(searchengines[i].token)) != ' ')
     44 +			continue;
     45 +		if (g_str_has_prefix(uri, searchengines[i].token))
     46 +			return g_strdup_printf(searchengines[i].uri, uri + strlen(searchengines[i].token) + 1);
     47 +	}
     48 +	return g_strrstr(uri, "://") ? g_strdup(uri) : g_strdup_printf("http://%s", uri);
     49 +}
     50 +
     51  void
     52  loaduri(Client *c, const Arg *arg) {
     53  	char *u;
     54  	const char *uri = (char *)arg->v;
     55  
     56 -	u = g_strrstr(uri, "://") ? g_strdup(uri)
     57 -		: g_strdup_printf("http://%s", uri);
     58 +	u = parseuri(uri);
     59  	webkit_web_view_load_uri(c->view, u);
     60  	c->progress = 0;
     61  	c->title = copystr(&c->title, u);