diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-04-24 21:37:38 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-04-24 22:09:15 +0200 |
commit | b7f3127bf81d53ea51a4147bb6ae3b7edcff2acd (patch) | |
tree | 1abcf4b64fd9f6c73e75da4a4079a31a97b2812b | |
parent | f69ef840e0baa40456eda6dcad43e2ec26c7a968 (diff) | |
download | weechat-b7f3127bf81d53ea51a4147bb6ae3b7edcff2acd.zip |
api: allow to catch multiple signals in functions hook_signal and hook_hsignal (closes #1780)
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | doc/en/weechat_plugin_api.en.adoc | 18 | ||||
-rw-r--r-- | doc/fr/weechat_plugin_api.fr.adoc | 18 | ||||
-rw-r--r-- | doc/it/weechat_plugin_api.it.adoc | 20 | ||||
-rw-r--r-- | doc/ja/weechat_plugin_api.ja.adoc | 20 | ||||
-rw-r--r-- | doc/sr/weechat_plugin_api.sr.adoc | 23 | ||||
-rw-r--r-- | src/core/hook/wee-hook-hsignal.c | 66 | ||||
-rw-r--r-- | src/core/hook/wee-hook-hsignal.h | 6 | ||||
-rw-r--r-- | src/core/hook/wee-hook-signal.c | 66 | ||||
-rw-r--r-- | src/core/hook/wee-hook-signal.h | 6 | ||||
-rw-r--r-- | src/gui/gui-bar-item.c | 139 | ||||
-rw-r--r-- | src/gui/gui-chat.c | 8 | ||||
-rw-r--r-- | src/plugins/perl/weechat-perl.c | 4 | ||||
-rw-r--r-- | src/plugins/trigger/trigger.c | 30 |
14 files changed, 226 insertions, 199 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 2dc32468b..1d0d53f10 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -23,6 +23,7 @@ New features:: * core: add bar item "spacer" (issue #1700) * core: add case conversion in evaluation of expressions with `lower:string` and `upper:string` (issue #1778) * core: move detailed list of hooks from command `/plugin listfull` to `/debug hooks <plugin>` + * api: allow to catch multiple signals in functions hook_signal and hook_hsignal (issue #1780) Bug fixes:: diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 826ef5bd9..6e9b10f76 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -10282,7 +10282,7 @@ hook = weechat.hook_print("", "", "", 1, "my_print_cb", "") ==== hook_signal -_Updated in 1.5._ +_Updated in 1.5, 3.6._ Hook a signal. @@ -10302,7 +10302,8 @@ struct t_hook *weechat_hook_signal (const char *signal, Arguments: -* _signal_: signal to catch, wildcard `+*+` is allowed +* _signal_: signal to catch, wildcard `+*+` is allowed; multiple signals can + be separated by semi-colons (priority allowed, see note about <<hook_priority,priority>>) (see table below) * _callback_: function called when signal is received, arguments and return @@ -10982,8 +10983,8 @@ my_signal_cb (const void *pointer, void *data, const char *signal, return WEECHAT_RC_OK; } -/* catch signal "quit" */ -struct t_hook *my_signal_hook = weechat_hook_signal ("quit", +/* catch signals "quit" and "upgrade" */ +struct t_hook *my_signal_hook = weechat_hook_signal ("quit;upgrade", &my_signal_cb, NULL, NULL); ---- @@ -10999,8 +11000,8 @@ def my_signal_cb(data, signal, signal_data): # ... return weechat.WEECHAT_RC_OK -# catch signal "quit" -hook = weechat.hook_signal("quit", "my_signal_cb", "") +# catch signals "quit" and "upgrade" +hook = weechat.hook_signal("quit;upgrade", "my_signal_cb", "") ---- ==== hook_signal_send @@ -11204,7 +11205,7 @@ weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, ==== hook_hsignal -_WeeChat ≥ 0.3.4, updated in 1.5._ +_WeeChat ≥ 0.3.4, updated in 1.5, 3.6._ Hook a hsignal (signal with hashtable). @@ -11223,7 +11224,8 @@ struct t_hook *weechat_hook_hsignal (const char *signal, Arguments: -* _signal_: signal to catch, wildcard `+*+` is allowed +* _signal_: signal to catch, wildcard `+*+` is allowed; multiple signals can + be separated by semi-colons (priority allowed, see note about <<hook_priority,priority>>) (see table below) * _callback_: function called when signal is received, arguments and return diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index bfd58bee3..2404de926 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -10487,7 +10487,7 @@ hook = weechat.hook_print("", "", "", 1, "my_print_cb", "") ==== hook_signal -_Mis à jour dans la 1.5._ +_Mis à jour dans la 1.5, 3.6._ S'accrocher à un signal. @@ -10507,7 +10507,8 @@ struct t_hook *weechat_hook_signal (const char *signal, Paramètres : -* _signal_ : signal à intercepter, le caractère joker `+*+` est autorisé +* _signal_ : signal à intercepter, le caractère joker `+*+` est autorisé, + plusieurs signaux peuvent être séparés par des point-virgules (priorité autorisée, voir la note sur la <<hook_priority,priorité>>) (voir le tableau ci-dessous) * _callback_ : fonction appelée quand le signal est reçu, paramètres et valeur @@ -11201,8 +11202,8 @@ my_signal_cb (const void *pointer, void *data, const char *signal, return WEECHAT_RC_OK; } -/* intercepter le signal "quit" */ -struct t_hook *my_signal_hook = weechat_hook_signal ("quit", +/* intercepter les signaux "quit" et "upgrade" */ +struct t_hook *my_signal_hook = weechat_hook_signal ("quit;upgrade", &my_signal_cb, NULL, NULL); ---- @@ -11218,8 +11219,8 @@ def my_signal_cb(data, signal, signal_data): # ... return weechat.WEECHAT_RC_OK -# intercepter le signal "quit" -hook = weechat.hook_signal("quit", "my_signal_cb", "") +# intercepter les signaux "quit" et "upgrade" +hook = weechat.hook_signal("quit;upgrade", "my_signal_cb", "") ---- ==== hook_signal_send @@ -11431,7 +11432,7 @@ weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, ==== hook_hsignal -_WeeChat ≥ 0.3.4, mis à jour dans la 1.5._ +_WeeChat ≥ 0.3.4, mis à jour dans la 1.5, 3.6._ S'accrocher à un hsignal (signal avec une table de hachage). @@ -11450,7 +11451,8 @@ struct t_hook *weechat_hook_hsignal (const char *signal, Paramètres : -* _signal_ : signal à intercepter, le caractère joker `+*+` est autorisé +* _signal_ : signal à intercepter, le caractère joker `+*+` est autorisé, + plusieurs signaux peuvent être séparés par des point-virgules (priorité autorisée, voir la note sur la <<hook_priority,priorité>>) (voir le tableau ci-dessous) * _callback_ : fonction appelée quand le signal est reçu, paramètres et valeur diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 87f05262b..20b606fc7 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -10610,7 +10610,7 @@ hook = weechat.hook_print("", "", "", 1, "my_print_cb", "") ==== hook_signal // TRANSLATION MISSING -_Updated in 1.5._ +_Updated in 1.5, 3.6._ Hook su un segnale. @@ -10631,7 +10631,8 @@ struct t_hook *weechat_hook_signal (const char *signal, Argomenti: // TRANSLATION MISSING -* _signal_: segnale da catturare, wildcard `+*+` is allowed +* _signal_: segnale da catturare, wildcard `+*+` is allowed, multiple signals + can be separated by semi-colons (priorità consentita, consultare la nota riguardo la <<hook_priority,priority>>), see table below * _callback_: funzione chiamata a segnale ricevuto, argomenti e valore @@ -11402,6 +11403,7 @@ List of signals sent by WeeChat and plugins: Esempio in C: +// TRANSLATION MISSING [source,c] ---- int @@ -11412,13 +11414,14 @@ my_signal_cb (const void *pointer, void *data, const char *signal, return WEECHAT_RC_OK; } -/* cattura il segnale "quit" */ -struct t_hook *my_signal_hook = weechat_hook_signal ("quit", +/* catch signals "quit" and "upgrade" */ +struct t_hook *my_signal_hook = weechat_hook_signal ("quit;upgrade", &my_signal_cb, NULL, NULL); ---- Script (Python): +// TRANLSATION MISSING [source,python] ---- # prototipo @@ -11429,8 +11432,8 @@ def my_signal_cb(data, signal, signal_data): # ... return weechat.WEECHAT_RC_OK -# cattura il segnale "quit" -hook = weechat.hook_signal("quit", "my_signal_cb", "") +# catch signals "quit" and "upgrade" +hook = weechat.hook_signal("quit;upgrade", "my_signal_cb", "") ---- ==== hook_signal_send @@ -11648,7 +11651,7 @@ weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, ==== hook_hsignal -_WeeChat ≥ 0.3.4, updated in 1.5._ +_WeeChat ≥ 0.3.4, updated in 1.5, 3.6._ Hook su hsignal (segnale con tabella hash). @@ -11668,7 +11671,8 @@ struct t_hook *weechat_hook_hsignal (const char *signal, Argomenti: // TRANSLATION MISSING -* _signal_: segnale da catturare, wildcard `+*+` is allowed +* _signal_: segnale da catturare, wildcard `+*+` is allowed, multiple signals can + be separated by semi-colons (priorità consentita, consultare la nota a proposito di <<hook_priority,priority>>), see table below * _callback_: funzione chiamata a segnale ricevuto, argomenti e valore diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 029a5c80d..7e46c0bdd 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -10311,7 +10311,7 @@ hook = weechat.hook_print("", "", "", 1, "my_print_cb", "") ==== hook_signal -_WeeChat バージョン 1.5 で更新。_ +_WeeChat バージョン 1.5, 3.6 で更新。_ シグナルをフックする。 @@ -10331,7 +10331,9 @@ struct t_hook *weechat_hook_signal (const char *signal, 引数: -* _signal_: キャッチするシグナル、ワイルドカード `+*+` を使うことができます +// TRANSLATION MISSING +* _signal_: キャッチするシグナル、ワイルドカード `+*+` を使うことができます, + multiple signals can be separated by semi-colons (優先度の設定が可能、<<hook_priority,フックの優先度>>に関する注意を参照) (以下の表を参照) * _callback_: @@ -11024,8 +11026,8 @@ my_signal_cb (const void *pointer, void *data, const char *signal, return WEECHAT_RC_OK; } -/* catch signal "quit" */ -struct t_hook *my_signal_hook = weechat_hook_signal ("quit", +/* catch signals "quit" and "upgrade" */ +struct t_hook *my_signal_hook = weechat_hook_signal ("quit;upgrade", &my_signal_cb, NULL, NULL); ---- @@ -11041,8 +11043,8 @@ def my_signal_cb(data, signal, signal_data): # ... return weechat.WEECHAT_RC_OK -# catch signal "quit" -hook = weechat.hook_signal("quit", "my_signal_cb", "") +# catch signals "quit" and "upgrade" +hook = weechat.hook_signal("quit;upgrade", "my_signal_cb", "") ---- ==== hook_signal_send @@ -11247,7 +11249,7 @@ weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, ==== hook_hsignal -_WeeChat バージョン 0.3.4 以上で利用可、バージョン 1.5 で更新。_ +_WeeChat バージョン 0.3.4 以上で利用可、バージョン 1.5, 3.6 で更新。_ hsignal (ハッシュテーブルを持つシグナル) をフック。 @@ -11266,7 +11268,9 @@ struct t_hook *weechat_hook_hsignal (const char *signal, 引数: -* _signal_: キャッチするシグナル、ワイルドカード `+*+` を使うことができます +// TRANSLATION MISSING +* _signal_: キャッチするシグナル、ワイルドカード `+*+` を使うことができます, + multiple signals can be separated by semi-colons (優先度の設定が可能、<<hook_priority,フックの優先度>>に関する注意を参照) (以下の表を参照) * _callback_: diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index 7d1e4b53f..bc9d65ac6 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -9912,7 +9912,7 @@ hook = weechat.hook_print("", "", "", 1, "my_print_cb", "") ==== hook_signal -_Ажурирано у верзији 1.5._ +_Ажурирано у верзији 1.5, 3.6._ Качи се на сигнал. @@ -9932,7 +9932,10 @@ struct t_hook *weechat_hook_signal (const char *signal, Аргументи: -* _signal_: сигнал који се хвата, дозвољава се џокер `+*+` (дозвољен је приоритет, погледајте напомену о <<hook_priority,приоритетима>>) (погледајте табелу испод) +// TRANSLATION MISSING +* _signal_: сигнал који се хвата, дозвољава се џокер `+*+`, multiple signals can + be separated by semi-colons + (дозвољен је приоритет, погледајте напомену о <<hook_priority,приоритетима>>) (погледајте табелу испод) * _callback_: функција која се позива када се прими сигнал, аргументи и повратна вредност су: ** _const void *pointer_: показивач ** _void *data_: показивач @@ -10596,6 +10599,7 @@ struct t_hook *weechat_hook_signal (const char *signal, C пример: +// TRANSLATION MISSING [source,c] ---- int @@ -10606,13 +10610,14 @@ my_signal_cb (const void *pointer, void *data, const char *signal, return WEECHAT_RC_OK; } -/* хвата сигнал "quit" */ -struct t_hook *my_signal_hook = weechat_hook_signal ("quit", +/* catch signals "quit" and "upgrade" */ +struct t_hook *my_signal_hook = weechat_hook_signal ("quit;upgrade", &my_signal_cb, NULL, NULL); ---- Скрипта (Python): +// TRANSLATION MISSING [source,python] ---- # прототип @@ -10623,8 +10628,8 @@ def my_signal_cb(data, signal, signal_data): # ... return weechat.WEECHAT_RC_OK -# хвата сигнал "quit" -hook = weechat.hook_signal("quit", "my_signal_cb", "") +# catch signals "quit" and "upgrade" +hook = weechat.hook_signal("quit;upgrade", "my_signal_cb", "") ---- ==== hook_signal_send @@ -10820,7 +10825,7 @@ weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, ==== hook_hsignal -_WeeChat ≥ 0.3.4, ажурирано у верзији 1.5._ +_WeeChat ≥ 0.3.4, ажурирано у верзији 1.5, 3.6._ Качи се на hsignal (сигнал са хеш табелом). @@ -10839,7 +10844,9 @@ struct t_hook *weechat_hook_hsignal (const char *signal, Аргументи: -* _signal_: сигнал који се хвата, дозвољава се џокер `+*+` (дозвољен је приоритет, погледајте напомену о <<hook_priority,приоритетима>>) (погледајте табелу испод) +* _signal_: сигнал који се хвата, дозвољава се џокер `+*+`, multiple signals can + be separated by semi-colons + (дозвољен је приоритет, погледајте напомену о <<hook_priority,приоритетима>>) (погледајте табелу испод) * _callback_: функција која се позива када се прими сигнал, аргументи и повратна вредност су: ** _const void *pointer_: показивач ** _void *data_: показивач diff --git a/src/core/hook/wee-hook-hsignal.c b/src/core/hook/wee-hook-hsignal.c index 82198c3c0..a9856fbb3 100644 --- a/src/core/hook/wee-hook-hsignal.c +++ b/src/core/hook/wee-hook-hsignal.c @@ -43,7 +43,8 @@ char * hook_hsignal_get_description (struct t_hook *hook) { - return strdup (HOOK_HSIGNAL(hook, signal)); + return string_build_with_split_string ( + (const char **)(HOOK_HSIGNAL(hook, signals)), ";"); } /* @@ -82,7 +83,14 @@ hook_hsignal (struct t_weechat_plugin *plugin, const char *signal, new_hook->hook_data = new_hook_hsignal; new_hook_hsignal->callback = callback; - new_hook_hsignal->signal = strdup ((ptr_signal) ? ptr_signal : signal); + new_hook_hsignal->signals = string_split ( + (ptr_signal) ? ptr_signal : signal, + ";", + NULL, + WEECHAT_STRING_SPLIT_STRIP_LEFT + | WEECHAT_STRING_SPLIT_STRIP_RIGHT + | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, + 0, &new_hook_hsignal->num_signals); hook_add_to_list (new_hook); @@ -90,6 +98,29 @@ hook_hsignal (struct t_weechat_plugin *plugin, const char *signal, } /* + * Checks if a hooked hsignal matches a signal sent: it matches if at least + * one of the signal masks are matching the signal sent. + * + * Returns: + * 1: hook matches signal sent + * 0: hook does not match signal sent + */ + +int +hook_hsignal_match (const char *signal, struct t_hook *hook) +{ + int i; + + for (i = 0; i < HOOK_HSIGNAL(hook, num_signals); i++) + { + if (string_match (signal, HOOK_HSIGNAL(hook, signals)[i], 0)) + return 1; + } + + return 0; +} + +/* * Sends a hsignal (signal with hashtable). */ @@ -110,7 +141,7 @@ hook_hsignal_send (const char *signal, struct t_hashtable *hashtable) if (!ptr_hook->deleted && !ptr_hook->running - && (string_match (signal, HOOK_HSIGNAL(ptr_hook, signal), 0))) + && (hook_hsignal_match (signal, ptr_hook))) { ptr_hook->running = 1; rc = (HOOK_HSIGNAL(ptr_hook, callback)) @@ -142,11 +173,12 @@ hook_hsignal_free_data (struct t_hook *hook) if (!hook || !hook->hook_data) return; - if (HOOK_HSIGNAL(hook, signal)) + if (HOOK_HSIGNAL(hook, signals)) { - free (HOOK_HSIGNAL(hook, signal)); - HOOK_HSIGNAL(hook, signal) = NULL; + string_free_split (HOOK_HSIGNAL(hook, signals)); + HOOK_HSIGNAL(hook, signals) = NULL; } + HOOK_HSIGNAL(hook, num_signals) = 0; free (hook->hook_data); hook->hook_data = NULL; @@ -164,12 +196,24 @@ int hook_hsignal_add_to_infolist (struct t_infolist_item *item, struct t_hook *hook) { + int i; + char option_name[64]; + if (!item || !hook || !hook->hook_data) return 0; if (!infolist_new_var_pointer (item, "callback", HOOK_HSIGNAL(hook, callback))) return 0; - if (!infolist_new_var_string (item, "signal", HOOK_HSIGNAL(hook, signal))) + i = 0; + for (i = 0; i < HOOK_HSIGNAL(hook, num_signals); i++) + { + snprintf (option_name, sizeof (option_name), "signal_%05d", i); + if (!infolist_new_var_string (item, option_name, + HOOK_HSIGNAL(hook, signals)[i])) + return 0; + } + if (!infolist_new_var_integer (item, "num_signals", + HOOK_HSIGNAL(hook, num_signals))) return 0; return 1; @@ -182,10 +226,16 @@ hook_hsignal_add_to_infolist (struct t_infolist_item *item, void hook_hsignal_print_log (struct t_hook *hook) { + int i; + if (!hook || !hook->hook_data) return; log_printf (" signal data:"); log_printf (" callback. . . . . . . : 0x%lx", HOOK_HSIGNAL(hook, callback)); - log_printf (" signal. . . . . . . . : '%s'", HOOK_HSIGNAL(hook, signal)); + log_printf (" signals:"); + for (i = 0; i < HOOK_HSIGNAL(hook, num_signals); i++) + { + log_printf (" '%s'", HOOK_HSIGNAL(hook, signals)[i]); + } } diff --git a/src/core/hook/wee-hook-hsignal.h b/src/core/hook/wee-hook-hsignal.h index b90304529..c2ebe343a 100644 --- a/src/core/hook/wee-hook-hsignal.h +++ b/src/core/hook/wee-hook-hsignal.h @@ -32,8 +32,10 @@ typedef int (t_hook_callback_hsignal)(const void *pointer, void *data, struct t_hook_hsignal { t_hook_callback_hsignal *callback; /* signal callback */ - char *signal; /* signal selected (may begin or end */ - /* with "*", "*" == any signal) */ + char **signals; /* signals selected; each one may */ + /* begin or end with "*", */ + /* "*" == any signal */ + int num_signals; /* number of signals */ }; extern char *hook_hsignal_get_description (struct t_hook *hook); diff --git a/src/core/hook/wee-hook-signal.c b/src/core/hook/wee-hook-signal.c index 5be0fb81b..158fcbd47 100644 --- a/src/core/hook/wee-hook-signal.c +++ b/src/core/hook/wee-hook-signal.c @@ -43,7 +43,8 @@ char * hook_signal_get_description (struct t_hook *hook) { - return strdup (HOOK_SIGNAL(hook, signal)); + return string_build_with_split_string ( + (const char **)(HOOK_SIGNAL(hook, signals)), ";"); } /* @@ -82,7 +83,14 @@ hook_signal (struct t_weechat_plugin *plugin, const char *signal, new_hook->hook_data = new_hook_signal; new_hook_signal->callback = callback; - new_hook_signal->signal = strdup ((ptr_signal) ? ptr_signal : signal); + new_hook_signal->signals = string_split ( + (ptr_signal) ? ptr_signal : signal, + ";", + NULL, + WEECHAT_STRING_SPLIT_STRIP_LEFT + | WEECHAT_STRING_SPLIT_STRIP_RIGHT + | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, + 0, &new_hook_signal->num_signals); hook_add_to_list (new_hook); @@ -90,6 +98,29 @@ hook_signal (struct t_weechat_plugin *plugin, const char *signal, } /* + * Checks if a hooked signal matches a signal sent: it matches if at least + * one of the signal masks are matching the signal sent. + * + * Returns: + * 1: hook matches signal sent + * 0: hook does not match signal sent + */ + +int +hook_signal_match (const char *signal, struct t_hook *hook) +{ + int i; + + for (i = 0; i < HOOK_SIGNAL(hook, num_signals); i++) + { + if (string_match (signal, HOOK_SIGNAL(hook, signals)[i], 0)) + return 1; + } + + return 0; +} + +/* * Sends a signal. */ @@ -110,7 +141,7 @@ hook_signal_send (const char *signal, const char *type_data, void *signal_data) if (!ptr_hook->deleted && !ptr_hook->running - && (string_match (signal, HOOK_SIGNAL(ptr_hook, signal), 0))) + && hook_signal_match (signal, ptr_hook)) { ptr_hook->running = 1; rc = (HOOK_SIGNAL(ptr_hook, callback)) @@ -143,11 +174,12 @@ hook_signal_free_data (struct t_hook *hook) if (!hook || !hook->hook_data) return; - if (HOOK_SIGNAL(hook, signal)) + if (HOOK_SIGNAL(hook, signals)) { - free (HOOK_SIGNAL(hook, signal)); - HOOK_SIGNAL(hook, signal) = NULL; + string_free_split (HOOK_SIGNAL(hook, signals)); + HOOK_SIGNAL(hook, signals) = NULL; } + HOOK_SIGNAL(hook, num_signals) = 0; free (hook->hook_data); hook->hook_data = NULL; @@ -165,12 +197,24 @@ int hook_signal_add_to_infolist (struct t_infolist_item *item, struct t_hook *hook) { + int i; + char option_name[64]; + if (!item || !hook || !hook->hook_data) return 0; if (!infolist_new_var_pointer (item, "callback", HOOK_SIGNAL(hook, callback))) return 0; - if (!infolist_new_var_string (item, "signal", HOOK_SIGNAL(hook, signal))) + i = 0; + for (i = 0; i < HOOK_SIGNAL(hook, num_signals); i++) + { + snprintf (option_name, sizeof (option_name), "signal_%05d", i); + if (!infolist_new_var_string (item, option_name, + HOOK_SIGNAL(hook, signals)[i])) + return 0; + } + if (!infolist_new_var_integer (item, "num_signals", + HOOK_SIGNAL(hook, num_signals))) return 0; return 1; @@ -183,10 +227,16 @@ hook_signal_add_to_infolist (struct t_infolist_item *item, void hook_signal_print_log (struct t_hook *hook) { + int i; + if (!hook || !hook->hook_data) return; log_printf (" signal data:"); log_printf (" callback. . . . . . . : 0x%lx", HOOK_SIGNAL(hook, callback)); - log_printf (" signal. . . . . . . . : '%s'", HOOK_SIGNAL(hook, signal)); + log_printf (" signals:"); + for (i = 0; i < HOOK_SIGNAL(hook, num_signals); i++) + { + log_printf (" '%s'", HOOK_SIGNAL(hook, signals)[i]); + } } diff --git a/src/core/hook/wee-hook-signal.h b/src/core/hook/wee-hook-signal.h index 0d00e11c1..5a1c25183 100644 --- a/src/core/hook/wee-hook-signal.h +++ b/src/core/hook/wee-hook-signal.h @@ -32,8 +32,10 @@ typedef int (t_hook_callback_signal)(const void *pointer, void *data, struct t_hook_signal { t_hook_callback_signal *callback; /* signal callback */ - char *signal; /* signal selected (may begin or end */ - /* with "*", "*" == any signal) */ + char **signals; /* signals selected; each one may */ + /* begin or end with "*", */ + /* "*" == any signal */ + int num_signals; /* number of signals */ }; extern char *hook_signal_get_description (struct t_hook *hook); diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index 758d34702..2bff28269 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -2205,33 +2205,21 @@ gui_bar_item_init () gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT], &gui_bar_item_input_prompt_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT]); - gui_bar_item_hook_signal ("buffer_localvar_*", + gui_bar_item_hook_signal ("window_switch;buffer_switch;buffer_localvar_*", gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT]); /* input search */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_INPUT_SEARCH], &gui_bar_item_input_search_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_INPUT_SEARCH]); - gui_bar_item_hook_signal ("input_search", - gui_bar_item_names[GUI_BAR_ITEM_INPUT_SEARCH]); - gui_bar_item_hook_signal ("input_text_changed", + gui_bar_item_hook_signal ("window_switch;input_search;input_text_changed", gui_bar_item_names[GUI_BAR_ITEM_INPUT_SEARCH]); /* input text */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT], &gui_bar_item_input_text_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT]); - gui_bar_item_hook_signal ("input_text_*", + gui_bar_item_hook_signal ("window_switch;buffer_switch;input_text_*", gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT]); /* time */ @@ -2247,166 +2235,103 @@ gui_bar_item_init () gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_COUNT], &gui_bar_item_buffer_count_cb, NULL, NULL); - gui_bar_item_hook_signal ("buffer_opened", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_COUNT]); - gui_bar_item_hook_signal ("buffer_closed", + gui_bar_item_hook_signal ("buffer_opened;buffer_closed", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_COUNT]); /* last buffer number */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_LAST_NUMBER], &gui_bar_item_buffer_last_number_cb, NULL, NULL); - gui_bar_item_hook_signal ("buffer_opened", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_LAST_NUMBER]); - gui_bar_item_hook_signal ("buffer_closed", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_LAST_NUMBER]); - gui_bar_item_hook_signal ("buffer_moved", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_LAST_NUMBER]); - gui_bar_item_hook_signal ("buffer_merged", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_LAST_NUMBER]); - gui_bar_item_hook_signal ("buffer_unmerged", + gui_bar_item_hook_signal ("buffer_opened;buffer_closed;buffer_moved;" + "buffer_merged;buffer_unmerged", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_LAST_NUMBER]); /* buffer plugin */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_PLUGIN], &gui_bar_item_buffer_plugin_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_PLUGIN]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_PLUGIN]); - gui_bar_item_hook_signal ("buffer_renamed", + gui_bar_item_hook_signal ("window_switch;buffer_switch;buffer_renamed", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_PLUGIN]); /* buffer number */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NUMBER], &gui_bar_item_buffer_number_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NUMBER]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NUMBER]); - gui_bar_item_hook_signal ("buffer_moved", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NUMBER]); - gui_bar_item_hook_signal ("buffer_merged", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NUMBER]); - gui_bar_item_hook_signal ("buffer_unmerged", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NUMBER]); - gui_bar_item_hook_signal ("buffer_closed", + gui_bar_item_hook_signal ("window_switch;buffer_switch;buffer_moved;" + "buffer_merged;buffer_unmerged;buffer_closed", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NUMBER]); /* buffer name */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME], &gui_bar_item_buffer_name_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME]); - gui_bar_item_hook_signal ("buffer_renamed", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME]); - gui_bar_item_hook_signal ("buffer_moved", + gui_bar_item_hook_signal ("window_switch;buffer_switch;buffer_renamed;" + "buffer_moved", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME]); /* buffer short name */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_SHORT_NAME], &gui_bar_item_buffer_short_name_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_SHORT_NAME]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_SHORT_NAME]); - gui_bar_item_hook_signal ("buffer_renamed", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_SHORT_NAME]); - gui_bar_item_hook_signal ("buffer_moved", + gui_bar_item_hook_signal ("window_switch;buffer_switch;buffer_renamed;" + "buffer_moved", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_SHORT_NAME]); /* buffer modes */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_MODES], &gui_bar_item_buffer_modes_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_MODES]); - gui_bar_item_hook_signal ("buffer_switch", + gui_bar_item_hook_signal ("window_switch;buffer_switch", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_MODES]); /* buffer filter */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_FILTER], &gui_bar_item_buffer_filter_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_FILTER]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_FILTER]); - gui_bar_item_hook_signal ("buffer_lines_hidden", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_FILTER]); - gui_bar_item_hook_signal ("filters_*", + gui_bar_item_hook_signal ("window_switch;buffer_switch;buffer_lines_hidden;" + "filters_*", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_FILTER]); /* buffer zoom */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_ZOOM], &gui_bar_item_buffer_zoom_cb, NULL, NULL); - gui_bar_item_hook_signal ("buffer_zoomed", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_ZOOM]); - gui_bar_item_hook_signal ("buffer_unzoomed", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_ZOOM]); - gui_bar_item_hook_signal ("buffer_switch", + gui_bar_item_hook_signal ("buffer_zoomed;buffer_unzoomed;buffer_switch", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_ZOOM]); /* buffer nicklist count: nicks displayed */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT], &gui_bar_item_buffer_nicklist_count_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT]); - gui_bar_item_hook_signal ("nicklist_*", + gui_bar_item_hook_signal ("window_switch;buffer_switch;nicklist_*", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT]); /* buffer nicklist count: groups displayed */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT_GROUPS], &gui_bar_item_buffer_nicklist_count_groups_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT_GROUPS]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT_GROUPS]); - gui_bar_item_hook_signal ("nicklist_*", + gui_bar_item_hook_signal ("window_switch;buffer_switch;nicklist_*", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT_GROUPS]); /* buffer nicklist count: groups + nicks displayed */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT_ALL], &gui_bar_item_buffer_nicklist_count_all_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT_ALL]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT_ALL]); - gui_bar_item_hook_signal ("nicklist_*", + gui_bar_item_hook_signal ("window_switch;buffer_switch;nicklist_*", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST_COUNT_ALL]); /* scroll indicator */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_SCROLL], &gui_bar_item_scroll_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_SCROLL]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_SCROLL]); - gui_bar_item_hook_signal ("window_scrolled", + gui_bar_item_hook_signal ("window_switch;buffer_switch;window_scrolled", gui_bar_item_names[GUI_BAR_ITEM_SCROLL]); /* hotlist */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_HOTLIST], &gui_bar_item_hotlist_cb, NULL, NULL); - gui_bar_item_hook_signal ("hotlist_changed", - gui_bar_item_names[GUI_BAR_ITEM_HOTLIST]); - gui_bar_item_hook_signal ("buffer_moved", - gui_bar_item_names[GUI_BAR_ITEM_HOTLIST]); - gui_bar_item_hook_signal ("buffer_closed", + gui_bar_item_hook_signal ("hotlist_changed;buffer_moved;buffer_closed", gui_bar_item_names[GUI_BAR_ITEM_HOTLIST]); /* completion (possible words when a partial completion occurs) */ @@ -2420,22 +2345,14 @@ gui_bar_item_init () gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_TITLE], &gui_bar_item_buffer_title_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_TITLE]); - gui_bar_item_hook_signal ("buffer_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_TITLE]); - gui_bar_item_hook_signal ("buffer_title_changed", + gui_bar_item_hook_signal ("window_switch;buffer_switch;buffer_title_changed", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_TITLE]); /* buffer nicklist */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST], &gui_bar_item_buffer_nicklist_cb, NULL, NULL); - gui_bar_item_hook_signal ("nicklist_*", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST]); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST]); - gui_bar_item_hook_signal ("buffer_switch", + gui_bar_item_hook_signal ("nicklist_*;window_switch;buffer_switch", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST]); snprintf (name, sizeof (name), "2000|%s", gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NICKLIST]); @@ -2446,18 +2363,14 @@ gui_bar_item_init () gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_WINDOW_NUMBER], &gui_bar_item_window_number_cb, NULL, NULL); - gui_bar_item_hook_signal ("window_switch", - gui_bar_item_names[GUI_BAR_ITEM_WINDOW_NUMBER]); - gui_bar_item_hook_signal ("window_closed", + gui_bar_item_hook_signal ("window_switch;window_closed", gui_bar_item_names[GUI_BAR_ITEM_WINDOW_NUMBER]); /* mouse status */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_MOUSE_STATUS], &gui_bar_item_mouse_status_cb, NULL, NULL); - gui_bar_item_hook_signal ("mouse_enabled", - gui_bar_item_names[GUI_BAR_ITEM_MOUSE_STATUS]); - gui_bar_item_hook_signal ("mouse_disabled", + gui_bar_item_hook_signal ("mouse_enabled;mouse_disabled", gui_bar_item_names[GUI_BAR_ITEM_MOUSE_STATUS]); /* away message */ diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 3d12b51aa..f7bc8943f 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -82,11 +82,9 @@ gui_chat_init () } /* some hsignals */ - hook_hsignal (NULL, "chat_quote_time_prefix_message", - &gui_chat_hsignal_quote_line_cb, NULL, NULL); - hook_hsignal (NULL, "chat_quote_prefix_message", - &gui_chat_hsignal_quote_line_cb, NULL, NULL); - hook_hsignal (NULL, "chat_quote_message", + hook_hsignal (NULL, + "chat_quote_time_prefix_message;chat_quote_prefix_message;" + "chat_quote_message", &gui_chat_hsignal_quote_line_cb, NULL, NULL); } diff --git a/src/plugins/perl/weechat-perl.c b/src/plugins/perl/weechat-perl.c index ede5bea73..751571437 100644 --- a/src/plugins/perl/weechat-perl.c +++ b/src/plugins/perl/weechat-perl.c @@ -1307,9 +1307,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) plugin_script_display_short_list (weechat_perl_plugin, perl_scripts); - weechat_hook_signal ("quit", - &weechat_perl_signal_quit_upgrade_cb, NULL, NULL); - weechat_hook_signal ("upgrade", + weechat_hook_signal ("quit;upgrade", &weechat_perl_signal_quit_upgrade_cb, NULL, NULL); /* init OK */ diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c index ee201b5bd..af2ad0c4e 100644 --- a/src/plugins/trigger/trigger.c +++ b/src/plugins/trigger/trigger.c @@ -301,34 +301,28 @@ trigger_hook (struct t_trigger *trigger) case TRIGGER_HOOK_SIGNAL: if (argv && (argc >= 1)) { - trigger->hooks = malloc (argc * sizeof (trigger->hooks[0])); + trigger->hooks = malloc (sizeof (trigger->hooks[0])); if (trigger->hooks) { - trigger->hooks_count = argc; - for (i = 0; i < argc; i++) - { - trigger->hooks[i] = weechat_hook_signal ( - argv[i], - &trigger_callback_signal_cb, - trigger, NULL); - } + trigger->hooks_count = 1; + trigger->hooks[0] = weechat_hook_signal ( + weechat_config_string (trigger->options[TRIGGER_OPTION_ARGUMENTS]), + &trigger_callback_signal_cb, + trigger, NULL); } } break; case TRIGGER_HOOK_HSIGNAL: if (argv && (argc >= 1)) { - trigger->hooks = malloc (argc * sizeof (trigger->hooks[0])); + trigger->hooks = malloc (sizeof (trigger->hooks[0])); if (trigger->hooks) { - trigger->hooks_count = argc; - for (i = 0; i < argc; i++) - { - trigger->hooks[i] = weechat_hook_hsignal ( - argv[i], - &trigger_callback_hsignal_cb, - trigger, NULL); - } + trigger->hooks_count = 1; + trigger->hooks[0] = weechat_hook_hsignal ( + weechat_config_string (trigger->options[TRIGGER_OPTION_ARGUMENTS]), + &trigger_callback_hsignal_cb, + trigger, NULL); } } break; |