core: add priority in plugins to initialize them in order

Current order is: charset, logger, exec, trigger, aspell, alias, fifo, xfer,
irc, relay, guile/lua/perl/python/ruby/tcl, script.
v2.8-utf8proc
Sébastien Helleu 2015-01-15 07:40:38 +01:00
parent 66e0455951
commit cf5501f69c
38 changed files with 406 additions and 93 deletions

View File

@ -843,6 +843,8 @@
*** 'version' (string)
*** 'license' (string)
*** 'charset' (string)
*** 'priority' (integer)
*** 'initialized' (integer)
*** 'debug' (integer)
*** 'prev_plugin' (pointer, hdata: "plugin")
*** 'next_plugin' (pointer, hdata: "plugin")

View File

@ -0,0 +1,12 @@
. charset (13000)
. logger (12000)
. exec (11000)
. trigger (10000)
. aspell (9000)
. alias (8000)
. fifo (7000)
. xfer (6000)
. irc (5000)
. relay (4000)
. guile, lua, perl, python, ruby, tcl (3000)
. script (2000)

View File

@ -351,6 +351,23 @@ def get_irc_colors():
return irc_colors
def get_plugins_priority():
"""
Get priority of default WeeChat plugins as a dictionary.
"""
plugins_priority = {}
infolist = weechat.infolist_get('plugin', '', '')
while weechat.infolist_next(infolist):
name = weechat.infolist_string(infolist, 'name')
priority = weechat.infolist_integer(infolist, 'priority')
if priority in plugins_priority:
plugins_priority[priority].append(name)
else:
plugins_priority[priority] = [name]
weechat.infolist_free(infolist)
return plugins_priority
def update_file(oldfile, newfile, num_files, num_files_updated, obj):
"""Update a doc file."""
try:
@ -394,6 +411,7 @@ def docgen_cmd_cb(data, buf, args):
completions = get_completions()
url_options = get_url_options()
irc_colors = get_irc_colors()
plugins_priority = get_plugins_priority()
# get path and replace ~ by home if needed
path = weechat.config_get_plugin('path')
@ -675,34 +693,23 @@ def docgen_cmd_cb(data, buf, args):
update_file(filename, tmpfilename, num_files, num_files_updated,
'irc_colors')
# write plugins priority
filename = directory + '/plugin_api/plugins_priority.asciidoc'
tmpfilename = filename + '.tmp'
_file = open(tmpfilename, 'w')
for priority in sorted(plugins_priority, reverse=True):
plugins = ', '.join(sorted(plugins_priority[priority]))
_file.write('. {0} ({1})\n'.format(escape(plugins), priority))
_file.close()
update_file(filename, tmpfilename, num_files, num_files_updated,
'plugins_priority')
# write counters
weechat.prnt('',
'docgen: {0}: {1:3d} files '
'({2:2d} cmd, {3:2d} opt, {4:2d} infos, '
'{5:2d} infos_hash, {6:2d} infolists, {7:2d} hdata, '
'{8:2d} complt)'
'docgen: {0}: {1} files, {2} updated'
''.format(locale,
num_files['total1'],
num_files['commands'],
num_files['options'],
num_files['infos'],
num_files['infos_hashtable'],
num_files['infolists'],
num_files['hdata'],
num_files['completions']))
weechat.prnt('',
' '
'{0:3d} updated ({1:2d} cmd, {2:2d} opt, {3:2d} infos, '
'{4:2d} infos_hash, {5:2d} infolists, {6:2d} hdata, '
'{7:2d} complt)'
''.format(num_files_updated['total1'],
num_files_updated['commands'],
num_files_updated['options'],
num_files_updated['infos'],
num_files_updated['infos_hashtable'],
num_files_updated['infolists'],
num_files_updated['hdata'],
num_files_updated['completions']))
num_files_updated['total1']))
weechat.prnt('',
'docgen: total: {0} files, {1} updated'
''.format(num_files['total2'], num_files_updated['total2']))

View File

