1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-05 09:13:14 +02:00

core: fix check of tags in lines

All changes:
- fix check of tags in lines: check lines without tags, fix check of tags with
  negation ("!tag")
- add string functions string_split_tags and string_free_split_tags
- add tests on function gui_line_match_tags
This commit is contained in:
Sébastien Helleu
2018-08-07 21:50:04 +02:00
parent d699ae89aa
commit 12a6f74ec0
23 changed files with 382 additions and 275 deletions
+5 -31
View File
@@ -885,9 +885,6 @@ void
config_change_highlight_tags (const void *pointer, void *data,
struct t_config_option *option)
{
int i;
char **tags_array;
/* make C compiler happy */
(void) pointer;
(void) data;
@@ -895,11 +892,7 @@ config_change_highlight_tags (const void *pointer, void *data,
if (config_highlight_tags)
{
for (i = 0; i < config_num_highlight_tags; i++)
{
string_free_split (config_highlight_tags[i]);
}
free (config_highlight_tags);
string_free_split_tags (config_highlight_tags);
config_highlight_tags = NULL;
}
config_num_highlight_tags = 0;
@@ -907,22 +900,9 @@ config_change_highlight_tags (const void *pointer, void *data,
if (CONFIG_STRING(config_look_highlight_tags)
&& CONFIG_STRING(config_look_highlight_tags)[0])
{
tags_array = string_split (CONFIG_STRING(config_look_highlight_tags),
",", 0, 0, &config_num_highlight_tags);
if (tags_array)
{
config_highlight_tags = malloc (config_num_highlight_tags *
sizeof (*config_highlight_tags));
if (config_highlight_tags)
{
for (i = 0; i < config_num_highlight_tags; i++)
{
config_highlight_tags[i] = string_split (tags_array[i],
"+", 0, 0, NULL);
}
}
string_free_split (tags_array);
}
config_highlight_tags = string_split_tags (
CONFIG_STRING(config_look_highlight_tags),
&config_num_highlight_tags);
}
}
@@ -4618,8 +4598,6 @@ config_weechat_write ()
void
config_weechat_free ()
{
int i;
config_file_free (weechat_config_file);
if (config_highlight_regex)
@@ -4631,11 +4609,7 @@ config_weechat_free ()
if (config_highlight_tags)
{
for (i = 0; i < config_num_highlight_tags; i++)
{
string_free_split (config_highlight_tags[i]);
}
free (config_highlight_tags);
string_free_split_tags (config_highlight_tags);
config_highlight_tags = NULL;
}
config_num_highlight_tags = 0;
+16 -29
View File
@@ -2419,8 +2419,6 @@ 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;
@@ -2441,28 +2439,8 @@ 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)
{
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->tags_array = string_split_tags (tags,
&new_hook_print->tags_count);
new_hook_print->message = (message) ? strdup (message) : NULL;
new_hook_print->strip_colors = strip_colors;
@@ -4016,11 +3994,7 @@ unhook (struct t_hook *hook)
case HOOK_TYPE_PRINT:
if (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));
string_free_split_tags (HOOK_PRINT(hook, tags_array));
HOOK_PRINT(hook, tags_array) = NULL;
}
if (HOOK_PRINT(hook, message))
@@ -4897,6 +4871,19 @@ hook_print_log ()
log_printf (" buffer. . . . . . . . : 0x%lx", HOOK_PRINT(ptr_hook, buffer));
log_printf (" tags_count. . . . . . : %d", HOOK_PRINT(ptr_hook, tags_count));
log_printf (" tags_array. . . . . . : 0x%lx", HOOK_PRINT(ptr_hook, tags_array));
if (HOOK_PRINT(ptr_hook, tags_array))
{
for (i = 0; i < HOOK_PRINT(ptr_hook, tags_count); i++)
{
for (j = 0; HOOK_PRINT(ptr_hook, tags_array)[i][j]; j++)
{
log_printf (" tags_array[%03d][%03d]: '%s'",
i,
j,
HOOK_PRINT(ptr_hook, tags_array)[i][j]);
}
}
}
log_printf (" message . . . . . . . : '%s'", HOOK_PRINT(ptr_hook, message));
log_printf (" strip_colors. . . . . : %d", HOOK_PRINT(ptr_hook, strip_colors));
break;
+67
View File
@@ -2306,6 +2306,73 @@ string_free_split_command (char **split_command)
}
}
/*
* Splits tags in an array of tags.
*
* The format of tags is a list of tags separated by commas (logical OR),
* and for each item, multiple tags can be separated by "+" (logical AND).
*
* For example:
* irc_join
* irc_join,irc_quit
* irc_join+nick_toto,irc_quit
*/
char ***
string_split_tags (const char *tags, int *num_tags)
{
char ***tags_array, **tags_array_temp;
int i, tags_count;
tags_array = NULL;
tags_count = 0;
if (tags)
{
tags_array_temp = string_split (tags, ",", 0, 0, &tags_count);
if (tags_array_temp && (tags_count > 0))
{
tags_array = malloc ((tags_count + 1) * sizeof (*tags_array));
if (tags_array)
{
for (i = 0; i < tags_count; i++)
{
tags_array[i] = string_split_shared (tags_array_temp[i],
"+", 0, 0,
NULL);
}
tags_array[tags_count] = NULL;
}
}
if (tags_array_temp)
string_free_split (tags_array_temp);
}
if (num_tags)
*num_tags = tags_count;
return tags_array;
}
/*
* Frees tags split.
*/
void
string_free_split_tags (char ***split_tags)
{
int i;
if (split_tags)
{
for (i = 0; split_tags[i]; i++)
{
string_free_split_shared (split_tags[i]);
}
free (split_tags);
}
}
/*
* Converts a string to another charset.
*
+2
View File
@@ -95,6 +95,8 @@ extern char *string_build_with_split_string (const char **split_string,
const char *separator);
extern char **string_split_command (const char *command, char separator);
extern void string_free_split_command (char **split_command);
extern char ***string_split_tags (const char *tags, int *num_tags);
extern void string_free_split_tags (char ***split_tags);
extern char *string_iconv (int from_utf8, const char *from_code,
const char *to_code, const char *string);
extern char *string_iconv_to_internal (const char *charset, const char *string);