comparison mcabber/src/hooks.c @ 1207:8f0af3b88cef

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.
author Mikael Berthe <mikael@lilotux.net>
date Sun, 29 Apr 2007 11:07:36 +0200
parents 2de8f8ba1f34
children 7c8672bbede5
comparison
equal deleted inserted replaced
1206:abc5847d1613 1207:8f0af3b88cef
121 if (nick) { 121 if (nick) {
122 // Let's see if we are the message sender, in which case we'll 122 // Let's see if we are the message sender, in which case we'll
123 // highlight it. 123 // highlight it.
124 if (resname && !strcmp(resname, nick)) { 124 if (resname && !strcmp(resname, nick)) {
125 message_flags |= HBB_PREFIX_HLIGHT_OUT; 125 message_flags |= HBB_PREFIX_HLIGHT_OUT;
126 } else { 126 } else if (!settings_opt_get_int("muc_disable_nick_hl")) {
127 // We're not the sender. Can we see our nick? 127 // We're not the sender. Can we see our nick?
128 if (startswith(msg, nick, TRUE)) { 128 const char *msgptr = msg;
129 // The message starts with our nick. Let's check it's not 129 while ((msgptr = strcasestr(msgptr, nick)) != NULL) {
130 // followed immediately by an alphnumeric character. 130 const char *leftb, *rightb;
131 if (!iswalnum(get_char(msg+strlen(nick)))) 131 // The message contains our nick. Let's check it's not
132 // in the middle of another word (i.e. preceded/followed
133 // immediately by an alphanumeric character or an underscore.
134 rightb = msgptr+strlen(nick);
135 if (msgptr == msg)
136 leftb = NULL;
137 else
138 leftb = prev_char((char*)msgptr, msg);
139 msgptr = next_char((char*)msgptr);
140 // Check left boundary
141 if (leftb && (iswalnum(get_char(leftb)) || get_char(leftb) == '_'))
142 continue;
143 // Check right boundary
144 if (!iswalnum(get_char(rightb)) && get_char(rightb) != '_')
132 message_flags |= HBB_PREFIX_HLIGHT; 145 message_flags |= HBB_PREFIX_HLIGHT;
133 } 146 }
134 // We could do a more global check...
135 } 147 }
136 } 148 }
137 } 149 }
138 } 150 }
139 151