@ -843,6 +843,8 @@
*** 'version' (string)
*** 'license' (string)
*** 'charset' (string)
*** 'priority' (integer)
*** 'initialized' (integer)
*** 'debug' (integer)
*** 'prev_plugin' (pointer, hdata: "plugin")
*** 'next_plugin' (pointer, hdata: "plugin")

View File

@ -0,0 +1,12 @@
. charset (13000)
. logger (12000)
. exec (11000)
. trigger (10000)
. aspell (9000)
. alias (8000)
. fifo (7000)
. xfer (6000)
. irc (5000)
. relay (4000)
. guile, lua, perl, python, ruby, tcl (3000)
. script (2000)

View File

@ -45,16 +45,19 @@ This file defines structures and types used to communicate with WeeChat.
The plugin must use some macros (to define some variables):
WEECHAT_PLUGIN_NAME("name")::
plugin name
the plugin name
WEECHAT_PLUGIN_DESCRIPTION("description")::
short description of plugin
a short description of plugin
WEECHAT_PLUGIN_VERSION("1.0")::
plugin version
the plugin version
WEECHAT_PLUGIN_LICENSE("GPL3")::
plugin license
the plugin license
WEECHAT_PLUGIN_PRIORITY(1000)::
the plugin priority (optional, see below)
[[main_functions]]
=== Main functions
@ -87,6 +90,20 @@ Return value:
* 'WEECHAT_RC_OK' if successful (plugin will be loaded)
* 'WEECHAT_RC_ERROR' if error (plugin will NOT be loaded)
[[plugin_priority]]
===== Plugin priority
When plugins are auto-loaded (for example on startup), WeeChat first loads all
plugins, and then calls the 'init' functions, using the priority defined in
each plugin. A high priority means that the 'init' function is called first.
Default priority is 1000 (with such priority, the plugin is loaded after all
default plugins).
The default WeeChat plugins are initialized in this order:
include::autogen/plugin_api/plugins_priority.asciidoc[]
==== weechat_plugin_end
This function is called when plugin is unloaded by WeeChat.

View File

@ -843,6 +843,8 @@
*** 'version' (string)
*** 'license' (string)
*** 'charset' (string)
*** 'priority' (integer)
*** 'initialized' (integer)
*** 'debug' (integer)
*** 'prev_plugin' (pointer, hdata: "plugin")
*** 'next_plugin' (pointer, hdata: "plugin")

View File

@ -0,0 +1,12 @@
. charset (13000)
. logger (12000)
. exec (11000)
. trigger (10000)
. aspell (9000)
. alias (8000)
. fifo (7000)
. xfer (6000)
. irc (5000)
. relay (4000)
. guile, lua, perl, python, ruby, tcl (3000)
. script (2000)

View File

