Hi,
I've included a patch which allows "hilight" to be ircnet specific.
Feed-back would be appreciated since this is my first irssi patch :)

Ragards,
Jesper B. Rosenkilde
--- irssi-orig/src/fe-common/core/hilight-text.h	2004-10-06 18:25:34.000000000 +0200
+++ irssi/src/fe-common/core/hilight-text.h	2005-06-09 06:03:04.079968320 +0200
@@ -13,6 +13,7 @@
 	char *text;
 
 	char **channels; /* if non-NULL, check the text only from these channels */
+	char **ircnets; /* if non-NULL, check the text only from these ircnets */
 	int level; /* match only messages with this level, 0=default */
 	char *color; /* if starts with number, \003 is automatically
 	                inserted before it. */
--- irssi-orig/src/fe-common/core/hilight-text.c	2004-10-06 18:25:34.000000000 +0200
+++ irssi/src/fe-common/core/hilight-text.c	2005-06-09 06:25:02.956468616 +0200
@@ -57,7 +57,7 @@
 
 static void hilight_add_config(HILIGHT_REC *rec)
 {
-	CONFIG_NODE *node;
+	CONFIG_NODE *node, *node_temp;
 
 	g_return_if_fail(rec != NULL);
 
@@ -76,8 +76,13 @@
         if (rec->regexp) iconfig_node_set_bool(node, "regexp", TRUE);
 
 	if (rec->channels != NULL && *rec->channels != NULL) {
-		node = config_node_section(node, "channels", NODE_TYPE_LIST);
-		iconfig_node_add_list(node, rec->channels);
+		node_temp = config_node_section(node, "channels", NODE_TYPE_LIST);
+		iconfig_node_add_list(node_temp, rec->channels);
+	}
+	
+	if (rec->ircnets != NULL && *rec->ircnets != NULL) {
+	        node_temp = config_node_section(node, "ircnets", NODE_TYPE_LIST);
+		iconfig_node_add_list(node_temp, rec->ircnets);
 	}
 }
 
@@ -99,6 +104,7 @@
 	if (rec->regexp_compiled) regfree(&rec->preg);
 #endif
 	if (rec->channels != NULL) g_strfreev(rec->channels);
+	if (rec->ircnets != NULL) g_strfreev(rec->ircnets);
 	g_free_not_null(rec->color);
 	g_free_not_null(rec->act_color);
 	g_free(rec->text);
@@ -147,11 +153,11 @@
 	hilight_destroy(rec);
 }
 
-static HILIGHT_REC *hilight_find(const char *text, char **channels)
+static HILIGHT_REC *hilight_find(const char *text, char **channels, char **ircnets)
 {
 	GSList *tmp;
-	char **chan;
-
+	char **chan, **ircn;
+	
 	g_return_val_if_fail(text != NULL, NULL);
 
 	for (tmp = hilights; tmp != NULL; tmp = tmp->next) {
@@ -160,26 +166,45 @@
 		if (g_strcasecmp(rec->text, text) != 0)
 			continue;
 
-		if ((channels == NULL && rec->channels == NULL))
-			return rec; /* no channels - ok */
-
-		if (channels != NULL && strcmp(*channels, "*") == 0)
-			return rec; /* ignore channels */
+		if ((channels == NULL && rec->channels == NULL) && (ircnets == NULL && rec->channels == NULL))
+			return rec; /* no channels or ircnets - ok */
 
-		if (channels == NULL || rec->channels == NULL)
-			continue; /* other doesn't have channels */
+		if ((channels != NULL && strcmp(*channels, "*") == 0) && (ircnets != NULL && strcmp(*ircnets, "*") == 0))
+			return rec; /* ignore channels and ircnets */
 
-		if (strarray_length(channels) != strarray_length(rec->channels))
-			continue; /* different amount of channels */
-
-		/* check that channels match */
-		for (chan = channels; *chan != NULL; chan++) {
-			if (strarray_find(rec->channels, *chan) == -1)
-                                break;
+		if (channels) {
+			if  ((rec->channels != NULL) ||
+			   (strarray_length(channels) == strarray_length(rec->channels))) {
+				for (chan = channels; *chan != NULL; chan++) {
+					if (strarray_find(rec->channels, *chan) == -1)
+						break; /* a channel didn't match - break */
+				}
+			}
+		}
+		
+		if (ircnets) {
+			if ((rec->ircnets != NULL) || 
+			    (strarray_length(ircnets) == strarray_length(rec->ircnets))) {
+				for (ircn = ircnets; *ircn != NULL; ircn++) {
+					if (strarray_find(rec->ircnets, *ircn) == -1)
+						break; /* no ircnet match - break */
+				}
+			} else
+				continue;
 		}
 
-		if (*chan == NULL)
-			return rec; /* channels ok */
+		if (channels && ircnets) {
+			if (*chan == NULL && *ircn == NULL)
+				return rec; /* channels and ircnets ok */
+		} 
+		else if (channels && !ircnets) {
+			if (*chan == NULL) 
+				return rec; /* channels ok */
+		}
+		else if (!channels && ircnets) {
+			if(*ircn == NULL)
+				return rec; /* ircnets ok */
+		}
 	}
 
 	return NULL;
@@ -227,6 +252,10 @@
 	((rec)->channels == NULL || ((channel) != NULL && \
 		strarray_find((rec)->channels, (channel)) != -1))
 
+#define hilight_match_ircnet(rec, ircnet) \
+        ((rec)->ircnets == NULL || ((ircnet) != NULL && \
+                strarray_find((rec)->ircnets, (ircnet)) != -1))
+
 HILIGHT_REC *hilight_match(SERVER_REC *server, const char *channel,
 			   const char *nick, const char *address,
 			   int level, const char *str,
@@ -235,6 +264,7 @@
 	GSList *tmp;
         CHANNEL_REC *chanrec;
 	NICK_REC *nickrec;
+	char *ircnet;
 
 	g_return_val_if_fail(str != NULL, NULL);
 
@@ -258,11 +288,14 @@
 		}
 	}
 
+	ircnet = server != NULL ? server->tag : NULL;
+
 	for (tmp = hilights; tmp != NULL; tmp = tmp->next) {
 		HILIGHT_REC *rec = tmp->data;
 
 		if (!rec->nickmask && hilight_match_level(rec, level) &&
 		    hilight_match_channel(rec, channel) &&
+		    hilight_match_ircnet(rec, ircnet) &&
 		    hilight_match_text(rec, str, match_beg, match_end))
 			return rec;
 	}
@@ -413,7 +446,7 @@
 
 static void read_hilight_config(void)
 {
-	CONFIG_NODE *node;
+	CONFIG_NODE *node, *node_tmp;
 	HILIGHT_REC *rec;
 	GSList *tmp;
 	char *text, *color;
@@ -461,8 +494,11 @@
 
 		hilight_init_rec(rec);
 
-		node = config_node_section(node, "channels", -1);
-		if (node != NULL) rec->channels = config_node_get_list(node);
+		node_tmp = config_node_section(node, "channels", -1);
+		if (node_tmp != NULL) rec->channels = config_node_get_list(node_tmp);
+
+		node_tmp = config_node_section(node, "ircnets", -1);
+		if (node_tmp != NULL) rec->ircnets = config_node_get_list(node_tmp);
 	}
 
         reset_cache();
@@ -470,7 +506,7 @@
 
 static void hilight_print(int index, HILIGHT_REC *rec)
 {
-	char *chans, *levelstr;
+	char *chans, *ircn, *levelstr;
 	GString *options;
 
 	options = g_string_new(NULL);
@@ -498,14 +534,18 @@
 
 	chans = rec->channels == NULL ? NULL :
 		g_strjoinv(",", rec->channels);
+	ircn = rec->ircnets == NULL ? NULL :
+		g_strjoinv(",", rec->ircnets);
 	levelstr = rec->level == 0 ? NULL :
 		bits2level(rec->level);
 	printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
 		    TXT_HILIGHT_LINE, index, rec->text,
+		    ircn != NULL ? ircn : "",
 		    chans != NULL ? chans : "",
 		    levelstr != NULL ? levelstr : "",
 		    options->str);
 	g_free_not_null(chans);
+	g_free_not_null(ircn);
 	g_free_not_null(levelstr);
 	g_string_free(options, TRUE);
 }
