1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 10:13:12 +02:00

New plugin interface (loads dynamic C libraries)

This commit is contained in:
Sebastien Helleu
2005-10-15 12:34:21 +00:00
parent 5130b1dc4f
commit cdc33d08b0
60 changed files with 13636 additions and 7740 deletions
+224 -480
View File
@@ -89,21 +89,11 @@ t_weechat_command weechat_commands[] =
"functions: list internal functions for key bindings\n"
"reset: restore bindings to the default values and delete ALL personal binding (use carefully!)"),
0, MAX_ARGS, NULL, weechat_cmd_key },
{ "perl", N_("list/load/unload Perl scripts"),
{ "plugin", N_("list/load/unload plugins"),
N_("[load filename] | [autoload] | [reload] | [unload]"),
N_("filename: Perl script (file) to load\n\n"
"Without argument, /perl command lists all loaded Perl scripts."),
0, 2, weechat_cmd_perl, NULL },
{ "python", N_("list/load/unload Python scripts"),
N_("[load filename] | [autoload] | [reload] | [unload]"),
N_("filename: Python script (file) to load\n\n"
"Without argument, /python command lists all loaded Python scripts."),
0, 2, weechat_cmd_python, NULL },
{ "ruby", N_("list/load/unload Ruby scripts"),
N_("[load filename] | [autoload] | [reload] | [unload]"),
N_("filename: Ruby script (file) to load\n\n"
"Without argument, /ruby command lists all loaded Ruby scripts."),
0, 2, weechat_cmd_ruby, NULL },
N_("filename: WeeChat plugin (file) to load\n\n"
"Without argument, /plugin command lists all loaded plugins."),
0, 2, weechat_cmd_plugin, NULL },
{ "server", N_("list, add or remove servers"),
N_("[servername] | "
"[servername hostname port [-auto | -noauto] [-ipv6] [-ssl] [-pwd password] [-nicks nick1 "
@@ -381,7 +371,7 @@ alias_free_all ()
*/
char **
explode_string (/*@null@*/ char *string, char *separators, int num_items_max,
explode_string (char *string, char *separators, int num_items_max,
int *num_items)
{
int i, n_items;
@@ -461,6 +451,23 @@ explode_string (/*@null@*/ char *string, char *separators, int num_items_max,
return array;
}
/*
* free_exploded_string: free an exploded string
*/
void
free_exploded_string (char **exploded_string)
{
int i;
if (exploded_string)
{
for (i = 0; exploded_string[i]; i++)
free (exploded_string[i]);
free (exploded_string);
}
}
/*
* exec_weechat_command: executes a command (WeeChat internal or IRC)
* returns: 1 if command was executed succesfully
@@ -470,7 +477,7 @@ explode_string (/*@null@*/ char *string, char *separators, int num_items_max,
int
exec_weechat_command (t_irc_server *server, char *string)
{
int i, j, argc, return_code, length1, length2;
int i, argc, return_code, length1, length2;
char *command, *pos, *ptr_args, **argv, *alias_command;
t_weechat_alias *ptr_alias;
@@ -502,7 +509,11 @@ exec_weechat_command (t_irc_server *server, char *string)
ptr_args = NULL;
}
if (!plugin_exec_command (command + 1, (server) ? server->name : "", ptr_args))
#ifdef PLUGINS
if (!plugin_cmd_handler_exec ((server) ? server->name : "", command + 1, ptr_args))
#else
if (1)
#endif
{
argv = explode_string (ptr_args, " ", 0, &argc);
@@ -556,12 +567,7 @@ exec_weechat_command (t_irc_server *server, char *string)
WEECHAT_ERROR, command + 1);
}
}
if (argv)
{
for (j = 0; argv[j]; j++)
free (argv[j]);
free (argv);
}
free_exploded_string (argv);
free (command);
return 1;
}
@@ -626,12 +632,7 @@ exec_weechat_command (t_irc_server *server, char *string)
WEECHAT_ERROR, command + 1);
}
}
if (argv)
{
for (j = 0; argv[j]; j++)
free (argv[j]);
free (argv);
}
free_exploded_string (argv);
free (command);
return 1;
}
@@ -659,12 +660,7 @@ exec_weechat_command (t_irc_server *server, char *string)
else
(void) exec_weechat_command (server, ptr_alias->alias_command);
if (argv)
{
for (j = 0; argv[j]; j++)
free (argv[j]);
free (argv);
}
free_exploded_string (argv);
free (command);
return 1;
}
@@ -674,12 +670,7 @@ exec_weechat_command (t_irc_server *server, char *string)
_("%s unknown command \"%s\" (type /help for help)\n"),
WEECHAT_ERROR,
command + 1);
if (argv)
{
for (j = 0; argv[j]; j++)
free (argv[j]);
free (argv);
}
free_exploded_string (argv);
}
free (command);
return 0;
@@ -767,7 +758,9 @@ user_command (t_irc_server *server, t_gui_buffer *buffer, char *command)
snprintf (plugin_args, plugin_args_length,
"localhost PRIVMSG %s :%s",
CHANNEL(buffer)->name, command);
plugin_event_msg ("privmsg", server->name, plugin_args);
#ifdef PLUGINS
plugin_msg_handler_exec (server->name, "privmsg", plugin_args);
#endif
free (plugin_args);
}
else
@@ -1294,88 +1287,144 @@ int
weechat_cmd_help (int argc, char **argv)
{
int i;
#ifdef PLUGINS
t_weechat_plugin *ptr_plugin;
t_plugin_cmd_handler *ptr_cmd_handler;
#endif
if (argc == 0)
switch (argc)
{
gui_printf (NULL, "\n");
gui_printf (NULL, _("%s internal commands:\n"), PACKAGE_NAME);
for (i = 0; weechat_commands[i].command_name; i++)
{
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
weechat_commands[i].command_name);
gui_printf (NULL, " - %s\n",
_(weechat_commands[i].command_description));
}
gui_printf (NULL, "\n");
gui_printf (NULL, _("IRC commands:\n"));
for (i = 0; irc_commands[i].command_name; i++)
{
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
case 0:
gui_printf (NULL, "\n");
gui_printf (NULL, _("%s internal commands:\n"), PACKAGE_NAME);
for (i = 0; weechat_commands[i].command_name; i++)
{
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
irc_commands[i].command_name);
gui_printf (NULL, " - %s\n",
_(irc_commands[i].command_description));
}
}
}
if (argc == 1)
{
for (i = 0; weechat_commands[i].command_name; i++)
{
if (ascii_strcasecmp (weechat_commands[i].command_name, argv[0]) == 0)
{
gui_printf (NULL, "\n");
gui_printf (NULL, "[w]");
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
weechat_commands[i].command_name);
if (weechat_commands[i].arguments &&
weechat_commands[i].arguments[0])
gui_printf (NULL, " %s\n",
_(weechat_commands[i].arguments));
else
gui_printf (NULL, "\n");
if (weechat_commands[i].command_description &&
weechat_commands[i].command_description[0])
gui_printf (NULL, "\n%s\n",
_(weechat_commands[i].command_description));
if (weechat_commands[i].arguments_description &&
weechat_commands[i].arguments_description[0])
gui_printf (NULL, "\n%s\n",
_(weechat_commands[i].arguments_description));
return 0;
gui_printf (NULL, " - %s\n",
_(weechat_commands[i].command_description));
}
}
for (i = 0; irc_commands[i].command_name; i++)
{
if ((ascii_strcasecmp (irc_commands[i].command_name, argv[0]) == 0)
&& (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg))
gui_printf (NULL, "\n");
gui_printf (NULL, _("IRC commands:\n"));
for (i = 0; irc_commands[i].command_name; i++)
{
gui_printf (NULL, "\n");
gui_printf (NULL, "[i]");
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
irc_commands[i].command_name);
if (irc_commands[i].arguments &&
irc_commands[i].arguments[0])
gui_printf (NULL, " %s\n",
_(irc_commands[i].arguments));
else
gui_printf (NULL, "\n");
if (irc_commands[i].command_description &&
irc_commands[i].command_description[0])
gui_printf (NULL, "\n%s\n",
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
{
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
irc_commands[i].command_name);
gui_printf (NULL, " - %s\n",
_(irc_commands[i].command_description));
if (irc_commands[i].arguments_description &&
irc_commands[i].arguments_description[0])
gui_printf (NULL, "\n%s\n",
_(irc_commands[i].arguments_description));
return 0;
}
}
}
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("No help available, \"%s\" is an unknown command\n"),
argv[0]);
#ifdef PLUGINS
gui_printf (NULL, "\n");
gui_printf (NULL, _("Plugin commands:\n"));
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
for (ptr_cmd_handler = ptr_plugin->cmd_handlers; ptr_cmd_handler;
ptr_cmd_handler = ptr_cmd_handler->next_handler)
{
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " %s",
ptr_cmd_handler->command);
if (ptr_cmd_handler->description
&& ptr_cmd_handler->description[0])
gui_printf (NULL, " - %s",
ptr_cmd_handler->description);
gui_printf (NULL, "\n");
}
}
#endif
break;
case 1:
for (i = 0; weechat_commands[i].command_name; i++)
{
if (ascii_strcasecmp (weechat_commands[i].command_name, argv[0]) == 0)
{
gui_printf (NULL, "\n");
gui_printf (NULL, "[w]");
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
weechat_commands[i].command_name);
if (weechat_commands[i].arguments &&
weechat_commands[i].arguments[0])
gui_printf (NULL, " %s\n",
_(weechat_commands[i].arguments));
else
gui_printf (NULL, "\n");
if (weechat_commands[i].command_description &&
weechat_commands[i].command_description[0])
gui_printf (NULL, "\n%s\n",
_(weechat_commands[i].command_description));
if (weechat_commands[i].arguments_description &&
weechat_commands[i].arguments_description[0])
gui_printf (NULL, "\n%s\n",
_(weechat_commands[i].arguments_description));
return 0;
}
}
for (i = 0; irc_commands[i].command_name; i++)
{
if ((ascii_strcasecmp (irc_commands[i].command_name, argv[0]) == 0)
&& (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg))
{
gui_printf (NULL, "\n");
gui_printf (NULL, "[i]");
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
irc_commands[i].command_name);
if (irc_commands[i].arguments &&
irc_commands[i].arguments[0])
gui_printf (NULL, " %s\n",
_(irc_commands[i].arguments));
else
gui_printf (NULL, "\n");
if (irc_commands[i].command_description &&
irc_commands[i].command_description[0])
gui_printf (NULL, "\n%s\n",
_(irc_commands[i].command_description));
if (irc_commands[i].arguments_description &&
irc_commands[i].arguments_description[0])
gui_printf (NULL, "\n%s\n",
_(irc_commands[i].arguments_description));
return 0;
}
}
#ifdef PLUGINS
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
for (ptr_cmd_handler = ptr_plugin->cmd_handlers; ptr_cmd_handler;
ptr_cmd_handler = ptr_cmd_handler->next_handler)
{
if (ascii_strcasecmp (ptr_cmd_handler->command, argv[0]) == 0)
{
gui_printf (NULL, "\n");
gui_printf (NULL, "[p]");
gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, " /%s",
ptr_cmd_handler->command);
if (ptr_cmd_handler->arguments &&
ptr_cmd_handler->arguments[0])
gui_printf (NULL, " %s\n",
ptr_cmd_handler->arguments);
else
gui_printf (NULL, "\n");
if (ptr_cmd_handler->description &&
ptr_cmd_handler->description[0])
gui_printf (NULL, "\n%s\n",
ptr_cmd_handler->description);
if (ptr_cmd_handler->arguments_description &&
ptr_cmd_handler->arguments_description[0])
gui_printf (NULL, "\n%s\n",
ptr_cmd_handler->arguments_description);
return 0;
}
}
}
#endif
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("No help available, \"%s\" is an unknown command\n"),
argv[0]);
break;
}
return 0;
}
@@ -1601,92 +1650,82 @@ weechat_cmd_key (char *arguments)
}
/*
* weechat_cmd_perl: list/load/unload Perl scripts
* weechat_cmd_plugin: list/load/unload WeeChat plugins
*/
int
weechat_cmd_perl (int argc, char **argv)
weechat_cmd_plugin (int argc, char **argv)
{
#ifdef PLUGIN_PERL
t_plugin_script *ptr_plugin_script;
t_plugin_handler *ptr_plugin_handler;
int handler_found, path_length;
char *path_script;
#ifdef PLUGINS
t_weechat_plugin *ptr_plugin;
t_plugin_msg_handler *ptr_msg_handler;
t_plugin_cmd_handler *ptr_cmd_handler;
switch (argc)
{
case 0:
/* list registered Perl scripts */
/* list plugins */
gui_printf (NULL, "\n");
gui_printf (NULL, _("Registered %s scripts:\n"), "Perl");
if (perl_scripts)
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _("Plugins loaded:\n"));
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
for (ptr_plugin_script = perl_scripts; ptr_plugin_script;
ptr_plugin_script = ptr_plugin_script->next_script)
/* plugin info */
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, " %s v%s - %s (%s)\n",
ptr_plugin->name,
ptr_plugin->version,
ptr_plugin->description,
ptr_plugin->filename);
/* message handlers */
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" message handlers:\n"));
for (ptr_msg_handler = ptr_plugin->msg_handlers;
ptr_msg_handler;
ptr_msg_handler = ptr_msg_handler->next_handler)
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, " %s v%s%s%s\n",
ptr_plugin_script->name,
ptr_plugin_script->version,
(ptr_plugin_script->description[0]) ? " - " : "",
ptr_plugin_script->description);
gui_printf (NULL, _(" IRC(%s)\n"),
ptr_msg_handler->irc_command);
}
}
else
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" (none)\n"));
}
/* list Perl message handlers */
gui_printf (NULL, "\n");
gui_printf (NULL, _("%s message handlers:\n"), "Perl");
handler_found = 0;
for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler;
ptr_plugin_handler = ptr_plugin_handler->next_handler)
{
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
if (!ptr_plugin->msg_handlers)
{
handler_found = 1;
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" IRC(%s) => %s(%s)\n"),
ptr_plugin_handler->name,
"Perl",
ptr_plugin_handler->function_name);
gui_printf (NULL, _(" (no message handler)\n"));
}
}
if (!handler_found)
{
/* command handlers */
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" (none)\n"));
}
/* list Perl command handlers */
gui_printf (NULL, "\n");
gui_printf (NULL, _("%s command handlers:\n"), "Perl");
handler_found = 0;
for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler;
ptr_plugin_handler = ptr_plugin_handler->next_handler)
{
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
gui_printf (NULL, _(" command handlers:\n"));
for (ptr_cmd_handler = ptr_plugin->cmd_handlers;
ptr_cmd_handler;
ptr_cmd_handler = ptr_cmd_handler->next_handler)
{
handler_found = 1;
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" Command /%s => %s(%s)\n"),
ptr_plugin_handler->name,
"Perl",
ptr_plugin_handler->function_name);
gui_printf (NULL, " /%s",
ptr_cmd_handler->command);
if (ptr_cmd_handler->description
&& ptr_cmd_handler->description[0])
gui_printf (NULL, " (%s)",
ptr_cmd_handler->description);
gui_printf (NULL, "\n");
}
if (!ptr_plugin->cmd_handlers)
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" (no command handler)\n"));
}
}
if (!handler_found)
if (!weechat_plugins)
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" (none)\n"));
gui_printf (NULL, _(" (no plugin)\n"));
}
break;
case 1:
if (ascii_strcasecmp (argv[0], "autoload") == 0)
/*if (ascii_strcasecmp (argv[0], "autoload") == 0)
plugin_auto_load (PLUGIN_TYPE_PERL, "perl/autoload");
else if (ascii_strcasecmp (argv[0], "reload") == 0)
{
@@ -1694,337 +1733,42 @@ weechat_cmd_perl (int argc, char **argv)
plugin_auto_load (PLUGIN_TYPE_PERL, "perl/autoload");
}
else if (ascii_strcasecmp (argv[0], "unload") == 0)
plugin_unload (PLUGIN_TYPE_PERL, NULL);
plugin_unload (PLUGIN_TYPE_PERL, NULL);*/
break;
case 2:
if (ascii_strcasecmp (argv[0], "load") == 0)
{
/* load Perl script */
if (strstr(argv[1], DIR_SEPARATOR))
path_script = NULL;
else
{
path_length = strlen (weechat_home) + strlen (argv[1]) + 7;
path_script = (char *) malloc (path_length * sizeof (char));
snprintf (path_script, path_length, "%s%s%s%s%s",
weechat_home, DIR_SEPARATOR, "perl",
DIR_SEPARATOR, argv[1]);
}
plugin_load (PLUGIN_TYPE_PERL,
(path_script) ? path_script : argv[1]);
if (path_script)
free (path_script);
}
else
{
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("%s unknown option for \"%s\" command\n"),
WEECHAT_ERROR, "perl");
}
break;
default:
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("%s wrong argument count for \"%s\" command\n"),
WEECHAT_ERROR, "perl");
}
#else
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("WeeChat was build without Perl support.\n"
"Please rebuild WeeChat with "
"\"--enable-perl\" option for ./configure script\n"));
/* make gcc happy */
(void) argc;
(void) argv;
#endif /* PLUGIN_PERL */
return 0;
}
/*
* weechat_cmd_python: list/load/unload Python scripts
*/
int
weechat_cmd_python (int argc, char **argv)
{
#ifdef PLUGIN_PYTHON
t_plugin_script *ptr_plugin_script;
t_plugin_handler *ptr_plugin_handler;
int handler_found, path_length;
char *path_script;
switch (argc)
{
case 0:
/* list registered Python scripts */
gui_printf (NULL, "\n");
gui_printf (NULL, _("Registered %s scripts:\n"), "Python");
if (python_scripts)
{
for (ptr_plugin_script = python_scripts; ptr_plugin_script;
ptr_plugin_script = ptr_plugin_script->next_script)
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, " %s v%s%s%s\n",
ptr_plugin_script->name,
ptr_plugin_script->version,
(ptr_plugin_script->description[0]) ? " - " : "",
ptr_plugin_script->description);
}
}
else
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" (none)\n"));
}
/* list Python message handlers */
gui_printf (NULL, "\n");
gui_printf (NULL, _("%s message handlers:\n"), "Python");
handler_found = 0;
for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler;
ptr_plugin_handler = ptr_plugin_handler->next_handler)
{
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON)
{
handler_found = 1;
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" IRC(%s) => %s(%s)\n"),
ptr_plugin_handler->name,
"Python",
ptr_plugin_handler->function_name);
}
}
if (!handler_found)
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" (none)\n"));
}
/* list Python command handlers */
gui_printf (NULL, "\n");
gui_printf (NULL, _("%s command handlers:\n"), "Python");
handler_found = 0;
for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler;
ptr_plugin_handler = ptr_plugin_handler->next_handler)
{
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON)
{
handler_found = 1;
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" Command /%s => %s(%s)\n"),
ptr_plugin_handler->name,
"Python",
ptr_plugin_handler->function_name);
}
}
if (!handler_found)
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" (none)\n"));
}
break;
case 1:
if (ascii_strcasecmp (argv[0], "autoload") == 0)
plugin_auto_load (PLUGIN_TYPE_PYTHON, "python/autoload");
else if (ascii_strcasecmp (argv[0], "reload") == 0)
{
plugin_unload (PLUGIN_TYPE_PYTHON, NULL);
plugin_auto_load (PLUGIN_TYPE_PYTHON, "python/autoload");
/* load plugin */
plugin_load (argv[1]);
}
else if (ascii_strcasecmp (argv[0], "unload") == 0)
plugin_unload (PLUGIN_TYPE_PYTHON, NULL);
break;
case 2:
if (ascii_strcasecmp (argv[0], "load") == 0)
{
/* load Python script */
if (strstr(argv[1], DIR_SEPARATOR))
path_script = NULL;
else
{
path_length = strlen (weechat_home) + strlen (argv[1]) + 9;
path_script = (char *) malloc (path_length * sizeof (char));
snprintf (path_script, path_length, "%s%s%s%s%s",
weechat_home, DIR_SEPARATOR, "python",
DIR_SEPARATOR, argv[1]);
}
plugin_load (PLUGIN_TYPE_PYTHON,
(path_script) ? path_script : argv[1]);
if (path_script)
free (path_script);
/* unload plugin */
plugin_unload_name (argv[1]);
}
else
{
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("%s unknown option for \"%s\" command\n"),
WEECHAT_ERROR, "python");
WEECHAT_ERROR, "plugin");
}
break;
default:
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("%s wrong argument count for \"%s\" command\n"),
WEECHAT_ERROR, "python");
WEECHAT_ERROR, "plugin");
}
#else
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("WeeChat was build without Python support.\n"
"Please rebuild WeeChat with "
"\"--enable-python\" option for ./configure script\n"));
_("Command \"plugin\" is not available, WeeChat was built "
"without plugins support.\n"));
/* make gcc happy */
(void) argc;
(void) argv;
#endif /* PLUGIN_PYTHON */
return 0;
}
/*
* weechat_cmd_ruby: list/load/unload Ruby scripts
*/
int
weechat_cmd_ruby (int argc, char **argv)
{
#ifdef PLUGIN_RUBY
t_plugin_script *ptr_plugin_script;
t_plugin_handler *ptr_plugin_handler;
int handler_found, path_length;
char *path_script;
switch (argc)
{
case 0:
/* list registered Ruby scripts */
gui_printf (NULL, "\n");
gui_printf (NULL, _("Registered %s scripts:\n"), "Ruby");
if (ruby_scripts)
{
for (ptr_plugin_script = ruby_scripts; ptr_plugin_script;
ptr_plugin_script = ptr_plugin_script->next_script)
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, " %s v%s%s%s\n",
ptr_plugin_script->name,
ptr_plugin_script->version,
(ptr_plugin_script->description[0]) ? " - " : "",
ptr_plugin_script->description);
}
}
else
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" (none)\n"));
}
/* list Ruby message handlers */
gui_printf (NULL, "\n");
gui_printf (NULL, _("%s message handlers:\n"), "Ruby");
handler_found = 0;
for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler;
ptr_plugin_handler = ptr_plugin_handler->next_handler)
{
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_RUBY)
{
handler_found = 1;
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" IRC(%s) => %s(%s)\n"),
ptr_plugin_handler->name,
"Ruby",
ptr_plugin_handler->function_name);
}
}
if (!handler_found)
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" (none)\n"));
}
/* list Ruby command handlers */
gui_printf (NULL, "\n");
gui_printf (NULL, _("%s command handlers:\n"), "Ruby");
handler_found = 0;
for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler;
ptr_plugin_handler = ptr_plugin_handler->next_handler)
{
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_RUBY)
{
handler_found = 1;
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" Command /%s => %s(%s)\n"),
ptr_plugin_handler->name,
"Ruby",
ptr_plugin_handler->function_name);
}
}
if (!handler_found)
{
irc_display_prefix (NULL, PREFIX_PLUGIN);
gui_printf (NULL, _(" (none)\n"));
}
break;
case 1:
if (ascii_strcasecmp (argv[0], "autoload") == 0)
plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload");
else if (ascii_strcasecmp (argv[0], "reload") == 0)
{
plugin_unload (PLUGIN_TYPE_RUBY, NULL);
plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload");
}
else if (ascii_strcasecmp (argv[0], "unload") == 0)
plugin_unload (PLUGIN_TYPE_RUBY, NULL);
break;
case 2:
if (ascii_strcasecmp (argv[0], "load") == 0)
{
/* load Ruby script */
if (strstr(argv[1], DIR_SEPARATOR))
path_script = NULL;
else
{
path_length = strlen (weechat_home) + strlen (argv[1]) + 9;
path_script = (char *) malloc (path_length * sizeof (char));
snprintf (path_script, path_length, "%s%s%s%s%s",
weechat_home, DIR_SEPARATOR, "ruby",
DIR_SEPARATOR, argv[1]);
}
plugin_load (PLUGIN_TYPE_RUBY,
(path_script) ? path_script : argv[1]);
if (path_script)
free (path_script);
}
else
{
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("%s unknown option for \"%s\" command\n"),
WEECHAT_ERROR, "ruby");
}
break;
default:
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("%s wrong argument count for \"%s\" command\n"),
WEECHAT_ERROR, "ruby");
}
#else
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("WeeChat was build without Ruby support.\n"
"Please rebuild WeeChat with "
"\"--enable-ruby\" option for ./configure script\n"));
/* make gcc happy */
(void) argc;
(void) argv;
#endif /* PLUGIN_RUBY */
#endif /* PLUGINS */
return 0;
}
+3 -3
View File
@@ -60,6 +60,8 @@ extern void command_index_build ();
extern void command_index_free ();
extern t_weechat_alias *alias_new (char *, char *);
extern void alias_free_all ();
extern char **explode_string (char *, char *, int, int *);
extern void free_exploded_string (char **);
extern int exec_weechat_command (t_irc_server *, char *);
extern void user_command (t_irc_server *, t_gui_buffer *, char *);
extern int weechat_cmd_alias (char *);
@@ -72,9 +74,7 @@ extern int weechat_cmd_help (int, char **);
extern void weechat_cmd_ignore_display (char *, t_irc_ignore *);
extern int weechat_cmd_ignore (int, char **);
extern int weechat_cmd_key (char *);
extern int weechat_cmd_perl (int, char **);
extern int weechat_cmd_python (int, char **);
extern int weechat_cmd_ruby (int, char **);
extern int weechat_cmd_plugin (int, char **);
extern int weechat_cmd_save (int, char **);
extern int weechat_cmd_server (int, char **);
extern int weechat_cmd_set (char *);
+23 -2
View File
@@ -34,6 +34,10 @@
#include "weeconfig.h"
#include "../irc/irc.h"
#ifdef PLUGINS
#include "../plugins/plugins.h"
#endif
/*
* completion_init: init completion
@@ -108,6 +112,10 @@ completion_build_list (t_completion *completion, void *channel)
t_config_option *option;
void *option_value;
char option_string[2048];
#ifdef PLUGINS
t_weechat_plugin *ptr_plugin;
t_plugin_cmd_handler *ptr_cmd_handler;
#endif
/* WeeChat internal commands */
@@ -200,6 +208,20 @@ completion_build_list (t_completion *completion, void *channel)
&completion->last_completion,
irc_commands[i].command_name);
}
#ifdef PLUGINS
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
for (ptr_cmd_handler = ptr_plugin->cmd_handlers;
ptr_cmd_handler;
ptr_cmd_handler = ptr_cmd_handler->next_handler)
{
weelist_add (&completion->completion_list,
&completion->last_completion,
ptr_cmd_handler->command);
}
}
#endif
return;
}
if (ascii_strcasecmp (completion->base_command, "ignore") == 0)
@@ -312,8 +334,7 @@ completion_build_list (t_completion *completion, void *channel)
return;
}
}
if (((ascii_strcasecmp (completion->base_command, "perl") == 0)
|| (ascii_strcasecmp (completion->base_command, "python") == 0))
if ((ascii_strcasecmp (completion->base_command, "plugin") == 0)
&& (completion->base_command_arg == 1))
{
weelist_add (&completion->completion_list,
+9 -49
View File
@@ -9,7 +9,7 @@
* ### Fast & light environment for Chat ###
* ### ###
* ### By FlashCode <flashcode@flashtux.org> ###
### ###
* ### ###
* ### http://weechat.flashtux.org ###
* ### ###
* ############################################################################
@@ -66,7 +66,10 @@
#include "fifo.h"
#include "../irc/irc.h"
#include "../gui/gui.h"
#ifdef PLUGINS
#include "../plugins/plugins.h"
#endif
int quit_weechat; /* = 1 if quit request from user... why ? :'( */
@@ -590,53 +593,6 @@ wee_create_home_dirs ()
dir_length = strlen (weechat_home) + 64;
dir_name = (char *) malloc (dir_length * sizeof (char));
#ifdef PLUGIN_PERL
/* create "~/.weechat/perl" */
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
"perl");
if (wee_create_dir (dir_name))
{
/* create "~/.weechat/perl/autoload" */
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
DIR_SEPARATOR, "perl", DIR_SEPARATOR, "autoload");
wee_create_dir (dir_name);
/* create "~/.weechat/perl/config" */
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
DIR_SEPARATOR, "perl", DIR_SEPARATOR, "config");
wee_create_dir (dir_name);
}
#endif
#ifdef PLUGIN_PYTHON
/* create "~/.weechat/python" */
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
"python");
if (wee_create_dir (dir_name))
{
/* create "~/.weechat/python/autoload" */
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
DIR_SEPARATOR, "python", DIR_SEPARATOR, "autoload");
wee_create_dir (dir_name);
/* create "~/.weechat/python/config" */
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
DIR_SEPARATOR, "python", DIR_SEPARATOR, "config");
wee_create_dir (dir_name);
}
#endif
#ifdef PLUGIN_RUBY
/* create "~/.weechat/ruby" */
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
"ruby");
if (wee_create_dir (dir_name))
{
/* create "~/.weechat/ruby/autoload" */
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
DIR_SEPARATOR, "ruby", DIR_SEPARATOR, "autoload");
wee_create_dir (dir_name);
}
#endif
/* create "~/.weechat/logs" */
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
"logs");
@@ -925,14 +881,18 @@ main (int argc, char *argv[])
gui_init (); /* init WeeChat interface */
weechat_welcome_message (); /* display WeeChat welcome message */
plugin_init (); /* init plugin interface(s) */
#ifdef PLUGINS
plugin_init (); /* init plugin interface(s) */
#endif
/* auto-connect to servers */
server_auto_connect (server_cmd_line);
fifo_create (); /* create FIFO pipe for remote control */
gui_main_loop (); /* WeeChat main loop */
#ifdef PLUGINS
plugin_end (); /* end plugin interface(s) */
#endif
server_disconnect_all (); /* disconnect from all servers */
(void) config_write (NULL); /* save config file */
command_index_free (); /* free commands index */
+33 -1
View File
@@ -53,6 +53,7 @@ t_config_section config_sections[CONFIG_NUMBER_SECTIONS] =
{ CONFIG_SECTION_IRC, "irc" },
{ CONFIG_SECTION_DCC, "dcc" },
{ CONFIG_SECTION_PROXY, "proxy" },
{ CONFIG_SECTION_PLUGINS, "plugins" },
{ CONFIG_SECTION_KEYS, "keys" },
{ CONFIG_SECTION_ALIAS, "alias" },
{ CONFIG_SECTION_IGNORE, "ignore" },
@@ -747,6 +748,36 @@ t_config_option weechat_options_proxy[] =
{ NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
};
/* config, plugins section */
char *cfg_plugins_path;
char *cfg_plugins_autoload;
char *cfg_plugins_extension;
t_config_option weechat_options_plugins[] =
{ { "plugins_path", N_("path for searching plugins"),
N_("path for searching plugins"),
OPTION_TYPE_STRING, 0, 0, 0,
"~/.weechat/plugins", NULL, NULL, &cfg_plugins_path, config_change_noop },
{ "plugins_autoload", N_("list of plugins to load automatically"),
N_("comma separated list of plugins to load automatically at startup, "
"\"*\" means all plugins found "
"(names may be partial, for example \"perl\" is ok for \"libperl.so\")"),
OPTION_TYPE_STRING, 0, 0, 0,
"*", NULL, NULL, &cfg_plugins_autoload, config_change_noop },
{ "plugins_extension", N_("standard plugins extension in filename"),
N_("standard plugins extension in filename, used for autoload "
"(if empty, then all files are loaded when autoload is \"*\")"),
OPTION_TYPE_STRING, 0, 0, 0,
#ifdef WIN32
".dll",
#else
".so",
#endif
NULL, NULL, &cfg_plugins_extension, config_change_noop },
{ NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
};
/* config, server section */
static t_irc_server cfg_server;
@@ -836,7 +867,8 @@ t_config_option weechat_options_server[] =
t_config_option *weechat_options[CONFIG_NUMBER_SECTIONS] =
{ weechat_options_look, weechat_options_colors, weechat_options_history,
weechat_options_log, weechat_options_irc, weechat_options_dcc,
weechat_options_proxy, NULL, NULL, NULL, weechat_options_server
weechat_options_proxy, weechat_options_plugins, NULL, NULL, NULL,
weechat_options_server
};
+10 -5
View File
@@ -33,11 +33,12 @@
#define CONFIG_SECTION_IRC 4
#define CONFIG_SECTION_DCC 5
#define CONFIG_SECTION_PROXY 6
#define CONFIG_SECTION_KEYS 7
#define CONFIG_SECTION_ALIAS 8
#define CONFIG_SECTION_IGNORE 9
#define CONFIG_SECTION_SERVER 10
#define CONFIG_NUMBER_SECTIONS 11
#define CONFIG_SECTION_PLUGINS 7
#define CONFIG_SECTION_KEYS 8
#define CONFIG_SECTION_ALIAS 9
#define CONFIG_SECTION_IGNORE 10
#define CONFIG_SECTION_SERVER 11
#define CONFIG_NUMBER_SECTIONS 12
#define OPTION_TYPE_BOOLEAN 1 /* values: on/off */
#define OPTION_TYPE_INT 2 /* values: from min to max */
@@ -202,6 +203,10 @@ extern int cfg_proxy_port;
extern char *cfg_proxy_username;
extern char *cfg_proxy_password;
extern char *cfg_plugins_path;
extern char *cfg_plugins_autoload;
extern char *cfg_plugins_extension;
extern t_config_section config_sections [CONFIG_NUMBER_SECTIONS];
extern t_config_option * weechat_options [CONFIG_NUMBER_SECTIONS];
+3
View File
@@ -140,6 +140,9 @@ weelist_remove (t_weelist **weelist, t_weelist **last_weelist, t_weelist *elemen
{
t_weelist *new_weelist;
if (!element)
return;
/* remove element from list */
if (*last_weelist == element)
*last_weelist = element->prev_weelist;