From 93038a3634640dc762c2ba186de2436606dac454 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 14 Feb 2014 12:37:34 +0100 Subject: [PATCH] trigger: add options "input" and "output" in command /trigger --- src/plugins/trigger/trigger-command.c | 49 ++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/plugins/trigger/trigger-command.c b/src/plugins/trigger/trigger-command.c index 66757ff4f..b420c576a 100644 --- a/src/plugins/trigger/trigger-command.c +++ b/src/plugins/trigger/trigger-command.c @@ -405,7 +405,7 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_trigger *ptr_trigger; - char *value, **sargv, **items, input[1024]; + char *value, **sargv, **items, input[1024], str_pos[16]; int i, type, count, index_option, enable, sargc, num_items; /* make C compiler happy */ @@ -532,6 +532,49 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc, goto end; } + /* get command to create a trigger (in input or send it to buffer) */ + if ((weechat_strcasecmp (argv[1], "input") == 0) + || (weechat_strcasecmp (argv[1], "output") == 0)) + { + if (argc < 3) + { + weechat_printf_tags (NULL, "no_trigger", + _("%sError: missing arguments for \"%s\" " + "command"), + weechat_prefix ("error"), "trigger"); + goto end; + } + ptr_trigger = trigger_search (argv[2]); + if (!ptr_trigger) + { + weechat_printf_tags (NULL, "no_trigger", + _("%sError: trigger \"%s\" not found"), + weechat_prefix ("error"), argv[2]); + goto end; + } + snprintf (input, sizeof (input), + "//trigger add %s %s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", + ptr_trigger->name, + weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_HOOK]), + weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_ARGUMENTS]), + weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_CONDITIONS]), + weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_REGEX]), + weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_COMMAND]), + weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_RETURN_CODE])); + if (weechat_strcasecmp (argv[1], "input") == 0) + { + weechat_buffer_set (buffer, "input", input + 1); + snprintf (str_pos, sizeof (str_pos), + "%d", weechat_utf8_strlen (input + 1)); + weechat_buffer_set (buffer, "input_pos", str_pos); + } + else + { + weechat_command (buffer, input); + } + goto end; + } + /* set option in a trigger */ if (weechat_strcasecmp (argv[1], "set") == 0) { @@ -763,6 +806,7 @@ trigger_command_init () " || add [\"\" [\"\" " "[\"\" [\"\" [\"\"]]]]]" " || addinput []" + " || input|output " " || set