# HG changeset patch # User Mikael Berthe # Date 1177837656 -7200 # Node ID 8f0af3b88cef0699699490e89c9c22855bb03df6 # Parent abc5847d161386c28d69e277a4504bb4f3196d08 MUC: improve nickname detection and add option 'muc_disable_nick_hl' The nickname is recognized anywhere in the message, not only at the beginning. Line highlighting can be disabled with the new option. diff -r abc5847d1613 -r 8f0af3b88cef mcabber/mcabberrc.example --- a/mcabber/mcabberrc.example Sat Apr 28 22:30:13 2007 +0200 +++ b/mcabber/mcabberrc.example Sun Apr 29 11:07:36 2007 +0200 @@ -212,6 +212,10 @@ # Set 'muc_auto_whois' to 1 if you want to call /room whois each time # somebody joins a room. (default: 0) #set muc_auto_whois = 0 +# +# Set 'muc_disable_nick_hl' to 1 if you don't want mcabber to color lines +# containing your nickname in a MUC room. +#set muc_disable_nick_hl = 0 # Status messages # The "message" value will override all others, take care! diff -r abc5847d1613 -r 8f0af3b88cef mcabber/src/hooks.c --- a/mcabber/src/hooks.c Sat Apr 28 22:30:13 2007 +0200 +++ b/mcabber/src/hooks.c Sun Apr 29 11:07:36 2007 +0200 @@ -123,15 +123,27 @@ // highlight it. if (resname && !strcmp(resname, nick)) { message_flags |= HBB_PREFIX_HLIGHT_OUT; - } else { + } else if (!settings_opt_get_int("muc_disable_nick_hl")) { // We're not the sender. Can we see our nick? - if (startswith(msg, nick, TRUE)) { - // The message starts with our nick. Let's check it's not - // followed immediately by an alphnumeric character. - if (!iswalnum(get_char(msg+strlen(nick)))) + const char *msgptr = msg; + while ((msgptr = strcasestr(msgptr, nick)) != NULL) { + const char *leftb, *rightb; + // The message contains our nick. Let's check it's not + // in the middle of another word (i.e. preceded/followed + // immediately by an alphanumeric character or an underscore. + rightb = msgptr+strlen(nick); + if (msgptr == msg) + leftb = NULL; + else + leftb = prev_char((char*)msgptr, msg); + msgptr = next_char((char*)msgptr); + // Check left boundary + if (leftb && (iswalnum(get_char(leftb)) || get_char(leftb) == '_')) + continue; + // Check right boundary + if (!iswalnum(get_char(rightb)) && get_char(rightb) != '_') message_flags |= HBB_PREFIX_HLIGHT; } - // We could do a more global check... } } }