summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/tree.c2
-rw-r--r--src/common/tree.h2
-rw-r--r--src/common/url.c470
-rw-r--r--src/common/url.h3
-rw-r--r--src/common/userlist.c2
-rw-r--r--src/common/userlist.h2
-rw-r--r--src/fe-gtk/fe-gtk.c2
-rw-r--r--src/fe-gtk/maingui.c65
-rw-r--r--src/fe-gtk/xtext.c123
-rw-r--r--src/fe-gtk/xtext.h4
10 files changed, 405 insertions, 270 deletions
diff --git a/src/common/tree.c b/src/common/tree.c
index 33fe1d41..715b0e56 100644
--- a/src/common/tree.c
+++ b/src/common/tree.c
@@ -142,7 +142,7 @@ mybsearch (const void *key, void **array, size_t nmemb,
 }
 
 void *
-tree_find (tree *t, void *key, tree_cmp_func *cmp, void *data, int *pos)
+tree_find (tree *t, const void *key, tree_cmp_func *cmp, void *data, int *pos)
 {
 	if (!t || !t->array)
 		return NULL;
diff --git a/src/common/tree.h b/src/common/tree.h
index 4a158052..ced8e425 100644
--- a/src/common/tree.h
+++ b/src/common/tree.h
@@ -8,7 +8,7 @@ typedef int (tree_traverse_func) (const void *key, void *data);
 
 tree *tree_new (tree_cmp_func *cmp, void *data);
 void tree_destroy (tree *t);
-void *tree_find (tree *t, void *key, tree_cmp_func *cmp, void *data, int *pos);
+void *tree_find (tree *t, const void *key, tree_cmp_func *cmp, void *data, int *pos);
 int tree_remove (tree *t, void *key, int *pos);
 void *tree_remove_at_pos (tree *t, int pos);
 void tree_foreach (tree *t, tree_traverse_func *func, void *data);
diff --git a/src/common/url.c b/src/common/url.c
index c5335859..0ee09988 100644
--- a/src/common/url.c
+++ b/src/common/url.c
@@ -32,6 +32,13 @@
 
 void *url_tree = NULL;
 GTree *url_btree = NULL;
+static int do_an_re (const char *word, int *start, int *end, int *type);
+static GRegex *re_url (void);
+static GRegex *re_host (void);
+static GRegex *re_email (void);
+static GRegex *re_nick (void);
+static GRegex *re_channel (void);
+static GRegex *re_path (void);
 
 
 static int
@@ -177,158 +184,39 @@ url_add (char *urltext, int len)
    keep it FAST! This new version was found to be almost 3x faster than
    2.4.4 release. */
 
+static int laststart = 0;
+static int lastend = 0;
+static int lasttype = 0;
+
 int
-url_check_word (const char *word, int len)
+url_check_word (const char *word)
 {
-#define D(x) (x), ((sizeof (x)) - 1)
-	static const struct {
-		const char *s;
-		int len;
-	}
-	prefix[] = {
-		{ D("irc.") },
-		{ D("ftp.") },
-		{ D("www.") },
-		{ D("irc://") },
-		{ D("ftp://") },
-		{ D("http://") },
-		{ D("https://") },
-		{ D("file://") },
-		{ D("rtsp://") },
-		{ D("ut2004://") },
-	},
-	suffix[] = {
-		{ D(".org") },
-		{ D(".net") },
-		{ D(".com") },
-		{ D(".edu") },
-		{ D(".html") },
-		{ D(".info") },
-		{ D(".name") },
-		/* Some extra common suffixes.
-		foo.blah/baz.php etc should work now, rather than
-		needing  http:// at the beginning. */
-		{ D(".php") },
-		{ D(".htm") },
-		{ D(".aero") },
-		{ D(".asia") },
-		{ D(".biz") },
-		{ D(".cat") },
-		{ D(".coop") },
-		{ D(".int") },
-		{ D(".jobs") },
-		{ D(".mobi") },
-		{ D(".museum") },
-		{ D(".pro") },
-		{ D(".tel") },
-		{ D(".travel") },
-		{ D(".xxx") },
-		{ D(".asp") },
-		{ D(".aspx") },
-		{ D(".shtml") },
-		{ D(".xml") },
-	};
-#undef D
-	const char *at, *dot;
-	int i, dots;
-
-	/* this is pretty much the same as in logmask_is_fullpath() except with length checks and .\ for portable mode */
-#ifdef WIN32
-	if ((len > 1 && word[0] == '\\') ||
-		(len > 2 && word[0] == '.' && word[1] == '\\') ||
-		(len > 2 && (((word[0] >= 'A' && word[0] <= 'Z') || (word[0] >= 'a' && word[0] <= 'z')) && word[1] == ':')))
-#else
-	if (len > 1 && word[0] == '/')
-#endif
-	{
-		return WORD_PATH;
-	}
-
-	if (len > 1 && word[1] == '#' && strchr("@+^%*#", word[0]))
-		return WORD_CHANNEL;
-
-	if ((word[0] == '#' || word[0] == '&') && word[1] != '#' && word[1] != 0)
-		return WORD_CHANNEL;
-
-	for (i = 0; i < G_N_ELEMENTS(prefix); i++)
-	{
-		int l;
-
-		l = prefix[i].len;
-		if (len > l)
-		{
-			int j;
-
-			/* This is pretty much g_ascii_strncasecmp(). */
-			for (j = 0; j < l; j++)
-			{
-				unsigned char c = word[j];
-				if (tolower(c) != prefix[i].s[j])
-					break;
-			}
-			if (j == l)
-				return WORD_URL;
-		}
-	}
-
-	at = strchr (word, '@');	  /* check for email addy */
-	dot = strrchr (word, '.');
-	if (at && dot)
-	{
-		if (at < dot)
-		{
-			if (strchr (word, '*'))
-				return WORD_HOST;
-			else
-				return WORD_EMAIL;
-		}
-	}
- 
-	/* check if it's an IP number */
-	dots = 0;
-	for (i = 0; i < len; i++)
-	{
-		if (word[i] == '.' && i > 0)
-			dots++;	/* allow 127.0.0.1:80 */
-		else if (!isdigit ((unsigned char) word[i]) && word[i] != ':')
-		{
-			dots = 0;
-			break;
-		}
-	}
-	if (dots == 3)
-		return WORD_HOST;
-
-	if (len > 5)
+	laststart = lastend = lasttype = 0;
+	if (do_an_re (word, &laststart, &lastend, &lasttype))
 	{
-		for (i = 0; i < G_N_ELEMENTS(suffix); i++)
+		switch (lasttype)
 		{
-			int l;
-
-			l = suffix[i].len;
-			if (len > l)
-			{
-				const unsigned char *p = &word[len - l];
-				int j;
-
-				/* This is pretty much g_ascii_strncasecmp(). */
-				for (j = 0; j < l; j++)
-				{
-					if (tolower(p[j]) != suffix[i].s[j])
-						break;
-				}
-				if (j == l)
-					return WORD_HOST;
-			}
+			case WORD_NICK:
+				if (!isalnum (word[laststart]))
+					laststart++;
+				if (!userlist_find (current_sess, &word[laststart]))
+					lasttype = 0;
+				return lasttype;
+			case WORD_EMAIL:
+				if (!isalnum (word[laststart]))
+					laststart++;
+				/* Fall through */
+			case WORD_URL:
+			case WORD_HOST:
+			case WORD_CHANNEL:
+			case WORD_PATH:
+				return lasttype;
+			default:
+				return 0;	/* Should not occur */
 		}
-
-		if (word[len - 3] == '.' &&
-			 isalpha ((unsigned char) word[len - 2]) &&
-				isalpha ((unsigned char) word[len - 1]))
-			return WORD_HOST;
 	}
-
-	return 0;
+	else
+		return 0;
 }
 
 /* List of IRC commands for which contents (and thus possible URLs)
@@ -346,9 +234,10 @@ static char *commands[] = {
 void
 url_check_line (char *buf, int len)
 {
+	GRegex *re(void);
+	GMatchInfo *gmi;
 	char *po = buf;
-	char *start;
-	int i, wlen;
+	int i;
 
 	/* Skip over message prefix */
 	if (*po == ':')
@@ -379,50 +268,255 @@ url_check_line (char *buf, int len)
 		return;
 	po++;
 
-	if (buf[0] == ':' && buf[1] != 0)
-		po++;
+	g_regex_match(re_url(), po, 0, &gmi);
+	while (g_match_info_matches(gmi))
+	{
+		int start, end;
+
+		g_match_info_fetch_pos(gmi, 0, &start, &end);
+		if (po[end - 1] == '\r')
+			po[--end] = 0;
+		if (g_strstr_len (po + start, end - start, "://"))
+			url_add(po + start, end - start);
+		g_match_info_next(gmi, NULL);
+	}
+	g_match_info_free(gmi);
+}
+
+int
+url_last (int *lstart, int *lend)
+{
+	*lstart = laststart;
+	*lend = lastend;
+	return lasttype;
+}
+
+static int
+do_an_re(const char *word,int *start, int *end, int *type)
+{
+	typedef struct func_s {
+		GRegex *(*fn)(void);
+		int type;
+	} func_t;
+	func_t funcs[] =
+	{
+		{ re_email, WORD_EMAIL },
+		{ re_url, WORD_URL },
+		{ re_host, WORD_HOST },
+		{ re_channel, WORD_CHANNEL },
+		{ re_path, WORD_PATH },
+		{ re_nick, WORD_NICK }
+	};
 
-	start = po;
+	GMatchInfo *gmi;
+	int k;
 
-	/* check each "word" (space separated) */
-	while (1)
+	for (k = 0; k < sizeof funcs / sizeof (func_t); k++)
 	{
-		switch (po[0])
+		g_regex_match (funcs[k].fn(), word, 0, &gmi);
+		if (!g_match_info_matches (gmi))
 		{
-		case 0:
-		case ' ':
-		case '\r':
-
-			wlen = po - start;
-			if (wlen > 2)
-			{
-				/* HACK! :( */
-				/* This is to work around not being able to detect URLs that are at
-				   the start of messages. */
-				if (start[0] == ':')
-				{
-					start++;
-					wlen--;
-				}
-				if (start[0] == '+' || start[0] == '-')
-				{
-					start++;
-					wlen--;
-				}
-
-				if (wlen > 2 && url_check_word (start, wlen) == WORD_URL)
-				{
-					url_add (start, wlen);
-				}
-			}
-			if (po[0] == 0)
-				return;
-			po++;
-			start = po;
-			break;
-
-		default:
-			po++;
+			g_match_info_free (gmi);
+			continue;
+		}
+		while (g_match_info_matches (gmi))
+		{
+			g_match_info_fetch_pos (gmi, 0, start, end);
+			g_match_info_next (gmi, NULL);
 		}
+		g_match_info_free (gmi);
+		*type = funcs[k].type;
+		return TRUE;
 	}
+
+	return FALSE;
+}
+
+/*	Miscellaneous description --- */
+#define DOMAIN "[-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+"
+#define IPADDR "[0-9]+(\\.[0-9]+){3}"
+#define HOST "(" DOMAIN "|" IPADDR ")"
+#define OPT_PORT "(:[1-9][0-9]{0,4})?"
+
+GRegex *
+make_re(char *grist, char *type)
+{
+	GRegex *ret;
+	GError *err = NULL;
+
+	ret = g_regex_new (grist, G_REGEX_CASELESS + G_REGEX_OPTIMIZE, 0, &err);
+	g_free (grist);
+	return ret;
+}
+
+/*	HOST description --- */
+/* (see miscellaneous above) */
+static GRegex *
+re_host (void)
+{
+	static GRegex *host_ret;
+	char *grist;
+	grist = g_strdup_printf (
+		"("	/* HOST */
+			HOST OPT_PORT
+		")"
+	);
+	host_ret = make_re (grist, "re_host");
+	return host_ret;
+}
+
+/*	URL description --- */
+#define SCHEME "(%s)"
+#define LPAR "\\("
+#define RPAR "\\)"
+#define NOPARENS "[^() \t]*"
+
+char *prefix[] = {
+	"irc\\.",
+	"ftp\\.",
+	"www\\.",
+	"irc://",
+	"ircs://",
+	"ftp://",
+	"http://",
+	"https://",
+	"file://",
+	"rtsp://",
+	NULL
+};
+
+static GRegex *
+re_url (void)
+{
+	static GRegex *url_ret;
+	char *grist;
+	char *scheme;
+
+	if (url_ret) return url_ret;
+
+	scheme = g_strjoinv ("|", prefix);
+	grist = g_strdup_printf (
+		"("	/* URL or HOST */
+			"("
+				SCHEME HOST OPT_PORT
+				"("	/* Optional "/path?query_string#fragment_id" */
+					"/"	/* Must start with slash */
+					"("	
+						"(" LPAR NOPARENS RPAR ")"
+						"|"
+						"(" NOPARENS ")"
+					")*"	/* Zero or more occurrences of either of these */
+					"(?<![.,?!\\]])"	/* Not allowed to end with these */
+				")?"	/* Zero or one of this /path?query_string#fragment_id thing */
+			")|("
+				HOST OPT_PORT "/"
+				"("	/* Optional "path?query_string#fragment_id" */
+					"("
+						"(" LPAR NOPARENS RPAR ")"
+						"|"
+						"(" NOPARENS ")"
+					")*"	/* Zero or more occurrences of either of these */
+					"(?<![.,?!\\]])"	/* Not allowed to end with these */
+				")?"	/* Zero or one of this /path?query_string#fragment_id thing */
+			")"
+		")"
+		, scheme
+	);
+	url_ret = make_re (grist, "re_url");
+	g_free (scheme);
+	return url_ret;
+}
+
+/*	EMAIL description --- */
+#define EMAIL "[a-z][-_a-z0-9]+@" "(" HOST ")"
+
+static GRegex *
+re_email (void)
+{
+	static GRegex *email_ret;
+	char *grist;
+
+	if (email_ret) return email_ret;
+
+	grist = g_strdup_printf (
+		"("	/* EMAIL */
+			EMAIL
+		")"
+	);
+	email_ret = make_re (grist, "re_email");
+	return email_ret;
+}
+
+/*	NICK description --- */
+#define NICKPRE "~+!@%%&"
+#define NICKHYP	"-"
+#define NICKLET "a-z"
+#define NICKDIG "0-9"
+/*	Note for NICKSPE:  \\\\ boils down to a single \ */
+#define NICKSPE	"\\[\\]\\\\`_^{|}"
+#define NICK0 "[" NICKPRE "]?[" NICKLET NICKSPE "]"
+#define NICK1 "[" NICKHYP NICKLET NICKDIG NICKSPE "]*"
+#define NICK	NICK0 NICK1
+
+static GRegex *
+re_nick (void)
+{
+	static GRegex *nick_ret;
+	char *grist;
+
+	if (nick_ret) return nick_ret;
+
+	grist = g_strdup_printf (
+		"("	/* NICK */
+			NICK
+		")"
+	);
+	nick_ret = make_re (grist, "re_nick");
+	return nick_ret;
+}
+
+/*	CHANNEL description --- */
+#define CHANNEL "#[^ \t\a,:]+"
+
+static GRegex *
+re_channel (void)
+{
+	static GRegex *channel_ret;
+	char *grist;
+
+	if (channel_ret) return channel_ret;
+
+	grist = g_strdup_printf (
+		"("	/* CHANNEL */
+			CHANNEL
+		")"
+	);
+	channel_ret = make_re (grist, "re_channel");
+	return channel_ret;
+}
+
+/*	PATH description --- */
+#ifdef WIN32
+/* Windows path can be \ or .\ or ..\ or e.g. C: etc */
+#define PATH "^(\\\\|\\.{1,2}\\\\|[a-z]:).*"
+#else
+/* Linux path can be / or ./ or ../ etc */
+#define PATH "^(/|\\./|\\.\\./).*"
+#endif
+
+static GRegex *
+re_path (void)
+{
+	static GRegex *path_ret;
+	char *grist;
+
+	if (path_ret) return path_ret;
+
+	grist = g_strdup_printf (
+		"("	/* PATH */
+			PATH
+		")"
+	);
+	path_ret = make_re (grist, "re_path");
+	return path_ret;
 }
