1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-05 01:03:14 +02:00

scripts: add signals for scripts loaded/unloaded/installed/removed

This commit is contained in:
Sebastien Helleu
2012-08-08 11:38:27 +02:00
parent 068d0df56b
commit 46bc181933
11 changed files with 549 additions and 90 deletions
+10
View File
@@ -412,6 +412,9 @@ weechat_guile_load (const char *filename)
&weechat_guile_api_buffer_input_data_cb,
&weechat_guile_api_buffer_close_cb);
weechat_hook_signal_send ("guile_script_loaded", WEECHAT_HOOK_SIGNAL_STRING,
guile_current_script->filename);
return 1;
}
@@ -437,6 +440,7 @@ weechat_guile_unload (struct t_plugin_script *script)
{
int *rc;
void *interpreter;
char *filename;
if ((weechat_guile_plugin->debug >= 2) || !guile_quiet)
{
@@ -453,6 +457,7 @@ weechat_guile_unload (struct t_plugin_script *script)
free (rc);
}
filename = strdup (script->filename);
interpreter = script->interpreter;
if (guile_current_script == script)
@@ -464,6 +469,11 @@ weechat_guile_unload (struct t_plugin_script *script)
if (interpreter)
weechat_guile_catch (scm_gc_unprotect_object, interpreter);
weechat_hook_signal_send ("guile_script_unloaded",
WEECHAT_HOOK_SIGNAL_STRING, filename);
if (filename)
free (filename);
}
/*
+10
View File
@@ -383,6 +383,9 @@ weechat_lua_load (const char *filename)
&weechat_lua_api_buffer_input_data_cb,
&weechat_lua_api_buffer_close_cb);
weechat_hook_signal_send ("lua_script_loaded", WEECHAT_HOOK_SIGNAL_STRING,
lua_current_script->filename);
return 1;
}
@@ -408,6 +411,7 @@ weechat_lua_unload (struct t_plugin_script *script)
{
int *rc;
void *interpreter;
char *filename;
if ((weechat_lua_plugin->debug >= 2) || !lua_quiet)
{
@@ -426,6 +430,7 @@ weechat_lua_unload (struct t_plugin_script *script)
free (rc);
}
filename = strdup (script->filename);
interpreter = script->interpreter;
if (lua_current_script == script)
@@ -436,6 +441,11 @@ weechat_lua_unload (struct t_plugin_script *script)
if (interpreter)
lua_close (interpreter);
weechat_hook_signal_send ("lua_script_unloaded",
WEECHAT_HOOK_SIGNAL_STRING, filename);
if (filename)
free (filename);
}
/*
+12
View File
@@ -531,6 +531,9 @@ weechat_perl_load (const char *filename)
&weechat_perl_api_buffer_input_data_cb,
&weechat_perl_api_buffer_close_cb);
weechat_hook_signal_send ("perl_script_loaded", WEECHAT_HOOK_SIGNAL_STRING,
perl_current_script->filename);
return 1;
}
@@ -556,6 +559,7 @@ weechat_perl_unload (struct t_plugin_script *script)
{
int *rc;
void *interpreter;
char *filename;
if ((weechat_perl_plugin->debug >= 2) || !perl_quiet)
{
@@ -580,11 +584,14 @@ weechat_perl_unload (struct t_plugin_script *script)
free (rc);
}
filename = strdup (script->filename);
interpreter = script->interpreter;
if (perl_current_script == script)
{
perl_current_script = (perl_current_script->prev_script) ?
perl_current_script->prev_script : perl_current_script->next_script;
}
plugin_script_remove (weechat_perl_plugin, &perl_scripts, &last_perl_script,
script);
@@ -599,6 +606,11 @@ weechat_perl_unload (struct t_plugin_script *script)
if (interpreter)
free (interpreter);
#endif
weechat_hook_signal_send ("perl_script_unloaded",
WEECHAT_HOOK_SIGNAL_STRING, filename);
if (filename)
free (filename);
}
/*
+101 -89
View File
@@ -926,97 +926,103 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
char **list)
{
char **argv, *name, *ptr_base_name, *base_name, *new_path, *autoload_path;
char *symlink_path;
char *symlink_path, str_signal[128];
const char *dir_home, *dir_separator;
int argc, i, length, rc;
struct t_plugin_script *ptr_script;
if (*list)
if (!*list)
return;
argv = weechat_string_split (*list, ",", 0, 0, &argc);
if (argv)
{
argv = weechat_string_split (*list, ",", 0, 0, &argc);
if (argv)
for (i = 0; i < argc; i++)
{
for (i = 0; i < argc; i++)
name = strdup (argv[i]);
if (name)
{
name = strdup (argv[i]);
if (name)
ptr_base_name = basename (name);
base_name = strdup (ptr_base_name);
if (base_name)
{
ptr_base_name = basename (name);
base_name = strdup (ptr_base_name);
if (base_name)
/* unload script, if script is loaded */
ptr_script = plugin_script_search_by_full_name (scripts,
base_name);
if (ptr_script)
(*script_unload) (ptr_script);
/* remove script file(s) */
plugin_script_remove_file (weechat_plugin, base_name, 0);
/* move file from install dir to language dir */
dir_home = weechat_info_get ("weechat_dir", "");
length = strlen (dir_home) + strlen (weechat_plugin->name) +
strlen (base_name) + 16;
new_path = malloc (length);
if (new_path)
{
/* unload script, if script is loaded */
ptr_script = plugin_script_search_by_full_name (scripts,
base_name);
if (ptr_script)
(*script_unload) (ptr_script);
/* remove script file(s) */
plugin_script_remove_file (weechat_plugin, base_name, 0);
/* move file from install dir to language dir */
dir_home = weechat_info_get ("weechat_dir", "");
length = strlen (dir_home) + strlen (weechat_plugin->name) +
strlen (base_name) + 16;
new_path = malloc (length);
if (new_path)
snprintf (new_path, length, "%s/%s/%s",
dir_home, weechat_plugin->name, base_name);
if (rename (name, new_path) == 0)
{
snprintf (new_path, length, "%s/%s/%s",
dir_home, weechat_plugin->name, base_name);
if (rename (name, new_path) == 0)
/* make link in autoload dir */
length = strlen (dir_home) +
strlen (weechat_plugin->name) + 8 +
strlen (base_name) + 16;
autoload_path = malloc (length);
if (autoload_path)
{
/* make link in autoload dir */
length = strlen (dir_home) +
strlen (weechat_plugin->name) + 8 +
strlen (base_name) + 16;
autoload_path = malloc (length);
if (autoload_path)
snprintf (autoload_path, length,
"%s/%s/autoload/%s",
dir_home, weechat_plugin->name,
base_name);
dir_separator = weechat_info_get ("dir_separator", "");
length = 2 + strlen (dir_separator) +
strlen (base_name) + 1;
symlink_path = malloc (length);
if (symlink_path)
{
snprintf (autoload_path, length,
"%s/%s/autoload/%s",
dir_home, weechat_plugin->name,
base_name);
dir_separator = weechat_info_get ("dir_separator", "");
length = 2 + strlen (dir_separator) +
strlen (base_name) + 1;
symlink_path = malloc (length);
if (symlink_path)
{
snprintf (symlink_path, length, "..%s%s",
dir_separator, base_name);
rc = symlink (symlink_path, autoload_path);
(void) rc;
free (symlink_path);
}
free (autoload_path);
snprintf (symlink_path, length, "..%s%s",
dir_separator, base_name);
rc = symlink (symlink_path, autoload_path);
(void) rc;
free (symlink_path);
}
free (autoload_path);
}
/* load script */
(*script_load) (new_path);
}
else
{
weechat_printf (NULL,
_("%s%s: failed to move script %s "
"to %s (%s)"),
weechat_prefix ("error"),
weechat_plugin->name,
name,
new_path,
strerror (errno));
}
free (new_path);
/* load script */
(*script_load) (new_path);
}
free (base_name);
else
{
weechat_printf (NULL,
_("%s%s: failed to move script %s "
"to %s (%s)"),
weechat_prefix ("error"),
weechat_plugin->name,
name,
new_path,
strerror (errno));
}
free (new_path);
}
free (name);
free (base_name);
}
free (name);
}
weechat_string_free_split (argv);
}
free (*list);
*list = NULL;
weechat_string_free_split (argv);
}
snprintf (str_signal, sizeof (str_signal),
"%s_script_installed", weechat_plugin->name);
weechat_hook_signal_send (str_signal, WEECHAT_HOOK_SIGNAL_STRING,
*list);
free (*list);
*list = NULL;
}
/*
@@ -1032,30 +1038,36 @@ plugin_script_action_remove (struct t_weechat_plugin *weechat_plugin,
void (*script_unload)(struct t_plugin_script *script),
char **list)
{
char **argv;
char **argv, str_signal[128];
int argc, i;
struct t_plugin_script *ptr_script;
if (*list)
{
argv = weechat_string_split (*list, ",", 0, 0, &argc);
if (argv)
{
for (i = 0; i < argc; i++)
{
/* unload script, if script is loaded */
ptr_script = plugin_script_search_by_full_name (scripts, argv[i]);
if (ptr_script)
(*script_unload) (ptr_script);
if (!*list)
return;
/* remove script file(s) */
plugin_script_remove_file (weechat_plugin, argv[i], 1);
}
weechat_string_free_split (argv);
argv = weechat_string_split (*list, ",", 0, 0, &argc);
if (argv)
{
for (i = 0; i < argc; i++)
{
/* unload script, if script is loaded */
ptr_script = plugin_script_search_by_full_name (scripts, argv[i]);
if (ptr_script)
(*script_unload) (ptr_script);
/* remove script file(s) */
plugin_script_remove_file (weechat_plugin, argv[i], 1);
}
free (*list);
*list = NULL;
weechat_string_free_split (argv);
}
snprintf (str_signal, sizeof (str_signal),
"%s_script_removed", weechat_plugin->name);
weechat_hook_signal_send (str_signal, WEECHAT_HOOK_SIGNAL_STRING,
*list);
free (*list);
*list = NULL;
}
/*
+10
View File
@@ -740,6 +740,9 @@ weechat_python_load (const char *filename)
&weechat_python_api_buffer_input_data_cb,
&weechat_python_api_buffer_close_cb);
weechat_hook_signal_send ("python_script_loaded", WEECHAT_HOOK_SIGNAL_STRING,
python_current_script->filename);
return 1;
}
@@ -766,6 +769,7 @@ weechat_python_unload (struct t_plugin_script *script)
int *rc;
void *interpreter;
PyThreadState *old_interpreter;
char *filename;
if ((weechat_python_plugin->debug >= 2) || !python_quiet)
{
@@ -782,6 +786,7 @@ weechat_python_unload (struct t_plugin_script *script)
free (rc);
}
filename = strdup (script->filename);
old_interpreter = PyThreadState_Swap (NULL);
interpreter = script->interpreter;
@@ -800,6 +805,11 @@ weechat_python_unload (struct t_plugin_script *script)
if (old_interpreter)
PyThreadState_Swap (old_interpreter);
weechat_hook_signal_send ("python_script_unloaded",
WEECHAT_HOOK_SIGNAL_STRING, filename);
if (filename)
free (filename);
}
/*
+10
View File
@@ -595,6 +595,9 @@ weechat_ruby_load (const char *filename)
&weechat_ruby_api_buffer_input_data_cb,
&weechat_ruby_api_buffer_close_cb);
weechat_hook_signal_send ("ruby_script_loaded", WEECHAT_HOOK_SIGNAL_STRING,
ruby_current_script->filename);
return 1;
}
@@ -620,6 +623,7 @@ weechat_ruby_unload (struct t_plugin_script *script)
{
int *rc;
void *interpreter;
char *filename;
if ((weechat_ruby_plugin->debug >= 2) || !ruby_quiet)
{
@@ -638,6 +642,7 @@ weechat_ruby_unload (struct t_plugin_script *script)
free (rc);
}
filename = strdup (script->filename);
interpreter = script->interpreter;
if (ruby_current_script == script)
@@ -649,6 +654,11 @@ weechat_ruby_unload (struct t_plugin_script *script)
if (interpreter)
rb_gc_unregister_address (interpreter);
weechat_hook_signal_send ("ruby_script_unloaded",
WEECHAT_HOOK_SIGNAL_STRING, filename);
if (filename)
free (filename);
}
/*
+10
View File
@@ -343,6 +343,9 @@ weechat_tcl_load (const char *filename)
&weechat_tcl_api_buffer_input_data_cb,
&weechat_tcl_api_buffer_close_cb);
weechat_hook_signal_send ("tcl_script_loaded", WEECHAT_HOOK_SIGNAL_STRING,
tcl_current_script->filename);
return 1;
}
@@ -368,6 +371,7 @@ weechat_tcl_unload (struct t_plugin_script *script)
{
Tcl_Interp* interp;
int *rc;
char *filename;
if ((weechat_tcl_plugin->debug >= 2) || !tcl_quiet)
{
@@ -386,6 +390,7 @@ weechat_tcl_unload (struct t_plugin_script *script)
free (rc);
}
filename = strdup (script->filename);
interp = (Tcl_Interp*)script->interpreter;
if (tcl_current_script == script)
@@ -395,6 +400,11 @@ weechat_tcl_unload (struct t_plugin_script *script)
plugin_script_remove (weechat_tcl_plugin, &tcl_scripts, &last_tcl_script, script);
Tcl_DeleteInterp(interp);
weechat_hook_signal_send ("tcl_script_unloaded",
WEECHAT_HOOK_SIGNAL_STRING, filename);
if (filename)
free (filename);
}
/*