@ -58,6 +58,9 @@ WEECHAT_PLUGIN_VERSION("1.0")::
WEECHAT_PLUGIN_LICENSE("GPL3")::
licence de l'extension
WEECHAT_PLUGIN_PRIORITY(1000)::
priorité de l'extension (facultatif, voir ci-dessous)
[[main_functions]]
=== Fonctions principales
@ -90,6 +93,21 @@ Valeur de retour :
* 'WEECHAT_RC_OK' si ok (l'extension sera chargée)
* 'WEECHAT_RC_ERROR' si erreur (l'extension ne sera PAS chargée)
[[plugin_priority]]
===== Priorité de l'extension
Lorsque les extensions sont automatiquement chargées (par exemple au
démarrage), WeeChat charge d'abord toutes les extensions, puis appelle les
fonctions 'init', en utilisant la priorité définie dans chaque extension.
Une grande priorité signifie que la fonction 'init' est appelée en premier.
La priorité par défaut est 1000 (avec une telle priorité, l'extension est
chargée après toutes les extensions par défaut).
Les extensions par défaut de WeeChat sont initialisées dans cet ordre :
include::autogen/plugin_api/plugins_priority.asciidoc[]
==== weechat_plugin_end
Cette fonction est appelée quand l'extension est déchargée par WeeChat.

View File

@ -843,6 +843,8 @@
*** 'version' (string)
*** 'license' (string)
*** 'charset' (string)
*** 'priority' (integer)
*** 'initialized' (integer)
*** 'debug' (integer)
*** 'prev_plugin' (pointer, hdata: "plugin")
*** 'next_plugin' (pointer, hdata: "plugin")

View File

@ -0,0 +1,12 @@
. charset (13000)
. logger (12000)
. exec (11000)
. trigger (10000)
. aspell (9000)
. alias (8000)
. fifo (7000)
. xfer (6000)
. irc (5000)
. relay (4000)
. guile, lua, perl, python, ruby, tcl (3000)
. script (2000)

View File

@ -63,6 +63,10 @@ WEECHAT_PLUGIN_VERSION("1.0")::
WEECHAT_PLUGIN_LICENSE("GPL3")::
licenza del plugin
// TRANSLATION MISSING
WEECHAT_PLUGIN_PRIORITY(1000)::
the plugin priority (optional, see below)
[[main_functions]]
=== Funzioni principali
@ -98,6 +102,22 @@ Valori restituiti:
* 'WEECHAT_RC_ERROR' se c'è un errore (il plugin NON
verrà caricato)
// TRANSLATION MISSING
[[plugin_priority]]
===== Plugin priority
// TRANSLATION MISSING
When plugins are auto-loaded (for example on startup), WeeChat first loads all
plugins, and then calls the 'init' functions, using the priority defined in
each plugin. A high priority means that the 'init' function is called first.
Default priority is 1000 (with such priority, the plugin is loaded after all
default plugins).
The default WeeChat plugins are initialized in this order:
include::autogen/plugin_api/plugins_priority.asciidoc[]
==== weechat_plugin_end
Questa funzione viene chiamata quando il plugin viene

View File

@ -843,6 +843,8 @@
*** 'version' (string)
*** 'license' (string)
*** 'charset' (string)
*** 'priority' (integer)
*** 'initialized' (integer)
*** 'debug' (integer)
*** 'prev_plugin' (pointer, hdata: "plugin")
*** 'next_plugin' (pointer, hdata: "plugin")

View File

@ -0,0 +1,12 @@
. charset (13000)
. logger (12000)
. exec (11000)
. trigger (10000)
. aspell (9000)
. alias (8000)
. fifo (7000)
. xfer (6000)
. irc (5000)
. relay (4000)
. guile, lua, perl, python, ruby, tcl (3000)
. script (2000)

View File

@ -62,6 +62,10 @@ WEECHAT_PLUGIN_VERSION("1.0")::
WEECHAT_PLUGIN_LICENSE("GPL3")::
プラグインのライセンス
// TRANSLATION MISSING
WEECHAT_PLUGIN_PRIORITY(1000)::
the plugin priority (optional, see below)
[[main_functions]]
=== 重要な関数
@ -93,6 +97,22 @@ int weechat_plugin_init (struct t_weechat_plugin *plugin,
* 'WEECHAT_RC_OK' 成功した場合 (プラグインを読み込みます)
* 'WEECHAT_RC_ERROR' エラーが起きた場合 (プラグインを読み込みません)
// TRANSLATION MISSING
[[plugin_priority]]
===== Plugin priority
// TRANSLATION MISSING
When plugins are auto-loaded (for example on startup), WeeChat first loads all
plugins, and then calls the 'init' functions, using the priority defined in
each plugin. A high priority means that the 'init' function is called first.
Default priority is 1000 (with such priority, the plugin is loaded after all
default plugins).
The default WeeChat plugins are initialized in this order:
include::autogen/plugin_api/plugins_priority.asciidoc[]
==== weechat_plugin_end
WeeChat プラグインを再読み込みする際にこの関数を呼び出します。

View File

@ -843,6 +843,8 @@
*** 'version' (string)
*** 'license' (string)
*** 'charset' (string)
*** 'priority' (integer)
*** 'initialized' (integer)
*** 'debug' (integer)
*** 'prev_plugin' (pointer, hdata: "plugin")
*** 'next_plugin' (pointer, hdata: "plugin")

View File

@ -0,0 +1,12 @@
. charset (13000)
. logger (12000)
. exec (11000)
. trigger (10000)
. aspell (9000)
. alias (8000)
. fifo (7000)
. xfer (6000)
. irc (5000)
. relay (4000)
. guile, lua, perl, python, ruby, tcl (3000)
. script (2000)

View File

@ -4395,7 +4395,7 @@ COMMAND_CALLBACK(plugin)
&plugin_argc);
}
full_name = util_search_full_lib_name (argv[2], "plugins");
plugin_load (full_name, plugin_argc, plugin_argv);
plugin_load (full_name, 1, plugin_argc, plugin_argv);
if (full_name)
free (full_name);
if (plugin_argv)

