1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 08:43:13 +02:00

trigger: add hook "info_hashtable"

This commit is contained in:
Sébastien Helleu
2019-04-13 13:53:16 +02:00
parent 8bc06ea101
commit 30768d4d24
31 changed files with 574 additions and 314 deletions
+54
View File
@@ -1200,6 +1200,60 @@ end:
TRIGGER_CALLBACK_CB_END(info);
}
/*
* Callback for an info_hashtable hooked.
*/
struct t_hashtable *
trigger_callback_info_hashtable_cb (const void *pointer, void *data,
const char *info_name,
struct t_hashtable *hashtable)
{
struct t_hashtable *ret_hashtable;
struct t_weelist_item *ptr_item;
const char *ptr_key;
TRIGGER_CALLBACK_CB_INIT(NULL);
ret_hashtable = NULL;
TRIGGER_CALLBACK_CB_NEW_POINTERS;
TRIGGER_CALLBACK_CB_NEW_VARS_UPDATED;
extra_vars = weechat_hashtable_dup (hashtable);
/* add data in hashtable used for conditions/replace/command */
weechat_hashtable_set (extra_vars, "tg_info_name", info_name);
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, NULL, pointers, extra_vars,
vars_updated);
ret_hashtable = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
if (ret_hashtable)
{
/* copy updated variables into the result "ret_hashtable" */
for (ptr_item = weechat_list_get (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))
{
weechat_hashtable_set (
ret_hashtable,
ptr_key,
weechat_hashtable_get (extra_vars, ptr_key));
}
}
}
end:
TRIGGER_CALLBACK_CB_END(ret_hashtable);
}
/*
* Initializes trigger callback.
*/
+4
View File
@@ -131,6 +131,10 @@ extern char *trigger_callback_info_cb (const void *pointer,
void *data,
const char *info_name,
const char *arguments);
extern struct t_hashtable *trigger_callback_info_hashtable_cb (const void *pointer,
void *data,
const char *info_name,
struct t_hashtable *hashtable);
extern void trigger_callback_init ();
extern void trigger_callback_end ();
+4 -3
View File
@@ -1157,7 +1157,7 @@ trigger_command_init ()
" addreplace: add or replace an existing trigger\n"
" name: name of trigger\n"
" hook: signal, hsignal, modifier, line, print, command, "
"command_run, timer, config, focus, info\n"
"command_run, timer, config, focus, info, info_hashtable\n"
" arguments: arguments for the hook, depending on hook (separated "
"by semicolons):\n"
" signal: name(s) of signal (required)\n"
@@ -1173,6 +1173,7 @@ trigger_command_init ()
" config: name(s) of option (required)\n"
" focus: name(s) of area (required)\n"
" info: name(s) of info (required)\n"
" info_hashtable: name(s) of info (required)\n"
" conditions: evaluated conditions for the trigger\n"
" regex: one or more regular expressions to replace strings "
"in variables\n"
@@ -1218,8 +1219,8 @@ trigger_command_init ()
" 2. replace text using POSIX extended regular expression(s) (if "
"defined in trigger)\n"
" 3. execute command(s) (if defined in trigger)\n"
" 4. exit with a return code (except for modifier, line, focus "
"and info)\n"
" 4. exit with a return code (except for modifier, line, focus, "
"info and info_hashtable)\n"
" 5. perform post action\n"
"\n"
"Examples (you can also look at default triggers with /trigger "
+25 -5
View File
@@ -50,20 +50,20 @@ char *trigger_option_default[TRIGGER_NUM_OPTIONS] =
char *trigger_hook_type_string[TRIGGER_NUM_HOOK_TYPES] =
{ "signal", "hsignal", "modifier", "line", "print", "command", "command_run",
"timer", "config", "focus", "info" };
"timer", "config", "focus", "info", "info_hashtable" };
char *trigger_hook_option_values =
"signal|hsignal|modifier|line|print|command|command_run|timer|config|"
"focus|info";
"focus|info|info_hashtable";
char *trigger_hook_default_arguments[TRIGGER_NUM_HOOK_TYPES] =
{ "xxx", "xxx", "xxx", "", "", "cmd;desc;args;args_desc;%(buffers_names)",
"/cmd", "60000;0;0", "xxx", "chat", "xxx" };
"/cmd", "60000;0;0", "xxx", "chat", "xxx", "xxx" };
char *trigger_hook_default_rc[TRIGGER_NUM_HOOK_TYPES] =
{ "ok,ok_eat,error", "ok,ok_eat,error", "", "", "ok,error", "ok,error",
"ok,ok_eat,error", "ok", "ok", "", "" };
"ok,ok_eat,error", "ok", "ok", "", "", "" };
char *trigger_hook_regex_default_var[TRIGGER_NUM_HOOK_TYPES] =
{ "tg_signal_data", "", "tg_string", "message", "tg_message", "tg_argv_eol1",
"tg_command", "tg_remaining_calls", "tg_value", "", "tg_info" };
"tg_command", "tg_remaining_calls", "tg_value", "", "tg_info", "" };
char *trigger_return_code_string[TRIGGER_NUM_RETURN_CODES] =
{ "ok", "ok_eat", "error" };
@@ -509,6 +509,26 @@ trigger_hook (struct t_trigger *trigger)
}
}
break;
case TRIGGER_HOOK_INFO_HASHTABLE:
if (argv && (argc >= 1))
{
trigger->hooks = malloc (argc * sizeof (trigger->hooks[0]));
if (trigger->hooks)
{
trigger->hooks_count = argc;
for (i = 0; i < argc; i++)
{
trigger->hooks[i] = weechat_hook_info_hashtable (
argv[i],
NULL,
NULL,
NULL,
&trigger_callback_info_hashtable_cb,
trigger, NULL);
}
}
}
break;
}
if (!trigger->hooks)
+1
View File
@@ -56,6 +56,7 @@ enum t_trigger_hook_type
TRIGGER_HOOK_CONFIG,
TRIGGER_HOOK_FOCUS,
TRIGGER_HOOK_INFO,
TRIGGER_HOOK_INFO_HASHTABLE,
/* number of hook types */
TRIGGER_NUM_HOOK_TYPES,
};