diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/plugin-script-callback.c | 38 | ||||
-rw-r--r-- | src/plugins/plugin-script-callback.h | 2 | ||||
-rw-r--r-- | src/plugins/plugin-script.c | 13 | ||||
-rw-r--r-- | src/plugins/script/script-buffer.c | 234 |
4 files changed, 284 insertions, 3 deletions
diff --git a/src/plugins/plugin-script-callback.c b/src/plugins/plugin-script-callback.c index 1596b123f..486cea058 100644 --- a/src/plugins/plugin-script-callback.c +++ b/src/plugins/plugin-script-callback.c @@ -21,7 +21,9 @@ #include <stdlib.h> #include <unistd.h> +#include <stdio.h> #include <string.h> +#include <stddef.h> #include "weechat-plugin.h" #include "plugin-script.h" @@ -140,6 +142,42 @@ plugin_script_callback_remove_all (struct t_plugin_script *script) } /* + * Gets hdata for script callback. + */ + +struct t_hdata * +plugin_script_callback_hdata_callback_cb (void *data, + const char *hdata_name) +{ + struct t_weechat_plugin *weechat_plugin; + struct t_hdata *hdata; + char str_hdata_script[128]; + + weechat_plugin = (struct t_weechat_plugin *)data; + + hdata = weechat_hdata_new (hdata_name, "prev_callback", "next_callback", + 0, 0, NULL, NULL); + if (hdata) + { + snprintf (str_hdata_script, sizeof (str_hdata_script), + "%s_script", weechat_plugin->name); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, script, POINTER, 0, NULL, str_hdata_script); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, function, STRING, 0, NULL, NULL); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, data, STRING, 0, NULL, NULL); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, config_file, POINTER, 0, NULL, "config_file"); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, config_section, POINTER, 0, NULL, "config_section"); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, config_option, POINTER, 0, NULL, "config_option"); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, hook, POINTER, 0, NULL, NULL); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, buffer, POINTER, 0, NULL, "buffer"); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, bar_item, POINTER, 0, NULL, "bar_item"); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, upgrade_file, POINTER, 0, NULL, NULL); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, prev_callback, POINTER, 0, NULL, hdata_name); + WEECHAT_HDATA_VAR(struct t_plugin_script_cb, next_callback, POINTER, 0, NULL, hdata_name); + } + return hdata; +} + +/* * Prints callbacks in WeeChat log file (usually for crash dump). */ diff --git a/src/plugins/plugin-script-callback.h b/src/plugins/plugin-script-callback.h index f9db72f25..7b783ede6 100644 --- a/src/plugins/plugin-script-callback.h +++ b/src/plugins/plugin-script-callback.h @@ -42,6 +42,8 @@ extern struct t_plugin_script_cb *plugin_script_callback_add (struct t_plugin_sc extern void plugin_script_callback_remove (struct t_plugin_script *script, struct t_plugin_script_cb *script_callback); extern void plugin_script_callback_remove_all (struct t_plugin_script *script); +extern struct t_hdata *plugin_script_callback_hdata_callback_cb (void *data, + const char *hdata_name); extern void plugin_script_callback_print_log (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script_cb *script_callback); diff --git a/src/plugins/plugin-script.c b/src/plugins/plugin-script.c index 6dccac325..d2956a84f 100644 --- a/src/plugins/plugin-script.c +++ b/src/plugins/plugin-script.c @@ -184,7 +184,7 @@ plugin_script_init (struct t_weechat_plugin *weechat_plugin, free (completion); /* add completion, hdata and infolist */ - length = strlen (weechat_plugin->name) + 16; + length = strlen (weechat_plugin->name) + 64; string = malloc (length); if (string) { @@ -192,11 +192,15 @@ plugin_script_init (struct t_weechat_plugin *weechat_plugin, weechat_hook_completion (string, N_("list of scripts"), init->callback_completion, NULL); weechat_hook_hdata (string, N_("list of scripts"), - init->callback_hdata, NULL); + init->callback_hdata, weechat_plugin); weechat_hook_infolist (string, N_("list of scripts"), N_("script pointer (optional)"), N_("script name (can start or end with \"*\" as wildcard) (optional)"), init->callback_infolist, NULL); + snprintf (string, length, "%s_callback", weechat_plugin->name); + weechat_hook_hdata (string, N_("callback of a script"), + &plugin_script_callback_hdata_callback_cb, + weechat_plugin); free (string); } @@ -1354,11 +1358,14 @@ plugin_script_hdata_script (struct t_weechat_plugin *weechat_plugin, const char *hdata_name) { struct t_hdata *hdata; + char str_hdata_callback[128]; hdata = weechat_hdata_new (hdata_name, "prev_script", "next_script", 0, 0, NULL, NULL); if (hdata) { + snprintf (str_hdata_callback, sizeof (str_hdata_callback), + "%s_callback", weechat_plugin->name); WEECHAT_HDATA_VAR(struct t_plugin_script, filename, STRING, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_plugin_script, interpreter, POINTER, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_plugin_script, name, STRING, 0, NULL, NULL); @@ -1368,7 +1375,7 @@ plugin_script_hdata_script (struct t_weechat_plugin *weechat_plugin, WEECHAT_HDATA_VAR(struct t_plugin_script, description, STRING, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_plugin_script, shutdown_func, STRING, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_plugin_script, charset, STRING, 0, NULL, NULL); - WEECHAT_HDATA_VAR(struct t_plugin_script, callbacks, POINTER, 0, NULL, NULL); + WEECHAT_HDATA_VAR(struct t_plugin_script, callbacks, POINTER, 0, NULL, str_hdata_callback); WEECHAT_HDATA_VAR(struct t_plugin_script, unloading, INTEGER, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_plugin_script, prev_script, POINTER, 0, NULL, hdata_name); WEECHAT_HDATA_VAR(struct t_plugin_script, next_script, POINTER, 0, NULL, hdata_name); diff --git a/src/plugins/script/script-buffer.c b/src/plugins/script/script-buffer.c index 65d5d09d1..e3f7d9f57 100644 --- a/src/plugins/script/script-buffer.c +++ b/src/plugins/script/script-buffer.c @@ -23,6 +23,7 @@ #include <stdio.h> #include <string.h> #include <time.h> +#include <libgen.h> #include "../weechat-plugin.h" #include "script.h" @@ -354,6 +355,208 @@ script_buffer_detail_label (const char *text, int max_length) } /* + * Gets pointer to a script (to the script managed by the appropriate plugin, + * for example python). + */ + +struct t_plugin_script * +script_buffer_get_script_pointer (struct t_script_repo *script, + struct t_hdata *hdata_script) +{ + char *filename, *ptr_base_name; + const char *ptr_filename; + void *ptr_script; + + ptr_script = weechat_hdata_get_list (hdata_script, "scripts"); + while (ptr_script) + { + ptr_filename = weechat_hdata_string (hdata_script, + ptr_script, "filename"); + if (ptr_filename) + { + filename = strdup (ptr_filename); + if (filename) + { + ptr_base_name = basename (filename); + if (strcmp (ptr_base_name, script->name_with_extension) == 0) + { + free (filename); + return ptr_script; + } + free (filename); + } + } + ptr_script = weechat_hdata_move (hdata_script, ptr_script, 1); + } + + /* script not found */ + return NULL; +} + +/* + * Gets a list with usage of the script (commands, config options...). + */ + +struct t_weelist * +script_buffer_get_script_usage (struct t_script_repo *script) +{ + struct t_weelist *list; + char hdata_name[128], str_option[256], str_info[1024]; + int config_files; + const char *ptr_name_hdata_callback, *type; + struct t_hdata *ptr_hdata_script, *ptr_hdata_callback; + struct t_hdata *ptr_hdata_config_file, *ptr_hdata_bar_item; + void *ptr_script, *ptr_callback; + struct t_config_file *ptr_config_file; + struct t_hook *ptr_hook; + struct t_gui_bar_item *ptr_bar_item; + struct t_infolist *infolist; + + list = weechat_list_new (); + + config_files = 0; + + snprintf (hdata_name, sizeof (hdata_name), + "%s_script", script_language[script->language]); + ptr_hdata_script = weechat_hdata_get (hdata_name); + if (!ptr_hdata_script) + goto end; + + ptr_script = script_buffer_get_script_pointer (script, ptr_hdata_script); + if (!ptr_script) + goto end; + + ptr_name_hdata_callback = weechat_hdata_get_var_hdata (ptr_hdata_script, + "callbacks"); + if (!ptr_name_hdata_callback) + goto end; + ptr_hdata_callback = weechat_hdata_get (ptr_name_hdata_callback); + if (!ptr_hdata_callback) + goto end; + + ptr_hdata_config_file = weechat_hdata_get ("config_file"); + ptr_hdata_bar_item = weechat_hdata_get ("bar_item"); + + ptr_callback = weechat_hdata_pointer (ptr_hdata_script, + ptr_script, + "callbacks"); + while (ptr_callback) + { + str_info[0] = '\0'; + ptr_config_file = weechat_hdata_pointer (ptr_hdata_callback, + ptr_callback, + "config_file"); + ptr_hook = weechat_hdata_pointer (ptr_hdata_callback, + ptr_callback, + "hook"); + ptr_bar_item = weechat_hdata_pointer (ptr_hdata_callback, + ptr_callback, + "bar_item"); + if (ptr_config_file) + { + snprintf (str_info, sizeof (str_info), + _("configuration file \"%s\" (options %s.*)"), + weechat_hdata_string (ptr_hdata_config_file, + ptr_config_file, + "filename"), + weechat_hdata_string (ptr_hdata_config_file, + ptr_config_file, + "name")); + config_files++; + } + else if (ptr_hook) + { + infolist = weechat_infolist_get ("hook", ptr_hook, NULL); + if (infolist) + { + if (weechat_infolist_next (infolist)) + { + type = weechat_infolist_string (infolist, "type"); + if (type) + { + if (strcmp (type, "command") == 0) + { + snprintf (str_info, sizeof (str_info), + _("command /%s"), + weechat_infolist_string (infolist, + "command")); + } + else if (strcmp (type, "completion") == 0) + { + snprintf (str_info, sizeof (str_info), + _("completion %%(%s)"), + weechat_infolist_string (infolist, + "completion_item")); + } + else if (strcmp (type, "info") == 0) + { + snprintf (str_info, sizeof (str_info), + "info \"%s\"", + weechat_infolist_string (infolist, + "info_name")); + } + else if (strcmp (type, "info_hashtable") == 0) + { + snprintf (str_info, sizeof (str_info), + "info_hashtable \"%s\"", + weechat_infolist_string (infolist, + "info_name")); + } + else if (strcmp (type, "infolist") == 0) + { + snprintf (str_info, sizeof (str_info), + "infolist \"%s\"", + weechat_infolist_string (infolist, + "infolist_name")); + } + } + } + weechat_infolist_free (infolist); + } + } + else if (ptr_bar_item) + { + snprintf (str_info, sizeof (str_info), + _("bar item \"%s\""), + weechat_hdata_string (ptr_hdata_bar_item, + ptr_bar_item, + "name")); + } + if (str_info[0]) + { + weechat_list_add (list, str_info, + WEECHAT_LIST_POS_END, NULL); + } + ptr_callback = weechat_hdata_move (ptr_hdata_callback, + ptr_callback, + 1); + } + +end: + snprintf (str_option, sizeof (str_option), + "plugins.var.%s.%s.*", + script_language[script->language], + weechat_hdata_string (ptr_hdata_script, ptr_script, "name")); + infolist = weechat_infolist_get ("option", NULL, str_option); + if (infolist) + { + if (weechat_infolist_next (infolist)) + { + snprintf (str_info, sizeof (str_info), + _("options %s%s%s"), + str_option, + (config_files > 0) ? " " : "", + (config_files > 0) ? _("(old options?)") : ""); + weechat_list_add (list, str_info, + WEECHAT_LIST_POS_END, NULL); + } + weechat_infolist_free (infolist); + } + + return list; +} + +/* * Displays detail on a script. */ @@ -369,6 +572,8 @@ script_buffer_display_detail_script (struct t_script_repo *script) N_("Min WeeChat"), N_("Max WeeChat"), NULL }; int i, length, max_length, line; + struct t_weelist *list; + struct t_weelist_item *ptr_item; max_length = 0; for (i = 0; labels[i]; i++) @@ -475,6 +680,35 @@ script_buffer_display_detail_script (struct t_script_repo *script) (script->max_weechat) ? script->max_weechat : "-"); line++; + if (script->status & SCRIPT_STATUS_RUNNING) + { + list = script_buffer_get_script_usage (script); + if (list) + { + line++; + weechat_printf_y (script_buffer, line + 1, + _("Script has defined:")); + i = 0; + ptr_item = weechat_list_get (list, 0); + while (ptr_item) + { + line++; + weechat_printf_y (script_buffer, line + 1, + " %s", weechat_list_string (ptr_item)); + ptr_item = weechat_list_next (ptr_item); + i++; + } + if (i == 0) + { + line++; + weechat_printf_y (script_buffer, line + 1, + " %s", _("(nothing)")); + } + line++; + weechat_list_free (list); + } + } + script_buffer_detail_script_last_line = line + 2; script_buffer_detail_script_line_diff = -1; } |