summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/trigger/trigger-callback.c33
-rw-r--r--src/plugins/trigger/trigger-config.c21
-rw-r--r--src/plugins/trigger/trigger.c46
-rw-r--r--src/plugins/trigger/trigger.h5
4 files changed, 85 insertions, 20 deletions
diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c
index 82ec50750..7bc519ded 100644
--- a/src/plugins/trigger/trigger-callback.c
+++ b/src/plugins/trigger/trigger-callback.c
@@ -139,32 +139,27 @@ trigger_callback_run_command (struct t_trigger *trigger,
struct t_hashtable *pointers,
struct t_hashtable *extra_vars)
{
- const char *command;
- char *command_eval, **commands, **ptr_command;
+ char *command_eval;
+ int i;
- command = weechat_config_string (trigger->options[TRIGGER_OPTION_COMMAND]);
- if (!command || !command[0])
+ if (!trigger->commands)
return;
- command_eval = weechat_string_eval_expression (command, pointers,
- extra_vars, NULL);
- if (command_eval)
+ for (i = 0; trigger->commands[i]; i++)
{
- commands = weechat_string_split_command (command_eval, ';');
- if (commands)
+ command_eval = weechat_string_eval_expression (trigger->commands[i],
+ pointers, extra_vars,
+ NULL);
+ if (command_eval)
{
- for (ptr_command = commands; *ptr_command; ptr_command++)
+ /* display debug info on trigger buffer */
+ if (trigger_buffer)
{
- /* display debug info on trigger buffer */
- if (trigger_buffer)
- {
- weechat_printf_tags (trigger_buffer, "no_trigger",
- "\t running command \"%s\"",
- *ptr_command);
- }
- weechat_command (buffer, *ptr_command);
+ weechat_printf_tags (trigger_buffer, "no_trigger",
+ "\t running command \"%s\"",
+ trigger->commands[i]);
}
- weechat_string_free_split_command (commands);
+ weechat_command (buffer, trigger->commands[i]);
trigger->hook_count_cmd++;
}
free (command_eval);
diff --git a/src/plugins/trigger/trigger-config.c b/src/plugins/trigger/trigger-config.c
index 992d3da6a..1dc27c0c2 100644
--- a/src/plugins/trigger/trigger-config.c
+++ b/src/plugins/trigger/trigger-config.c
@@ -125,6 +125,25 @@ trigger_config_change_regex (void *data, struct t_config_option *option)
}
/*
+ * Callback called when trigger option "command" is changed.
+ */
+
+void
+trigger_config_change_command (void *data, struct t_config_option *option)
+{
+ struct t_trigger *ptr_trigger;
+
+ /* make C compiler happy */
+ (void) data;
+
+ ptr_trigger = trigger_search_with_option (option);
+ if (!ptr_trigger)
+ return;
+
+ trigger_set_commands (ptr_trigger);
+}
+
+/*
* Creates an option for a trigger.
*
* Returns pointer to new option, NULL if error.
@@ -212,7 +231,7 @@ trigger_config_create_option (const char *trigger_name, int index_option,
option_name, "string",
N_("command run if conditions are OK, after regex replacements"),
NULL, 0, 0, value, NULL, 0,
- NULL, NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, &trigger_config_change_command, NULL, NULL, NULL);
break;
case TRIGGER_OPTION_RETURN_CODE:
ptr_option = weechat_config_new_option (
diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c
index df5ab291b..6aebc8793 100644
--- a/src/plugins/trigger/trigger.c
+++ b/src/plugins/trigger/trigger.c
@@ -586,6 +586,37 @@ end:
}
/*
+ * Sets the commands in a trigger.
+ */
+
+void
+trigger_set_commands (struct t_trigger *trigger)
+{
+ const char *option_command;
+ int i;
+
+ if (trigger->commands)
+ {
+ weechat_string_free_split (trigger->commands);
+ trigger->commands = NULL;
+ }
+ trigger->commands_count = 0;
+
+ option_command = weechat_config_string (trigger->options[TRIGGER_OPTION_COMMAND]);
+ if (option_command && option_command[0])
+ {
+ trigger->commands = weechat_string_split_command (option_command, ';');
+ if (trigger->commands)
+ {
+ for (i = 0; trigger->commands[i]; i++)
+ {
+ }
+ trigger->commands_count = i;
+ }
+ }
+}
+
+/*
* Checks if a trigger name is valid: it must not start with "-" and not have
* any spaces.
*
@@ -643,6 +674,8 @@ trigger_alloc (const char *name)
new_trigger->hook_print_buffers = NULL;
new_trigger->regex_count = 0;
new_trigger->regex = NULL;
+ new_trigger->commands_count = 0;
+ new_trigger->commands = NULL;
new_trigger->prev_trigger = NULL;
new_trigger->next_trigger = NULL;
@@ -729,6 +762,7 @@ trigger_new_with_options (const char *name, struct t_config_option **options)
triggers_count++;
trigger_set_regex (new_trigger);
+ trigger_set_commands (new_trigger);
if (weechat_config_boolean (new_trigger->options[TRIGGER_OPTION_ENABLED]))
trigger_hook (new_trigger);
@@ -877,6 +911,8 @@ trigger_free (struct t_trigger *trigger)
if (trigger->options[i])
weechat_config_option_free (trigger->options[i]);
}
+ if (trigger->commands)
+ weechat_string_free_split (trigger->commands);
free (trigger);
@@ -954,6 +990,16 @@ trigger_print_log ()
weechat_log_printf (" regex[%03d].replace_eval : '%s'",
i, ptr_trigger->regex[i].replace_eval);
}
+ weechat_log_printf (" commands_count. . . . . : %d", ptr_trigger->commands_count);
+ weechat_log_printf (" commands. . . . . . . . : 0x%lx", ptr_trigger->commands);
+ if (ptr_trigger->commands)
+ {
+ for (i = 0; ptr_trigger->commands[i]; i++)
+ {
+ weechat_log_printf (" commands[%03d] . . . . : '%s'",
+ i, ptr_trigger->commands[i]);
+ }
+ }
weechat_log_printf (" prev_trigger. . . . . . : 0x%lx", ptr_trigger->prev_trigger);
weechat_log_printf (" next_trigger. . . . . . : 0x%lx", ptr_trigger->next_trigger);
}
diff --git a/src/plugins/trigger/trigger.h b/src/plugins/trigger/trigger.h
index 7c72a52b4..672dd2eb0 100644
--- a/src/plugins/trigger/trigger.h
+++ b/src/plugins/trigger/trigger.h
@@ -88,6 +88,10 @@ struct t_trigger
int regex_count; /* number of regex */
struct t_trigger_regex *regex; /* array of regex */
+ /* commands */
+ int commands_count; /* number of commands */
+ char **commands; /* commands */
+
/* links to other triggers */
struct t_trigger *prev_trigger; /* link to previous trigger */
struct t_trigger *next_trigger; /* link to next trigger */
@@ -117,6 +121,7 @@ extern int trigger_search_return_code (const char *return_code);
extern struct t_trigger *trigger_search (const char *name);
extern struct t_trigger *trigger_search_with_option (struct t_config_option *option);
extern void trigger_set_regex (struct t_trigger *trigger);
+extern void trigger_set_commands (struct t_trigger *trigger);
extern void trigger_unhook (struct t_trigger *trigger);
extern void trigger_hook (struct t_trigger *trigger);
extern int trigger_name_valid (const char *name);