diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2013-12-14 11:26:03 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2013-12-14 11:26:03 +0100 |
commit | 811b68991e1635967334b9a2f0ba4468bbb9f44b (patch) | |
tree | caf48db443e263d81955ca83f9e56575eb73d437 /src/gui | |
parent | 542dc8cd33e1be4c310cba4253b986a01abe7675 (diff) | |
download | weechat-811b68991e1635967334b9a2f0ba4468bbb9f44b.zip |
core: add logical "and" between tags in filters, weechat.look.highlight_tags and buffer property "highlight_tags"
The logical "and" is made with the separator "+".
Example: "irc_notice+nick_toto,nick_test"
will match a notice from nick "toto" or any message from nick "test".
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui-buffer.c | 47 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 2 | ||||
-rw-r--r-- | src/gui/gui-filter.c | 85 | ||||
-rw-r--r-- | src/gui/gui-filter.h | 2 | ||||
-rw-r--r-- | src/gui/gui-line.c | 68 | ||||
-rw-r--r-- | src/gui/gui-line.h | 3 |
6 files changed, 136 insertions, 71 deletions
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 7379685c7..c9e33e88e 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -1413,6 +1413,9 @@ void gui_buffer_set_highlight_tags (struct t_gui_buffer *buffer, const char *new_highlight_tags) { + int i; + char **tags_array; + if (buffer->highlight_tags) { free (buffer->highlight_tags); @@ -1420,20 +1423,38 @@ gui_buffer_set_highlight_tags (struct t_gui_buffer *buffer, } if (buffer->highlight_tags_array) { - string_free_split (buffer->highlight_tags_array); + for (i = 0; i < buffer->highlight_tags_count; i++) + { + string_free_split (buffer->highlight_tags_array[i]); + } + free (buffer->highlight_tags_array); buffer->highlight_tags_array = NULL; } buffer->highlight_tags_count = 0; - if (new_highlight_tags) + if (!new_highlight_tags) + return; + + buffer->highlight_tags = strdup (new_highlight_tags); + if (!buffer->highlight_tags) + return; + + tags_array = string_split (buffer->highlight_tags, ",", 0, 0, + &buffer->highlight_tags_count); + if (tags_array) { - buffer->highlight_tags = strdup (new_highlight_tags); - if (buffer->highlight_tags) + buffer->highlight_tags_array = malloc (buffer->highlight_tags_count * + sizeof (*buffer->highlight_tags_array)); + if (buffer->highlight_tags_array) { - buffer->highlight_tags_array = string_split (new_highlight_tags, - ",", 0, 0, - &buffer->highlight_tags_count); + for (i = 0; i < buffer->highlight_tags_count; i++) + { + buffer->highlight_tags_array[i] = string_split (tags_array[i], + "+", 0, 0, + NULL); + } } + string_free_split (tags_array); } } @@ -2317,7 +2338,7 @@ gui_buffer_close (struct t_gui_buffer *buffer) struct t_gui_window *ptr_window; struct t_gui_buffer *ptr_buffer, *ptr_back_to_buffer; struct t_gui_buffer *ptr_buffer_visited_buffer; - int index; + int index, i; struct t_gui_buffer_visited *ptr_buffer_visited; hook_signal_send ("buffer_closing", @@ -2468,7 +2489,13 @@ gui_buffer_close (struct t_gui_buffer *buffer) if (buffer->highlight_tags) free (buffer->highlight_tags); if (buffer->highlight_tags_array) - string_free_split (buffer->highlight_tags_array); + { + for (i = 0; i < buffer->highlight_tags_count; i++) + { + string_free_split (buffer->highlight_tags_array[i]); + } + free (buffer->highlight_tags_array); + } /* remove buffer from buffers list */ if (buffer->prev_buffer) @@ -3668,7 +3695,7 @@ gui_buffer_hdata_buffer_cb (void *data, const char *hdata_name) HDATA_VAR(struct t_gui_buffer, highlight_regex_compiled, POINTER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, highlight_tags, STRING, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, highlight_tags_count, INTEGER, 0, NULL, NULL); - HDATA_VAR(struct t_gui_buffer, highlight_tags_array, STRING, 0, "highlight_tags_count", NULL); + HDATA_VAR(struct t_gui_buffer, highlight_tags_array, POINTER, 0, "highlight_tags_count", NULL); HDATA_VAR(struct t_gui_buffer, hotlist_max_level_nicks, HASHTABLE, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, keys, POINTER, 0, NULL, "key"); HDATA_VAR(struct t_gui_buffer, last_key, POINTER, 0, NULL, "key"); diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index a370abb90..70ca1696b 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -180,7 +180,7 @@ struct t_gui_buffer char *highlight_tags; /* tags to highlight */ int highlight_tags_count; /* number of tags to highlight */ /* (if 0, any tag is highlighted) */ - char **highlight_tags_array; /* tags to highlight */ + char ***highlight_tags_array; /* tags to highlight */ /* hotlist settings for buffer */ struct t_hashtable *hotlist_max_level_nicks; /* max hotlist level for */ diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c index c4ee81de7..f912369d9 100644 --- a/src/gui/gui-filter.c +++ b/src/gui/gui-filter.c @@ -48,30 +48,6 @@ int gui_filters_enabled = 1; /* filters enabled? */ /* - * Checks if a line has tag "no_filter" (which means that line should never been - * filtered: it is always displayed). - * - * Returns: - * 1: line has tag "no_filter" - * 0: line does not have tag "no_filter" - */ - -int -gui_filter_line_has_tag_no_filter (struct t_gui_line_data *line_data) -{ - int i; - - for (i = 0; i < line_data->tags_count; i++) - { - if (strcmp (line_data->tags_array[i], GUI_FILTER_TAG_NO_FILTER) == 0) - return 1; - } - - /* tag not found, line may be filtered */ - return 0; -} - -/* * Checks if a line must be displayed or not (filtered). * * Returns: @@ -89,7 +65,7 @@ gui_filter_check_line (struct t_gui_line_data *line_data) if (!gui_filters_enabled) return 1; - if (gui_filter_line_has_tag_no_filter (line_data)) + if (gui_line_has_tag_no_filter (line_data)) return 1; for (ptr_filter = gui_filters; ptr_filter; @@ -289,8 +265,9 @@ 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, *regex_prefix; + char *pos_tab, *regex_prefix, **tags_array; const char *ptr_start_regex, *pos_regex_message; + int i; if (!name || !buffer_name || !tags || !regex) return NULL; @@ -367,17 +344,25 @@ gui_filter_new (int enabled, const char *name, const char *buffer_name, new_filter->buffers = string_split (new_filter->buffer_name, ",", 0, 0, &new_filter->num_buffers); - if (tags) - { - new_filter->tags = (tags) ? strdup (tags) : NULL; - new_filter->tags_array = string_split (tags, ",", 0, 0, - &new_filter->tags_count); - } - else + new_filter->tags = (tags) ? strdup (tags) : NULL; + new_filter->tags_count = 0; + new_filter->tags_array = NULL; + if (new_filter->tags) { - new_filter->tags = NULL; - new_filter->tags_count = 0; - new_filter->tags_array = NULL; + tags_array = string_split (new_filter->tags, ",", 0, 0, + &new_filter->tags_count); + if (tags_array) + { + new_filter->tags_array = malloc (new_filter->tags_count * + sizeof (*new_filter->tags_array)); + for (i = 0; i < new_filter->tags_count; i++) + { + new_filter->tags_array[i] = string_split (tags_array[i], + "+", 0, 0, + NULL); + } + string_free_split (tags_array); + } } new_filter->regex = strdup (regex); new_filter->regex_prefix = regex1; @@ -429,6 +414,8 @@ gui_filter_rename (struct t_gui_filter *filter, const char *new_name) void gui_filter_free (struct t_gui_filter *filter) { + int i; + hook_signal_send ("filter_removing", WEECHAT_HOOK_SIGNAL_POINTER, filter); @@ -442,7 +429,13 @@ gui_filter_free (struct t_gui_filter *filter) if (filter->tags) free (filter->tags); if (filter->tags_array) - string_free_split (filter->tags_array); + { + for (i = 0; i < filter->tags_count; i++) + { + string_free_split (filter->tags_array[i]); + } + free (filter->tags_array); + } if (filter->regex) free (filter->regex); if (filter->regex_prefix) @@ -507,7 +500,7 @@ gui_filter_hdata_filter_cb (void *data, const char *hdata_name) HDATA_VAR(struct t_gui_filter, buffers, POINTER, 0, NULL, NULL); HDATA_VAR(struct t_gui_filter, tags, STRING, 0, NULL, NULL); HDATA_VAR(struct t_gui_filter, tags_count, INTEGER, 0, NULL, NULL); - HDATA_VAR(struct t_gui_filter, tags_array, STRING, 0, "tags_count", NULL); + HDATA_VAR(struct t_gui_filter, tags_array, POINTER, 0, "tags_count", NULL); HDATA_VAR(struct t_gui_filter, regex, STRING, 0, NULL, NULL); HDATA_VAR(struct t_gui_filter, regex_prefix, POINTER, 0, NULL, NULL); HDATA_VAR(struct t_gui_filter, regex_message, POINTER, 0, NULL, NULL); @@ -532,7 +525,7 @@ gui_filter_add_to_infolist (struct t_infolist *infolist, struct t_gui_filter *filter) { struct t_infolist_item *ptr_item; - char option_name[64]; + char option_name[64], *tags; int i; if (!infolist || !filter) @@ -555,9 +548,17 @@ gui_filter_add_to_infolist (struct t_infolist *infolist, for (i = 0; i < filter->tags_count; i++) { snprintf (option_name, sizeof (option_name), "tag_%05d", i + 1); - if (!infolist_new_var_string (ptr_item, option_name, - filter->tags_array[i])) - return 0; + tags = string_build_with_split_string ((const char **)filter->tags_array[i], + "+"); + if (tags) + { + if (!infolist_new_var_string (ptr_item, option_name, tags)) + { + free (tags); + return 0; + } + free (tags); + } } if (!infolist_new_var_string (ptr_item, "regex", filter->regex)) return 0; diff --git a/src/gui/gui-filter.h b/src/gui/gui-filter.h index b89263559..1eb019bac 100644 --- a/src/gui/gui-filter.h +++ b/src/gui/gui-filter.h @@ -37,7 +37,7 @@ struct t_gui_filter char **buffers; /* list of buffer names */ char *tags; /* tags */ int tags_count; /* number of tags */ - char **tags_array; /* array of tags */ + char ***tags_array; /* array of tags */ char *regex; /* regex */ regex_t *regex_prefix; /* regex for line prefix */ regex_t *regex_message; /* regex for line message */ diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index 4136c3d3b..f6e4d863f 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -562,6 +562,30 @@ gui_line_match_regex (struct t_gui_line_data *line_data, regex_t *regex_prefix, } /* + * Checks if a line has tag "no_filter" (which means that line should never been + * filtered: it is always displayed). + * + * Returns: + * 1: line has tag "no_filter" + * 0: line does not have tag "no_filter" + */ + +int +gui_line_has_tag_no_filter (struct t_gui_line_data *line_data) +{ + int i; + + for (i = 0; i < line_data->tags_count; i++) + { + if (strcmp (line_data->tags_array[i], GUI_FILTER_TAG_NO_FILTER) == 0) + return 1; + } + + /* tag not found, line may be filtered */ + return 0; +} + +/* * Checks if line matches tags. * * Returns: @@ -571,9 +595,9 @@ gui_line_match_regex (struct t_gui_line_data *line_data, regex_t *regex_prefix, int gui_line_match_tags (struct t_gui_line_data *line_data, - int tags_count, char **tags_array) + int tags_count, char ***tags_array) { - int i, j; + int i, j, k, match, tag_found; if (!line_data) return 0; @@ -583,14 +607,28 @@ gui_line_match_tags (struct t_gui_line_data *line_data, for (i = 0; i < tags_count; i++) { - for (j = 0; j < line_data->tags_count; j++) + match = 1; + for (j = 0; tags_array[i][j]; j++) { - /* check tag */ - if (string_match (line_data->tags_array[j], - tags_array[i], - 0)) - return 1; + tag_found = 0; + for (k = 0; k < line_data->tags_count; k++) + { + if (string_match (line_data->tags_array[k], + tags_array[i][j], + 0)) + { + tag_found = 1; + break; + } + } + if (!tag_found) + { + match = 0; + break; + } } + if (match) + return 1; } return 0; @@ -648,7 +686,7 @@ gui_line_get_nick_tag (struct t_gui_line *line) int gui_line_has_highlight (struct t_gui_line *line) { - int rc, i, j, no_highlight, action, length; + int rc, i, no_highlight, action, length; char *msg_no_color, *ptr_msg_no_color, *highlight_words; const char *ptr_nick; @@ -671,14 +709,12 @@ gui_line_has_highlight (struct t_gui_line *line) ptr_nick = NULL; for (i = 0; i < line->data->tags_count; i++) { - if (config_highlight_tags) + if (config_highlight_tags + && gui_line_match_tags (line->data, + config_num_highlight_tags, + config_highlight_tags)) { - for (j = 0; j < config_num_highlight_tags; j++) - { - if (string_strcasecmp (line->data->tags_array[i], - config_highlight_tags[j]) == 0) - return 1; - } + return 1; } if (strcmp (line->data->tags_array[i], GUI_CHAT_TAG_NO_HIGHLIGHT) == 0) no_highlight = 1; diff --git a/src/gui/gui-line.h b/src/gui/gui-line.h index 7004b6353..a53f6e9e5 100644 --- a/src/gui/gui-line.h +++ b/src/gui/gui-line.h @@ -85,8 +85,9 @@ extern int gui_line_search_text (struct t_gui_buffer *buffer, extern int gui_line_match_regex (struct t_gui_line_data *line_data, regex_t *regex_prefix, regex_t *regex_message); +extern int gui_line_has_tag_no_filter (struct t_gui_line_data *line_data); extern int gui_line_match_tags (struct t_gui_line_data *line_data, - int tags_count, char **tags_array); + int tags_count, char ***tags_array); extern const char *gui_line_search_tag_starting_with (struct t_gui_line *line, const char *tag); extern const char *gui_line_get_nick_tag (struct t_gui_line *line); |