sites

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

surf-0.1-searchengines.diff (1964B)


      1 diff -r fee97b4579f2 config.def.h
      2 --- a/config.def.h	Mon Sep 21 03:27:20 2009 +0200
      3 +++ b/config.def.h	Wed Sep 23 22:58:21 2009 +0200
      4 @@ -30,3 +30,6 @@
      5      { 0,                    GDK_Return, hideurl,    { 0 },          UrlBar },
      6  };
      7  
      8 +static SearchEngine searchengines[] = {
      9 +    { NULL, NULL },
     10 +};
     11 diff -r fee97b4579f2 surf.c
     12 --- a/surf.c	Mon Sep 21 03:27:20 2009 +0200
     13 +++ b/surf.c	Wed Sep 23 22:58:21 2009 +0200
     14 @@ -58,6 +58,11 @@
     15  	KeyFocus focus;
     16  } Key;
     17  
     18 +typedef struct {
     19 +    char *token;
     20 +    char *uri;
     21 +} SearchEngine;
     22 +
     23  static Display *dpy;
     24  static Atom urlprop;
     25  static SoupCookieJar *cookiejar;
     26 @@ -92,6 +97,7 @@
     27  static Client *newclient(void);
     28  static WebKitWebView *newwindow(WebKitWebView  *v, WebKitWebFrame *f, Client *c);
     29  static void pasteurl(GtkClipboard *clipboard, const gchar *text, gpointer d);
     30 +static gchar *parseuri(const gchar *uri);
     31  static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
     32  static void print(Client *c, const Arg *arg);
     33  static void proccookies(SoupMessage *m, Client *c);
     34 @@ -348,14 +354,25 @@
     35  	g_free(uri);
     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  loaduri(Client *c, const Arg *arg) {
     52  	gchar *u;
     53  	const gchar *uri = (gchar *)arg->v;
     54  	if(!uri)
     55  		uri = gtk_entry_get_text(GTK_ENTRY(c->urlbar));
     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);