diff --git a/src/common/url.h b/src/common/url.h
index 9a815fe1..b8e5c848 100644
--- a/src/common/url.h
+++ b/src/common/url.h
@@ -14,7 +14,8 @@ extern void *url_tree;
 
 void url_clear (void);
 void url_save_tree (const char *fname, const char *mode, gboolean fullpath);
-int url_check_word (const char *word, int len);
+int url_last (int *, int *);
+int url_check_word (const char *word);
 void url_check_line (char *buf, int len);
 
 #endif
diff --git a/src/common/userlist.c b/src/common/userlist.c
index f6a091a4..868f8a38 100644
--- a/src/common/userlist.c
+++ b/src/common/userlist.c
@@ -192,7 +192,7 @@ find_cmp (const char *name, struct User *user, server *serv)
 }
 
 struct User *
-userlist_find (struct session *sess, char *name)
+userlist_find (struct session *sess, const char *name)
 {
 	int pos;
 
diff --git a/src/common/userlist.h b/src/common/userlist.h
index 74ab4029..d0d79da8 100644
--- a/src/common/userlist.h
+++ b/src/common/userlist.h
@@ -26,7 +26,7 @@ int userlist_add_hostname (session *sess, char *nick,
 									char *hostname, char *realname,
 									char *servername, unsigned int away);
 void userlist_set_away (session *sess, char *nick, unsigned int away);
-struct User *userlist_find (session *sess, char *name);
+struct User *userlist_find (session *sess, const char *name);
 struct User *userlist_find_global (server *serv, char *name);
 void userlist_clear (session *sess);
 void userlist_free (session *sess);
diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c
index 9f6c439a..2767fc52 100644
--- a/src/fe-gtk/fe-gtk.c
+++ b/src/fe-gtk/fe-gtk.c
@@ -1059,7 +1059,7 @@ static void
 fe_open_url_locale (const char *url)
 {
 	/* the http:// part's missing, prepend it, otherwise it won't always work */
-	if (strchr (url, ':') == NULL && url_check_word (url, strlen (url)) != WORD_PATH)
+	if (strchr (url, ':') == NULL && url_check_word (url) != WORD_PATH)
 	{
 		url = g_strdup_printf ("http://%s", url);
 		fe_open_url_inner (url);
diff --git a/src/fe-gtk/maingui.c b/src/fe-gtk/maingui.c
index 388ca97d..fee8f320 100644
--- a/src/fe-gtk/maingui.c
+++ b/src/fe-gtk/maingui.c
@@ -2244,20 +2244,14 @@ mg_create_topicbar (session *sess, GtkWidget *box)
 /* check if a word is clickable */
 
 static int
-mg_word_check (GtkWidget * xtext, char *word, int len)
+mg_word_check (GtkWidget * xtext, char *word)
 {
 	session *sess = current_sess;
 	int ret;
 
-	ret = url_check_word (word, len);	/* common/url.c */
-	if (ret == 0)
-	{
-		if (( (word[0]=='@' || word[0]=='+' || word[0]=='%') && userlist_find (sess, word+1)) || userlist_find (sess, word))
-			return WORD_NICK;
-
-		if (sess->type == SESS_DIALOG)
-			return WORD_DIALOG;
-	}
+	ret = url_check_word (word);
+	if (ret == 0 && sess->type == SESS_DIALOG)
+		return WORD_DIALOG;
 
 	return ret;
 }
@@ -2268,23 +2262,28 @@ static void
 mg_word_clicked (GtkWidget *xtext, char *word, GdkEventButton *even)
 {
 	session *sess = current_sess;
+	int word_type, start, end;
+	char *tmp;
 
-	if (even->button == 1)			/* left button */
+	if (word == NULL)
 	{
-		if (word == NULL)
-		{
+		if (even->button == 1)		/* left button */
 			mg_focus (sess);
-			return;
-		}
+		return;
+	}
+
+	word_type = mg_word_check (xtext, word);
+	url_last (&start, &end);
 
-		if ((even->state & 13) == prefs.hex_gui_url_mod)
+	if (even->button == 1 && (even->state & 13) == prefs.hex_gui_url_mod)
+	{
+		switch (word_type)
 		{
-			switch (mg_word_check (xtext, word, strlen (word)))
-			{
-			case WORD_URL:
-			case WORD_HOST:
-				fe_open_url (word);
-			}
+		case WORD_URL:
+		case WORD_HOST:
+			word[end] = 0;
+			word += start;
+			fe_open_url (word);
 		}
 		return;
 	}
@@ -2298,7 +2297,7 @@ mg_word_clicked (GtkWidget *xtext, char *word, GdkEventButton *even)
 		return;
 	}
 
-	switch (mg_word_check (xtext, word, strlen (word)))
+	switch (word_type)
 	{
 	case 0:
 	case WORD_PATH:
@@ -2306,26 +2305,22 @@ mg_word_clicked (GtkWidget *xtext, char *word, GdkEventButton *even)
 		break;
 	case WORD_URL:
 	case WORD_HOST:
+		word[end] = 0;
+		word += start;
 		menu_urlmenu (even, word);
 		break;
 	case WORD_NICK:
-		menu_nickmenu (sess, even, (word[0]=='@' || word[0]=='+' || word[0]=='%') ?
-			word+1 : word, FALSE);
+		menu_nickmenu (sess, even, word + (ispunct (*word)? 1: 0), FALSE);
 		break;
 	case WORD_CHANNEL:
-		if (*word == '@' || *word == '+' || *word=='^' || *word=='%' || *word=='*')
-			word++;
 		menu_chanmenu (sess, even, word);
 		break;
 	case WORD_EMAIL:
-		{
-			char *newword = malloc (strlen (word) + 10);
-			if (*word == '~')
-				word++;
-			sprintf (newword, "mailto:%s", word);
-			menu_urlmenu (even, newword);
-			free (newword);
-		}
+		word[end] = 0;
+		word += start;
+		tmp = g_strdup_printf("mailto:%s", word + (ispunct (*word)? 1: 0));
+		menu_urlmenu (even, tmp);
+		g_free (tmp);
 		break;
 	case WORD_DIALOG:
 		menu_nickmenu (sess, even, sess->channel, FALSE);
diff --git a/src/fe-gtk/xtext.c b/src/fe-gtk/xtext.c
index e8419b5a..e2dc2b7c 100644
--- a/src/fe-gtk/xtext.c
+++ b/src/fe-gtk/xtext.c
@@ -73,6 +73,7 @@
 #include "../common/fe.h"
 #include "../common/util.h"
 #include "../common/hexchatc.h"
+#include "../common/url.h"
 #include "fe-gtk.h"
 #include "xtext.h"
 #include "fkeys.h"
@@ -1901,7 +1902,7 @@ gtk_xtext_selection_update (GtkXText * xtext, GdkEventMotion * event, int p_y, g
 
 static char *
 gtk_xtext_get_word (GtkXText * xtext, int x, int y, textentry ** ret_ent,
-						  int *ret_off, int *ret_len)
+						  int *ret_off, int *ret_len, GSList **slp)
 {
 	textentry *ent;
 	int offset;
@@ -1950,9 +1951,9 @@ gtk_xtext_get_word (GtkXText * xtext, int x, int y, textentry ** ret_ent,
 	if (ret_off)
 		*ret_off = word - ent->str;
 	if (ret_len)
-		*ret_len = str - word;
+		*ret_len = len;		/* Length before stripping */
 
-	return gtk_xtext_strip_color (word, len, xtext->scratch_buffer, NULL, NULL, NULL, FALSE);
+	return gtk_xtext_strip_color (word, len, xtext->scratch_buffer, NULL, NULL, slp, FALSE);
 }
 
 #ifdef MOTION_MONITOR
@@ -2028,14 +2029,62 @@ gtk_xtext_check_mark_stamp (GtkXText *xtext, GdkModifierType mask)
 	return redraw;
 }
 
+static int
+gtk_xtext_get_word_adjust (GtkXText *xtext, int x, int y, textentry **word_ent, int *offset, int *len)
+{
+	GSList *slp = NULL;
+	unsigned char *word;
+	int word_type = 0;
+
+	word = gtk_xtext_get_word (xtext, x, y, word_ent, offset, len, &slp);
+	if (word)
+	{
+		int laststart, lastend;
+
+		word_type = xtext->urlcheck_function (GTK_WIDGET (xtext), word);
+		if (word_type > 0)
+		{
+			if (url_last (&laststart, &lastend))
+			{
+				int cumlen, startadj = 0, endadj = 0;
+				offlen_t o;
+				GSList *sl;
+
+				for (sl = slp, cumlen = 0; sl; sl = g_slist_next (sl))
+				{
+					o.u = GPOINTER_TO_UINT (sl->data);
+					startadj = o.o.off - cumlen;
+					cumlen += o.o.len;
+					if (laststart < cumlen)
+						break;
+				}
+				for (sl = slp, cumlen = 0; sl; sl = g_slist_next (sl))
+				{
+					o.u = GPOINTER_TO_UINT (sl->data);
+					endadj = o.o.off - cumlen;
+					cumlen += o.o.len;
+					if (lastend < cumlen)
+						break;
+				}
+				laststart += startadj;
+				*offset += laststart;
+				*len = lastend + endadj - laststart;
+			}
+		}
+	}
+	g_slist_free (slp);
+
+	return word_type;
+}
+
 static gboolean
 gtk_xtext_motion_notify (GtkWidget * widget, GdkEventMotion * event)
 {
 	GtkXText *xtext = GTK_XTEXT (widget);
 	GdkModifierType mask;
 	int redraw, tmp, x, y, offset, len, line_x;
-	unsigned char *word;
 	textentry *word_ent;
+	int word_type;
 
 	gdk_window_get_pointer (widget->window, &x, &y, &mask);
 
@@ -2104,43 +2153,40 @@ gtk_xtext_motion_notify (GtkWidget * widget, GdkEventMotion * event)
 	if (xtext->urlcheck_function == NULL)
 		return FALSE;
 
-	word = gtk_xtext_get_word (xtext, x, y, &word_ent, &offset, &len);
-	if (word)
+	word_type = gtk_xtext_get_word_adjust (xtext, x, y, &word_ent, &offset, &len);
+	if (word_type > 0)
 	{
-		if (xtext->urlcheck_function (GTK_WIDGET (xtext), word, len) > 0)
+		if (!xtext->cursor_hand ||
+			 xtext->hilight_ent != word_ent ||
+			 xtext->hilight_start != offset ||
+			 xtext->hilight_end != offset + len)
 		{
-			if (!xtext->cursor_hand ||
-				 xtext->hilight_ent != word_ent ||
-				 xtext->hilight_start != offset ||
-				 xtext->hilight_end != offset + len)
+			if (!xtext->cursor_hand)
 			{
-				if (!xtext->cursor_hand)
-				{
-					gdk_window_set_cursor (GTK_WIDGET (xtext)->window,
-											  		xtext->hand_cursor);
-					xtext->cursor_hand = TRUE;
-				}
+				gdk_window_set_cursor (GTK_WIDGET (xtext)->window,
+										  		xtext->hand_cursor);
+				xtext->cursor_hand = TRUE;
+			}
 
-				/* un-render the old hilight */
-				if (xtext->hilight_ent)
-					gtk_xtext_unrender_hilight (xtext);
+			/* un-render the old hilight */
+			if (xtext->hilight_ent)
+				gtk_xtext_unrender_hilight (xtext);
 
-				xtext->hilight_ent = word_ent;
-				xtext->hilight_start = offset;
-				xtext->hilight_end = offset + len;
+			xtext->hilight_ent = word_ent;
+			xtext->hilight_start = offset;
+			xtext->hilight_end = offset + len;
 
-				xtext->skip_border_fills = TRUE;
-				xtext->render_hilights_only = TRUE;
-				xtext->skip_stamp = TRUE;
+			xtext->skip_border_fills = TRUE;
+			xtext->render_hilights_only = TRUE;
+			xtext->skip_stamp = TRUE;
 
-				gtk_xtext_render_ents (xtext, word_ent, NULL);
+			gtk_xtext_render_ents (xtext, word_ent, NULL);
 
-				xtext->skip_border_fills = FALSE;
-				xtext->render_hilights_only = FALSE;
-				xtext->skip_stamp = FALSE;
-			}
-			return FALSE;
+			xtext->skip_border_fills = FALSE;
+			xtext->render_hilights_only = FALSE;
+			xtext->skip_stamp = FALSE;
 		}
+		return FALSE;
 	}
 
 	gtk_xtext_leave_notify (widget, NULL);
@@ -2280,7 +2326,7 @@ gtk_xtext_button_release (GtkWidget * widget, GdkEventButton * event)
 
 		if (!xtext->hilighting)
 		{
-			word = gtk_xtext_get_word (xtext, event->x, event->y, 0, 0, 0);
+			word = gtk_xtext_get_word (xtext, event->x, event->y, 0, 0, 0, 0);
 			g_signal_emit (G_OBJECT (xtext), xtext_signals[WORD_CLICK], 0, word ? word : NULL, event);
 		} else
 		{
@@ -2288,7 +2334,6 @@ gtk_xtext_button_release (GtkWidget * widget, GdkEventButton * event)
 		}
 	}
 
-
 	return FALSE;
 }
 
@@ -2305,7 +2350,7 @@ gtk_xtext_button_press (GtkWidget * widget, GdkEventButton * event)
 
 	if (event->button == 3 || event->button == 2) /* right/middle click */
 	{
-		word = gtk_xtext_get_word (xtext, x, y, 0, 0, 0);
+		word = gtk_xtext_get_word (xtext, x, y, 0, 0, 0, 0);
 		if (word)
 		{
 			g_signal_emit (G_OBJECT (xtext), xtext_signals[WORD_CLICK], 0,
@@ -2322,7 +2367,7 @@ gtk_xtext_button_press (GtkWidget * widget, GdkEventButton * event)
 	if (event->type == GDK_2BUTTON_PRESS)	/* WORD select */
 	{
 		gtk_xtext_check_mark_stamp (xtext, mask);
-		if (gtk_xtext_get_word (xtext, x, y, &ent, &offset, &len))
+		if (gtk_xtext_get_word (xtext, x, y, &ent, &offset, &len, 0))
 		{
 			if (len == 0)
 				return FALSE;
@@ -2343,7 +2388,7 @@ gtk_xtext_button_press (GtkWidget * widget, GdkEventButton * event)
 	if (event->type == GDK_3BUTTON_PRESS)	/* LINE select */
 	{
 		gtk_xtext_check_mark_stamp (xtext, mask);
-		if (gtk_xtext_get_word (xtext, x, y, &ent, 0, 0))
+		if (gtk_xtext_get_word (xtext, x, y, &ent, 0, 0, 0))
 		{
 			gtk_xtext_selection_clear (xtext->buffer);
 			ent->mark_start = 0;
@@ -2852,7 +2897,7 @@ gtk_xtext_render_flush (GtkXText * xtext, int x, int y, unsigned char *str,
 {
 	int str_width, dofill;
 	GdkDrawable *pix = NULL;
-	int dest_x, dest_y;
+	int dest_x = 0, dest_y = 0;
 
 	if (xtext->dont_render || len < 1 || xtext->hidden)
 		return 0;
@@ -5904,7 +5949,7 @@ gtk_xtext_set_tint (GtkXText *xtext, int tint_red, int tint_green, int tint_blue
 }
 
 void
-gtk_xtext_set_urlcheck_function (GtkXText *xtext, int (*urlcheck_function) (GtkWidget *, char *, int))
+gtk_xtext_set_urlcheck_function (GtkXText *xtext, int (*urlcheck_function) (GtkWidget *, char *))
 {
 	xtext->urlcheck_function = urlcheck_function;
 }
diff --git a/src/fe-gtk/xtext.h b/src/fe-gtk/xtext.h
index 48c71d0c..cc6bbebb 100644
--- a/src/fe-gtk/xtext.h
+++ b/src/fe-gtk/xtext.h
@@ -179,7 +179,7 @@ struct _GtkXText
 	unsigned char scratch_buffer[4096];
 
 	void (*error_function) (int type);
-	int (*urlcheck_function) (GtkWidget * xtext, char *word, int len);
+	int (*urlcheck_function) (GtkWidget * xtext, char *word);
 
 	int jump_out_offset;	/* point at which to stop rendering */
 	int jump_in_offset;	/* "" start rendering */
@@ -274,7 +274,7 @@ void gtk_xtext_set_show_separator (GtkXText *xtext, gboolean show_separator);
 void gtk_xtext_set_thin_separator (GtkXText *xtext, gboolean thin_separator);
 void gtk_xtext_set_time_stamp (xtext_buffer *buf, gboolean timestamp);
 void gtk_xtext_set_tint (GtkXText *xtext, int tint_red, int tint_green, int tint_blue);
-void gtk_xtext_set_urlcheck_function (GtkXText *xtext, int (*urlcheck_function) (GtkWidget *, char *, int));
+void gtk_xtext_set_urlcheck_function (GtkXText *xtext, int (*urlcheck_function) (GtkWidget *, char *));
 void gtk_xtext_set_wordwrap (GtkXText *xtext, gboolean word_wrap);
 
 xtext_buffer *gtk_xtext_buffer_new (GtkXText *xtext);
' href='#n1632'>1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457