diff options
Diffstat (limited to 'src/plugins')
21 files changed, 448 insertions, 120 deletions
diff --git a/src/plugins/charset/charset.c b/src/plugins/charset/charset.c index 410abe070..d9c48d067 100644 --- a/src/plugins/charset/charset.c +++ b/src/plugins/charset/charset.c @@ -381,6 +381,18 @@ charset_set (struct t_config_section *section, const char *type, } /* + * charset_display_charsets: display charsets + */ + +void +charset_display_charsets () +{ + weechat_printf (NULL, + _("%s: terminal: %s, internal: %s"), + CHARSET_PLUGIN_NAME, charset_terminal, charset_internal); +} + +/* * charset_command_cb: callback for /charset command */ @@ -398,10 +410,8 @@ charset_command_cb (void *data, struct t_gui_buffer *buffer, int argc, if (argc < 2) { - weechat_printf (NULL, - _("%s%s: missing parameters"), - weechat_prefix ("error"), CHARSET_PLUGIN_NAME); - return WEECHAT_RC_ERROR; + charset_display_charsets (); + return WEECHAT_RC_OK; } ptr_section = NULL; @@ -504,9 +514,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) charset_internal = weechat_info_get ("charset_internal", ""); /* display message */ - weechat_printf (NULL, - _("%s: terminal: %s, internal: %s"), - CHARSET_PLUGIN_NAME, charset_terminal, charset_internal); + if (weechat_charset_plugin->debug >= 1) + charset_display_charsets (); if (!charset_config_init ()) { diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c index 3484af9eb..5e8fd14db 100644 --- a/src/plugins/fifo/fifo.c +++ b/src/plugins/fifo/fifo.c @@ -42,6 +42,7 @@ WEECHAT_PLUGIN_LICENSE("GPL3"); struct t_weechat_plugin *weechat_fifo_plugin = NULL; #define weechat_plugin weechat_fifo_plugin +int fifo_quiet = 0; int fifo_fd = -1; struct t_hook *fifo_fd_hook = NULL; char *fifo_filename; @@ -95,9 +96,12 @@ fifo_create () if ((fifo_fd = open (fifo_filename, O_RDONLY | O_NONBLOCK)) != -1) { - weechat_printf (NULL, - _("%s: pipe opened"), - FIFO_PLUGIN_NAME), + if ((weechat_fifo_plugin->debug >= 1) || !fifo_quiet) + { + weechat_printf (NULL, + _("%s: pipe opened"), + FIFO_PLUGIN_NAME); + } rc = 1; } else @@ -366,6 +370,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_plugin = plugin; + fifo_quiet = 1; + if (fifo_create ()) fifo_fd_hook = weechat_hook_fd (fifo_fd, 1, 0, 0, &fifo_read, NULL); @@ -374,6 +380,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) fifo_info_init (); + fifo_quiet = 0; + return WEECHAT_RC_OK; } diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index ed6b0e860..4e92d3d77 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -55,6 +55,7 @@ #include "plugin-config.h" +int plugin_quiet = 0; struct t_weechat_plugin *weechat_plugins = NULL; struct t_weechat_plugin *last_weechat_plugin = NULL; @@ -126,6 +127,67 @@ plugin_get_name (struct t_weechat_plugin *plugin) } /* + * plugin_find_pos: find position for a plugin (for sorting plugins list) + */ + +struct t_weechat_plugin * +plugin_find_pos (struct t_weechat_plugin *plugin) +{ + struct t_weechat_plugin *ptr_plugin; + + for (ptr_plugin = weechat_plugins; ptr_plugin; + ptr_plugin = ptr_plugin->next_plugin) + { + if (string_strcasecmp (plugin->name, ptr_plugin->name) < 0) + return ptr_plugin; + } + return NULL; +} + +/* + * plugin_insert_sorted: insert a plugin in list, keeping sort on name + */ + +void +plugin_insert_sorted (struct t_weechat_plugin *plugin) +{ + struct t_weechat_plugin *pos_plugin; + + if (weechat_plugins) + { + pos_plugin = plugin_find_pos (plugin); + + if (pos_plugin) + { + /* insert plugin into the list (before plugin found) */ + plugin->prev_plugin = pos_plugin->prev_plugin; + plugin->next_plugin = pos_plugin; + if (pos_plugin->prev_plugin) + (pos_plugin->prev_plugin)->next_plugin = plugin; + else + weechat_plugins = plugin; + pos_plugin->prev_plugin = plugin; + } + else + { + /* add plugin to the end */ + plugin->prev_plugin = last_weechat_plugin; + plugin->next_plugin = NULL; + last_weechat_plugin->next_plugin = plugin; + last_weechat_plugin = plugin; + } + } + else + { + /* first plugin in list */ + plugin->prev_plugin = NULL; + plugin->next_plugin = NULL; + weechat_plugins = plugin; + last_weechat_plugin = plugin; + } +} + +/* * plugin_load: load a WeeChat plugin (a dynamic library) * return: pointer to new WeeChat plugin, NULL if error */ @@ -518,15 +580,8 @@ plugin_load (const char *filename) new_plugin->upgrade_read = &upgrade_file_read; new_plugin->upgrade_close = &upgrade_file_close; - /* add new plugin to list */ - new_plugin->prev_plugin = last_weechat_plugin; - new_plugin->next_plugin = NULL; - if (weechat_plugins) - last_weechat_plugin->next_plugin = new_plugin; - else - weechat_plugins = new_plugin; - last_weechat_plugin = new_plugin; - + plugin_insert_sorted (new_plugin); + /* associate orphan buffers with this plugin (if asked during upgrade process) */ gui_buffer_set_plugin_for_upgrade (name, new_plugin); @@ -591,9 +646,12 @@ plugin_load (const char *filename) return NULL; } - gui_chat_printf (NULL, - _("Plugin \"%s\" loaded"), - name); + if ((weechat_debug_core >= 1) || !plugin_quiet) + { + gui_chat_printf (NULL, + _("Plugin \"%s\" loaded"), + name); + } free (full_name); @@ -825,7 +883,7 @@ plugin_unload_all () { while (weechat_plugins) { - plugin_unload (last_weechat_plugin); + plugin_unload (weechat_plugins); } } @@ -860,6 +918,49 @@ plugin_reload_name (const char *name) } /* + * plugin_display_short_list: print list of plugins on one line + */ + +void +plugin_display_short_list () +{ + const char *plugins_loaded; + char *buf; + int length; + struct t_weechat_plugin *ptr_plugin; + + if (weechat_plugins) + { + plugins_loaded = _("Plugins loaded:"); + + length = strlen (plugins_loaded) + 1; + + for (ptr_plugin = weechat_plugins; ptr_plugin; + ptr_plugin = ptr_plugin->next_plugin) + { + length += strlen (ptr_plugin->name) + 2; + } + length++; + + buf = malloc (length); + if (buf) + { + strcpy (buf, plugins_loaded); + strcat (buf, " "); + for (ptr_plugin = weechat_plugins; ptr_plugin; + ptr_plugin = ptr_plugin->next_plugin) + { + strcat (buf, ptr_plugin->name); + if (ptr_plugin->next_plugin) + strcat (buf, ", "); + } + gui_chat_printf (NULL, "%s", buf); + free (buf); + } + } +} + +/* * plugin_init: init plugin support */ @@ -878,7 +979,12 @@ plugin_init (int auto_load, int argc, char *argv[]) /* auto-load plugins if asked */ if (auto_load) + { + plugin_quiet = 1; plugin_auto_load (); + plugin_display_short_list (); + plugin_quiet = 0; + } /* discard command arguments for future plugins */ plugin_argc = 0; diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 522c4a30e..0f0d50fa8 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -107,7 +107,7 @@ weechat_lua_api_register (lua_State *L) /* register script */ lua_current_script = script_add (weechat_lua_plugin, - &lua_scripts, + &lua_scripts, &last_lua_script, (lua_current_script_filename) ? lua_current_script_filename : "", name, @@ -119,10 +119,13 @@ weechat_lua_api_register (lua_State *L) charset); if (lua_current_script) { - weechat_printf (NULL, - weechat_gettext ("%s: registered script \"%s\", " - "version %s (%s)"), - LUA_PLUGIN_NAME, name, version, description); + if ((weechat_lua_plugin->debug >= 1) || !lua_quiet) + { + weechat_printf (NULL, + weechat_gettext ("%s: registered script \"%s\", " + "version %s (%s)"), + LUA_PLUGIN_NAME, name, version, description); + } } else { diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c index 9ac4f81ae..2f8a918f6 100644 --- a/src/plugins/scripts/lua/weechat-lua.c +++ b/src/plugins/scripts/lua/weechat-lua.c @@ -42,7 +42,9 @@ WEECHAT_PLUGIN_LICENSE("GPL3"); struct t_weechat_plugin *weechat_lua_plugin; +int lua_quiet = 0; struct t_plugin_script *lua_scripts = NULL; +struct t_plugin_script *last_lua_script = NULL; struct t_plugin_script *lua_current_script = NULL; const char *lua_current_script_filename = NULL; lua_State *lua_current_interpreter = NULL; @@ -95,7 +97,8 @@ weechat_lua_exec (struct t_plugin_script *script, if (argv[6]) { argc = 7; - lua_pushstring (lua_current_interpreter, argv[6]); + lua_pushstring (lua_current_interpreter, + argv[6]); } } } @@ -160,9 +163,12 @@ weechat_lua_load (const char *filename) return 0; } - weechat_printf (NULL, - weechat_gettext ("%s: loading script \"%s\""), - LUA_PLUGIN_NAME, filename); + if ((weechat_lua_plugin->debug >= 1) || !lua_quiet) + { + weechat_printf (NULL, + weechat_gettext ("%s: loading script \"%s\""), + LUA_PLUGIN_NAME, filename); + } lua_current_script = NULL; @@ -233,7 +239,7 @@ weechat_lua_load (const char *filename) fclose (fp); /* if script was registered, removing from list */ if (lua_current_script) - script_remove (weechat_lua_plugin, &lua_scripts, + script_remove (weechat_lua_plugin, &lua_scripts, &last_lua_script, lua_current_script); return 0; } @@ -298,7 +304,7 @@ weechat_lua_unload (struct t_plugin_script *script) lua_current_script = (lua_current_script->prev_script) ? lua_current_script->prev_script : lua_current_script->next_script; - script_remove (weechat_lua_plugin, &lua_scripts, script); + script_remove (weechat_lua_plugin, &lua_scripts, &last_lua_script, script); lua_close (script->interpreter); } @@ -448,8 +454,8 @@ weechat_lua_completion_cb (void *data, const char *completion_item, */ int -weechat_lua_debug_dump_cb (void *data, const char *signal, const char *type_data, - void *signal_data) +weechat_lua_debug_dump_cb (void *data, const char *signal, + const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; @@ -467,8 +473,8 @@ weechat_lua_debug_dump_cb (void *data, const char *signal, const char *type_data */ int -weechat_lua_buffer_closed_cb (void *data, const char *signal, const char *type_data, - void *signal_data) +weechat_lua_buffer_closed_cb (void *data, const char *signal, + const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; @@ -494,12 +500,17 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_lua_plugin = plugin; + lua_quiet = 1; script_init (weechat_lua_plugin, &weechat_lua_command_cb, &weechat_lua_completion_cb, &weechat_lua_debug_dump_cb, &weechat_lua_buffer_closed_cb, &weechat_lua_load_cb); + lua_quiet = 0; + + script_display_short_list (weechat_lua_plugin, + lua_scripts); /* init ok */ return WEECHAT_RC_OK; diff --git a/src/plugins/scripts/lua/weechat-lua.h b/src/plugins/scripts/lua/weechat-lua.h index 8eef0843e..e26c16763 100644 --- a/src/plugins/scripts/lua/weechat-lua.h +++ b/src/plugins/scripts/lua/weechat-lua.h @@ -25,7 +25,9 @@ extern struct t_weechat_plugin *weechat_lua_plugin; +extern int lua_quiet; extern struct t_plugin_script *lua_scripts; +extern struct t_plugin_script *last_lua_script; extern struct t_plugin_script *lua_current_script; extern const char *lua_current_script_filename; extern lua_State *lua_current_interpreter; diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index 192e3ed2e..e38361d65 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -104,17 +104,20 @@ static XS (XS_weechat_api_register) /* register script */ perl_current_script = script_add (weechat_perl_plugin, - &perl_scripts, + &perl_scripts, &last_perl_script, (perl_current_script_filename) ? perl_current_script_filename : "", name, author, version, license, description, shutdown_func, charset); if (perl_current_script) { - weechat_printf (NULL, - weechat_gettext ("%s: registered script \"%s\", " - "version %s (%s)"), - PERL_PLUGIN_NAME, name, version, description); + if ((weechat_perl_plugin->debug >= 1) || !perl_quiet) + { + weechat_printf (NULL, + weechat_gettext ("%s: registered script \"%s\", " + "version %s (%s)"), + PERL_PLUGIN_NAME, name, version, description); + } } else { diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c index df97e925e..04c0437ad 100644 --- a/src/plugins/scripts/perl/weechat-perl.c +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -40,7 +40,9 @@ WEECHAT_PLUGIN_LICENSE("GPL3"); struct t_weechat_plugin *weechat_perl_plugin = NULL; +int perl_quiet = 0; struct t_plugin_script *perl_scripts = NULL; +struct t_plugin_script *last_perl_script = NULL; struct t_plugin_script *perl_current_script = NULL; const char *perl_current_script_filename = NULL; @@ -259,9 +261,12 @@ weechat_perl_load (const char *filename) return 0; } - weechat_printf (NULL, - weechat_gettext ("%s: loading script \"%s\""), - PERL_PLUGIN_NAME, filename); + if ((weechat_perl_plugin->debug >= 1) || !perl_quiet) + { + weechat_printf (NULL, + weechat_gettext ("%s: loading script \"%s\""), + PERL_PLUGIN_NAME, filename); + } perl_current_script = NULL; @@ -354,7 +359,8 @@ weechat_perl_load (const char *filename) #endif if (perl_current_script && (perl_current_script != &temp_script)) { - script_remove (weechat_perl_plugin, &perl_scripts, + script_remove (weechat_perl_plugin, + &perl_scripts, &last_perl_script, perl_current_script); } @@ -436,7 +442,8 @@ weechat_perl_unload (struct t_plugin_script *script) perl_current_script = (perl_current_script->prev_script) ? perl_current_script->prev_script : perl_current_script->next_script; - script_remove (weechat_perl_plugin, &perl_scripts, script); + script_remove (weechat_perl_plugin, &perl_scripts, &last_perl_script, + script); #ifdef MULTIPLICITY perl_destruct (interpreter); @@ -592,8 +599,8 @@ weechat_perl_completion_cb (void *data, const char *completion_item, */ int -weechat_perl_debug_dump_cb (void *data, const char *signal, const char *type_data, - void *signal_data) +weechat_perl_debug_dump_cb (void *data, const char *signal, + const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; @@ -611,8 +618,8 @@ weechat_perl_debug_dump_cb (void *data, const char *signal, const char *type_dat */ int -weechat_perl_buffer_closed_cb (void *data, const char *signal, const char *type_data, - void *signal_data) +weechat_perl_buffer_closed_cb (void *data, const char *signal, + const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; @@ -669,12 +676,17 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) eval_pv (perl_weechat_code, TRUE); #endif + perl_quiet = 1; script_init (weechat_perl_plugin, &weechat_perl_command_cb, &weechat_perl_completion_cb, &weechat_perl_debug_dump_cb, &weechat_perl_buffer_closed_cb, &weechat_perl_load_cb); + perl_quiet = 0; + + script_display_short_list (weechat_perl_plugin, + perl_scripts); /* init ok */ return WEECHAT_RC_OK; diff --git a/src/plugins/scripts/perl/weechat-perl.h b/src/plugins/scripts/perl/weechat-perl.h index 5320f4e08..23c9deccf 100644 --- a/src/plugins/scripts/perl/weechat-perl.h +++ b/src/plugins/scripts/perl/weechat-perl.h @@ -25,7 +25,9 @@ extern struct t_weechat_plugin *weechat_perl_plugin; +extern int perl_quiet; extern struct t_plugin_script *perl_scripts; +extern struct t_plugin_script *last_perl_script; extern struct t_plugin_script *perl_current_script; extern const char *perl_current_script_filename; diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 6e3a7716c..76f580ee3 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -95,17 +95,20 @@ weechat_python_api_register (PyObject *self, PyObject *args) /* register script */ python_current_script = script_add (weechat_python_plugin, - &python_scripts, + &python_scripts, &last_python_script, (python_current_script_filename) ? python_current_script_filename : "", name, author, version, license, description, shutdown_func, charset); if (python_current_script) { - weechat_printf (NULL, - weechat_gettext ("%s: registered script \"%s\", " - "version %s (%s)"), - PYTHON_PLUGIN_NAME, name, version, description); + if ((weechat_python_plugin->debug >= 1) || !python_quiet) + { + weechat_printf (NULL, + weechat_gettext ("%s: registered script \"%s\", " + "version %s (%s)"), + PYTHON_PLUGIN_NAME, name, version, description); + } } else { diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index 8cc68459b..2f4aa68e3 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -38,7 +38,9 @@ WEECHAT_PLUGIN_LICENSE("GPL3"); struct t_weechat_plugin *weechat_python_plugin = NULL; +int python_quiet; struct t_plugin_script *python_scripts = NULL; +struct t_plugin_script *last_python_script = NULL; struct t_plugin_script *python_current_script = NULL; const char *python_current_script_filename = NULL; PyThreadState *python_mainThreadState = NULL; @@ -94,21 +96,25 @@ weechat_python_exec (struct t_plugin_script *script, { if (argv[6]) { - rc = PyObject_CallFunction (evFunc, "sssssss", argv[0], - argv[1], argv[2], argv[3], - argv[4], argv[5], argv[6]); + rc = PyObject_CallFunction (evFunc, "sssssss", + argv[0], argv[1], + argv[2], argv[3], + argv[4], argv[5], + argv[6]); } else { - rc = PyObject_CallFunction (evFunc, "ssssss", argv[0], - argv[1], argv[2], argv[3], + rc = PyObject_CallFunction (evFunc, "ssssss", + argv[0], argv[1], + argv[2], argv[3], argv[4], argv[5]); } } else { - rc = PyObject_CallFunction (evFunc, "sssss", argv[0], - argv[1], argv[2], argv[3], + rc = PyObject_CallFunction (evFunc, "sssss", + argv[0], argv[1], + argv[2], argv[3], argv[4]); } } @@ -283,9 +289,12 @@ weechat_python_load (const char *filename) return 0; } - weechat_printf (NULL, - weechat_gettext ("%s: loading script \"%s\""), - PYTHON_PLUGIN_NAME, filename); + if ((weechat_python_plugin->debug >= 1) || !python_quiet) + { + weechat_printf (NULL, + weechat_gettext ("%s: loading script \"%s\""), + PYTHON_PLUGIN_NAME, filename); + } python_current_script = NULL; @@ -389,7 +398,8 @@ weechat_python_load (const char *filename) PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_SIGNAL_INT", PyString_FromString(WEECHAT_HOOK_SIGNAL_INT)); PyDict_SetItemString(weechat_dict, "WEECHAT_HOOK_SIGNAL_POINTER", PyString_FromString(WEECHAT_HOOK_SIGNAL_POINTER)); - weechat_outputs = Py_InitModule("weechatOutputs", weechat_python_output_funcs); + weechat_outputs = Py_InitModule("weechatOutputs", + weechat_python_output_funcs); if (weechat_outputs == NULL) { weechat_printf (NULL, @@ -426,11 +436,14 @@ weechat_python_load (const char *filename) PyErr_Print (); Py_EndInterpreter (python_current_interpreter); /* PyEval_ReleaseLock (); */ - + /* if script was registered, removing from list */ if (python_current_script != NULL) - script_remove (weechat_python_plugin, &python_scripts, - python_current_script); + { + script_remove (weechat_python_plugin, + &python_scripts, &last_python_script, + python_current_script); + } return 0; } @@ -501,7 +514,8 @@ weechat_python_unload (struct t_plugin_script *script) python_current_script = (python_current_script->prev_script) ? python_current_script->prev_script : python_current_script->next_script; - script_remove (weechat_python_plugin, &python_scripts, script); + script_remove (weechat_python_plugin, &python_scripts, &last_python_script, + script); PyThreadState_Swap (interpreter); Py_EndInterpreter (interpreter); @@ -653,8 +667,8 @@ weechat_python_completion_cb (void *data, const char *completion_item, */ int -weechat_python_debug_dump_cb (void *data, const char *signal, const char *type_data, - void *signal_data) +weechat_python_debug_dump_cb (void *data, const char *signal, + const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; @@ -672,8 +686,8 @@ weechat_python_debug_dump_cb (void *data, const char *signal, const char *type_d */ int -weechat_python_buffer_closed_cb (void *data, const char *signal, const char *type_data, - void *signal_data) +weechat_python_buffer_closed_cb (void *data, const char *signal, + const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; @@ -725,13 +739,18 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_prefix ("error"), PYTHON_PLUGIN_NAME); return WEECHAT_RC_ERROR; } - + + python_quiet = 1; script_init (weechat_python_plugin, &weechat_python_command_cb, &weechat_python_completion_cb, &weechat_python_debug_dump_cb, &weechat_python_buffer_closed_cb, &weechat_python_load_cb); + python_quiet = 0; + + script_display_short_list (weechat_python_plugin, + python_scripts); /* init ok */ return WEECHAT_RC_OK; diff --git a/src/plugins/scripts/python/weechat-python.h b/src/plugins/scripts/python/weechat-python.h index a506c0763..d69b93591 100644 --- a/src/plugins/scripts/python/weechat-python.h +++ b/src/plugins/scripts/python/weechat-python.h @@ -25,7 +25,9 @@ extern struct t_weechat_plugin *weechat_python_plugin; +extern int python_quiet; extern struct t_plugin_script *python_scripts; +extern struct t_plugin_script *last_python_script; extern struct t_plugin_script *python_current_script; extern const char *python_current_script_filename; diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index e3b2ff7c9..86ec14ef4 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -111,7 +111,7 @@ weechat_ruby_api_register (VALUE class, VALUE name, VALUE author, /* register script */ ruby_current_script = script_add (weechat_ruby_plugin, - &ruby_scripts, + &ruby_scripts, &last_ruby_script, (ruby_current_script_filename) ? ruby_current_script_filename : "", c_name, c_author, c_version, c_license, @@ -120,10 +120,13 @@ weechat_ruby_api_register (VALUE class, VALUE name, VALUE author, if (ruby_current_script) { - weechat_printf (NULL, - weechat_gettext ("%s: registered script \"%s\", " - "version %s (%s)"), - RUBY_PLUGIN_NAME, c_name, c_version, c_description); + if ((weechat_ruby_plugin->debug >= 1) || !ruby_quiet) + { + weechat_printf (NULL, + weechat_gettext ("%s: registered script \"%s\", " + "version %s (%s)"), + RUBY_PLUGIN_NAME, c_name, c_version, c_description); + } } else { diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c index 481679a32..18f1d5398 100644 --- a/src/plugins/scripts/ruby/weechat-ruby.c +++ b/src/plugins/scripts/ruby/weechat-ruby.c @@ -41,7 +41,9 @@ WEECHAT_PLUGIN_LICENSE("GPL3"); struct t_weechat_plugin *weechat_ruby_plugin = NULL; +int ruby_quiet = 0; struct t_plugin_script *ruby_scripts = NULL; +struct t_plugin_script *last_ruby_script = NULL; struct t_plugin_script *ruby_current_script = NULL; const char *ruby_current_script_filename = NULL; @@ -340,9 +342,12 @@ weechat_ruby_load (const char *filename) return 0; } - weechat_printf (NULL, - weechat_gettext ("%s: loading script \"%s\""), - RUBY_PLUGIN_NAME, filename); + if ((weechat_ruby_plugin->debug >= 1) || !ruby_quiet) + { + weechat_printf (NULL, + weechat_gettext ("%s: loading script \"%s\""), + RUBY_PLUGIN_NAME, filename); + } ruby_current_script = NULL; @@ -429,7 +434,8 @@ weechat_ruby_load (const char *filename) if (ruby_current_script != NULL) { - script_remove (weechat_ruby_plugin, &ruby_scripts, + script_remove (weechat_ruby_plugin, + &ruby_scripts, &last_ruby_script, ruby_current_script); } @@ -495,7 +501,8 @@ weechat_ruby_unload (struct t_plugin_script *script) ruby_current_script = (ruby_current_script->prev_script) ? ruby_current_script->prev_script : ruby_current_script->next_script; - script_remove (weechat_ruby_plugin, &ruby_scripts, script); + script_remove (weechat_ruby_plugin, &ruby_scripts, &last_ruby_script, + script); if (interpreter) rb_gc_unregister_address (interpreter); @@ -646,8 +653,8 @@ weechat_ruby_completion_cb (void *data, const char *completion_item, */ int -weechat_ruby_debug_dump_cb (void *data, const char *signal, const char *type_data, - void *signal_data) +weechat_ruby_debug_dump_cb (void *data, const char *signal, + const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; @@ -665,8 +672,8 @@ weechat_ruby_debug_dump_cb (void *data, const char *signal, const char *type_dat */ int -weechat_ruby_buffer_closed_cb (void *data, const char *signal, const char *type_data, - void *signal_data) +weechat_ruby_buffer_closed_cb (void *data, const char *signal, + const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; @@ -750,10 +757,14 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) /* redirect stdin and stdout */ ruby_mWeechatOutputs = rb_define_module("WeechatOutputs"); - rb_define_singleton_method(ruby_mWeechatOutputs, "write", weechat_ruby_output, 1); - rb_define_singleton_method(ruby_mWeechatOutputs, "puts", weechat_ruby_output, 1); - rb_define_singleton_method(ruby_mWeechatOutputs, "p", weechat_ruby_output, 1); - rb_define_singleton_method(ruby_mWeechatOutputs, "flush", weechat_ruby_output_flush, 0); + rb_define_singleton_method(ruby_mWeechatOutputs, "write", + weechat_ruby_output, 1); + rb_define_singleton_method(ruby_mWeechatOutputs, "puts", + weechat_ruby_output, 1); + rb_define_singleton_method(ruby_mWeechatOutputs, "p", + weechat_ruby_output, 1); + rb_define_singleton_method(ruby_mWeechatOutputs, "flush", + weechat_ruby_output_flush, 0); rb_eval_string_protect(weechat_ruby_code, &ruby_error); if (ruby_error) @@ -770,12 +781,17 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) return WEECHAT_RC_ERROR; } + ruby_quiet = 1; script_init (weechat_ruby_plugin, &weechat_ruby_command_cb, &weechat_ruby_completion_cb, &weechat_ruby_debug_dump_cb, &weechat_ruby_buffer_closed_cb, &weechat_ruby_load_cb); + ruby_quiet = 0; + + script_display_short_list (weechat_ruby_plugin, + ruby_scripts); /* init ok */ return WEECHAT_RC_OK; diff --git a/src/plugins/scripts/ruby/weechat-ruby.h b/src/plugins/scripts/ruby/weechat-ruby.h index 7f6753b33..337ccb3c3 100644 --- a/src/plugins/scripts/ruby/weechat-ruby.h +++ b/src/plugins/scripts/ruby/weechat-ruby.h @@ -25,7 +25,9 @@ extern struct t_weechat_plugin *weechat_ruby_plugin; +extern int ruby_quiet; extern struct t_plugin_script *ruby_scripts; +extern struct t_plugin_script *last_ruby_script; extern struct t_plugin_script *ruby_current_script; extern const char *ruby_current_script_filename; diff --git a/src/plugins/scripts/script-callback.c b/src/plugins/scripts/script-callback.c index 6fd7134f3..934f40bd8 100644 --- a/src/plugins/scripts/script-callback.c +++ b/src/plugins/scripts/script-callback.c @@ -90,10 +90,10 @@ script_callback_remove (struct t_plugin_script *script, { /* remove callback from list */ if (script_callback->prev_callback) - script_callback->prev_callback->next_callback = + (script_callback->prev_callback)->next_callback = script_callback->next_callback; if (script_callback->next_callback) - script_callback->next_callback->prev_callback = + (script_callback->next_callback)->prev_callback = script_callback->prev_callback; if (script->callbacks == script_callback) script->callbacks = script_callback->next_callback; diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c index 1f4e074db..9b633d371 100644 --- a/src/plugins/scripts/script.c +++ b/src/plugins/scripts/script.c @@ -343,12 +343,78 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin, } /* + * script_find_pos: find position for a script (for sorting scripts list) + */ + +struct t_plugin_script * +script_find_pos (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *scripts, + struct t_plugin_script *script) +{ + struct t_plugin_script *ptr_script; + + for (ptr_script = scripts; ptr_script; ptr_script = ptr_script->next_script) + { + if (weechat_strcasecmp (script->name, ptr_script->name) < 0) + return ptr_script; + } + return NULL; +} + +/* + * script_insert_sorted: insert a script in list, keeping sort on name + */ + +void +script_insert_sorted (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script **scripts, + struct t_plugin_script **last_script, + struct t_plugin_script *script) +{ + struct t_plugin_script *pos_script; + + if (*scripts) + { + pos_script = script_find_pos (weechat_plugin, *scripts, script); + + if (pos_script) + { + /* insert script into the list (before script found) */ + script->prev_script = pos_script->prev_script; + script->next_script = pos_script; + if (pos_script->prev_script) + (pos_script->prev_script)->next_script = script; + else + *scripts = script; + pos_script->prev_script = script; + } + else + { + /* add script to the end */ + script->prev_script = *last_script; + script->next_script = NULL; + (*last_script)->next_script = script; + *last_script = script; + } + } + else + { + /* first script in list */ + script->prev_script = NULL; + script->next_script = NULL; + *scripts = script; + *last_script = script; + } +} + +/* * script_add: add a script to list of scripts */ struct t_plugin_script * script_add (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script **scripts, + struct t_plugin_script **last_script, const char *filename, const char *name, const char *author, const char *version, const char *license, const char *description, const char *shutdown_func, const char *charset) @@ -388,15 +454,9 @@ script_add (struct t_weechat_plugin *weechat_plugin, new_script->shutdown_func = (shutdown_func) ? strdup (shutdown_func) : NULL; new_script->charset = (charset) ? strdup (charset) : NULL; - new_script->callbacks = NULL; - /* add new script to list */ - if (*scripts) - (*scripts)->prev_script = new_script; - new_script->prev_script = NULL; - new_script->next_script = *scripts; - *scripts = new_script; + script_insert_sorted (weechat_plugin, scripts, last_script, new_script); return new_script; } @@ -443,6 +503,7 @@ script_remove_buffer_callbacks (struct t_plugin_script *scripts, void script_remove (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script **scripts, + struct t_plugin_script **last_script, struct t_plugin_script *script) { struct t_script_callback *ptr_script_callback, *next_script_callback; @@ -456,7 +517,7 @@ script_remove (struct t_weechat_plugin *weechat_plugin, weechat_unhook (ptr_script_callback->hook); } } - + ptr_script_callback = script->callbacks; while (ptr_script_callback) { @@ -516,10 +577,12 @@ script_remove (struct t_weechat_plugin *weechat_plugin, /* remove script from list */ if (script->prev_script) (script->prev_script)->next_script = script->next_script; - else - *scripts = script->next_script; if (script->next_script) (script->next_script)->prev_script = script->prev_script; + if (*scripts == script) + *scripts = script->next_script; + if (*last_script == script) + *last_script = script->prev_script; /* free script */ free (script); @@ -592,6 +655,51 @@ script_display_list (struct t_weechat_plugin *weechat_plugin, } /* + * script_display_short_list: print list of scripts on one line + */ + +void +script_display_short_list (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *scripts) +{ + const char *scripts_loaded; + char *buf; + int length; + struct t_plugin_script *ptr_script; + + if (scripts) + { + /* TRANSLATORS: %s is language (for example "perl") */ + scripts_loaded = _("%s scripts loaded:"); + + length = strlen (scripts_loaded) + strlen (weechat_plugin->name) + 1; + + for (ptr_script = scripts; ptr_script; + ptr_script = ptr_script->next_script) + { + length += strlen (ptr_script->name) + 2; + } + length++; + + buf = malloc (length); + if (buf) + { + snprintf (buf, length, scripts_loaded, weechat_plugin->name); + strcat (buf, " "); + for (ptr_script = scripts; ptr_script; + ptr_script = ptr_script->next_script) + { + strcat (buf, ptr_script->name); + if (ptr_script->next_script) + strcat (buf, ", "); + } + weechat_printf (NULL, "%s", buf); + free (buf); + } + } +} + +/* * script_print_log: print script infos in log (usually for crash dump) */ diff --git a/src/plugins/scripts/script.h b/src/plugins/scripts/script.h index 62b7ab73b..8e05401a1 100644 --- a/src/plugins/scripts/script.h +++ b/src/plugins/scripts/script.h @@ -85,6 +85,7 @@ extern char *script_search_full_name (struct t_weechat_plugin *weechat_plugin, const char *filename); extern struct t_plugin_script *script_add (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script **scripts, + struct t_plugin_script **last_script, const char *filename, const char *name, const char *author, const char *version, const char *license, const char *description, @@ -93,6 +94,7 @@ extern void script_remove_buffer_callbacks (struct t_plugin_script *scripts, struct t_gui_buffer *buffer); extern void script_remove (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script **scripts, + struct t_plugin_script **last_script, struct t_plugin_script *script); extern void script_completion (struct t_weechat_plugin *weechat_plugin, struct t_gui_completion *completion, @@ -100,6 +102,8 @@ extern void script_completion (struct t_weechat_plugin *weechat_plugin, extern void script_display_list (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *scripts, const char *name, int full); +extern void script_display_short_list (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *scripts); extern void script_print_log (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *scripts); diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index 94e32e718..60ede1b70 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -198,17 +198,20 @@ weechat_tcl_api_register (ClientData clientData, Tcl_Interp *interp, int objc, /* register script */ tcl_current_script = script_add (weechat_tcl_plugin, - &tcl_scripts, + &tcl_scripts, &last_tcl_script, (tcl_current_script_filename) ? tcl_current_script_filename : "", name, author, version, license, description, shutdown_func, charset); if (tcl_current_script) { - weechat_printf (NULL, - weechat_gettext ("%s: registered script \"%s\", " - "version %s (%s)"), - TCL_PLUGIN_NAME, name, version, description); + if ((weechat_tcl_plugin->debug >= 1) || !tcl_quiet) + { + weechat_printf (NULL, + weechat_gettext ("%s: registered script \"%s\", " + "version %s (%s)"), + TCL_PLUGIN_NAME, name, version, description); + } tcl_current_script->interpreter = (void *)interp; } else diff --git a/src/plugins/scripts/tcl/weechat-tcl.c b/src/plugins/scripts/tcl/weechat-tcl.c index f56ee803a..910e20551 100644 --- a/src/plugins/scripts/tcl/weechat-tcl.c +++ b/src/plugins/scripts/tcl/weechat-tcl.c @@ -43,7 +43,9 @@ WEECHAT_PLUGIN_LICENSE("GPL3"); struct t_weechat_plugin *weechat_tcl_plugin = NULL; +int tcl_quiet = 0; struct t_plugin_script *tcl_scripts = NULL; +struct t_plugin_script *last_tcl_script = NULL; struct t_plugin_script *tcl_current_script = NULL; const char *tcl_current_script_filename = NULL; @@ -155,9 +157,12 @@ weechat_tcl_load (const char *filename) return 0; } - weechat_printf (NULL, - weechat_gettext ("%s: loading script \"%s\""), - TCL_PLUGIN_NAME, filename); + if ((weechat_tcl_plugin->debug >= 1) || !tcl_quiet) + { + weechat_printf (NULL, + weechat_gettext ("%s: loading script \"%s\""), + TCL_PLUGIN_NAME, filename); + } tcl_current_script = NULL; @@ -239,7 +244,7 @@ weechat_tcl_unload (struct t_plugin_script *script) tcl_current_script = (tcl_current_script->prev_script) ? tcl_current_script->prev_script : tcl_current_script->next_script; - script_remove (weechat_tcl_plugin, &tcl_scripts, script); + script_remove (weechat_tcl_plugin, &tcl_scripts, &last_tcl_script, script); Tcl_DeleteInterp(interp); } @@ -389,8 +394,8 @@ weechat_tcl_completion_cb (void *data, const char *completion_item, */ int -weechat_tcl_debug_dump_cb (void *data, const char *signal, const char *type_data, - void *signal_data) +weechat_tcl_debug_dump_cb (void *data, const char *signal, + const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; @@ -408,8 +413,8 @@ weechat_tcl_debug_dump_cb (void *data, const char *signal, const char *type_data */ int -weechat_tcl_buffer_closed_cb (void *data, const char *signal, const char *type_data, - void *signal_data) +weechat_tcl_buffer_closed_cb (void *data, const char *signal, + const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; @@ -435,12 +440,17 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_tcl_plugin = plugin; + tcl_quiet = 1; script_init (weechat_tcl_plugin, weechat_tcl_command_cb, weechat_tcl_completion_cb, weechat_tcl_debug_dump_cb, weechat_tcl_buffer_closed_cb, weechat_tcl_load_cb); + tcl_quiet = 0; + + script_display_short_list (weechat_tcl_plugin, + tcl_scripts); /* init ok */ return WEECHAT_RC_OK; diff --git a/src/plugins/scripts/tcl/weechat-tcl.h b/src/plugins/scripts/tcl/weechat-tcl.h index 40a4335c7..581030112 100644 --- a/src/plugins/scripts/tcl/weechat-tcl.h +++ b/src/plugins/scripts/tcl/weechat-tcl.h @@ -25,7 +25,9 @@ extern struct t_weechat_plugin *weechat_tcl_plugin; +extern int tcl_quiet; extern struct t_plugin_script *tcl_scripts; +extern struct t_plugin_script *last_tcl_script; extern struct t_plugin_script *tcl_current_script; extern const char *tcl_current_script_filename; |