diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua-api.h | 6 | ||||
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua.c | 13 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl-api.h | 5 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl.c | 12 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python-api.h | 6 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python.c | 11 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby-api.h | 5 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby.c | 11 | ||||
-rw-r--r-- | src/plugins/scripts/script-api.c | 7 | ||||
-rw-r--r-- | src/plugins/scripts/script.c | 110 | ||||
-rw-r--r-- | src/plugins/scripts/script.h | 10 | ||||
-rw-r--r-- | src/plugins/scripts/tcl/weechat-tcl-api.h | 5 | ||||
-rw-r--r-- | src/plugins/scripts/tcl/weechat-tcl.c | 11 |
13 files changed, 182 insertions, 30 deletions
diff --git a/src/plugins/scripts/lua/weechat-lua-api.h b/src/plugins/scripts/lua/weechat-lua-api.h index b2bccaa23..48a4b1ec1 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.h +++ b/src/plugins/scripts/lua/weechat-lua-api.h @@ -22,4 +22,10 @@ extern struct luaL_reg weechat_lua_api_funcs[]; +extern int weechat_lua_api_buffer_input_data_cb (void *data, + struct t_gui_buffer *buffer, + const char *input_data); +extern int weechat_lua_api_buffer_close_cb (void *data, + struct t_gui_buffer *buffer); + #endif /* weechat-lua.h */ diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c index 46ca1e4b8..d87ad2417 100644 --- a/src/plugins/scripts/lua/weechat-lua.c +++ b/src/plugins/scripts/lua/weechat-lua.c @@ -600,21 +600,22 @@ weechat_lua_signal_script_action_cb (void *data, const char *signal, int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { - /* make C compiler happy */ - (void) argc; - (void) argv; - weechat_lua_plugin = plugin; - + lua_quiet = 1; script_init (weechat_lua_plugin, + argc, + argv, + &lua_scripts, &weechat_lua_command_cb, &weechat_lua_completion_cb, &weechat_lua_infolist_cb, &weechat_lua_signal_debug_dump_cb, &weechat_lua_signal_buffer_closed_cb, &weechat_lua_signal_script_action_cb, - &weechat_lua_load_cb); + &weechat_lua_load_cb, + &weechat_lua_api_buffer_input_data_cb, + &weechat_lua_api_buffer_close_cb); lua_quiet = 0; script_display_short_list (weechat_lua_plugin, diff --git a/src/plugins/scripts/perl/weechat-perl-api.h b/src/plugins/scripts/perl/weechat-perl-api.h index fdfd1d695..5dbd0067d 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.h +++ b/src/plugins/scripts/perl/weechat-perl-api.h @@ -20,6 +20,11 @@ #ifndef __WEECHAT_PERL_API_H #define __WEECHAT_PERL_API_H 1 +extern int weechat_perl_api_buffer_input_data_cb (void *data, + struct t_gui_buffer *buffer, + const char *input_data); +extern int weechat_perl_api_buffer_close_cb (void *data, + struct t_gui_buffer *buffer); extern void weechat_perl_api_init (pTHX); #endif /* weechat-perl.h */ diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c index 5ef70fe8f..c49f445cd 100644 --- a/src/plugins/scripts/perl/weechat-perl.c +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -772,11 +772,6 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) char **perl_args_local; char *perl_env[] = {}; #endif - - /* make C compiler happy */ - (void) argc; - (void) argv; - #ifdef PERL_SYS_INIT3 a = perl_args_count; perl_args_local = perl_args; @@ -806,13 +801,18 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) perl_quiet = 1; script_init (weechat_perl_plugin, + argc, + argv, + &perl_scripts, &weechat_perl_command_cb, &weechat_perl_completion_cb, &weechat_perl_infolist_cb, &weechat_perl_signal_debug_dump_cb, &weechat_perl_signal_buffer_closed_cb, &weechat_perl_signal_script_action_cb, - &weechat_perl_load_cb); + &weechat_perl_load_cb, + &weechat_perl_api_buffer_input_data_cb, + &weechat_perl_api_buffer_close_cb); perl_quiet = 0; script_display_short_list (weechat_perl_plugin, diff --git a/src/plugins/scripts/python/weechat-python-api.h b/src/plugins/scripts/python/weechat-python-api.h index 8b56e565c..6933113ea 100644 --- a/src/plugins/scripts/python/weechat-python-api.h +++ b/src/plugins/scripts/python/weechat-python-api.h @@ -22,4 +22,10 @@ extern PyMethodDef weechat_python_funcs[]; +extern int weechat_python_api_buffer_input_data_cb (void *data, + struct t_gui_buffer *buffer, + const char *input_data); +extern int weechat_python_api_buffer_close_cb (void *data, + struct t_gui_buffer *buffer); + #endif /* weechat-python.h */ diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index 02f09bcc1..4f9087897 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -834,10 +834,6 @@ weechat_python_signal_script_action_cb (void *data, const char *signal, int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { - /* make C compiler happy */ - (void) argc; - (void) argv; - weechat_python_plugin = plugin; /* init stdout/stderr buffer */ @@ -869,13 +865,18 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) python_quiet = 1; script_init (weechat_python_plugin, + argc, + argv, + &python_scripts, &weechat_python_command_cb, &weechat_python_completion_cb, &weechat_python_infolist_cb, &weechat_python_signal_debug_dump_cb, &weechat_python_signal_buffer_closed_cb, &weechat_python_signal_script_action_cb, - &weechat_python_load_cb); + &weechat_python_load_cb, + &weechat_python_api_buffer_input_data_cb, + &weechat_python_api_buffer_close_cb); python_quiet = 0; script_display_short_list (weechat_python_plugin, diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.h b/src/plugins/scripts/ruby/weechat-ruby-api.h index 040d92edf..ac2a60572 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.h +++ b/src/plugins/scripts/ruby/weechat-ruby-api.h @@ -20,6 +20,11 @@ #ifndef __WEECHAT_RUBY_API_H #define __WEECHAT_RUBY_API_H 1 +extern int weechat_ruby_api_buffer_input_data_cb (void *data, + struct t_gui_buffer *buffer, + const char *input_data); +extern int weechat_ruby_api_buffer_close_cb (void *data, + struct t_gui_buffer *buffer); extern void weechat_ruby_api_init (VALUE ruby_mWeechat); #endif /* weechat-ruby.h */ diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c index 836f68602..144700497 100644 --- a/src/plugins/scripts/ruby/weechat-ruby.c +++ b/src/plugins/scripts/ruby/weechat-ruby.c @@ -843,10 +843,6 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) "end\n" }; - /* make C compiler happy */ - (void) argc; - (void) argv; - weechat_ruby_plugin = plugin; ruby_error = 0; @@ -889,13 +885,18 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) ruby_quiet = 1; script_init (weechat_ruby_plugin, + argc, + argv, + &ruby_scripts, &weechat_ruby_command_cb, &weechat_ruby_completion_cb, &weechat_ruby_infolist_cb, &weechat_ruby_signal_debug_dump_cb, &weechat_ruby_signal_buffer_closed_cb, &weechat_ruby_signal_script_action_cb, - &weechat_ruby_load_cb); + &weechat_ruby_load_cb, + &weechat_ruby_api_buffer_input_data_cb, + &weechat_ruby_api_buffer_close_cb); ruby_quiet = 0; script_display_short_list (weechat_ruby_plugin, diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c index 2aa4db899..18fdab1fe 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -1364,6 +1364,13 @@ script_api_buffer_new (struct t_weechat_plugin *weechat_plugin, script_callback_add (script, new_script_callback_close); } + weechat_buffer_set (new_buffer, "localvar_set_script_name", + script->name); + weechat_buffer_set (new_buffer, "localvar_set_script_input_cb", + function_input); + weechat_buffer_set (new_buffer, "localvar_set_script_close_cb", + function_close); + return new_buffer; } diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c index cce516c9f..42de1e057 100644 --- a/src/plugins/scripts/script.c +++ b/src/plugins/scripts/script.c @@ -78,11 +78,97 @@ script_config_cb (void *data, const char *option, const char *value) } /* + * script_upgrade_set_buffer_callbacks: restore buffers callbacks (input and + * close) for buffers created by script + * plugin + */ + +void +script_upgrade_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script **scripts, + int (*callback_buffer_input) (void *data, + struct t_gui_buffer *buffer, + const char *input_data), + int (*callback_buffer_close) (void *data, + struct t_gui_buffer *buffer)) +{ + struct t_infolist *infolist; + struct t_gui_buffer *ptr_buffer; + const char *script_name, *script_input_cb, *script_close_cb; + struct t_plugin_script *ptr_script; + struct t_script_callback *new_script_callback_input; + struct t_script_callback *new_script_callback_close; + + infolist = weechat_infolist_get ("buffer", NULL, NULL); + if (infolist) + { + while (weechat_infolist_next (infolist)) + { + if (weechat_infolist_pointer (infolist, "plugin") == weechat_plugin) + { + ptr_buffer = weechat_infolist_pointer (infolist, "pointer"); + script_name = weechat_buffer_get_string (ptr_buffer, "localvar_script_name"); + if (script_name && script_name[0]) + { + ptr_script = script_search (weechat_plugin, *scripts, + script_name); + if (ptr_script) + { + script_input_cb = weechat_buffer_get_string (ptr_buffer, "localvar_script_input_cb"); + script_close_cb = weechat_buffer_get_string (ptr_buffer, "localvar_script_close_cb"); + + if (script_input_cb && script_input_cb[0]) + { + new_script_callback_input = script_callback_alloc (); + if (new_script_callback_input) + { + new_script_callback_input->script = ptr_script; + new_script_callback_input->function = strdup (script_input_cb); + new_script_callback_input->buffer = ptr_buffer; + script_callback_add (ptr_script, + new_script_callback_input); + weechat_buffer_set_pointer (ptr_buffer, + "input_callback", + callback_buffer_input); + weechat_buffer_set_pointer (ptr_buffer, + "input_callback_data", + new_script_callback_input); + } + } + if (script_close_cb && script_close_cb[0]) + { + new_script_callback_close = script_callback_alloc (); + if (new_script_callback_close) + { + new_script_callback_close->script = ptr_script; + new_script_callback_close->function = strdup (script_close_cb); + new_script_callback_close->buffer = ptr_buffer; + script_callback_add (ptr_script, + new_script_callback_close); + weechat_buffer_set_pointer (ptr_buffer, + "close_callback", + callback_buffer_close); + weechat_buffer_set_pointer (ptr_buffer, + "close_callback_data", + new_script_callback_close); + } + } + } + } + } + } + } +} + +/* * script_init: initialize script */ void script_init (struct t_weechat_plugin *weechat_plugin, + int argc, + char *argv[], + struct t_plugin_script **scripts, int (*callback_command)(void *data, struct t_gui_buffer *buffer, int argc, char **argv, @@ -103,11 +189,16 @@ script_init (struct t_weechat_plugin *weechat_plugin, int (*callback_signal_script_action)(void *data, const char *signal, const char *type_data, void *signal_data), - void (*callback_load_file)(void *data, const char *filename)) + void (*callback_load_file)(void *data, const char *filename), + int (*callback_buffer_input) (void *data, + struct t_gui_buffer *buffer, + const char *input_data), + int (*callback_buffer_close) (void *data, + struct t_gui_buffer *buffer)) { char *string, *completion = "list|listfull|load|autoload|reload|unload %(filename)"; char infolist_description[512], signal_name[128]; - int length; + int length, i, upgrading; /* read script configuration */ script_config_read (weechat_plugin); @@ -188,6 +279,21 @@ script_init (struct t_weechat_plugin *weechat_plugin, /* autoload scripts */ script_auto_load (weechat_plugin, callback_load_file); + + /* actions after upgrade */ + upgrading = 0; + for (i = 0; i < argc; i++) + { + if (weechat_strcasecmp (argv[i], "--upgrade") == 0) + upgrading = 1; + } + if (upgrading) + { + script_upgrade_set_buffer_callbacks (weechat_plugin, + scripts, + callback_buffer_input, + callback_buffer_close); + } } /* diff --git a/src/plugins/scripts/script.h b/src/plugins/scripts/script.h index 94f9c318c..715b9cc48 100644 --- a/src/plugins/scripts/script.h +++ b/src/plugins/scripts/script.h @@ -57,6 +57,9 @@ struct t_plugin_script }; extern void script_init (struct t_weechat_plugin *weechat_plugin, + int argc, + char *argv[], + struct t_plugin_script **scripts, int (*callback_command)(void *data, struct t_gui_buffer *buffer, int argc, char **argv, @@ -81,7 +84,12 @@ extern void script_init (struct t_weechat_plugin *weechat_plugin, const char *signal, const char *type_data, void *signal_data), - void (*callback_load_file)(void *data, const char *filename)); + void (*callback_load_file)(void *data, const char *filename), + int (*callback_buffer_input) (void *data, + struct t_gui_buffer *buffer, + const char *input_data), + int (*callback_buffer_close) (void *data, + struct t_gui_buffer *buffer)); extern int script_valid (struct t_plugin_script *scripts, struct t_plugin_script *script); extern char *script_ptr2str (void *pointer); diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.h b/src/plugins/scripts/tcl/weechat-tcl-api.h index d6a09970e..eb1a5e055 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.h +++ b/src/plugins/scripts/tcl/weechat-tcl-api.h @@ -20,6 +20,11 @@ #ifndef __WEECHAT_TCL_API_H #define __WEECHAT_TCL_API_H 1 +extern int weechat_tcl_api_buffer_input_data_cb (void *data, + struct t_gui_buffer *buffer, + const char *input_data); +extern int weechat_tcl_api_buffer_close_cb (void *data, + struct t_gui_buffer *buffer); extern void weechat_tcl_api_init (Tcl_Interp *interp); #endif /* weechat-tcl.h */ diff --git a/src/plugins/scripts/tcl/weechat-tcl.c b/src/plugins/scripts/tcl/weechat-tcl.c index 47563c13b..9e84c1f01 100644 --- a/src/plugins/scripts/tcl/weechat-tcl.c +++ b/src/plugins/scripts/tcl/weechat-tcl.c @@ -540,21 +540,22 @@ weechat_tcl_signal_script_action_cb (void *data, const char *signal, int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { - /* make C compiler happy */ - (void) argc; - (void) argv; - weechat_tcl_plugin = plugin; tcl_quiet = 1; script_init (weechat_tcl_plugin, + argc, + argv, + &tcl_scripts, &weechat_tcl_command_cb, &weechat_tcl_completion_cb, &weechat_tcl_infolist_cb, &weechat_tcl_signal_debug_dump_cb, &weechat_tcl_signal_buffer_closed_cb, &weechat_tcl_signal_script_action_cb, - &weechat_tcl_load_cb); + &weechat_tcl_load_cb, + &weechat_tcl_api_buffer_input_data_cb, + &weechat_tcl_api_buffer_close_cb); tcl_quiet = 0; script_display_short_list (weechat_tcl_plugin, |