mirror of
https://github.com/weechat/weechat.git
synced 2026-06-25 12:26:40 +02:00
Update of translations for scripts, fix bugs and code factorized in script plugins
This commit is contained in:
@@ -23,15 +23,8 @@
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
//#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <stdarg.h>
|
||||
//#include <time.h>
|
||||
//#include <sys/socket.h>
|
||||
//#include <netinet/in.h>
|
||||
//#include <arpa/inet.h>
|
||||
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../script.h"
|
||||
@@ -132,7 +125,7 @@ weechat_lua_load (char *filename)
|
||||
char *weechat_lua_code = {
|
||||
"weechat_outputs = {\n"
|
||||
" write = function (self, str)\n"
|
||||
" weechat.print(\"Lua stdout/stderr : \" .. str)\n"
|
||||
" weechat.print(\"\", \"lua: stdout/stderr: \" .. str)\n"
|
||||
" end\n"
|
||||
"}\n"
|
||||
"io.stdout = weechat_outputs\n"
|
||||
@@ -328,11 +321,7 @@ int
|
||||
weechat_lua_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
//int handler_found, modifier_found;
|
||||
char *path_script;
|
||||
struct t_plugin_script *ptr_script;
|
||||
//t_plugin_handler *ptr_handler;
|
||||
//t_plugin_modifier *ptr_modifier;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -340,162 +329,29 @@ weechat_lua_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
/* list registered Lua scripts */
|
||||
weechat_printf (NULL, "");
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("Registered %s scripts:"),
|
||||
"lua");
|
||||
if (lua_scripts)
|
||||
{
|
||||
for (ptr_script = lua_scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext (" %s v%s (%s), by %s, "
|
||||
"license %s"),
|
||||
ptr_script->name,
|
||||
ptr_script->version,
|
||||
ptr_script->description,
|
||||
ptr_script->author,
|
||||
ptr_script->license);
|
||||
}
|
||||
}
|
||||
else
|
||||
weechat_printf (NULL, weechat_gettext (" (none)"));
|
||||
|
||||
/*
|
||||
// list Lua message handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " IRC(%s) => Lua(%s)",
|
||||
ptr_handler->irc_command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Lua command handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " /%s => Lua(%s)",
|
||||
ptr_handler->command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Lua timer handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua timer handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_TIMER)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %d seconds => Lua(%s)",
|
||||
ptr_handler->interval,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Lua keyboard handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua keyboard handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " Lua(%s)",
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Lua event handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua event handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_EVENT)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %s => Lua(%s)",
|
||||
ptr_handler->event,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Lua modifiers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua modifiers:");
|
||||
modifier_found = 0;
|
||||
for (ptr_modifier = plugin->modifiers;
|
||||
ptr_modifier; ptr_modifier = ptr_modifier->next_modifier)
|
||||
{
|
||||
modifier_found = 1;
|
||||
if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_IN)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Lua(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_IN_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_USER)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Lua(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_USER_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_OUT)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Lua(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_OUT_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
}
|
||||
if (!modifier_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
*/
|
||||
script_display_list (weechat_lua_plugin, lua_scripts,
|
||||
NULL, 0);
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
script_auto_load (weechat_lua_plugin,
|
||||
"lua", &weechat_lua_load_cb);
|
||||
if (weechat_strcasecmp (argv[1], "list") == 0)
|
||||
{
|
||||
script_display_list (weechat_lua_plugin, lua_scripts,
|
||||
NULL, 0);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "listfull") == 0)
|
||||
{
|
||||
script_display_list (weechat_lua_plugin, lua_scripts,
|
||||
NULL, 1);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
{
|
||||
script_auto_load (weechat_lua_plugin, &weechat_lua_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "reload") == 0)
|
||||
{
|
||||
weechat_lua_unload_all ();
|
||||
script_auto_load (weechat_lua_plugin,
|
||||
"lua", &weechat_lua_load_cb);
|
||||
script_auto_load (weechat_lua_plugin, &weechat_lua_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "unload") == 0)
|
||||
{
|
||||
@@ -504,11 +360,21 @@ weechat_lua_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "load") == 0)
|
||||
if (weechat_strcasecmp (argv[1], "list") == 0)
|
||||
{
|
||||
script_display_list (weechat_lua_plugin, lua_scripts,
|
||||
argv_eol[2], 0);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "listfull") == 0)
|
||||
{
|
||||
script_display_list (weechat_lua_plugin, lua_scripts,
|
||||
argv_eol[2], 1);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "load") == 0)
|
||||
{
|
||||
/* load Lua script */
|
||||
path_script = script_search_full_name (weechat_lua_plugin,
|
||||
"lua", argv_eol[2]);
|
||||
argv_eol[2]);
|
||||
weechat_lua_load ((path_script) ? path_script : argv_eol[2]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
@@ -558,26 +424,10 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
|
||||
weechat_lua_plugin = plugin;
|
||||
|
||||
weechat_hook_command ("lua",
|
||||
weechat_gettext ("list/load/unload Lua scripts"),
|
||||
weechat_gettext ("[load filename] | [autoload] | "
|
||||
"[reload] | [unload [script]]"),
|
||||
weechat_gettext ("filename: Lua script (file) to "
|
||||
"load\n"
|
||||
"script: script name to unload\n\n"
|
||||
"Without argument, /lua command "
|
||||
"lists all loaded Lua scripts."),
|
||||
"load|autoload|reload|unload %f",
|
||||
&weechat_lua_command_cb, NULL);
|
||||
|
||||
weechat_mkdir_home ("lua", 0644);
|
||||
weechat_mkdir_home ("lua/autoload", 0644);
|
||||
|
||||
weechat_hook_signal ("dump_data", &weechat_lua_dump_data_cb, NULL);
|
||||
|
||||
script_init (weechat_lua_plugin);
|
||||
script_auto_load (weechat_lua_plugin, "lua", &weechat_lua_load_cb);
|
||||
script_init (weechat_lua_plugin,
|
||||
&weechat_lua_command_cb, &weechat_lua_dump_data_cb,
|
||||
&weechat_lua_load_cb);
|
||||
|
||||
/* init ok */
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
@@ -98,8 +98,8 @@ char *perl_weechat_code =
|
||||
" }"
|
||||
" return 0;"
|
||||
"}"
|
||||
"$SIG{__WARN__} = sub { weechat::print \"Perl error: $_[0]\", \"\"; };"
|
||||
"$SIG{__DIE__} = sub { weechat::print \"Perl error: $_[0]\", \"\"; };"
|
||||
"$SIG{__WARN__} = sub { weechat::print(\"\", \"perl error: $_[0]\"); };"
|
||||
"$SIG{__DIE__} = sub { weechat::print(\"\", \"perl error: $_[0]\"); };"
|
||||
};
|
||||
|
||||
|
||||
@@ -462,176 +462,37 @@ int
|
||||
weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
//int handler_found, modifier_found;
|
||||
char *path_script;
|
||||
struct t_plugin_script *ptr_script;
|
||||
//struct t_plugin_handler *ptr_handler;
|
||||
//struct t_plugin_modifier *ptr_modifier;
|
||||
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
/* list registered Perl scripts */
|
||||
weechat_printf (NULL, "");
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("Registered %s scripts:"),
|
||||
"perl");
|
||||
if (perl_scripts)
|
||||
{
|
||||
for (ptr_script = perl_scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext (" %s v%s (%s), by %s, "
|
||||
"license %s"),
|
||||
ptr_script->name,
|
||||
ptr_script->version,
|
||||
ptr_script->description,
|
||||
ptr_script->author,
|
||||
ptr_script->license);
|
||||
}
|
||||
}
|
||||
else
|
||||
weechat_printf (NULL, weechat_gettext (" (none)"));
|
||||
|
||||
/*
|
||||
// list Perl message handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " IRC(%s) => Perl(%s)",
|
||||
ptr_handler->irc_command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Perl command handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " /%s => Perl(%s)",
|
||||
ptr_handler->command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Perl timer handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl timer handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_TIMER)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %d seconds => Perl(%s)",
|
||||
ptr_handler->interval,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Perl keyboard handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl keyboard handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " Perl(%s)",
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Perl event handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl event handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_EVENT)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %s => Perl(%s)",
|
||||
ptr_handler->event,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Perl modifiers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl modifiers:");
|
||||
modifier_found = 0;
|
||||
for (ptr_modifier = plugin->modifiers;
|
||||
ptr_modifier; ptr_modifier = ptr_modifier->next_modifier)
|
||||
{
|
||||
modifier_found = 1;
|
||||
if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_IN)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Perl(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_IN_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_USER)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Perl(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_USER_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_OUT)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Perl(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_OUT_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
}
|
||||
if (!modifier_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
*/
|
||||
script_display_list (weechat_perl_plugin, perl_scripts,
|
||||
NULL, 0);
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
if (weechat_strcasecmp (argv[1], "list") == 0)
|
||||
{
|
||||
script_auto_load (weechat_perl_plugin,
|
||||
"perl", &weechat_perl_load_cb);
|
||||
script_display_list (weechat_perl_plugin, perl_scripts,
|
||||
NULL, 0);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "listfull") == 0)
|
||||
{
|
||||
script_display_list (weechat_perl_plugin, perl_scripts,
|
||||
NULL, 1);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
{
|
||||
script_auto_load (weechat_perl_plugin, &weechat_perl_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "reload") == 0)
|
||||
{
|
||||
weechat_perl_unload_all ();
|
||||
script_auto_load (weechat_perl_plugin,
|
||||
"perl", &weechat_perl_load_cb);
|
||||
script_auto_load (weechat_perl_plugin, &weechat_perl_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "unload") == 0)
|
||||
{
|
||||
@@ -640,11 +501,21 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "load") == 0)
|
||||
if (weechat_strcasecmp (argv[1], "list") == 0)
|
||||
{
|
||||
script_display_list (weechat_perl_plugin, perl_scripts,
|
||||
argv_eol[2], 0);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "listfull") == 0)
|
||||
{
|
||||
script_display_list (weechat_perl_plugin, perl_scripts,
|
||||
argv_eol[2], 1);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "load") == 0)
|
||||
{
|
||||
/* load Perl script */
|
||||
path_script = script_search_full_name (weechat_perl_plugin,
|
||||
"perl", argv_eol[2]);
|
||||
argv_eol[2]);
|
||||
weechat_perl_load ((path_script) ? path_script : argv_eol[2]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
@@ -712,25 +583,9 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
eval_pv (perl_weechat_code, TRUE);
|
||||
#endif
|
||||
|
||||
weechat_hook_command ("perl",
|
||||
weechat_gettext ("list/load/unload Perl scripts"),
|
||||
weechat_gettext ("[load filename] | [autoload] | "
|
||||
"[reload] | [unload [script]]"),
|
||||
weechat_gettext ("filename: Perl script (file) to "
|
||||
"load\n"
|
||||
"script: script name to unload\n\n"
|
||||
"Without argument, /perl command "
|
||||
"lists all loaded Perl scripts."),
|
||||
"load|autoload|reload|unload %f",
|
||||
&weechat_perl_command_cb, NULL);
|
||||
|
||||
weechat_mkdir_home ("perl", 0644);
|
||||
weechat_mkdir_home ("perl/autoload", 0644);
|
||||
|
||||
weechat_hook_signal ("dump_data", &weechat_perl_dump_data_cb, NULL);
|
||||
|
||||
script_init (weechat_perl_plugin);
|
||||
script_auto_load (weechat_perl_plugin, "perl", &weechat_perl_load_cb);
|
||||
script_init (weechat_perl_plugin,
|
||||
&weechat_perl_command_cb, &weechat_perl_dump_data_cb,
|
||||
&weechat_perl_load_cb);
|
||||
|
||||
/* init ok */
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
@@ -153,7 +153,7 @@ weechat_python_exec (struct t_plugin_script *script,
|
||||
if (ret_value == NULL)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: not enough memory for "
|
||||
weechat_gettext ("%s%s: not enough memory in "
|
||||
"function \"%s\""),
|
||||
weechat_prefix ("error"), "python", function);
|
||||
/* PyEval_ReleaseThread (python_current_script->interpreter); */
|
||||
@@ -211,7 +211,7 @@ weechat_python_output (PyObject *self, PyObject *args)
|
||||
if (strlen(m) + strlen(python_buffer_output) > sizeof(python_buffer_output))
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s: stdout/stderr : %s%s"),
|
||||
weechat_gettext ("%s: stdout/stderr: %s%s"),
|
||||
"python", python_buffer_output, m);
|
||||
python_buffer_output[0] = '\0';
|
||||
}
|
||||
@@ -490,11 +490,7 @@ int
|
||||
weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
//int handler_found, modifier_found;
|
||||
char *path_script;
|
||||
struct t_plugin_script *ptr_script;
|
||||
//struct t_plugin_handler *ptr_handler;
|
||||
//struct t_plugin_modifier *ptr_modifier;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -502,164 +498,29 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
/* list registered Python scripts */
|
||||
weechat_printf (NULL, "");
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("Registered %s scripts:"),
|
||||
"python");
|
||||
if (python_scripts)
|
||||
{
|
||||
for (ptr_script = python_scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext (" %s v%s (%s), by %s, "
|
||||
"license %s"),
|
||||
ptr_script->name,
|
||||
ptr_script->version,
|
||||
ptr_script->description,
|
||||
ptr_script->author,
|
||||
ptr_script->license);
|
||||
}
|
||||
}
|
||||
else
|
||||
weechat_printf (NULL, weechat_gettext (" (none)"));
|
||||
|
||||
/*
|
||||
// list Python message handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " IRC(%s) => Python(%s)",
|
||||
ptr_handler->irc_command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Python command handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " /%s => Python(%s)",
|
||||
ptr_handler->command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Python timer handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python timer handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_TIMER)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %d seconds => Python(%s)",
|
||||
ptr_handler->interval,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Python keyboard handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python keyboard handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " Python(%s)",
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Python event handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python event handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_EVENT)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %s => Python(%s)",
|
||||
ptr_handler->event,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Python modifiers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python modifiers:");
|
||||
modifier_found = 0;
|
||||
for (ptr_modifier = plugin->modifiers;
|
||||
ptr_modifier; ptr_modifier = ptr_modifier->next_modifier)
|
||||
{
|
||||
modifier_found = 1;
|
||||
if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_IN)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Python(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_IN_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_USER)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Python(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_USER_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_OUT)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Python(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_OUT_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
}
|
||||
if (!modifier_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
*/
|
||||
script_display_list (weechat_python_plugin, python_scripts,
|
||||
NULL, 0);
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
if (weechat_strcasecmp (argv[1], "list") == 0)
|
||||
{
|
||||
script_auto_load (weechat_python_plugin,
|
||||
"python", &weechat_python_load_cb);
|
||||
script_display_list (weechat_python_plugin, python_scripts,
|
||||
NULL, 0);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "listfull") == 0)
|
||||
{
|
||||
script_display_list (weechat_python_plugin, python_scripts,
|
||||
NULL, 1);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
{
|
||||
script_auto_load (weechat_python_plugin, &weechat_python_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "reload") == 0)
|
||||
{
|
||||
weechat_python_unload_all ();
|
||||
script_auto_load (weechat_python_plugin,
|
||||
"python", &weechat_python_load_cb);
|
||||
script_auto_load (weechat_python_plugin, &weechat_python_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "unload") == 0)
|
||||
{
|
||||
@@ -668,11 +529,21 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "load") == 0)
|
||||
if (weechat_strcasecmp (argv[1], "list") == 0)
|
||||
{
|
||||
script_display_list (weechat_python_plugin, python_scripts,
|
||||
argv_eol[2], 0);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "listfull") == 0)
|
||||
{
|
||||
script_display_list (weechat_python_plugin, python_scripts,
|
||||
argv_eol[2], 1);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "load") == 0)
|
||||
{
|
||||
/* load Python script */
|
||||
path_script = script_search_full_name (weechat_python_plugin,
|
||||
"python", argv_eol[2]);
|
||||
argv_eol[2]);
|
||||
weechat_python_load ((path_script) ? path_script : argv_eol[2]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
@@ -749,25 +620,9 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
weechat_hook_command ("python",
|
||||
weechat_gettext ("list/load/unload Python scripts"),
|
||||
weechat_gettext ("[load filename] | [autoload] | "
|
||||
"[reload] | [unload [script]]"),
|
||||
weechat_gettext ("filename: Python script (file) to "
|
||||
"load\n"
|
||||
"script: script name to unload\n\n"
|
||||
"Without argument, /python command "
|
||||
"lists all loaded Python scripts."),
|
||||
"load|autoload|reload|unload %f",
|
||||
&weechat_python_command_cb, NULL);
|
||||
|
||||
weechat_mkdir_home ("python", 0644);
|
||||
weechat_mkdir_home ("python/autoload", 0644);
|
||||
|
||||
weechat_hook_signal ("dump_data", &weechat_python_dump_data_cb, NULL);
|
||||
|
||||
script_init (weechat_python_plugin);
|
||||
script_auto_load (weechat_python_plugin, "python", &weechat_python_load_cb);
|
||||
script_init (weechat_python_plugin,
|
||||
&weechat_python_command_cb, &weechat_python_dump_data_cb,
|
||||
&weechat_python_load_cb);
|
||||
|
||||
/* init ok */
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
@@ -21,16 +21,6 @@
|
||||
#undef _
|
||||
|
||||
#include <ruby.h>
|
||||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
//#include <string.h>
|
||||
//#include <stdarg.h>
|
||||
//#include <time.h>
|
||||
//#include <sys/socket.h>
|
||||
//#include <netinet/in.h>
|
||||
//#include <arpa/inet.h>
|
||||
//#include <sys/types.h>
|
||||
//#include <sys/stat.h>
|
||||
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../script.h"
|
||||
|
||||
@@ -21,14 +21,7 @@
|
||||
#undef _
|
||||
|
||||
#include <ruby.h>
|
||||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
//#include <string.h>
|
||||
#include <stdarg.h>
|
||||
//#include <time.h>
|
||||
//#include <sys/socket.h>
|
||||
//#include <netinet/in.h>
|
||||
//#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
@@ -239,7 +232,7 @@ weechat_ruby_output (VALUE self, VALUE str)
|
||||
if (strlen (m) + strlen (ruby_buffer_output) > 0)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: stdout/stderr : %s%s"),
|
||||
weechat_gettext ("%s%s: stdout/stderr: %s%s"),
|
||||
weechat_prefix ("error"), "ruby",
|
||||
ruby_buffer_output, m);
|
||||
}
|
||||
@@ -251,7 +244,7 @@ weechat_ruby_output (VALUE self, VALUE str)
|
||||
if (strlen(m) + strlen(ruby_buffer_output) > sizeof(ruby_buffer_output))
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: stdout/stderr : %s%s"),
|
||||
weechat_gettext ("%s%s: stdout/stderr: %s%s"),
|
||||
weechat_prefix ("error"), "ruby",
|
||||
ruby_buffer_output, m);
|
||||
ruby_buffer_output[0] = '\0';
|
||||
@@ -344,8 +337,8 @@ weechat_ruby_load (char *filename)
|
||||
break;
|
||||
case 3:
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to find "
|
||||
"\"weechat_init\" function "
|
||||
weechat_gettext ("%s%s: function "
|
||||
"\"weechat_init\" is missing "
|
||||
"in file \"%s\""),
|
||||
weechat_prefix ("error"), "ruby", filename);
|
||||
break;
|
||||
@@ -366,12 +359,13 @@ weechat_ruby_load (char *filename)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ruby_retcode = rb_protect_funcall (curModule, rb_intern("weechat_init"), &ruby_error, 0);
|
||||
ruby_retcode = rb_protect_funcall (curModule, rb_intern("weechat_init"),
|
||||
&ruby_error, 0);
|
||||
|
||||
if (ruby_error)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to eval "
|
||||
weechat_gettext ("%s%s: unable to eval function "
|
||||
"\"weechat_init\" in file \"%s\""),
|
||||
weechat_prefix ("error"), "ruby", filename);
|
||||
|
||||
@@ -493,11 +487,7 @@ int
|
||||
weechat_ruby_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
//int handler_found, modifier_found;
|
||||
char *path_script;
|
||||
struct t_plugin_script *ptr_script;
|
||||
//t_plugin_handler *ptr_handler;
|
||||
//t_plugin_modifier *ptr_modifier;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -505,164 +495,29 @@ weechat_ruby_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
/* list registered Ruby scripts */
|
||||
weechat_printf (NULL, "");
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("Registered %s scripts:"),
|
||||
"ruby");
|
||||
if (ruby_scripts)
|
||||
{
|
||||
for (ptr_script = ruby_scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext (" %s v%s (%s), by %s, "
|
||||
"license %s"),
|
||||
ptr_script->name,
|
||||
ptr_script->version,
|
||||
ptr_script->description,
|
||||
ptr_script->author,
|
||||
ptr_script->license);
|
||||
}
|
||||
}
|
||||
else
|
||||
weechat_printf (NULL, weechat_gettext (" (none)"));
|
||||
|
||||
/*
|
||||
// list Ruby message handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " IRC(%s) => Ruby(%s)",
|
||||
ptr_handler->irc_command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Ruby command handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " /%s => Ruby(%s)",
|
||||
ptr_handler->command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Ruby timer handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby timer handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_TIMER)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %d seconds => Ruby(%s)",
|
||||
ptr_handler->interval,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Ruby keyboard handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby keyboard handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " Ruby(%s)",
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Ruby event handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby event handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_EVENT)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %s => Ruby(%s)",
|
||||
ptr_handler->event,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Ruby modifiers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby modifiers:");
|
||||
modifier_found = 0;
|
||||
for (ptr_modifier = plugin->modifiers;
|
||||
ptr_modifier; ptr_modifier = ptr_modifier->next_modifier)
|
||||
{
|
||||
modifier_found = 1;
|
||||
if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_IN)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Ruby(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_IN_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_USER)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Ruby(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_USER_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_OUT)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Ruby(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_OUT_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
}
|
||||
if (!modifier_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
*/
|
||||
script_display_list (weechat_ruby_plugin, ruby_scripts,
|
||||
NULL, 0);
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
if (weechat_strcasecmp (argv[1], "list") == 0)
|
||||
{
|
||||
script_auto_load (weechat_ruby_plugin,
|
||||
"ruby", &weechat_ruby_load_cb);
|
||||
script_display_list (weechat_ruby_plugin, ruby_scripts,
|
||||
NULL, 0);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "listfull") == 0)
|
||||
{
|
||||
script_display_list (weechat_ruby_plugin, ruby_scripts,
|
||||
NULL, 1);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
{
|
||||
script_auto_load (weechat_ruby_plugin, &weechat_ruby_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "reload") == 0)
|
||||
{
|
||||
weechat_ruby_unload_all ();
|
||||
script_auto_load (weechat_ruby_plugin,
|
||||
"ruby", &weechat_ruby_load_cb);
|
||||
script_auto_load (weechat_ruby_plugin, &weechat_ruby_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "unload") == 0)
|
||||
{
|
||||
@@ -671,11 +526,21 @@ weechat_ruby_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "load") == 0)
|
||||
if (weechat_strcasecmp (argv[1], "list") == 0)
|
||||
{
|
||||
script_display_list (weechat_ruby_plugin, ruby_scripts,
|
||||
argv_eol[2], 0);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "listfull") == 0)
|
||||
{
|
||||
script_display_list (weechat_ruby_plugin, ruby_scripts,
|
||||
argv_eol[2], 1);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "load") == 0)
|
||||
{
|
||||
/* load Ruby script */
|
||||
path_script = script_search_full_name (weechat_ruby_plugin,
|
||||
"ruby", argv_eol[2]);
|
||||
argv_eol[2]);
|
||||
weechat_ruby_load ((path_script) ? path_script : argv_eol[2]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
@@ -793,7 +658,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
VALUE ruby_error_info = rb_inspect(ruby_errinfo);
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to eval weechat ruby "
|
||||
weechat_gettext ("%s%s: unable to eval WeeChat ruby "
|
||||
"internal code"),
|
||||
weechat_prefix ("error"), "ruby");
|
||||
weechat_printf (NULL,
|
||||
@@ -803,25 +668,9 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
weechat_hook_command ("ruby",
|
||||
weechat_gettext ("list/load/unload Ruby scripts"),
|
||||
weechat_gettext ("[load filename] | [autoload] | "
|
||||
"[reload] | [unload [script]]"),
|
||||
weechat_gettext ("filename: Ruby script (file) to "
|
||||
"load\n"
|
||||
"script: script name to unload\n\n"
|
||||
"Without argument, /ruby command "
|
||||
"lists all loaded Ruby scripts."),
|
||||
"load|autoload|reload|unload %f",
|
||||
&weechat_ruby_command_cb, NULL);
|
||||
|
||||
weechat_mkdir_home ("ruby", 0644);
|
||||
weechat_mkdir_home ("ruby/autoload", 0644);
|
||||
|
||||
weechat_hook_signal ("dump_data", &weechat_ruby_dump_data_cb, NULL);
|
||||
|
||||
script_init (weechat_ruby_plugin);
|
||||
script_auto_load (weechat_ruby_plugin, "ruby", &weechat_ruby_load_cb);
|
||||
script_init (weechat_ruby_plugin,
|
||||
&weechat_ruby_command_cb, &weechat_ruby_dump_data_cb,
|
||||
&weechat_ruby_load_cb);
|
||||
|
||||
/* init ok */
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
+107
-16
@@ -80,9 +80,17 @@ script_config_cb (void *data, char *type, char *option, char *value)
|
||||
*/
|
||||
|
||||
void
|
||||
script_init (struct t_weechat_plugin *weechat_plugin)
|
||||
script_init (struct t_weechat_plugin *weechat_plugin,
|
||||
int (*callback_command)(void *data,
|
||||
struct t_gui_buffer *buffer,
|
||||
int argc, char **argv,
|
||||
char **argv_eol),
|
||||
int (*callback_signal_dump)(void *data, char *signal,
|
||||
char *type_data,
|
||||
void *signal_data),
|
||||
int (*callback_load_file)(void *data, char *filename))
|
||||
{
|
||||
char *option;
|
||||
char *string;
|
||||
int length;
|
||||
|
||||
/* read script configuration */
|
||||
@@ -90,14 +98,45 @@ script_init (struct t_weechat_plugin *weechat_plugin)
|
||||
|
||||
/* add hook for config option */
|
||||
length = strlen (weechat_plugin->name) + 32;
|
||||
option= (char *)malloc (length);
|
||||
if (option)
|
||||
string = (char *)malloc (length);
|
||||
if (string)
|
||||
{
|
||||
snprintf (option, length - 1, "%s.%s",
|
||||
snprintf (string, length, "%s.%s",
|
||||
weechat_plugin->name, SCRIPT_OPTION_CHECK_LICENSE);
|
||||
weechat_hook_config ("plugin", option,
|
||||
weechat_hook_config ("plugin", string,
|
||||
&script_config_cb, weechat_plugin);
|
||||
free (string);
|
||||
}
|
||||
|
||||
/* create directories in WeeChat home */
|
||||
weechat_mkdir_home (weechat_plugin->name, 0644);
|
||||
length = strlen (weechat_plugin->name) + strlen ("/autoload") + 1;
|
||||
string = (char *)malloc (length);
|
||||
if (string)
|
||||
{
|
||||
snprintf (string, length, "%s/autoload", weechat_plugin->name);
|
||||
weechat_mkdir_home (string, 0644);
|
||||
free (string);
|
||||
}
|
||||
|
||||
/* add command */
|
||||
weechat_hook_command (weechat_plugin->name,
|
||||
_("list/load/unload scripts"),
|
||||
_("[list [name]] | [listfull [name]] "
|
||||
"[load filename] | [autoload] | "
|
||||
"[reload] | [unload [name]]"),
|
||||
_("filename: script (file) to load\n"
|
||||
"name: a script name\n\n"
|
||||
"Without argument, this command "
|
||||
"lists all loaded scripts."),
|
||||
"list|listfull|load|autoload|reload|unload %f",
|
||||
callback_command, NULL);
|
||||
|
||||
/* add signal for "dump_data" */
|
||||
weechat_hook_signal ("dump_data", callback_signal_dump, NULL);
|
||||
|
||||
/* autoload scripts */
|
||||
script_auto_load (weechat_plugin, callback_load_file);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -144,7 +183,7 @@ script_string_to_pointer (char *pointer_str)
|
||||
|
||||
void
|
||||
script_auto_load (struct t_weechat_plugin *weechat_plugin,
|
||||
char *language, int (*callback)(void *data, char *filename))
|
||||
int (*callback)(void *data, char *filename))
|
||||
{
|
||||
char *dir_home, *dir_name;
|
||||
int dir_length;
|
||||
@@ -153,12 +192,13 @@ script_auto_load (struct t_weechat_plugin *weechat_plugin,
|
||||
dir_home = weechat_info_get ("weechat_dir");
|
||||
if (!dir_home)
|
||||
return;
|
||||
dir_length = strlen (dir_home) + strlen (language) + 16;
|
||||
dir_length = strlen (dir_home) + strlen (weechat_plugin->name) + 16;
|
||||
dir_name = (char *)malloc (dir_length * sizeof (char));
|
||||
if (!dir_name)
|
||||
return;
|
||||
|
||||
snprintf (dir_name, dir_length, "%s/%s/autoload", dir_home, language);
|
||||
snprintf (dir_name, dir_length,
|
||||
"%s/%s/autoload", dir_home, weechat_plugin->name);
|
||||
weechat_exec_on_files (dir_name, NULL, callback);
|
||||
|
||||
free (dir_name);
|
||||
@@ -191,7 +231,7 @@ script_search (struct t_weechat_plugin *weechat_plugin,
|
||||
|
||||
char *
|
||||
script_search_full_name (struct t_weechat_plugin *weechat_plugin,
|
||||
char *language, char *filename)
|
||||
char *filename)
|
||||
{
|
||||
char *final_name, *dir_home, *dir_system;
|
||||
int length;
|
||||
@@ -216,24 +256,27 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
|
||||
if (dir_home)
|
||||
{
|
||||
/* try WeeChat user's autoload dir */
|
||||
length = strlen (dir_home) + strlen (language) + 8 + strlen (filename) + 16;
|
||||
length = strlen (dir_home) + strlen (weechat_plugin->name) + 8 +
|
||||
strlen (filename) + 16;
|
||||
final_name = (char *)malloc (length);
|
||||
if (final_name)
|
||||
{
|
||||
snprintf (final_name, length,
|
||||
"%s/%s/autoload/%s", dir_home, language, filename);
|
||||
"%s/%s/autoload/%s",
|
||||
dir_home, weechat_plugin->name, filename);
|
||||
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
|
||||
return final_name;
|
||||
free (final_name);
|
||||
}
|
||||
|
||||
/* try WeeChat language user's dir */
|
||||
length = strlen (dir_home) + strlen (language) + strlen (filename) + 16;
|
||||
length = strlen (dir_home) + strlen (weechat_plugin->name) +
|
||||
strlen (filename) + 16;
|
||||
final_name = (char *)malloc (length);
|
||||
if (final_name)
|
||||
{
|
||||
snprintf (final_name, length,
|
||||
"%s/%s/%s", dir_home, language, filename);
|
||||
"%s/%s/%s", dir_home, weechat_plugin->name, filename);
|
||||
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
|
||||
return final_name;
|
||||
free (final_name);
|
||||
@@ -256,12 +299,13 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
|
||||
dir_system = weechat_info_get ("weechat_sharedir");
|
||||
if (dir_system)
|
||||
{
|
||||
length = strlen (dir_system) + strlen (dir_system) + strlen (filename) + 16;
|
||||
length = strlen (dir_system) + strlen (weechat_plugin->name) +
|
||||
strlen (filename) + 16;
|
||||
final_name = (char *)malloc (length);
|
||||
if (final_name)
|
||||
{
|
||||
snprintf (final_name,length,
|
||||
"%s/%s/%s", dir_system, language, filename);
|
||||
"%s/%s/%s", dir_system, weechat_plugin->name, filename);
|
||||
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
|
||||
return final_name;
|
||||
free (final_name);
|
||||
@@ -375,6 +419,53 @@ script_remove (struct t_weechat_plugin *weechat_plugin,
|
||||
free (script);
|
||||
}
|
||||
|
||||
/*
|
||||
* script_display_list: print list of scripts
|
||||
*/
|
||||
|
||||
void
|
||||
script_display_list (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *scripts,
|
||||
char *name, int full)
|
||||
{
|
||||
struct t_plugin_script *ptr_script;
|
||||
|
||||
weechat_printf (NULL, "");
|
||||
weechat_printf (NULL,
|
||||
/* TRANSLATORS: %s is language (for example "perl") */
|
||||
_("%s scripts loaded:"),
|
||||
weechat_plugin->name);
|
||||
if (scripts)
|
||||
{
|
||||
for (ptr_script = scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
if (!name || (weechat_strcasestr (ptr_script->name, name)))
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
" %s%s%s v%s - %s",
|
||||
weechat_color ("color_chat_buffer"),
|
||||
ptr_script->name,
|
||||
weechat_color ("color_chat"),
|
||||
ptr_script->version,
|
||||
ptr_script->description);
|
||||
if (full)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_(" file: %s"),
|
||||
ptr_script->filename);
|
||||
weechat_printf (NULL,
|
||||
_(" written by \"%s\", license: %s"),
|
||||
ptr_script->author,
|
||||
ptr_script->license);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
weechat_printf (NULL, _(" (none)"));
|
||||
}
|
||||
|
||||
/*
|
||||
* script_print_log: print script infos in log (usually for crash dump)
|
||||
*/
|
||||
|
||||
@@ -56,17 +56,24 @@ struct t_plugin_script
|
||||
struct t_plugin_script *next_script; /* link to next script */
|
||||
};
|
||||
|
||||
extern void script_init (struct t_weechat_plugin *weechat_plugin);
|
||||
extern void script_init (struct t_weechat_plugin *weechat_plugin,
|
||||
int (*callback_command)(void *data,
|
||||
struct t_gui_buffer *buffer,
|
||||
int argc, char **argv,
|
||||
char **argv_eol),
|
||||
int (*callback_signal_dump)(void *data, char *signal,
|
||||
char *type_data,
|
||||
void *signal_data),
|
||||
int (*callback_load_file)(void *data, char *filename));
|
||||
extern char *script_pointer_to_string (void *pointer);
|
||||
extern void *script_string_to_pointer (char *pointer_str);
|
||||
extern void script_auto_load (struct t_weechat_plugin *weechat_plugin,
|
||||
char *language,
|
||||
int (*callback)(void *data, char *filename));
|
||||
extern struct t_plugin_script *script_search (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *scripts,
|
||||
char *name);
|
||||
extern char *script_search_full_name (struct t_weechat_plugin *weechat_plugin,
|
||||
char *language, char *filename);
|
||||
char *filename);
|
||||
extern struct t_plugin_script *script_add (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script **scripts,
|
||||
char *filename, char *name,
|
||||
@@ -76,6 +83,9 @@ extern struct t_plugin_script *script_add (struct t_weechat_plugin *weechat_plug
|
||||
extern void script_remove (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script **scripts,
|
||||
struct t_plugin_script *script);
|
||||
extern void script_display_list (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *scripts,
|
||||
char *name, int full);
|
||||
extern void script_print_log (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *scripts);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user