@@ -527,13 +567,15 @@
 
 /* SYNTAX: HILIGHT [-nick | -word | -line] [-mask | -full | -regexp]
                    [-color <color>] [-actcolor <color>] [-level <level>]
-		   [-channels <channels>] <text> */
+		   [-channels <channels>] [-ircnets <ircnets>] <text> */
 static void cmd_hilight(const char *data)
 {
         GHashTable *optlist;
 	HILIGHT_REC *rec;
-	char *colorarg, *actcolorarg, *levelarg, *priorityarg, *chanarg, *text;
+	char *colorarg, *actcolorarg, *levelarg, *priorityarg, *chanarg, 
+	     *ircnetarg,*text;
 	char **channels;
+	char **ircnets;
 	void *free_arg;
 
 	g_return_if_fail(data != NULL);
@@ -548,6 +590,7 @@
 		return;
 
 	chanarg = g_hash_table_lookup(optlist, "channels");
+	ircnetarg = g_hash_table_lookup(optlist, "ircnets");
 	levelarg = g_hash_table_lookup(optlist, "level");
 	priorityarg = g_hash_table_lookup(optlist, "priority");
 	colorarg = g_hash_table_lookup(optlist, "color");
@@ -558,7 +601,11 @@
 	channels = (chanarg == NULL || *chanarg == '\0') ? NULL :
 		g_strsplit(replace_chars(chanarg, ',', ' '), " ", -1);
 
-	rec = hilight_find(text, channels);
+	ircnets = (ircnetarg == NULL || *ircnetarg == '\0') ? NULL :
+		g_strsplit(replace_chars(ircnetarg, ',', ' '), " ", -1);
+
+
+	rec = hilight_find(text, channels, ircnets);
 	if (rec == NULL) {
 		rec = g_new0(HILIGHT_REC, 1);
 
@@ -568,8 +615,10 @@
 
 		rec->text = g_strdup(text);
 		rec->channels = channels;
+		rec->ircnets = ircnets;
 	} else {
 		g_strfreev(channels);
+		g_strfreev(ircnets);
 	}
 
 	rec->level = (levelarg == NULL || *levelarg == '\0') ? 0 :
@@ -625,7 +674,8 @@
 	} else {
 		/* with mask */
 		char *chans[2] = { "*", NULL };
-                rec = hilight_find(data, chans);
+		char *ircnets[2] = { "*", NULL };
+                rec = hilight_find(data, chans, ircnets);
 	}
 
 	if (rec == NULL)
@@ -692,7 +742,7 @@
 
 	command_bind("hilight", NULL, (SIGNAL_FUNC) cmd_hilight);
 	command_bind("dehilight", NULL, (SIGNAL_FUNC) cmd_dehilight);
-	command_set_options("hilight", "-color -actcolor -level -priority -channels nick word line mask full regexp");
+	command_set_options("hilight", "-color -actcolor -level -priority -channels -ircnets nick word line mask full regexp");
 }
 
 void hilight_text_deinit(void)

Reply via email to