diff --git a/ChangeLog b/ChangeLog index 841bf94f7..a1900a699 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] == Version 0.4.3 (under dev) +* core: add support of logical and/or for argument "tags" in function hook_print * core: rename buffer property "highlight_tags" to "highlight_tags_restrict", new behavior for buffer property "highlight_tags" (force highlight on tags), rename option irc.look.highlight_tags to irc.look.highlight_tags_restrict diff --git a/doc/en/weechat_plugin_api.en.txt b/doc/en/weechat_plugin_api.en.txt index 07b577f1b..1cbd635b7 100644 --- a/doc/en/weechat_plugin_api.en.txt +++ b/doc/en/weechat_plugin_api.en.txt @@ -7334,8 +7334,12 @@ struct t_hook *weechat_hook_print (struct t_gui_buffer *buffer, Arguments: * 'buffer': buffer pointer, if NULL, messages from any buffer are caught -* 'tags': only messages with these tags (comma separated list) will be caught - (optional) +* 'tags': catch only messages with these tags (optional): +** with WeeChat ≥ 0.4.3: comma-separated list of tags that must be in message + (logical "or"); it is possible to combine many tags as a logical "and" with + separator "+"; each tag can start or end with "*" to match many tags +** with WeeChat ≤ 0.4.2: comma-separated list of tags that must all be in + message (logical "and") * 'message': only messages with this string will be caught (optional, case insensitive) * 'strip_colors': if 1, colors will be stripped from message displayed, before diff --git a/doc/fr/weechat_plugin_api.fr.txt b/doc/fr/weechat_plugin_api.fr.txt index 0e7be7ae3..ce25abacb 100644 --- a/doc/fr/weechat_plugin_api.fr.txt +++ b/doc/fr/weechat_plugin_api.fr.txt @@ -7451,8 +7451,14 @@ Paramètres : * 'buffer' : pointeur vers le tampon, si NULL, les messages de tous les tampons sont interceptés -* 'tags' : seulement les messages avec ces étiquettes (liste séparée par des - virgules) seront interceptés (optionnel) +* 'tags' : intercepter seulement les messages avec ces étiquettes (optionnel) : +** avec WeeChat ≥ 0.4.3 : liste d'étiquettes (séparées par des virgules) qui + doivent être dans le message ("ou" logique); il est possible de combiner + plusieurs étiquettes sous forme d'un "et" logique avec le séparateur "+"; + chaque étiquette peut commencer ou se terminer par "*" pour correspondre à + plusieurs étiquettes +** avec WeeChat ≤ 0.4.2 : liste d'étiquettes (séparées par des virgules) qui + doivent toutes être dans le message ("et" logique) * 'message' : seulement les messages contenant cette chaîne seront interceptés (optionnel, insensible à la casse) * 'strip_colors' : si 1, les couleurs seront supprimées du message affiché, diff --git a/doc/it/weechat_plugin_api.it.txt b/doc/it/weechat_plugin_api.it.txt index c391dcb8b..2d0fa2a0f 100644 --- a/doc/it/weechat_plugin_api.it.txt +++ b/doc/it/weechat_plugin_api.it.txt @@ -7393,8 +7393,15 @@ Argomenti: * 'buffer': puntatore al buffer, se NULL, verranno catturati i messaggi da qualsiasi buffer -* 'tags': verranno catturati solo messaggi con queste tag (elenco separato da virgole) - (opzionale) +// TRANSLATION MISSING +* 'tags': catch only messages with these tags (optional): +// TRANSLATION MISSING +** with WeeChat ≥ 0.4.3: comma-separated list of tags that must be in message + (logical "or"); it is possible to combine many tags as a logical "and" with + separator "+"; each tag can start or end with "*" to match many tags +// TRANSLATION MISSING +** with WeeChat ≤ 0.4.2: comma-separated list of tags that must all be in + message (logical "and") * 'message': verranno catturati solo i messaggi con questa stringa (opzionale, non sensibile alle maiuscole) * 'strip_colors': se 1, i colori verranno estratti dal messaggio visualizzato, prima diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index 45a134622..3f91ca416 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -1987,6 +1987,8 @@ hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer, { struct t_hook *new_hook; struct t_hook_print *new_hook_print; + char **tags_array; + int i; if (!callback) return NULL; @@ -2007,15 +2009,27 @@ hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer, new_hook->hook_data = new_hook_print; new_hook_print->callback = callback; new_hook_print->buffer = buffer; + new_hook_print->tags_count = 0; + new_hook_print->tags_array = NULL; if (tags) { - new_hook_print->tags_array = string_split (tags, ",", 0, 0, - &new_hook_print->tags_count); - } - else - { - new_hook_print->tags_count = 0; - new_hook_print->tags_array = NULL; + tags_array = string_split (tags, ",", 0, 0, + &new_hook_print->tags_count); + if (tags_array) + { + new_hook_print->tags_array = malloc (new_hook_print->tags_count * + sizeof (*new_hook_print->tags_array)); + if (new_hook_print->tags_array) + { + for (i = 0; i < new_hook_print->tags_count; i++) + { + new_hook_print->tags_array[i] = string_split (tags_array[i], + "+", 0, 0, + NULL); + } + } + string_free_split (tags_array); + } } new_hook_print->message = (message) ? strdup (message) : NULL; new_hook_print->strip_colors = strip_colors; @@ -2034,7 +2048,6 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line) { struct t_hook *ptr_hook, *next_hook; char *prefix_no_color, *message_no_color; - int tags_match, tag_found, i, j; if (!line->data->message || !line->data->message[0]) return; @@ -2067,42 +2080,12 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line) || string_strcasestr (message_no_color, HOOK_PRINT(ptr_hook, message)))) { /* check if tags match */ - if (HOOK_PRINT(ptr_hook, tags_array)) - { - /* if there are tags in message printed */ - if (line->data->tags_array) - { - tags_match = 1; - for (i = 0; i < HOOK_PRINT(ptr_hook, tags_count); i++) - { - /* search for tag in message */ - tag_found = 0; - for (j = 0; j < line->data->tags_count; j++) - { - if (string_strcasecmp (HOOK_PRINT(ptr_hook, tags_array)[i], - line->data->tags_array[j]) == 0) - { - tag_found = 1; - break; - } - } - /* tag was asked by hook but not found in message? */ - if (!tag_found) - { - tags_match = 0; - break; - } - } - } - else - tags_match = 0; - } - else - tags_match = 1; - - /* run callback */ - if (tags_match) + if (!HOOK_PRINT(ptr_hook, tags_array) + || gui_line_match_tags (line->data, + HOOK_PRINT(ptr_hook, tags_count), + HOOK_PRINT(ptr_hook, tags_array))) { + /* run callback */ ptr_hook->running = 1; (void) (HOOK_PRINT(ptr_hook, callback)) (ptr_hook->callback_data, buffer, line->data->date, @@ -3334,7 +3317,13 @@ unhook (struct t_hook *hook) break; case HOOK_TYPE_PRINT: if (HOOK_PRINT(hook, tags_array)) - string_free_split (HOOK_PRINT(hook, tags_array)); + { + for (i = 0; i < HOOK_PRINT(hook, tags_count); i++) + { + string_free_split (HOOK_PRINT(hook, tags_array)[i]); + } + free (HOOK_PRINT(hook, tags_array)); + } if (HOOK_PRINT(hook, message)) free (HOOK_PRINT(hook, message)); break; diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h index 2198e28e1..25a418545 100644 --- a/src/core/wee-hook.h +++ b/src/core/wee-hook.h @@ -288,7 +288,7 @@ struct t_hook_print t_hook_callback_print *callback; /* print callback */ struct t_gui_buffer *buffer; /* buffer selected (NULL = all) */ int tags_count; /* number of tags selected */ - char **tags_array; /* tags selected (NULL = any) */ + char ***tags_array; /* tags selected (NULL = any) */ char *message; /* part of message (NULL/empty = all)*/ int strip_colors; /* strip colors in msg for callback? */ };