47 |
|
|
48 |
|
|
49 |
/* |
/* |
50 |
|
* irc_is_word_char: return 1 if given character is a "word character" |
51 |
|
*/ |
52 |
|
|
53 |
|
int |
54 |
|
irc_is_word_char (char c) |
55 |
|
{ |
56 |
|
if (isalnum (c)) |
57 |
|
return 1; |
58 |
|
|
59 |
|
switch (c) |
60 |
|
{ |
61 |
|
case '-': |
62 |
|
case '_': |
63 |
|
case '|': |
64 |
|
return 1; |
65 |
|
} |
66 |
|
|
67 |
|
/* not a 'word char' */ |
68 |
|
return 0; |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
/* |
73 |
* irc_is_highlight: returns 1 if given message contains highlight (with given nick |
* irc_is_highlight: returns 1 if given message contains highlight (with given nick |
74 |
* or at least one of string in "irc_higlight" setting |
* or at least one of string in "irc_higlight" setting) |
75 |
*/ |
*/ |
76 |
|
|
77 |
int |
int |
78 |
irc_is_highlight (char *message, char *nick) |
irc_is_highlight (char *message, char *nick) |
79 |
{ |
{ |
80 |
char *msg, *highlight, *pos, *pos_end; |
char *msg, *highlight, *match, *match_pre, *match_post, *msg_pos, *pos, *pos_end; |
81 |
int end, length; |
int end, length, startswith, endswith, wildcard_start, wildcard_end; |
82 |
|
|
83 |
/* empty message ? */ |
/* empty message ? */ |
84 |
if (!message || !message[0]) |
if (!message || !message[0]) |
85 |
return 0; |
return 0; |
86 |
|
|
87 |
/* highlight by nickname */ |
/* highlight by nickname */ |
88 |
if (strstr (message, nick)) |
match = strstr (message, nick); |
89 |
return 1; |
if (match) |
90 |
|
{ |
91 |
|
match_pre = match - 1; |
92 |
|
match_post = match + strlen(nick); |
93 |
|
startswith = ((match == message) || (!irc_is_word_char (match_pre[0]))); |
94 |
|
endswith = ((!match_post[0]) || (!irc_is_word_char (match_post[0]))); |
95 |
|
if (startswith && endswith) |
96 |
|
return 1; |
97 |
|
} |
98 |
|
|
99 |
/* no highlight by nickname and "irc_highlight" is empty */ |
/* no highlight by nickname and "irc_highlight" is empty */ |
100 |
if (!cfg_irc_highlight || !cfg_irc_highlight[0]) |
if (!cfg_irc_highlight || !cfg_irc_highlight[0]) |
111 |
pos = msg; |
pos = msg; |
112 |
while (pos[0]) |
while (pos[0]) |
113 |
{ |
{ |
114 |
if ((pos[0] >= 'A') && (pos[0] <= 'Z')) |
pos[0] = tolower (pos[0]); |
|
pos[0] += ('a' - 'A'); |
|
115 |
pos++; |
pos++; |
116 |
} |
} |
117 |
pos = highlight; |
pos = highlight; |
118 |
while (pos[0]) |
while (pos[0]) |
119 |
{ |
{ |
120 |
if ((pos[0] >= 'A') && (pos[0] <= 'Z')) |
pos[0] = tolower (pos[0]); |
|
pos[0] += ('a' - 'A'); |
|
121 |
pos++; |
pos++; |
122 |
} |
} |
123 |
|
|
144 |
pos_end[0] = '\0'; |
pos_end[0] = '\0'; |
145 |
if (length > 0) |
if (length > 0) |
146 |
{ |
{ |
147 |
|
if ((wildcard_start = (pos[0] == '*'))) |
148 |
|
{ |
149 |
|
pos++; |
150 |
|
length--; |
151 |
|
} |
152 |
|
if ((wildcard_end = (*(pos_end - 1) == '*'))) |
153 |
|
{ |
154 |
|
*(pos_end - 1) = '\0'; |
155 |
|
length--; |
156 |
|
} |
157 |
|
} |
158 |
|
|
159 |
|
if (length > 0) |
160 |
|
{ |
161 |
|
msg_pos = msg; |
162 |
/* highlight found! */ |
/* highlight found! */ |
163 |
if (strstr (msg, pos)) |
while ((match = strstr (msg_pos, pos)) != NULL) |
164 |
{ |
{ |
165 |
free (msg); |
match_pre = match - 1; |
166 |
free (highlight); |
match_post = match + length; |
167 |
return 1; |
startswith = ((match == msg) || (!irc_is_word_char (match_pre[0]))); |
168 |
|
endswith = ((!match_post[0]) || (!irc_is_word_char (match_post[0]))); |
169 |
|
if ((wildcard_start && wildcard_end) || |
170 |
|
(!wildcard_start && !wildcard_end && |
171 |
|
startswith && endswith) || |
172 |
|
(wildcard_start && endswith) || |
173 |
|
(wildcard_end && startswith)) |
174 |
|
{ |
175 |
|
free (msg); |
176 |
|
free (highlight); |
177 |
|
return 1; |
178 |
|
} |
179 |
|
msg_pos = match_post; |
180 |
} |
} |
181 |
} |
} |
182 |
|
|