1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-02 15:53:12 +02:00

Added partial match for highlights, patch by Jim Ramsay

This commit is contained in:
Sebastien Helleu
2005-10-26 23:15:38 +00:00
parent 9d52621c44
commit b86c95e7dc
14 changed files with 2086 additions and 1964 deletions
+2 -1
View File
@@ -1,10 +1,11 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
ChangeLog - 2005-10-22
ChangeLog - 2005-10-27
Version 0.1.6 (under dev!):
* added partial match for highlights
* added dcc_own_ip and dcc_port_range settings
* full UTF-8 support, auto-detection of UTF-8 usage (locale)
* added "Day changed to [date]" message when day changes
+242 -240
View File
File diff suppressed because it is too large Load Diff
+241 -240
View File
File diff suppressed because it is too large Load Diff
+243 -244
View File
File diff suppressed because it is too large Load Diff
+243 -242
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -665,7 +665,8 @@ t_config_option weechat_options_irc[] =
OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE,
NULL, NULL, &cfg_irc_fifo_pipe, NULL, &config_change_fifo_pipe },
{ "irc_highlight", N_("list of words to highlight"),
N_("comma separated list of words to highlight (case insensitive comparison)"),
N_("comma separated list of words to highlight (case insensitive comparison, "
"words may begin or end with \"*\" for partial match)"),
OPTION_TYPE_STRING, 0, 0, 0,
"", NULL, NULL, &cfg_irc_highlight, &config_change_noop },
{ NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
+70 -14
View File
@@ -46,24 +46,55 @@
int command_ignored;
/*
* irc_is_word_char: return 1 if given character is a "word character"
*/
int
irc_is_word_char (char c)
{
if (isalnum (c))
return 1;
switch (c)
{
case '-':
case '_':
case '|':
return 1;
}
/* not a 'word char' */
return 0;
}
/*
* irc_is_highlight: returns 1 if given message contains highlight (with given nick
* or at least one of string in "irc_higlight" setting
* or at least one of string in "irc_higlight" setting)
*/
int
irc_is_highlight (char *message, char *nick)
{
char *msg, *highlight, *pos, *pos_end;
int end, length;
char *msg, *highlight, *match, *match_pre, *match_post, *msg_pos, *pos, *pos_end;
int end, length, startswith, endswith, wildcard_start, wildcard_end;
/* empty message ? */
if (!message || !message[0])
return 0;
/* highlight by nickname */
if (strstr (message, nick))
return 1;
match = strstr (message, nick);
if (match)
{
match_pre = match - 1;
match_post = match + strlen(nick);
startswith = ((match == message) || (!irc_is_word_char (match_pre[0])));
endswith = ((!match_post[0]) || (!irc_is_word_char (match_post[0])));
if (startswith && endswith)
return 1;
}
/* no highlight by nickname and "irc_highlight" is empty */
if (!cfg_irc_highlight || !cfg_irc_highlight[0])
@@ -80,15 +111,13 @@ irc_is_highlight (char *message, char *nick)
pos = msg;
while (pos[0])
{
if ((pos[0] >= 'A') && (pos[0] <= 'Z'))
pos[0] += ('a' - 'A');
pos[0] = tolower (pos[0]);
pos++;
}
pos = highlight;
while (pos[0])
{
if ((pos[0] >= 'A') && (pos[0] <= 'Z'))
pos[0] += ('a' - 'A');
pos[0] = tolower (pos[0]);
pos++;
}
@@ -115,12 +144,39 @@ irc_is_highlight (char *message, char *nick)
pos_end[0] = '\0';
if (length > 0)
{
/* highlight found! */
if (strstr (msg, pos))
if ((wildcard_start = (pos[0] == '*')))
{
free (msg);
free (highlight);
return 1;
pos++;
length--;
}
if ((wildcard_end = (*(pos_end - 1) == '*')))
{
*(pos_end - 1) = '\0';
length--;
}
}
if (length > 0)
{
msg_pos = msg;
/* highlight found! */
while ((match = strstr (msg_pos, pos)) != NULL)
{
match_pre = match - 1;
match_post = match + length;
startswith = ((match == msg) || (!irc_is_word_char (match_pre[0])));
endswith = ((!match_post[0]) || (!irc_is_word_char (match_post[0])));
if ((wildcard_start && wildcard_end) ||
(!wildcard_start && !wildcard_end &&
startswith && endswith) ||
(wildcard_start && endswith) ||
(wildcard_end && startswith))
{
free (msg);
free (highlight);
return 1;
}
msg_pos = match_post;
}
}
+2 -1
View File
@@ -1,10 +1,11 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
ChangeLog - 2005-10-22
ChangeLog - 2005-10-27
Version 0.1.6 (under dev!):
* added partial match for highlights
* added dcc_own_ip and dcc_port_range settings
* full UTF-8 support, auto-detection of UTF-8 usage (locale)
* added "Day changed to [date]" message when day changes
+242 -240
View File
File diff suppressed because it is too large Load Diff
+241 -240
View File
File diff suppressed because it is too large Load Diff
+243 -244
View File
File diff suppressed because it is too large Load Diff
+243 -242
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -665,7 +665,8 @@ t_config_option weechat_options_irc[] =
OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE,
NULL, NULL, &cfg_irc_fifo_pipe, NULL, &config_change_fifo_pipe },
{ "irc_highlight", N_("list of words to highlight"),
N_("comma separated list of words to highlight (case insensitive comparison)"),
N_("comma separated list of words to highlight (case insensitive comparison, "
"words may begin or end with \"*\" for partial match)"),
OPTION_TYPE_STRING, 0, 0, 0,
"", NULL, NULL, &cfg_irc_highlight, &config_change_noop },
{ NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
+70 -14
View File
@@ -46,24 +46,55 @@
int command_ignored;
/*
* irc_is_word_char: return 1 if given character is a "word character"
*/
int
irc_is_word_char (char c)
{
if (isalnum (c))
return 1;
switch (c)
{
case '-':
case '_':
case '|':
return 1;
}
/* not a 'word char' */
return 0;
}
/*
* irc_is_highlight: returns 1 if given message contains highlight (with given nick
* or at least one of string in "irc_higlight" setting
* or at least one of string in "irc_higlight" setting)
*/
int
irc_is_highlight (char *message, char *nick)
{
char *msg, *highlight, *pos, *pos_end;
int end, length;
char *msg, *highlight, *match, *match_pre, *match_post, *msg_pos, *pos, *pos_end;
int end, length, startswith, endswith, wildcard_start, wildcard_end;
/* empty message ? */
if (!message || !message[0])
return 0;
/* highlight by nickname */
if (strstr (message, nick))
return 1;
match = strstr (message, nick);
if (match)
{
match_pre = match - 1;
match_post = match + strlen(nick);
startswith = ((match == message) || (!irc_is_word_char (match_pre[0])));
endswith = ((!match_post[0]) || (!irc_is_word_char (match_post[0])));
if (startswith && endswith)
return 1;
}
/* no highlight by nickname and "irc_highlight" is empty */
if (!cfg_irc_highlight || !cfg_irc_highlight[0])
@@ -80,15 +111,13 @@ irc_is_highlight (char *message, char *nick)
pos = msg;
while (pos[0])
{
if ((pos[0] >= 'A') && (pos[0] <= 'Z'))
pos[0] += ('a' - 'A');
pos[0] = tolower (pos[0]);
pos++;
}
pos = highlight;
while (pos[0])
{
if ((pos[0] >= 'A') && (pos[0] <= 'Z'))
pos[0] += ('a' - 'A');
pos[0] = tolower (pos[0]);
pos++;
}
@@ -115,12 +144,39 @@ irc_is_highlight (char *message, char *nick)
pos_end[0] = '\0';
if (length > 0)
{
/* highlight found! */
if (strstr (msg, pos))
if ((wildcard_start = (pos[0] == '*')))
{
free (msg);
free (highlight);
return 1;
pos++;
length--;
}
if ((wildcard_end = (*(pos_end - 1) == '*')))
{
*(pos_end - 1) = '\0';
length--;
}
}
if (length > 0)
{
msg_pos = msg;
/* highlight found! */
while ((match = strstr (msg_pos, pos)) != NULL)
{
match_pre = match - 1;
match_post = match + length;
startswith = ((match == msg) || (!irc_is_word_char (match_pre[0])));
endswith = ((!match_post[0]) || (!irc_is_word_char (match_post[0])));
if ((wildcard_start && wildcard_end) ||
(!wildcard_start && !wildcard_end &&
startswith && endswith) ||
(wildcard_start && endswith) ||
(wildcard_end && startswith))
{
free (msg);
free (highlight);
return 1;
}
msg_pos = match_post;
}
}