1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 08:43:13 +02:00

Use '!' to reverse a regex in a filter (to keep lines matching regex and hide other lines)

This commit is contained in:
Sebastien Helleu
2010-07-16 19:45:14 +02:00
parent 790b1cdf1a
commit 8dc23863c5
12 changed files with 119 additions and 44 deletions
+8 -4
View File
@@ -1239,7 +1239,7 @@ command_filter (void *data, struct t_gui_buffer *buffer,
{
if (argc > 2)
{
/* enable a filter */
/* disable a filter */
ptr_filter = gui_filter_search_by_name (argv[2]);
if (ptr_filter)
{
@@ -4605,9 +4605,11 @@ command_init ()
"(\"*\" for all buffers)\n"
" tags: comma separated list of tags, for "
"example: \"irc_join,irc_part,irc_quit\"\n"
" regex: regular expression to search in "
"line (use \\t to separate prefix from message, special "
"chars like '|' must be escaped: '\\|')\n\n"
" regex: regular expression to search in line\n"
" - use '\\t' to separate prefix from message, special "
"chars like '|' must be escaped: '\\|'\n"
" - if regex starts with '!', then matching "
"result is reversed (use '\\!' to start with '!')\n\n"
"The default key alt+'=' toggles filtering on/off.\n\n"
"Tags most commonly used:\n"
" no_filter, no_highlight, log0..log9 (log level),\n"
@@ -4624,6 +4626,8 @@ command_init ()
" /filter add nicks * irc_366 *\n"
" filter nick \"toto\" on IRC channel #weechat:\n"
" /filter add toto irc.freenode.#weechat * toto\\t\n"
" keep only nick \"titi\" on IRC channel #test:\n"
" /filter add titi irc.freenode.#test * !titi\\t\n"
" filter lines containing word \"spam\":\n"
" /filter add filterspam * * spam\n"
" filter lines containing \"weechat sucks\" on IRC "
+23 -8
View File
@@ -76,6 +76,7 @@ gui_filter_check_line (struct t_gui_buffer *buffer, struct t_gui_line *line)
{
struct t_gui_filter *ptr_filter;
const char *buffer_plugin_name;
int rc;
/* line is always displayed if filters are disabled */
if (!gui_filters_enabled)
@@ -103,12 +104,18 @@ gui_filter_check_line (struct t_gui_buffer *buffer, struct t_gui_line *line)
ptr_filter->tags_array)))
{
/* check line with regex */
rc = 1;
if (!ptr_filter->regex_prefix && !ptr_filter->regex_message)
return 0;
rc = 0;
if (gui_line_match_regex (line,
ptr_filter->regex_prefix,
ptr_filter->regex_message))
{
rc = 0;
}
if (ptr_filter->regex && (ptr_filter->regex[0] == '!'))
rc ^= 1;
if (rc == 0)
return 0;
}
}
@@ -291,28 +298,36 @@ gui_filter_new (int enabled, const char *name, const char *buffer_name,
struct t_gui_filter *new_filter;
regex_t *regex1, *regex2;
char *pos_tab, *pos_point, *regex_prefix;
const char *pos_regex_message;
const char *ptr_start_regex, *pos_regex_message;
if (!name || !buffer_name || !tags || !regex)
return NULL;
if (gui_filter_search_by_name (name))
return NULL;
ptr_start_regex = regex;
if ((ptr_start_regex[0] == '!')
|| ((ptr_start_regex[0] == '\\') && (ptr_start_regex[1] == '!')))
{
ptr_start_regex++;
}
regex1 = NULL;
regex2 = NULL;
if (strcmp (regex, "*") != 0)
if (strcmp (ptr_start_regex, "*") != 0)
{
pos_tab = strstr (regex, "\\t");
pos_tab = strstr (ptr_start_regex, "\\t");
if (pos_tab)
{
regex_prefix = string_strndup (regex, pos_tab - regex);
regex_prefix = string_strndup (ptr_start_regex,
pos_tab - ptr_start_regex);
pos_regex_message = pos_tab + 2;
}
else
{
regex_prefix = NULL;
pos_regex_message = regex;
pos_regex_message = ptr_start_regex;
}
if (regex_prefix)