summaryrefslogtreecommitdiff
path: root/src/plugins/script/script-info.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2024-02-19 18:33:36 +0100
committerSébastien Helleu <flashcode@flashtux.org>2024-02-19 18:33:36 +0100
commita44ffa147f8902028c58d202bd2d735782be970d (patch)
treedbbd0ba5b196c63ccffea179fe49f5335ae0193c /src/plugins/script/script-info.c
parenta167322d8b572948a0c2cf74139c8e6c1e1dc45c (diff)
downloadweechat-a44ffa147f8902028c58d202bd2d735782be970d.zip
script: add info "script_loaded"
Diffstat (limited to 'src/plugins/script/script-info.c')
-rw-r--r--src/plugins/script/script-info.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/plugins/script/script-info.c b/src/plugins/script/script-info.c
index 5a7fc2a2d..2d565632a 100644
--- a/src/plugins/script/script-info.c
+++ b/src/plugins/script/script-info.c
@@ -29,6 +29,57 @@
/*
+ * Returns script info "script_loaded".
+ */
+
+char *
+script_info_info_script_loaded_cb (const void *pointer, void *data,
+ const char *info_name,
+ const char *arguments)
+{
+ int i, length;
+ char hdata_name[128];
+ const char *ptr_name;
+ struct t_hdata *hdata;
+ void *ptr_script;
+
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) info_name;
+
+ if (!arguments || !arguments[0])
+ return NULL;
+
+ for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
+ {
+ snprintf (hdata_name, sizeof (hdata_name),
+ "%s_script", script_language[i]);
+ hdata = weechat_hdata_get (hdata_name);
+ ptr_script = weechat_hdata_get_list (hdata, "scripts");
+ while (ptr_script)
+ {
+ ptr_name = weechat_hdata_string (hdata, ptr_script, "name");
+ if (ptr_name)
+ {
+ length = strlen (ptr_name);
+ if ((strncmp (arguments, ptr_name, length) == 0)
+ && (arguments[length] == '.')
+ && (strcmp (arguments + length + 1, script_extension[i]) == 0))
+ {
+ /* script loaded */
+ return strdup ("1");
+ }
+ }
+ ptr_script = weechat_hdata_move (hdata, ptr_script, 1);
+ }
+ }
+
+ /* script not loaded */
+ return NULL;
+}
+
+/*
* Returns script infolist "script_script".
*/
@@ -93,6 +144,13 @@ script_info_infolist_script_script_cb (const void *pointer, void *data,
void
script_info_init ()
{
+ /* info hooks */
+ weechat_hook_info (
+ "script_loaded",
+ N_("1 if script is loaded"),
+ N_("script name with extension"),
+ &script_info_info_script_loaded_cb, NULL, NULL);
+
/* infolist hooks */
weechat_hook_infolist (
"script_script",