From 3d3dc1593db988c7649c9f7dc7e4289a576a6c77 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Tue, 23 Feb 2010 10:51:59 +0100 Subject: Allow script commands to reload only one script --- src/plugins/scripts/lua/weechat-lua.c | 37 +++++++++++++++++++++++++++++ src/plugins/scripts/perl/weechat-perl.c | 37 +++++++++++++++++++++++++++++ src/plugins/scripts/python/weechat-python.c | 37 +++++++++++++++++++++++++++++ src/plugins/scripts/ruby/weechat-ruby.c | 37 +++++++++++++++++++++++++++++ src/plugins/scripts/script.c | 4 ++-- src/plugins/scripts/tcl/weechat-tcl.c | 37 +++++++++++++++++++++++++++++ 6 files changed, 187 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c index 52c5ccf74..12ac19a85 100644 --- a/src/plugins/scripts/lua/weechat-lua.c +++ b/src/plugins/scripts/lua/weechat-lua.c @@ -353,6 +353,38 @@ weechat_lua_unload_name (const char *name) } } +/* + * weechat_lua_reload_name: reload a Lua script by name + */ + +void +weechat_lua_reload_name (const char *name) +{ + struct t_plugin_script *ptr_script; + char *filename; + + ptr_script = script_search (weechat_lua_plugin, lua_scripts, name); + if (ptr_script) + { + filename = strdup (ptr_script->filename); + if (filename) + { + weechat_lua_unload (ptr_script); + weechat_printf (NULL, + weechat_gettext ("%s: script \"%s\" unloaded"), + LUA_PLUGIN_NAME, name); + weechat_lua_load (filename); + free (filename); + } + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: script \"%s\" not loaded"), + weechat_prefix ("error"), LUA_PLUGIN_NAME, name); + } +} + /* * weechat_lua_unload_all: unload all Lua scripts */ @@ -432,6 +464,11 @@ weechat_lua_command_cb (void *data, struct t_gui_buffer *buffer, if (path_script) free (path_script); } + else if (weechat_strcasecmp (argv[1], "reload") == 0) + { + /* reload one Lua script */ + weechat_lua_reload_name (argv_eol[2]); + } else if (weechat_strcasecmp (argv[1], "unload") == 0) { /* unload Lua script */ diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c index 76b4b9948..50ee2845b 100644 --- a/src/plugins/scripts/perl/weechat-perl.c +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -506,6 +506,38 @@ weechat_perl_unload_all () } } +/* + * weechat_perl_reload_name: reload a Perl script by name + */ + +void +weechat_perl_reload_name (const char *name) +{ + struct t_plugin_script *ptr_script; + char *filename; + + ptr_script = script_search (weechat_perl_plugin, perl_scripts, name); + if (ptr_script) + { + filename = strdup (ptr_script->filename); + if (filename) + { + weechat_perl_unload (ptr_script); + weechat_printf (NULL, + weechat_gettext ("%s: script \"%s\" unloaded"), + PERL_PLUGIN_NAME, name); + weechat_perl_load (filename); + free (filename); + } + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: script \"%s\" not loaded"), + weechat_prefix ("error"), PERL_PLUGIN_NAME, name); + } +} + /* * weechat_perl_command_cb: callback for "/perl" command */ @@ -572,6 +604,11 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer, if (path_script) free (path_script); } + else if (weechat_strcasecmp (argv[1], "reload") == 0) + { + /* reload one Perl script */ + weechat_perl_reload_name (argv_eol[2]); + } else if (weechat_strcasecmp (argv[1], "unload") == 0) { /* unload Perl script */ diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index 446a16257..a2dc8312a 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -602,6 +602,38 @@ weechat_python_unload_all () } } +/* + * weechat_python_reload_name: reload a Python script by name + */ + +void +weechat_python_reload_name (const char *name) +{ + struct t_plugin_script *ptr_script; + char *filename; + + ptr_script = script_search (weechat_python_plugin, python_scripts, name); + if (ptr_script) + { + filename = strdup (ptr_script->filename); + if (filename) + { + weechat_python_unload (ptr_script); + weechat_printf (NULL, + weechat_gettext ("%s: script \"%s\" unloaded"), + PYTHON_PLUGIN_NAME, name); + weechat_python_load (filename); + free (filename); + } + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: script \"%s\" not loaded"), + weechat_prefix ("error"), PYTHON_PLUGIN_NAME, name); + } +} + /* * weechat_python_cmd: callback for "/python" command */ @@ -668,6 +700,11 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer, if (path_script) free (path_script); } + else if (weechat_strcasecmp (argv[1], "reload") == 0) + { + /* reload one Python script */ + weechat_python_reload_name (argv_eol[2]); + } else if (weechat_strcasecmp (argv[1], "unload") == 0) { /* unload Python script */ diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c index 166b4685a..8179d758d 100644 --- a/src/plugins/scripts/ruby/weechat-ruby.c +++ b/src/plugins/scripts/ruby/weechat-ruby.c @@ -642,6 +642,38 @@ weechat_ruby_unload_name (const char *name) } } +/* + * weechat_ruby_reload_name: reload a Ruby script by name + */ + +void +weechat_ruby_reload_name (const char *name) +{ + struct t_plugin_script *ptr_script; + char *filename; + + ptr_script = script_search (weechat_ruby_plugin, ruby_scripts, name); + if (ptr_script) + { + filename = strdup (ptr_script->filename); + if (filename) + { + weechat_ruby_unload (ptr_script); + weechat_printf (NULL, + weechat_gettext ("%s: script \"%s\" unloaded"), + RUBY_PLUGIN_NAME, name); + weechat_ruby_load (filename); + free (filename); + } + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: script \"%s\" not loaded"), + weechat_prefix ("error"), RUBY_PLUGIN_NAME, name); + } +} + /* * weechat_ruby_unload_all: unload all Ruby scripts */ @@ -721,6 +753,11 @@ weechat_ruby_command_cb (void *data, struct t_gui_buffer *buffer, if (path_script) free (path_script); } + else if (weechat_strcasecmp (argv[1], "reload") == 0) + { + /* reload one Ruby script */ + weechat_ruby_reload_name (argv_eol[2]); + } else if (weechat_strcasecmp (argv[1], "unload") == 0) { /* unload Ruby script */ diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c index 8d8cf8fc6..b08f4df98 100644 --- a/src/plugins/scripts/script.c +++ b/src/plugins/scripts/script.c @@ -248,7 +248,7 @@ script_init (struct t_weechat_plugin *weechat_plugin, " || listfull %s" " || load %(filename)" " || autoload" - " || reload" + " || reload %s" " || unload %s", "%s", string); @@ -257,7 +257,7 @@ script_init (struct t_weechat_plugin *weechat_plugin, N_("list/load/unload scripts"), N_("[list [name]] | [listfull [name]] | " "[load filename] | [autoload] | " - "[reload] | [unload [name]]"), + "[reload [name]] | [unload [name]]"), N_("filename: script (file) to load\n" "name: a script name\n\n" "Without argument, this command " diff --git a/src/plugins/scripts/tcl/weechat-tcl.c b/src/plugins/scripts/tcl/weechat-tcl.c index 61d08bb8c..89c7e40c4 100644 --- a/src/plugins/scripts/tcl/weechat-tcl.c +++ b/src/plugins/scripts/tcl/weechat-tcl.c @@ -301,6 +301,38 @@ weechat_tcl_unload_all () } } +/* + * weechat_tcl_reload_name: reload a Tcl script by name + */ + +void +weechat_tcl_reload_name (const char *name) +{ + struct t_plugin_script *ptr_script; + char *filename; + + ptr_script = script_search (weechat_tcl_plugin, tcl_scripts, name); + if (ptr_script) + { + filename = strdup (ptr_script->filename); + if (filename) + { + weechat_tcl_unload (ptr_script); + weechat_printf (NULL, + weechat_gettext ("%s: script \"%s\" unloaded"), + TCL_PLUGIN_NAME, name); + weechat_tcl_load (filename); + free (filename); + } + } + else + { + weechat_printf (NULL, + weechat_gettext ("%s%s: script \"%s\" not loaded"), + weechat_prefix ("error"), TCL_PLUGIN_NAME, name); + } +} + /* * weechat_tcl_command_cb: callback for "/tcl" command */ @@ -367,6 +399,11 @@ weechat_tcl_command_cb (void *data, struct t_gui_buffer *buffer, if (path_script) free (path_script); } + else if (weechat_strcasecmp (argv[1], "reload") == 0) + { + /* reload one Tcl script */ + weechat_tcl_reload_name (argv_eol[2]); + } else if (weechat_strcasecmp (argv[1], "unload") == 0) { /* unload Tcl script */ -- cgit v1.2.3