diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-04-24 10:00:09 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-04-24 10:06:54 +0200 |
commit | d16640130e65ed4af76d285a4339a0c200ee41b0 (patch) | |
tree | 1c78302f9726ac301af1f91e755ee863f6dcb17d /src/core/hook/wee-hook-timer.c | |
parent | 95cf2aa9565233e73c356c7f3c83ea9815fa4dbc (diff) | |
download | weechat-d16640130e65ed4af76d285a4339a0c200ee41b0.zip |
core: add functions to get short description of hooks
Diffstat (limited to 'src/core/hook/wee-hook-timer.c')
-rw-r--r-- | src/core/hook/wee-hook-timer.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/core/hook/wee-hook-timer.c b/src/core/hook/wee-hook-timer.c index d0278a850..4dbe4d955 100644 --- a/src/core/hook/wee-hook-timer.c +++ b/src/core/hook/wee-hook-timer.c @@ -24,6 +24,7 @@ #endif #include <stdlib.h> +#include <string.h> #include <time.h> #include "../weechat.h" @@ -38,6 +39,43 @@ time_t hook_last_system_time = 0; /* used to detect system clock skew */ /* + * Returns description of hook. + * + * Note: result must be freed after use. + */ + +char * +hook_timer_get_description (struct t_hook *hook) +{ + char str_desc[512]; + int unit_seconds; + long interval; + + unit_seconds = (HOOK_TIMER(hook, interval) % 1000 == 0); + interval = (unit_seconds) ? + HOOK_TIMER(hook, interval) / 1000 : + HOOK_TIMER(hook, interval); + + if (HOOK_TIMER(hook, remaining_calls) > 0) + { + snprintf (str_desc, sizeof (str_desc), + "%ld%s (%d calls remaining)", + interval, + (unit_seconds) ? "s" : "ms", + HOOK_TIMER(hook, remaining_calls)); + } + else + { + snprintf (str_desc, sizeof (str_desc), + "%ld%s (no call limit)", + interval, + (unit_seconds) ? "s" : "ms"); + } + + return strdup (str_desc); +} + +/* * Initializes a timer hook. */ |