View File

@ -34,6 +34,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Alias commands"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(8000);
#define ALIAS_IS_ARG_NUMBER(number) ((number >= '1') && (number <= '9'))

View File

@ -46,6 +46,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Spell checker for input (with Aspell)"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(9000);
struct t_weechat_plugin *weechat_aspell_plugin = NULL;

View File

@ -37,6 +37,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Charset conversions"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(13000);
#define CHARSET_CONFIG_NAME "charset"

View File

@ -37,6 +37,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Execution of external commands in WeeChat"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(11000);
struct t_weechat_plugin *weechat_exec_plugin = NULL;

View File

@ -40,6 +40,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("FIFO pipe for remote control"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(7000);
#define FIFO_FILENAME_PREFIX "weechat_fifo_"

View File

@ -42,6 +42,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of scheme scripts (with Guile)"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(3000);
struct t_weechat_plugin *weechat_guile_plugin = NULL;

View File

@ -50,6 +50,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("IRC (Internet Relay Chat) protocol"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(5000);
struct t_weechat_plugin *weechat_irc_plugin = NULL;

View File

@ -50,6 +50,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Log buffers to files"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(12000);
struct t_weechat_plugin *weechat_logger_plugin = NULL;

View File

@ -39,6 +39,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of lua scripts"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(3000);
struct t_weechat_plugin *weechat_lua_plugin;

View File

@ -37,6 +37,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of perl scripts"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(3000);
struct t_weechat_plugin *weechat_perl_plugin = NULL;

View File

@ -36,6 +36,7 @@
#include <dlfcn.h>
#include "../core/weechat.h"
#include "../core/wee-arraylist.h"
#include "../core/wee-config.h"
#include "../core/wee-eval.h"
#include "../core/wee-hashtable.h"
@ -281,38 +282,127 @@ plugin_check_autoload (const char *filename)
}
/*
* Searches for position of plugin (to keep list sorted).
* Returns arguments for plugins (only the relevant arguments for plugins,
* arguments for WeeChat core not returned).
*
* Note: plugin_argv must be freed after use (with free()).
*/
struct t_weechat_plugin *
plugin_find_pos (struct t_weechat_plugin *plugin)
void
plugin_get_args (struct t_weechat_plugin *plugin,
int argc, char **argv,
int *plugin_argc, char ***plugin_argv)
{
struct t_weechat_plugin *ptr_plugin;
int i, temp_argc;
char **temp_argv;
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
temp_argc = 0;
temp_argv = NULL;
if (argc > 0)
{
if (string_strcasecmp (plugin->name, ptr_plugin->name) < 0)
return ptr_plugin;
temp_argv = malloc ((argc + 1) * sizeof (*temp_argv));
if (temp_argv)
{
for (i = 0; i < argc; i++)
{
if ((strcmp (argv[i], "-a") == 0)
|| (strcmp (argv[i], "--no-connect") == 0)
|| (strcmp (argv[i], "-s") == 0)
|| (strcmp (argv[i], "--no-script") == 0)
|| (strcmp (argv[i], "--upgrade") == 0)
|| (strncmp (argv[i], plugin->name,
strlen (plugin->name)) == 0))
{
temp_argv[temp_argc++] = argv[i];
}
}
if (temp_argc == 0)
{
free (temp_argv);
temp_argv = NULL;
}
else
temp_argv[temp_argc] = NULL;
}
}
return NULL;
*plugin_argc = temp_argc;
*plugin_argv = temp_argv;
}
/*
* Initializes a plugin by calling its init() function.
*
* Returns:
* 1: OK
* 0: error
*/
int
plugin_call_init (struct t_weechat_plugin *plugin, int argc, char **argv)
{
t_weechat_init_func *init_func;
int plugin_argc, rc;
char **plugin_argv;
if (plugin->initialized)
return 1;
/* look for plugin init function */
init_func = dlsym (plugin->handle, "weechat_plugin_init");
if (!init_func)
return 0;
/* get arguments for the plugin */
plugin_get_args (plugin, argc, argv, &plugin_argc, &plugin_argv);
/* init plugin */
if (weechat_debug_core >= 1)
{
gui_chat_printf (NULL,
_("Initializing plugin \"%s\" (priority: %d)"),
plugin->name,
plugin->priority);
}
rc = ((t_weechat_init_func *)init_func) (plugin,
plugin_argc, plugin_argv);
if (rc == WEECHAT_RC_OK)
{
plugin->initialized = 1;
}
else
{
gui_chat_printf (NULL,
_("%sError: unable to initialize plugin "
"\"%s\""),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
plugin->filename);
}
if (plugin_argv)
free (plugin_argv);
return (rc == WEECHAT_RC_OK) ? 1 : 0;
}
/*
* Loads a WeeChat plugin (a dynamic library).
*
* If init_plugin == 1, then the init() function in plugin is called
* (with argc/argv), otherwise the plugin is just loaded but not initialized.
*
* Returns a pointer to new WeeChat plugin, NULL if error.
*/
struct t_weechat_plugin *
plugin_load (const char *filename, int argc, char **argv)
plugin_load (const char *filename, int init_plugin, int argc, char **argv)
{
void *handle;
char *name, *api_version, *author, *description, *version;
char *license, *charset;
t_weechat_init_func *init_func;
int rc, i, plugin_argc;
char **plugin_argv;
int *priority;
struct t_weechat_plugin *new_plugin;
struct t_config_option *ptr_option;
@ -477,6 +567,13 @@ plugin_load (const char *filename, int argc, char **argv)
return NULL;
}
/*
* look for plugin priority: it is used to initialize plugins in
* appropriate order: the important plugins that don't depend on other
* plugins are initialized first
*/
priority = dlsym (handle, "weechat_plugin_priority");
/* create new plugin */
new_plugin = malloc (sizeof (*new_plugin));
if (new_plugin)
@ -490,6 +587,9 @@ plugin_load (const char *filename, int argc, char **argv)
new_plugin->version = strdup (version);
new_plugin->license = strdup (license);
new_plugin->charset = (charset) ? strdup (charset) : NULL;
new_plugin->priority = (priority) ?
*priority : PLUGIN_PRIORITY_DEFAULT;
new_plugin->initialized = 0;
ptr_option = config_weechat_debug_get (name);
new_plugin->debug = (ptr_option) ? CONFIG_INTEGER(ptr_option) : 0;
@ -798,55 +898,14 @@ plugin_load (const char *filename, int argc, char **argv)
*/
gui_buffer_set_plugin_for_upgrade (name, new_plugin);
/* build arguments for plugin */
plugin_argc = 0;
plugin_argv = NULL;
if (argc > 0)
if (init_plugin)
{
plugin_argv = malloc ((argc + 1) * sizeof (*plugin_argv));
if (plugin_argv)
if (!plugin_call_init (new_plugin, argc, argv))
{
plugin_argc = 0;
for (i = 0; i < argc; i++)
{
if ((strcmp (argv[i], "-a") == 0)
|| (strcmp (argv[i], "--no-connect") == 0)
|| (strcmp (argv[i], "-s") == 0)
|| (strcmp (argv[i], "--no-script") == 0)
|| (strcmp (argv[i], "--upgrade") == 0)
|| (strncmp (argv[i], name, strlen (name)) == 0))
{
plugin_argv[plugin_argc] = argv[i];
plugin_argc++;
}
}
if (plugin_argc == 0)
{
free (plugin_argv);
plugin_argv = NULL;
}
else
plugin_argv[plugin_argc] = NULL;
plugin_remove (new_plugin);
return NULL;
}
}
/* init plugin */
rc = ((t_weechat_init_func *)init_func) (new_plugin,
plugin_argc, plugin_argv);
if (plugin_argv)
free (plugin_argv);
if (rc != WEECHAT_RC_OK)
{
gui_chat_printf (NULL,
_("%sError: unable to initialize plugin "
"\"%s\""),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
filename);
plugin_remove (new_plugin);
return NULL;
}
}
else
{
@ -885,7 +944,28 @@ plugin_auto_load_file (void *args, const char *filename)
plugin_args = (struct t_plugin_args *)args;
if (plugin_check_extension_allowed (filename))
plugin_load (filename, plugin_args->argc, plugin_args->argv);
plugin_load (filename, 0, plugin_args->argc, plugin_args->argv);
}
/*
* Callback used to sort plugins arraylist by priority (high priority first).
*/
int
plugin_arraylist_cmp_cb (void *data, struct t_arraylist *arraylist,
void *pointer1, void *pointer2)
{
struct t_weechat_plugin *plugin1, *plugin2;
/* make C compiler happy */
(void) data;
(void) arraylist;
plugin1 = (struct t_weechat_plugin *)pointer1;
plugin2 = (struct t_weechat_plugin *)pointer2;
return (plugin1->priority > plugin2->priority) ?
-1 : ((plugin1->priority < plugin2->priority) ? 1 : 0);
}
/*
@ -896,8 +976,10 @@ void
plugin_auto_load (int argc, char **argv)
{
char *dir_name, *plugin_path, *plugin_path2;
struct t_weechat_plugin *ptr_plugin;
struct t_plugin_args plugin_args;
int length;
struct t_arraylist *arraylist;
int length, i;
plugin_args.argc = argc;
plugin_args.argv = argv;
@ -950,6 +1032,36 @@ plugin_auto_load (int argc, char **argv)
plugin_autoload_array = NULL;
}
plugin_autoload_count = 0;
/* initialize all uninitialized plugins */
arraylist = arraylist_new (10, 1, 1,
&plugin_arraylist_cmp_cb, NULL, NULL, NULL);
if (arraylist)
{
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
arraylist_add (arraylist, ptr_plugin);
}
i = 0;
while (i < arraylist_size (arraylist))
{
ptr_plugin = arraylist_get (arraylist, i);
if (!ptr_plugin->initialized)
{
if (!plugin_call_init (ptr_plugin, argc, argv))
{
plugin_remove (ptr_plugin);
arraylist_remove (arraylist, i);
}
else
i++;
}
else
i++;
}
arraylist_free (arraylist);
}
}
/*
@ -1038,9 +1150,12 @@ plugin_unload (struct t_weechat_plugin *plugin)
name = (plugin->name) ? strdup (plugin->name) : NULL;
end_func = dlsym (plugin->handle, "weechat_plugin_end");
if (end_func)
(void) (end_func) (plugin);
if (plugin->initialized)
{
end_func = dlsym (plugin->handle, "weechat_plugin_end");
if (end_func)
(void) (end_func) (plugin);
}
plugin_remove (plugin);
@ -1118,7 +1233,7 @@ plugin_reload_name (const char *name, int argc, char **argv)
if (filename)
{
plugin_unload (ptr_plugin);
plugin_load (filename, argc, argv);
plugin_load (filename, 1, argc, argv);
free (filename);
}
}
@ -1244,6 +1359,8 @@ plugin_hdata_plugin_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_weechat_plugin, version, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_weechat_plugin, license, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_weechat_plugin, charset, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_weechat_plugin, priority, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_weechat_plugin, initialized, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_weechat_plugin, debug, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_weechat_plugin, prev_plugin, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_weechat_plugin, next_plugin, POINTER, 0, NULL, hdata_name);
@ -1296,6 +1413,10 @@ plugin_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!infolist_new_var_string (ptr_item, "charset", plugin->charset))
return 0;
if (!infolist_new_var_integer (ptr_item, "priority", plugin->priority))
return 0;
if (!infolist_new_var_integer (ptr_item, "initialized", plugin->initialized))
return 0;
if (!infolist_new_var_integer (ptr_item, "debug", plugin->debug))
return 0;
@ -1322,6 +1443,8 @@ plugin_print_log ()
log_printf (" description. . . . . . : '%s'", ptr_plugin->description);
log_printf (" version. . . . . . . . : '%s'", ptr_plugin->version);
log_printf (" charset. . . . . . . . : '%s'", ptr_plugin->charset);
log_printf (" priority . . . . . . . : %d", ptr_plugin->priority);
log_printf (" initialized. . . . . . : %d", ptr_plugin->initialized);
log_printf (" debug. . . . . . . . . : %d", ptr_plugin->debug);
log_printf (" prev_plugin. . . . . . : 0x%lx", ptr_plugin->prev_plugin);
log_printf (" next_plugin. . . . . . : 0x%lx", ptr_plugin->next_plugin);

View File

@ -24,6 +24,8 @@
#define PLUGIN_CORE "core"
#define PLUGIN_PRIORITY_DEFAULT 1000
typedef int (t_weechat_init_func) (struct t_weechat_plugin *plugin,
int argc, char *argv[]);
typedef int (t_weechat_end_func) (struct t_weechat_plugin *plugin);
@ -35,6 +37,7 @@ extern int plugin_valid (struct t_weechat_plugin *plugin);
extern struct t_weechat_plugin *plugin_search (const char *name);
extern const char *plugin_get_name (struct t_weechat_plugin *plugin);
extern struct t_weechat_plugin *plugin_load (const char *filename,
int init_plugin,
int argc, char **argv);
extern void plugin_auto_load (int argc, char **argv);
extern void plugin_unload (struct t_weechat_plugin *plugin);

View File

@ -39,6 +39,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of python scripts"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(3000);
struct t_weechat_plugin *weechat_python_plugin = NULL;

View File

@ -42,6 +42,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Relay WeeChat data to remote application "
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(4000);
struct t_weechat_plugin *weechat_relay_plugin = NULL;

View File

@ -61,6 +61,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of ruby scripts"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(3000);
struct t_weechat_plugin *weechat_ruby_plugin = NULL;

View File

@ -40,6 +40,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Scripts manager"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(2000);
struct t_weechat_plugin *weechat_script_plugin = NULL;

View File

@ -40,6 +40,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of tcl scripts"));
WEECHAT_PLUGIN_AUTHOR("Dmitry Kobylin <fnfal@academ.tsc.ru>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(3000);
struct t_weechat_plugin *weechat_tcl_plugin = NULL;

View File

@ -38,6 +38,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Text replacement and command execution on events
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(10000);
struct t_weechat_plugin *weechat_trigger_plugin = NULL;

View File

@ -57,7 +57,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
#define WEECHAT_PLUGIN_API_VERSION "20141122-01"
#define WEECHAT_PLUGIN_API_VERSION "20150114-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@ -71,6 +71,8 @@ struct timeval;
char weechat_plugin_version[] = __version;
#define WEECHAT_PLUGIN_LICENSE(__license) \
char weechat_plugin_license[] = __license;
#define WEECHAT_PLUGIN_PRIORITY(__priority) \
int weechat_plugin_priority = __priority;
/* return codes for plugin functions */
#define WEECHAT_RC_OK 0
@ -235,6 +237,8 @@ struct t_weechat_plugin
char *version; /* plugin version */
char *license; /* license */
char *charset; /* charset used by plugin */
int priority; /* plugin priority (default is 1000) */
int initialized; /* plugin initialized? (init called) */
int debug; /* debug level for plugin (0=off) */
struct t_weechat_plugin *prev_plugin; /* link to previous plugin */
struct t_weechat_plugin *next_plugin; /* link to next plugin */

View File

@ -50,6 +50,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("DCC file transfer and direct chat"));
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE);
WEECHAT_PLUGIN_PRIORITY(6000);
struct t_weechat_plugin *weechat_xfer_plugin = NULL;