1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 06:16:40 +02:00

Allow mask or regex for IRC command /ignore (mask is default)

This commit is contained in:
Sebastien Helleu
2008-10-31 13:12:56 +01:00
parent b5eeb9254e
commit f766dc2f11
15 changed files with 278 additions and 167 deletions
+32 -18
View File
@@ -770,6 +770,30 @@ command_command (void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_OK;
}
/*
* command_filter_display: display one filter
*/
void
command_filter_display (struct t_gui_filter *filter)
{
gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
_(" %s[%s%s%s]%s buffer: %s%s%s "
"/ tags: %s / regex: %s %s"),
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT),
filter->name,
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT),
GUI_COLOR(GUI_COLOR_CHAT_BUFFER),
filter->buffer,
GUI_COLOR(GUI_COLOR_CHAT),
filter->tags,
filter->regex,
(filter->enabled) ?
"" : _("(disabled)"));
}
/*
* command_filter: manage message filters
*/
@@ -787,7 +811,7 @@ command_filter (void *data, struct t_gui_buffer *buffer,
if ((argc == 1)
|| ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0)))
{
/* display all key bindings */
/* display all filters */
gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER, "");
gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
"%s",
@@ -802,21 +826,7 @@ command_filter (void *data, struct t_gui_buffer *buffer,
for (ptr_filter = gui_filters; ptr_filter;
ptr_filter = ptr_filter->next_filter)
{
gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
_(" %s[%s%s%s]%s buffer: %s%s%s "
"/ tags: %s / regex: %s %s"),
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT),
ptr_filter->name,
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT),
GUI_COLOR(GUI_COLOR_CHAT_BUFFER),
ptr_filter->buffer,
GUI_COLOR(GUI_COLOR_CHAT),
ptr_filter->tags,
ptr_filter->regex,
(ptr_filter->enabled) ?
"" : _("(disabled)"));
command_filter_display (ptr_filter);
}
}
else
@@ -968,11 +978,15 @@ command_filter (void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_ERROR;
}
if (gui_filter_new (1, argv[2], argv[3], argv[4], argv_eol[5]))
ptr_filter = gui_filter_new (1, argv[2], argv[3], argv[4], argv_eol[5]);
if (ptr_filter)
{
gui_chat_printf (NULL, "");
gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
_("Filter \"%s\" added"),
_("Filter \"%s\" added:"),
argv[2]);
command_filter_display (ptr_filter);
}
else
{
+50
View File
@@ -715,6 +715,56 @@ string_has_highlight (const char *string, const char *highlight_words)
return 0;
}
/*
* string_mask_to_regex: convert a mask (string with only "*" as joker) to a
* regex, paying attention to special chars in a regex
*/
char *
string_mask_to_regex (const char *mask)
{
char *result;
const char *ptr_mask;
int index_result;
char *regex_special_char = ".[]{}()|?+";
if (!mask)
return NULL;
result = malloc ((strlen (mask) * 2) + 1);
if (!result)
return NULL;
result[0] = '\0';
index_result = 0;
ptr_mask = mask;
while (ptr_mask[0])
{
/* '*' in string ? then replace by '.*' */
if (ptr_mask[0] == '*')
{
result[index_result++] = '.';
result[index_result++] = '*';
}
/* special regex char in string ? escape it with '\' */
else if (strchr (regex_special_char, ptr_mask[0]))
{
result[index_result++] = '\\';
result[index_result++] = ptr_mask[0];
}
/* standard char, just copy it */
else
result[index_result++] = ptr_mask[0];
ptr_mask++;
}
/* add final '\0' */
result[index_result] = '\0';
return result;
}
/*
* string_explode: explode a string according to separators
* examples:
+1
View File
@@ -41,6 +41,7 @@ extern char *string_strip (const char *string, int left, int right,
extern char *string_convert_hex_chars (const char *string);
extern int string_has_highlight (const char *string,
const char *highlight_words);
extern char *string_mask_to_regex (const char *mask);
extern char **string_explode (const char *string, const char *separators,
int keep_eol, int num_items_max, int *num_items);
extern void string_free_exploded (char **exploded_string);