From 96c22c41ba59080893a4c4a2ca1e66c16d88ff32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Fri, 16 Sep 2022 21:05:51 +0200 Subject: api: add support of priority in function hook_line (closes #1821) --- src/core/hook/wee-hook-line.c | 11 +++++++---- src/core/wee-hook.c | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/hook/wee-hook-line.c b/src/core/hook/wee-hook-line.c index 00bd7f138..366c9bf2e 100644 --- a/src/core/hook/wee-hook-line.c +++ b/src/core/hook/wee-hook-line.c @@ -71,6 +71,8 @@ hook_line (struct t_weechat_plugin *plugin, const char *buffer_type, { struct t_hook *new_hook; struct t_hook_line *new_hook_line; + int priority; + const char *ptr_buffer_type; if (!callback) return NULL; @@ -85,17 +87,18 @@ hook_line (struct t_weechat_plugin *plugin, const char *buffer_type, return NULL; } - hook_init_data (new_hook, plugin, HOOK_TYPE_LINE, HOOK_PRIORITY_DEFAULT, + hook_get_priority_and_name (buffer_type, &priority, &ptr_buffer_type); + hook_init_data (new_hook, plugin, HOOK_TYPE_LINE, priority, callback_pointer, callback_data); new_hook->hook_data = new_hook_line; new_hook_line->callback = callback; - if (!buffer_type || !buffer_type[0]) + if (!ptr_buffer_type || !ptr_buffer_type[0]) new_hook_line->buffer_type = GUI_BUFFER_TYPE_DEFAULT; - else if (strcmp (buffer_type, "*") == 0) + else if (strcmp (ptr_buffer_type, "*") == 0) new_hook_line->buffer_type = -1; else - new_hook_line->buffer_type = gui_buffer_search_type (buffer_type); + new_hook_line->buffer_type = gui_buffer_search_type (ptr_buffer_type); new_hook_line->buffers = string_split ( (buffer_name && buffer_name[0]) ? buffer_name : "*", ",", diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index 04b1acc2e..b50a664e7 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -362,6 +362,9 @@ hook_get_priority_and_name (const char *string, if (name) *name = string; + if (!string) + return; + pos = strchr (string, '|'); if (pos) { -- cgit v1.2.3