1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 21:36:37 +02:00

Merge remote-tracking branch 'origin/pr/509'

This commit is contained in:
Sébastien Helleu
2016-08-09 21:05:34 +02:00
8 changed files with 176 additions and 15 deletions
+43 -5
View File
@@ -44,9 +44,9 @@ struct t_weechat_plugin *weechat_trigger_plugin = NULL;
char *trigger_option_string[TRIGGER_NUM_OPTIONS] =
{ "enabled", "hook", "arguments", "conditions", "regex", "command",
"return_code" };
"return_code", "once_action" };
char *trigger_option_default[TRIGGER_NUM_OPTIONS] =
{ "on", "signal", "", "", "", "", "ok" };
{ "on", "signal", "", "", "", "", "ok", "none" };
char *trigger_hook_type_string[TRIGGER_NUM_HOOK_TYPES] =
{ "signal", "hsignal", "modifier", "print", "command", "command_run", "timer",
@@ -69,6 +69,9 @@ char *trigger_return_code_string[TRIGGER_NUM_RETURN_CODES] =
int trigger_return_code[TRIGGER_NUM_RETURN_CODES] =
{ WEECHAT_RC_OK, WEECHAT_RC_OK_EAT, WEECHAT_RC_ERROR };
char *trigger_once_action_string[TRIGGER_NUM_ONCE_ACTIONS] =
{ "none", "disable", "delete" };
struct t_trigger *triggers = NULL; /* first trigger */
struct t_trigger *last_trigger = NULL; /* last trigger */
int triggers_count = 0; /* number of triggers */
@@ -145,6 +148,27 @@ trigger_search_return_code (const char *return_code)
return -1;
}
/*
* Searches for trigger once action.
*
* Returns index of once action in enum t_trigger_once_action, -1 if not found.
*/
int
trigger_search_once_action (const char *once_action)
{
int i;
for (i = 0; i < TRIGGER_NUM_ONCE_ACTIONS; i++)
{
if (weechat_strcasecmp (trigger_once_action_string[i], once_action) == 0)
return i;
}
/* once action not found */
return -1;
}
/*
* Searches for a trigger by name.
*
@@ -872,7 +896,8 @@ trigger_new_with_options (const char *name, struct t_config_option **options)
struct t_trigger *
trigger_new (const char *name, const char *enabled, const char *hook,
const char *arguments, const char *conditions, const char *regex,
const char *command, const char *return_code)
const char *command, const char *return_code,
const char *once_action)
{
struct t_config_option *option[TRIGGER_NUM_OPTIONS];
const char *value[TRIGGER_NUM_OPTIONS];
@@ -890,6 +915,13 @@ trigger_new (const char *name, const char *enabled, const char *hook,
return NULL;
}
/* look for once action */
if (once_action && once_action[0]
&& (trigger_search_once_action (once_action) < 0))
{
return NULL;
}
value[TRIGGER_OPTION_ENABLED] = enabled;
value[TRIGGER_OPTION_HOOK] = hook;
value[TRIGGER_OPTION_ARGUMENTS] = arguments;
@@ -897,6 +929,7 @@ trigger_new (const char *name, const char *enabled, const char *hook,
value[TRIGGER_OPTION_REGEX] = regex;
value[TRIGGER_OPTION_COMMAND] = command;
value[TRIGGER_OPTION_RETURN_CODE] = return_code;
value[TRIGGER_OPTION_ONCE_ACTION] = once_action;
for (i = 0; i < TRIGGER_NUM_OPTIONS; i++)
{
@@ -933,7 +966,8 @@ trigger_create_default ()
trigger_config_default_list[i][4], /* conditions */
trigger_config_default_list[i][5], /* regex */
trigger_config_default_list[i][6], /* command */
trigger_config_default_list[i][7]); /* return code */
trigger_config_default_list[i][7], /* return code */
trigger_config_default_list[i][8]); /* once action */
}
}
@@ -1017,7 +1051,8 @@ trigger_copy (struct t_trigger *trigger, const char *name)
weechat_config_string (trigger->options[TRIGGER_OPTION_CONDITIONS]),
weechat_config_string (trigger->options[TRIGGER_OPTION_REGEX]),
weechat_config_string (trigger->options[TRIGGER_OPTION_COMMAND]),
weechat_config_string (trigger->options[TRIGGER_OPTION_RETURN_CODE]));
weechat_config_string (trigger->options[TRIGGER_OPTION_RETURN_CODE]),
weechat_config_string (trigger->options[TRIGGER_OPTION_ONCE_ACTION]));
}
/*
@@ -1105,6 +1140,9 @@ trigger_print_log ()
weechat_log_printf (" return_code . . . . . . : %d ('%s')",
weechat_config_integer (ptr_trigger->options[TRIGGER_OPTION_RETURN_CODE]),
trigger_return_code_string[weechat_config_integer (ptr_trigger->options[TRIGGER_OPTION_RETURN_CODE])]);
weechat_log_printf (" once_action . . . . . . : %d ('%s')",
weechat_config_integer (ptr_trigger->options[TRIGGER_OPTION_ONCE_ACTION]),
trigger_once_action_string[weechat_config_integer (ptr_trigger->options[TRIGGER_OPTION_ONCE_ACTION])]);
weechat_log_printf (" hooks_count . . . . . . : %d", ptr_trigger->hooks_count);
weechat_log_printf (" hooks . . . . . . . . . : 0x%lx", ptr_trigger->hooks);
for (i = 0; i < ptr_trigger->hooks_count; i++)