1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-28 13:56:37 +02:00

trigger: add elapsed time for trigger execution on monitor buffer when trigger debug is set (closes #1806)

This commit is contained in:
Sébastien Helleu
2022-08-15 12:44:16 +02:00
parent 1ce2d7f56d
commit 0f67f55098
28 changed files with 555 additions and 244 deletions
+230 -165
View File
@@ -22,14 +22,23 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <sys/time.h>
#include "../weechat-plugin.h"
#include "trigger.h"
#include "trigger-callback.h"
#include "trigger-buffer.h"
#include "trigger-config.h"
/*
* trigger context id to correlate messages in monitor buffer with
* the running trigger
*/
unsigned long trigger_context_id = 0;
/* hashtable used to evaluate "conditions" */
struct t_hashtable *trigger_callback_hashtable_options_conditions = NULL;
@@ -259,9 +268,7 @@ trigger_callback_check_conditions (struct t_trigger *trigger,
void
trigger_callback_replace_regex (struct t_trigger *trigger,
struct t_hashtable *pointers,
struct t_hashtable *extra_vars,
struct t_weelist *vars_updated,
struct t_trigger_context *context,
int display_monitor)
{
char *value;
@@ -274,13 +281,13 @@ trigger_callback_replace_regex (struct t_trigger *trigger,
if (trigger->regex_count == 0)
return;
if (!pointers)
if (!context->pointers)
{
pointers = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_POINTER,
NULL, NULL);
if (!pointers)
context->pointers = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_POINTER,
NULL, NULL);
if (!context->pointers)
return;
pointers_allocated = 1;
}
@@ -299,23 +306,30 @@ trigger_callback_replace_regex (struct t_trigger *trigger,
if (trigger_buffer && display_monitor)
{
weechat_printf_date_tags (trigger_buffer, 0, "no_trigger",
"\t regex %d: %s",
i + 1, _("no variable"));
"%s%lu\t regex %d: %s",
weechat_color (weechat_config_string (trigger_config_color_identifier)),
context->id,
i + 1,
_("no variable"));
}
continue;
}
ptr_value = weechat_hashtable_get (extra_vars, ptr_key);
ptr_value = weechat_hashtable_get (context->extra_vars, ptr_key);
if (!ptr_value)
{
if (trigger_buffer && display_monitor)
{
weechat_printf_date_tags (trigger_buffer, 0, "no_trigger",
"\t regex %d (%s): %s",
i + 1, ptr_key, _("creating variable"));
"%s%lu\t regex %d (%s): %s",
weechat_color (weechat_config_string (trigger_config_color_identifier)),
context->id,
i + 1,
ptr_key,
_("creating variable"));
}
weechat_hashtable_set (extra_vars, ptr_key, "");
ptr_value = weechat_hashtable_get (extra_vars, ptr_key);
weechat_hashtable_set (context->extra_vars, ptr_key, "");
ptr_value = weechat_hashtable_get (context->extra_vars, ptr_key);
}
hashtable_options_regex = weechat_hashtable_new (
@@ -324,15 +338,16 @@ trigger_callback_replace_regex (struct t_trigger *trigger,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
weechat_hashtable_set (pointers, "regex", trigger->regex[i].regex);
weechat_hashtable_set (context->pointers,
"regex", trigger->regex[i].regex);
weechat_hashtable_set (hashtable_options_regex,
"regex_replace",
trigger->regex[i].replace_escaped);
value = weechat_string_eval_expression (
ptr_value,
pointers,
extra_vars,
context->pointers,
context->extra_vars,
hashtable_options_regex);
weechat_hashtable_free (hashtable_options_regex);
@@ -343,8 +358,10 @@ trigger_callback_replace_regex (struct t_trigger *trigger,
if (trigger_buffer && display_monitor)
{
weechat_printf_date_tags (trigger_buffer, 0, "no_trigger",
"\t regex %d %s(%s%s%s)%s: "
"%s%lu\t regex %d %s(%s%s%s)%s: "
"%s\"%s%s%s\"",
weechat_color (weechat_config_string (trigger_config_color_identifier)),
context->id,
i + 1,
weechat_color ("chat_delimiters"),
weechat_color ("reset"),
@@ -356,10 +373,11 @@ trigger_callback_replace_regex (struct t_trigger *trigger,
value,
weechat_color ("chat_delimiters"));
}
weechat_hashtable_set (extra_vars, ptr_key, value);
if (vars_updated)
weechat_hashtable_set (context->extra_vars, ptr_key, value);
if (context->vars_updated)
{
weechat_list_add (vars_updated, ptr_key, WEECHAT_LIST_POS_END,
weechat_list_add (context->vars_updated,
ptr_key, WEECHAT_LIST_POS_END,
NULL);
}
free (value);
@@ -367,9 +385,14 @@ trigger_callback_replace_regex (struct t_trigger *trigger,
}
if (pointers_allocated)
weechat_hashtable_free (pointers);
{
weechat_hashtable_free (context->pointers);
context->pointers = NULL;
}
else
weechat_hashtable_remove (pointers, "regex");
{
weechat_hashtable_remove (context->pointers, "regex");
}
}
/*
@@ -378,17 +401,17 @@ trigger_callback_replace_regex (struct t_trigger *trigger,
void
trigger_callback_run_command (struct t_trigger *trigger,
struct t_gui_buffer *buffer,
struct t_hashtable *pointers,
struct t_hashtable *extra_vars,
struct t_trigger_context *context,
int display_monitor)
{
struct t_gui_buffer *buffer;
char *command_eval;
int i;
if (!trigger->commands)
return;
buffer = context->buffer;
if (!buffer)
{
buffer = weechat_buffer_search_main ();
@@ -399,7 +422,8 @@ trigger_callback_run_command (struct t_trigger *trigger,
for (i = 0; trigger->commands[i]; i++)
{
command_eval = weechat_string_eval_expression (trigger->commands[i],
pointers, extra_vars,
context->pointers,
context->extra_vars,
NULL);
if (command_eval)
{
@@ -408,8 +432,10 @@ trigger_callback_run_command (struct t_trigger *trigger,
{
weechat_printf_date_tags (
trigger_buffer, 0, "no_trigger",
_("%s running command %s\"%s%s%s\"%s "
_("%s%lu%s running command %s\"%s%s%s\"%s "
"on buffer %s%s%s"),
weechat_color (weechat_config_string (trigger_config_color_identifier)),
context->id,
"\t",
weechat_color ("chat_delimiters"),
weechat_color ("reset"),
@@ -444,36 +470,78 @@ trigger_callback_run_command (struct t_trigger *trigger,
int
trigger_callback_execute (struct t_trigger *trigger,
struct t_gui_buffer *buffer,
struct t_hashtable *pointers,
struct t_hashtable *extra_vars,
struct t_weelist *vars_updated)
struct t_trigger_context *context)
{
int display_monitor;
int rc, display_monitor;
long long time_init, time_cond, time_regex, time_cmd, time_total;
rc = 0;
trigger_context_id = (trigger_context_id < ULONG_MAX) ?
trigger_context_id + 1 : 0;
context->id = trigger_context_id;
/* display debug info on trigger buffer */
if (!trigger_buffer && (weechat_trigger_plugin->debug >= 1))
trigger_buffer_open (NULL, 0);
display_monitor = trigger_buffer_display_trigger (trigger,
buffer,
pointers,
extra_vars);
display_monitor = trigger_buffer_display_trigger (trigger, context);
/* check conditions */
if (trigger_callback_check_conditions (trigger, pointers, extra_vars))
if (weechat_trigger_plugin->debug >= 1)
{
/* replace text with regex */
trigger_callback_replace_regex (trigger, pointers, extra_vars,
vars_updated, display_monitor);
/* execute command(s) */
trigger_callback_run_command (trigger, buffer, pointers, extra_vars,
display_monitor);
return 1;
gettimeofday (&(context->start_check_conditions), NULL);
context->start_replace_regex = context->start_check_conditions;
context->start_run_command = context->start_check_conditions;
}
return 0;
/* check conditions */
if (trigger_callback_check_conditions (trigger,
context->pointers,
context->extra_vars))
{
/* replace text with regex */
if (weechat_trigger_plugin->debug >= 1)
gettimeofday (&(context->start_check_conditions), NULL);
trigger_callback_replace_regex (trigger, context, display_monitor);
/* execute command(s) */
if (weechat_trigger_plugin->debug >= 1)
gettimeofday (&(context->start_run_command), NULL);
trigger_callback_run_command (trigger, context, display_monitor);
rc = 1;
}
if (weechat_trigger_plugin->debug >= 1)
gettimeofday (&(context->end_exec), NULL);
if (trigger_buffer && display_monitor
&& (weechat_trigger_plugin->debug >= 1))
{
time_init = weechat_util_timeval_diff (&(context->start_exec),
&(context->start_check_conditions));
time_cond = weechat_util_timeval_diff (&(context->start_check_conditions),
&(context->start_replace_regex));
time_regex = weechat_util_timeval_diff (&(context->start_replace_regex),
&(context->start_run_command));
time_cmd = weechat_util_timeval_diff (&(context->start_run_command),
&(context->end_exec));
time_total = time_init + time_cond + time_regex + time_cmd;
weechat_printf_date_tags (trigger_buffer, 0, "no_trigger",
_("%s%lu%s elapsed: init=%.6fs, "
"conditions=%.6fs, regex=%.6fs, "
"command=%.6fs, total=%.6fs"),
weechat_color (weechat_config_string (trigger_config_color_identifier)),
context->id,
"\t",
(float)time_init / 1000000,
(float)time_cond / 1000000,
(float)time_regex / 1000000,
(float)time_cmd / 1000000,
(float)time_total / 1000000);
}
return rc;
}
/*
@@ -527,32 +595,33 @@ trigger_callback_signal_cb (const void *pointer, void *data,
}
if (irc_server_name && ptr_irc_message)
{
extra_vars = trigger_callback_irc_message_parse (ptr_irc_message,
irc_server_name);
if (extra_vars)
ctx.extra_vars = trigger_callback_irc_message_parse (
ptr_irc_message,
irc_server_name);
if (ctx.extra_vars)
{
weechat_hashtable_set (extra_vars, "server", irc_server_name);
weechat_hashtable_set (ctx.extra_vars, "server", irc_server_name);
trigger_callback_get_irc_server_channel (
irc_server_name,
weechat_hashtable_get (extra_vars, "channel"),
weechat_hashtable_get (ctx.extra_vars, "channel"),
&ptr_irc_server,
&ptr_irc_channel);
weechat_hashtable_set (pointers, "irc_server", ptr_irc_server);
weechat_hashtable_set (pointers, "irc_channel", ptr_irc_channel);
weechat_hashtable_set (ctx.pointers, "irc_server", ptr_irc_server);
weechat_hashtable_set (ctx.pointers, "irc_channel", ptr_irc_channel);
}
}
if (irc_server_name)
free (irc_server_name);
/* create hashtable (if not already created) */
if (!extra_vars)
if (!ctx.extra_vars)
{
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
}
/* add data in hashtable used for conditions/replace/command */
trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_signal", signal);
trigger_callback_set_common_vars (trigger, ctx.extra_vars);
weechat_hashtable_set (ctx.extra_vars, "tg_signal", signal);
ptr_signal_data = NULL;
if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0)
{
@@ -578,10 +647,10 @@ trigger_callback_signal_cb (const void *pointer, void *data,
}
ptr_signal_data = str_data;
}
weechat_hashtable_set (extra_vars, "tg_signal_data", ptr_signal_data);
weechat_hashtable_set (ctx.extra_vars, "tg_signal_data", ptr_signal_data);
/* execute the trigger (conditions, regex, command) */
if (!trigger_callback_execute (trigger, NULL, pointers, extra_vars, NULL))
if (!trigger_callback_execute (trigger, &ctx))
trigger_rc = WEECHAT_RC_OK;
end:
@@ -608,30 +677,30 @@ trigger_callback_hsignal_cb (const void *pointer, void *data,
type_values = weechat_hashtable_get_string (hashtable, "type_values");
if (strcmp (type_values, "pointer") == 0)
{
pointers = weechat_hashtable_dup (hashtable);
if (!pointers)
ctx.pointers = weechat_hashtable_dup (hashtable);
if (!ctx.pointers)
goto end;
}
else if (strcmp (type_values, "string") == 0)
{
extra_vars = weechat_hashtable_dup (hashtable);
if (!extra_vars)
ctx.extra_vars = weechat_hashtable_dup (hashtable);
if (!ctx.extra_vars)
goto end;
}
}
/* create hashtable (if not already created) */
if (!extra_vars)
if (!ctx.extra_vars)
{
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
}
/* add data in hashtable used for conditions/replace/command */
trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_signal", signal);
trigger_callback_set_common_vars (trigger, ctx.extra_vars);
weechat_hashtable_set (ctx.extra_vars, "tg_signal", signal);
/* execute the trigger (conditions, regex, command) */
if (!trigger_callback_execute (trigger, NULL, pointers, extra_vars, NULL))
if (!trigger_callback_execute (trigger, &ctx))
trigger_rc = WEECHAT_RC_OK;
end:
@@ -670,35 +739,35 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
|| (strncmp (modifier, "irc_out1_", 9) == 0)
|| (strncmp (modifier, "irc_out_", 8) == 0))
{
extra_vars = trigger_callback_irc_message_parse (string,
modifier_data);
if (extra_vars)
ctx.extra_vars = trigger_callback_irc_message_parse (string,
modifier_data);
if (ctx.extra_vars)
{
weechat_hashtable_set (extra_vars, "server", modifier_data);
weechat_hashtable_set (ctx.extra_vars, "server", modifier_data);
trigger_callback_get_irc_server_channel (
modifier_data,
weechat_hashtable_get (extra_vars, "channel"),
weechat_hashtable_get (ctx.extra_vars, "channel"),
&ptr_irc_server,
&ptr_irc_channel);
weechat_hashtable_set (pointers, "irc_server", ptr_irc_server);
weechat_hashtable_set (pointers, "irc_channel", ptr_irc_channel);
weechat_hashtable_set (ctx.pointers, "irc_server", ptr_irc_server);
weechat_hashtable_set (ctx.pointers, "irc_channel", ptr_irc_channel);
}
}
if (!extra_vars)
if (!ctx.extra_vars)
{
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
}
/* add data in hashtable used for conditions/replace/command */
trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_modifier", modifier);
weechat_hashtable_set (extra_vars, "tg_modifier_data", modifier_data);
weechat_hashtable_set (extra_vars, "tg_string", string);
trigger_callback_set_common_vars (trigger, ctx.extra_vars);
weechat_hashtable_set (ctx.extra_vars, "tg_modifier", modifier);
weechat_hashtable_set (ctx.extra_vars, "tg_modifier_data", modifier_data);
weechat_hashtable_set (ctx.extra_vars, "tg_string", string);
string_no_color = weechat_string_remove_color (string, NULL);
if (string_no_color)
{
weechat_hashtable_set (extra_vars,
weechat_hashtable_set (ctx.extra_vars,
"tg_string_nocolor", string_no_color);
}
@@ -714,17 +783,17 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
prefix = weechat_strndup (string, pos - string);
if (prefix)
{
weechat_hashtable_set (extra_vars, "tg_prefix", prefix);
weechat_hashtable_set (ctx.extra_vars, "tg_prefix", prefix);
free (prefix);
}
}
pos++;
if (pos[0] == '\t')
pos++;
weechat_hashtable_set (extra_vars, "tg_message", pos);
weechat_hashtable_set (ctx.extra_vars, "tg_message", pos);
}
else
weechat_hashtable_set (extra_vars, "tg_message", string);
weechat_hashtable_set (ctx.extra_vars, "tg_message", string);
/* set "tg_prefix_nocolor" and "tg_message_nocolor" */
if (string_no_color)
@@ -738,7 +807,7 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
pos - string_no_color);
if (prefix)
{
weechat_hashtable_set (extra_vars,
weechat_hashtable_set (ctx.extra_vars,
"tg_prefix_nocolor", prefix);
free (prefix);
}
@@ -746,11 +815,11 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
pos++;
if (pos[0] == '\t')
pos++;
weechat_hashtable_set (extra_vars, "tg_message_nocolor", pos);
weechat_hashtable_set (ctx.extra_vars, "tg_message_nocolor", pos);
}
else
{
weechat_hashtable_set (extra_vars,
weechat_hashtable_set (ctx.extra_vars,
"tg_message_nocolor", string_no_color);
}
}
@@ -771,11 +840,11 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
{
buffer = (struct t_gui_buffer *)value;
weechat_hashtable_set (
extra_vars,
ctx.extra_vars,
"tg_plugin",
weechat_buffer_get_string (buffer, "plugin"));
weechat_hashtable_set (
extra_vars,
ctx.extra_vars,
"tg_buffer",
weechat_buffer_get_string (buffer, "full_name"));
pos++;
@@ -795,7 +864,7 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
if (str_tags)
{
snprintf (str_tags, length, ",%s,", pos);
weechat_hashtable_set (extra_vars, "tg_tags",
weechat_hashtable_set (ctx.extra_vars, "tg_tags",
str_tags);
free (str_tags);
}
@@ -804,24 +873,23 @@ trigger_callback_modifier_cb (const void *pointer, void *data,
free (buffer_pointer);
}
}
weechat_hashtable_set (pointers, "buffer", buffer);
weechat_hashtable_set (ctx.pointers, "buffer", buffer);
}
if (tags)
{
if (!trigger_callback_set_tags (buffer, (const char **)tags, num_tags,
extra_vars))
ctx.extra_vars))
{
goto end;
}
}
/* execute the trigger (conditions, regex, command) */
(void) trigger_callback_execute (trigger, buffer, pointers, extra_vars,
NULL);
(void) trigger_callback_execute (trigger, &ctx);
end:
ptr_string = weechat_hashtable_get (extra_vars, "tg_string");
ptr_string = weechat_hashtable_get (ctx.extra_vars, "tg_string");
string_modified = (ptr_string && (strcmp (ptr_string, string) != 0)) ?
strdup (ptr_string) : NULL;
@@ -857,14 +925,14 @@ trigger_callback_line_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_POINTERS;
TRIGGER_CALLBACK_CB_NEW_VARS_UPDATED;
extra_vars = weechat_hashtable_dup (line);
ctx.extra_vars = weechat_hashtable_dup (line);
weechat_hashtable_remove (extra_vars, "buffer");
weechat_hashtable_remove (extra_vars, "tags_count");
weechat_hashtable_remove (extra_vars, "tags");
weechat_hashtable_remove (ctx.extra_vars, "buffer");
weechat_hashtable_remove (ctx.extra_vars, "tags_count");
weechat_hashtable_remove (ctx.extra_vars, "tags");
/* add data in hashtables used for conditions/replace/command */
trigger_callback_set_common_vars (trigger, extra_vars);
trigger_callback_set_common_vars (trigger, ctx.extra_vars);
ptr_value = weechat_hashtable_get (line, "buffer");
if (!ptr_value || (ptr_value[0] != '0') || (ptr_value[1] != 'x'))
goto end;
@@ -873,7 +941,7 @@ trigger_callback_line_cb (const void *pointer, void *data,
goto end;
buffer = (void *)value;
weechat_hashtable_set (pointers, "buffer", buffer);
weechat_hashtable_set (ctx.pointers, "buffer", buffer);
ptr_value = weechat_hashtable_get (line, "tags");
tags = weechat_string_split ((ptr_value) ? ptr_value : "",
",",
@@ -891,33 +959,32 @@ trigger_callback_line_cb (const void *pointer, void *data,
{
snprintf (str_tags, length, ",%s,",
(ptr_value) ? ptr_value : "");
weechat_hashtable_set (extra_vars, "tags", str_tags);
weechat_hashtable_set (ctx.extra_vars, "tags", str_tags);
free (str_tags);
}
/* build prefix without colors */
ptr_value = weechat_hashtable_get (line, "prefix");
string_no_color = weechat_string_remove_color (ptr_value, NULL);
weechat_hashtable_set (extra_vars, "tg_prefix_nocolor", string_no_color);
weechat_hashtable_set (ctx.extra_vars, "tg_prefix_nocolor", string_no_color);
if (string_no_color)
free (string_no_color);
/* build message without colors */
ptr_value = weechat_hashtable_get (line, "message");
string_no_color = weechat_string_remove_color (ptr_value, NULL);
weechat_hashtable_set (extra_vars, "tg_message_nocolor", string_no_color);
weechat_hashtable_set (ctx.extra_vars, "tg_message_nocolor", string_no_color);
if (string_no_color)
free (string_no_color);
if (!trigger_callback_set_tags (buffer, (const char **)tags, num_tags,
extra_vars))
ctx.extra_vars))
{
goto end;
}
/* execute the trigger (conditions, regex, command) */
(void) trigger_callback_execute (trigger, buffer, pointers, extra_vars,
vars_updated);
(void) trigger_callback_execute (trigger, &ctx);
hashtable = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
@@ -926,16 +993,16 @@ trigger_callback_line_cb (const void *pointer, void *data,
if (hashtable)
{
/* copy updated variables into the result "hashtable" */
for (ptr_item = weechat_list_get (vars_updated, 0); ptr_item;
for (ptr_item = weechat_list_get (ctx.vars_updated, 0); ptr_item;
ptr_item = weechat_list_next (ptr_item))
{
ptr_key = weechat_list_string (ptr_item);
if (weechat_hashtable_has_key (extra_vars, ptr_key))
if (weechat_hashtable_has_key (ctx.extra_vars, ptr_key))
{
if (strcmp (ptr_key, "tags") == 0)
{
/* remove commas at the beginning/end of tags */
ptr_value = weechat_hashtable_get (extra_vars, ptr_key);
ptr_value = weechat_hashtable_get (ctx.extra_vars, ptr_key);
if (ptr_value && ptr_value[0])
{
str_tags = strdup (
@@ -962,7 +1029,7 @@ trigger_callback_line_cb (const void *pointer, void *data,
weechat_hashtable_set (
hashtable,
ptr_key,
weechat_hashtable_get (extra_vars, ptr_key));
weechat_hashtable_get (ctx.extra_vars, ptr_key));
}
}
}
@@ -1001,32 +1068,32 @@ trigger_callback_print_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtables used for conditions/replace/command */
trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (pointers, "buffer", buffer);
trigger_callback_set_common_vars (trigger, ctx.extra_vars);
weechat_hashtable_set (ctx.pointers, "buffer", buffer);
date_tmp = localtime (&date);
if (date_tmp)
{
if (strftime (str_temp, sizeof (str_temp),
"%Y-%m-%d %H:%M:%S", date_tmp) == 0)
str_temp[0] = '\0';
weechat_hashtable_set (extra_vars, "tg_date", str_temp);
weechat_hashtable_set (ctx.extra_vars, "tg_date", str_temp);
}
snprintf (str_temp, sizeof (str_temp), "%d", displayed);
weechat_hashtable_set (extra_vars, "tg_displayed", str_temp);
weechat_hashtable_set (ctx.extra_vars, "tg_displayed", str_temp);
snprintf (str_temp, sizeof (str_temp), "%d", highlight);
weechat_hashtable_set (extra_vars, "tg_highlight", str_temp);
weechat_hashtable_set (extra_vars, "tg_prefix", prefix);
weechat_hashtable_set (ctx.extra_vars, "tg_highlight", str_temp);
weechat_hashtable_set (ctx.extra_vars, "tg_prefix", prefix);
str_no_color = weechat_string_remove_color (prefix, NULL);
if (str_no_color)
{
weechat_hashtable_set (extra_vars, "tg_prefix_nocolor", str_no_color);
weechat_hashtable_set (ctx.extra_vars, "tg_prefix_nocolor", str_no_color);
free (str_no_color);
}
weechat_hashtable_set (extra_vars, "tg_message", message);
weechat_hashtable_set (ctx.extra_vars, "tg_message", message);
str_no_color = weechat_string_remove_color (message, NULL);
if (str_no_color)
{
weechat_hashtable_set (extra_vars, "tg_message_nocolor", str_no_color);
weechat_hashtable_set (ctx.extra_vars, "tg_message_nocolor", str_no_color);
free (str_no_color);
}
@@ -1039,16 +1106,16 @@ trigger_callback_print_cb (const void *pointer, void *data,
if (str_tags2)
{
snprintf (str_tags2, length, ",%s,", str_tags);
weechat_hashtable_set (extra_vars, "tg_tags", str_tags2);
weechat_hashtable_set (ctx.extra_vars, "tg_tags", str_tags2);
free (str_tags2);
}
free (str_tags);
}
if (!trigger_callback_set_tags (buffer, tags, tags_count, extra_vars))
if (!trigger_callback_set_tags (buffer, tags, tags_count, ctx.extra_vars))
goto end;
/* execute the trigger (conditions, regex, command) */
if (!trigger_callback_execute (trigger, buffer, pointers, extra_vars, NULL))
if (!trigger_callback_execute (trigger, &ctx))
trigger_rc = WEECHAT_RC_OK;
end:
@@ -1073,36 +1140,36 @@ trigger_callback_command_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtables used for conditions/replace/command */
trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (pointers, "buffer", buffer);
trigger_callback_set_common_vars (trigger, ctx.extra_vars);
weechat_hashtable_set (ctx.pointers, "buffer", buffer);
snprintf (str_value, sizeof (str_value), "%d", argc);
weechat_hashtable_set (extra_vars, "tg_argc", str_value);
weechat_hashtable_set (ctx.extra_vars, "tg_argc", str_value);
for (i = 0; i < argc; i++)
{
snprintf (str_name, sizeof (str_name), "tg_argv%d", i);
weechat_hashtable_set (extra_vars, str_name, argv[i]);
weechat_hashtable_set (ctx.extra_vars, str_name, argv[i]);
snprintf (str_name, sizeof (str_name), "tg_argv_eol%d", i);
weechat_hashtable_set (extra_vars, str_name, argv_eol[i]);
weechat_hashtable_set (ctx.extra_vars, str_name, argv_eol[i]);
}
shell_argv = weechat_string_split_shell (argv_eol[0], &shell_argc);
if (shell_argv)
{
snprintf (str_value, sizeof (str_value), "%d", shell_argc);
weechat_hashtable_set (extra_vars, "tg_shell_argc", str_value);
weechat_hashtable_set (ctx.extra_vars, "tg_shell_argc", str_value);
for (i = 0; i < shell_argc; i++)
{
snprintf (str_name, sizeof (str_name), "tg_shell_argv%d", i);
weechat_hashtable_set (extra_vars, str_name, shell_argv[i]);
weechat_hashtable_set (ctx.extra_vars, str_name, shell_argv[i]);
}
weechat_string_free_split (shell_argv);
}
else
{
weechat_hashtable_set (extra_vars, "tg_shell_argc", "0");
weechat_hashtable_set (ctx.extra_vars, "tg_shell_argc", "0");
}
/* execute the trigger (conditions, regex, command) */
if (!trigger_callback_execute (trigger, buffer, pointers, extra_vars, NULL))
if (!trigger_callback_execute (trigger, &ctx))
trigger_rc = WEECHAT_RC_OK;
end:
@@ -1124,12 +1191,12 @@ trigger_callback_command_run_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtables used for conditions/replace/command */
trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (pointers, "buffer", buffer);
weechat_hashtable_set (extra_vars, "tg_command", command);
trigger_callback_set_common_vars (trigger, ctx.extra_vars);
weechat_hashtable_set (ctx.pointers, "buffer", buffer);
weechat_hashtable_set (ctx.extra_vars, "tg_command", command);
/* execute the trigger (conditions, regex, command) */
if (!trigger_callback_execute (trigger, buffer, pointers, extra_vars, NULL))
if (!trigger_callback_execute (trigger, &ctx))
trigger_rc = WEECHAT_RC_OK;
end:
@@ -1167,9 +1234,9 @@ trigger_callback_timer_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtable used for conditions/replace/command */
trigger_callback_set_common_vars (trigger, extra_vars);
trigger_callback_set_common_vars (trigger, ctx.extra_vars);
snprintf (str_temp, sizeof (str_temp), "%d", remaining_calls);
weechat_hashtable_set (extra_vars, "tg_remaining_calls", str_temp);
weechat_hashtable_set (ctx.extra_vars, "tg_remaining_calls", str_temp);
date = time (NULL);
date_tmp = localtime (&date);
if (date_tmp)
@@ -1177,11 +1244,11 @@ trigger_callback_timer_cb (const void *pointer, void *data,
if (strftime (str_temp, sizeof (str_temp),
"%Y-%m-%d %H:%M:%S", date_tmp) == 0)
str_temp[0] = '\0';
weechat_hashtable_set (extra_vars, "tg_date", str_temp);
weechat_hashtable_set (ctx.extra_vars, "tg_date", str_temp);
}
/* execute the trigger (conditions, regex, command) */
if (!trigger_callback_execute (trigger, NULL, pointers, extra_vars, NULL))
if (!trigger_callback_execute (trigger, &ctx))
trigger_rc = WEECHAT_RC_OK;
end:
@@ -1201,12 +1268,12 @@ trigger_callback_config_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtable used for conditions/replace/command */
trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_option", option);
weechat_hashtable_set (extra_vars, "tg_value", value);
trigger_callback_set_common_vars (trigger, ctx.extra_vars);
weechat_hashtable_set (ctx.extra_vars, "tg_option", option);
weechat_hashtable_set (ctx.extra_vars, "tg_value", value);
/* execute the trigger (conditions, regex, command) */
if (!trigger_callback_execute (trigger, NULL, pointers, extra_vars, NULL))
if (!trigger_callback_execute (trigger, &ctx))
trigger_rc = WEECHAT_RC_OK;
end:
@@ -1236,18 +1303,18 @@ trigger_callback_focus_cb (const void *pointer, void *data,
{
rc = sscanf (ptr_value + 2, "%lx", &value);
if ((rc != EOF) && (rc >= 1))
weechat_hashtable_set (pointers, "window", (void *)value);
weechat_hashtable_set (ctx.pointers, "window", (void *)value);
}
ptr_value = weechat_hashtable_get (info, "_buffer");
if (ptr_value && ptr_value[0] && (strncmp (ptr_value, "0x", 2) == 0))
{
rc = sscanf (ptr_value + 2, "%lx", &value);
if ((rc != EOF) && (rc >= 1))
weechat_hashtable_set (pointers, "buffer", (void *)value);
weechat_hashtable_set (ctx.pointers, "buffer", (void *)value);
}
/* execute the trigger (conditions, regex, command) */
(void) trigger_callback_execute (trigger, NULL, pointers, info, NULL);
(void) trigger_callback_execute (trigger, &ctx);
end:
TRIGGER_CALLBACK_CB_END(info);
@@ -1269,17 +1336,16 @@ trigger_callback_info_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtable used for conditions/replace/command */
trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_info_name", info_name);
weechat_hashtable_set (extra_vars, "tg_arguments", arguments);
weechat_hashtable_set (extra_vars, "tg_info", "");
trigger_callback_set_common_vars (trigger, ctx.extra_vars);
weechat_hashtable_set (ctx.extra_vars, "tg_info_name", info_name);
weechat_hashtable_set (ctx.extra_vars, "tg_arguments", arguments);
weechat_hashtable_set (ctx.extra_vars, "tg_info", "");
/* execute the trigger (conditions, regex, command) */
(void) trigger_callback_execute (trigger, NULL, pointers, extra_vars,
NULL);
(void) trigger_callback_execute (trigger, &ctx);
end:
ptr_info = weechat_hashtable_get (extra_vars, "tg_info");
ptr_info = weechat_hashtable_get (ctx.extra_vars, "tg_info");
info = (ptr_info) ? strdup (ptr_info) : NULL;
TRIGGER_CALLBACK_CB_END(info);
@@ -1305,15 +1371,14 @@ trigger_callback_info_hashtable_cb (const void *pointer, void *data,
TRIGGER_CALLBACK_CB_NEW_POINTERS;
TRIGGER_CALLBACK_CB_NEW_VARS_UPDATED;
extra_vars = weechat_hashtable_dup (hashtable);
ctx.extra_vars = weechat_hashtable_dup (hashtable);
/* add data in hashtable used for conditions/replace/command */
trigger_callback_set_common_vars (trigger, extra_vars);
weechat_hashtable_set (extra_vars, "tg_info_name", info_name);
trigger_callback_set_common_vars (trigger, ctx.extra_vars);
weechat_hashtable_set (ctx.extra_vars, "tg_info_name", info_name);
/* execute the trigger (conditions, regex, command) */
(void) trigger_callback_execute (trigger, NULL, pointers, extra_vars,
vars_updated);
(void) trigger_callback_execute (trigger, &ctx);
ret_hashtable = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
@@ -1322,16 +1387,16 @@ trigger_callback_info_hashtable_cb (const void *pointer, void *data,
if (ret_hashtable)
{
/* copy updated variables into the result "ret_hashtable" */
for (ptr_item = weechat_list_get (vars_updated, 0); ptr_item;
for (ptr_item = weechat_list_get (ctx.vars_updated, 0); ptr_item;
ptr_item = weechat_list_next (ptr_item))
{
ptr_key = weechat_list_string (ptr_item);
if (weechat_hashtable_has_key (extra_vars, ptr_key))
if (weechat_hashtable_has_key (ctx.extra_vars, ptr_key))
{
weechat_hashtable_set (
ret_hashtable,
ptr_key,
weechat_hashtable_get (extra_vars, ptr_key));
weechat_hashtable_get (ctx.extra_vars, ptr_key));
}
}
}