mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 07:46:38 +02:00
trigger: add elapsed time for trigger execution on monitor buffer when trigger debug is set (closes #1806)
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "../weechat-plugin.h"
|
||||
#include "trigger.h"
|
||||
#include "trigger-buffer.h"
|
||||
#include "trigger-callback.h"
|
||||
#include "trigger-config.h"
|
||||
|
||||
|
||||
@@ -250,13 +251,15 @@ trigger_buffer_hashtable_map_cb (void *data,
|
||||
struct t_hashtable *hashtable,
|
||||
const void *key, const void *value)
|
||||
{
|
||||
struct t_trigger_context *context;
|
||||
const char *value_type;
|
||||
char *value_no_color;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) hashtable;
|
||||
|
||||
context = (struct t_trigger_context *)data;
|
||||
|
||||
value_type = weechat_hashtable_get_string (hashtable, "type_values");
|
||||
if (!value_type)
|
||||
return;
|
||||
@@ -267,7 +270,9 @@ trigger_buffer_hashtable_map_cb (void *data,
|
||||
weechat_string_remove_color ((const char *)value, NULL) : NULL;
|
||||
weechat_printf_date_tags (
|
||||
trigger_buffer, 0, "no_trigger",
|
||||
"\t %s: %s\"%s%s%s\"",
|
||||
"%s%lu\t %s: %s\"%s%s%s\"",
|
||||
weechat_color (weechat_config_string (trigger_config_color_identifier)),
|
||||
context->id,
|
||||
(char *)key,
|
||||
weechat_color ("chat_delimiters"),
|
||||
weechat_color ("reset"),
|
||||
@@ -278,10 +283,13 @@ trigger_buffer_hashtable_map_cb (void *data,
|
||||
}
|
||||
else if (strcmp (value_type, "pointer") == 0)
|
||||
{
|
||||
weechat_printf_date_tags (trigger_buffer, 0, "no_trigger",
|
||||
"\t %s: 0x%lx",
|
||||
(char *)key,
|
||||
value);
|
||||
weechat_printf_date_tags (
|
||||
trigger_buffer, 0, "no_trigger",
|
||||
"%s%lu\t %s: 0x%lx",
|
||||
weechat_color (weechat_config_string (trigger_config_color_identifier)),
|
||||
context->id,
|
||||
(char *)key,
|
||||
value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,15 +298,22 @@ trigger_buffer_hashtable_map_cb (void *data,
|
||||
*/
|
||||
|
||||
void
|
||||
trigger_buffer_display_hashtable (const char *name,
|
||||
trigger_buffer_display_hashtable (struct t_trigger_context *context,
|
||||
const char *name,
|
||||
struct t_hashtable *hashtable)
|
||||
{
|
||||
if (!trigger_buffer)
|
||||
return;
|
||||
|
||||
weechat_printf_date_tags (trigger_buffer, 0, "no_trigger", " %s:", name);
|
||||
weechat_printf_date_tags (
|
||||
trigger_buffer, 0, "no_trigger",
|
||||
"%s%lu\t %s:",
|
||||
weechat_color (weechat_config_string (trigger_config_color_identifier)),
|
||||
context->id,
|
||||
name);
|
||||
|
||||
weechat_hashtable_map (hashtable, &trigger_buffer_hashtable_map_cb, NULL);
|
||||
weechat_hashtable_map (hashtable,
|
||||
&trigger_buffer_hashtable_map_cb, context);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -311,9 +326,7 @@ trigger_buffer_display_hashtable (const char *name,
|
||||
|
||||
int
|
||||
trigger_buffer_display_trigger (struct t_trigger *trigger,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_hashtable *pointers,
|
||||
struct t_hashtable *extra_vars)
|
||||
struct t_trigger_context *context)
|
||||
{
|
||||
if (!trigger_buffer)
|
||||
return 0;
|
||||
@@ -324,26 +337,37 @@ trigger_buffer_display_trigger (struct t_trigger *trigger,
|
||||
|
||||
weechat_printf_date_tags (
|
||||
trigger_buffer, 0, "no_trigger",
|
||||
"%s\t%s%s %s(%s%s%s)",
|
||||
"--> %s%lu\t%s: %s%s %s(%s%s%s)%s",
|
||||
weechat_color (weechat_config_string (trigger_config_color_identifier)),
|
||||
context->id,
|
||||
trigger_hook_type_string[weechat_config_integer (trigger->options[TRIGGER_OPTION_HOOK])],
|
||||
weechat_color (weechat_config_string (trigger_config_color_trigger)),
|
||||
trigger->name,
|
||||
weechat_color ("chat_delimiters"),
|
||||
weechat_color ("reset"),
|
||||
weechat_config_string (trigger->options[TRIGGER_OPTION_ARGUMENTS]),
|
||||
weechat_color ("chat_delimiters"));
|
||||
if (buffer)
|
||||
weechat_color ("chat_delimiters"),
|
||||
weechat_color ("reset"));
|
||||
if (context->buffer)
|
||||
{
|
||||
weechat_printf_date_tags (
|
||||
trigger_buffer, 0, "no_trigger",
|
||||
"\t buffer: %s%s",
|
||||
"%s%lu\t buffer: %s%s",
|
||||
weechat_color (weechat_config_string (trigger_config_color_identifier)),
|
||||
context->id,
|
||||
weechat_color ("chat_buffer"),
|
||||
weechat_buffer_get_string (buffer, "full_name"));
|
||||
weechat_buffer_get_string (context->buffer, "full_name"));
|
||||
}
|
||||
if (context->pointers)
|
||||
{
|
||||
trigger_buffer_display_hashtable (context,
|
||||
"pointers", context->pointers);
|
||||
}
|
||||
if (context->extra_vars)
|
||||
{
|
||||
trigger_buffer_display_hashtable (context,
|
||||
"extra_vars", context->extra_vars);
|
||||
}
|
||||
if (pointers)
|
||||
trigger_buffer_display_hashtable ("pointers", pointers);
|
||||
if (extra_vars)
|
||||
trigger_buffer_display_hashtable ("extra_vars", extra_vars);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@
|
||||
|
||||
#define TRIGGER_BUFFER_NAME "monitor"
|
||||
|
||||
struct t_trigger_context;
|
||||
|
||||
extern struct t_gui_buffer *trigger_buffer;
|
||||
|
||||
extern void trigger_buffer_set_callbacks ();
|
||||
extern void trigger_buffer_open (const char *filter, int switch_to_buffer);
|
||||
extern int trigger_buffer_display_trigger (struct t_trigger *trigger,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_hashtable *pointers,
|
||||
struct t_hashtable *extra_vars);
|
||||
struct t_trigger_context *context);
|
||||
extern void trigger_buffer_end ();
|
||||
|
||||
#endif /* WEECHAT_PLUGIN_TRIGGER_BUFFER_H */
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,23 +21,36 @@
|
||||
#define WEECHAT_PLUGIN_TRIGGER_CALLBACK_H
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
struct t_trigger_context
|
||||
{
|
||||
unsigned long id;
|
||||
struct t_gui_buffer *buffer;
|
||||
struct t_hashtable *pointers;
|
||||
struct t_hashtable *extra_vars;
|
||||
struct t_weelist *vars_updated;
|
||||
struct timeval start_exec;
|
||||
struct timeval start_check_conditions;
|
||||
struct timeval start_replace_regex;
|
||||
struct timeval start_run_command;
|
||||
struct timeval end_exec;
|
||||
};
|
||||
|
||||
#define TRIGGER_CALLBACK_CB_INIT(__rc) \
|
||||
struct t_trigger *trigger; \
|
||||
struct t_hashtable *pointers, *extra_vars; \
|
||||
struct t_weelist *vars_updated; \
|
||||
struct t_trigger_context ctx; \
|
||||
int trigger_rc; \
|
||||
pointers = NULL; \
|
||||
extra_vars = NULL; \
|
||||
vars_updated = NULL; \
|
||||
(void) data; \
|
||||
(void) vars_updated; \
|
||||
(void) trigger_rc; \
|
||||
if (!trigger_enabled) \
|
||||
return __rc; \
|
||||
trigger = (struct t_trigger *)pointer; \
|
||||
if (!trigger || trigger->hook_running) \
|
||||
return __rc; \
|
||||
memset (&ctx, 0, sizeof (ctx)); \
|
||||
if (weechat_trigger_plugin->debug >= 1) \
|
||||
gettimeofday (&(ctx.start_exec), NULL); \
|
||||
trigger->hook_count_cb++; \
|
||||
trigger->hook_running = 1; \
|
||||
trigger_rc = trigger_return_code[ \
|
||||
@@ -45,35 +58,35 @@
|
||||
trigger->options[TRIGGER_OPTION_RETURN_CODE])];
|
||||
|
||||
#define TRIGGER_CALLBACK_CB_NEW_POINTERS \
|
||||
pointers = weechat_hashtable_new ( \
|
||||
ctx.pointers = weechat_hashtable_new ( \
|
||||
32, \
|
||||
WEECHAT_HASHTABLE_STRING, \
|
||||
WEECHAT_HASHTABLE_POINTER, \
|
||||
NULL, NULL); \
|
||||
if (!pointers) \
|
||||
if (!ctx.pointers) \
|
||||
goto end;
|
||||
|
||||
#define TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS \
|
||||
extra_vars = weechat_hashtable_new ( \
|
||||
ctx.extra_vars = weechat_hashtable_new ( \
|
||||
32, \
|
||||
WEECHAT_HASHTABLE_STRING, \
|
||||
WEECHAT_HASHTABLE_STRING, \
|
||||
NULL, NULL); \
|
||||
if (!extra_vars) \
|
||||
if (!ctx.extra_vars) \
|
||||
goto end;
|
||||
|
||||
#define TRIGGER_CALLBACK_CB_NEW_VARS_UPDATED \
|
||||
vars_updated = weechat_list_new (); \
|
||||
if (!vars_updated) \
|
||||
ctx.vars_updated = weechat_list_new (); \
|
||||
if (!ctx.vars_updated) \
|
||||
goto end;
|
||||
|
||||
#define TRIGGER_CALLBACK_CB_END(__rc) \
|
||||
if (pointers) \
|
||||
weechat_hashtable_free (pointers); \
|
||||
if (extra_vars) \
|
||||
weechat_hashtable_free (extra_vars); \
|
||||
if (vars_updated) \
|
||||
weechat_list_free (vars_updated); \
|
||||
if (ctx.pointers) \
|
||||
weechat_hashtable_free (ctx.pointers); \
|
||||
if (ctx.extra_vars) \
|
||||
weechat_hashtable_free (ctx.extra_vars); \
|
||||
if (ctx.vars_updated) \
|
||||
weechat_list_free (ctx.vars_updated); \
|
||||
trigger->hook_running = 0; \
|
||||
switch (weechat_config_integer ( \
|
||||
trigger->options[TRIGGER_OPTION_POST_ACTION])) \
|
||||
|
||||
@@ -43,6 +43,7 @@ struct t_config_option *trigger_config_color_flag_conditions;
|
||||
struct t_config_option *trigger_config_color_flag_regex;
|
||||
struct t_config_option *trigger_config_color_flag_return_code;
|
||||
struct t_config_option *trigger_config_color_flag_post_action;
|
||||
struct t_config_option *trigger_config_color_identifier;
|
||||
struct t_config_option *trigger_config_color_regex;
|
||||
struct t_config_option *trigger_config_color_replace;
|
||||
struct t_config_option *trigger_config_color_trigger;
|
||||
@@ -764,6 +765,12 @@ trigger_config_init ()
|
||||
N_("text color for post action flag (in /trigger list)"),
|
||||
NULL, 0, 0, "lightblue", NULL, 0,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
trigger_config_color_identifier = weechat_config_new_option (
|
||||
trigger_config_file, ptr_section,
|
||||
"identifier", "color",
|
||||
N_("text color for trigger context identifier in monitor buffer"),
|
||||
NULL, 0, 0, "cyan", NULL, 0,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
trigger_config_color_regex = weechat_config_new_option (
|
||||
trigger_config_file, ptr_section,
|
||||
"regex", "color",
|
||||
|
||||
@@ -34,6 +34,7 @@ extern struct t_config_option *trigger_config_color_flag_conditions;
|
||||
extern struct t_config_option *trigger_config_color_flag_regex;
|
||||
extern struct t_config_option *trigger_config_color_flag_return_code;
|
||||
extern struct t_config_option *trigger_config_color_flag_post_action;
|
||||
extern struct t_config_option *trigger_config_color_identifier;
|
||||
extern struct t_config_option *trigger_config_color_regex;
|
||||
extern struct t_config_option *trigger_config_color_replace;
|
||||
extern struct t_config_option *trigger_config_color_trigger;
|
||||
|
||||
Reference in New Issue
Block a user