summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Makefile.am9
-rw-r--r--src/plugins/plugins.c116
-rw-r--r--src/plugins/plugins.h4
-rw-r--r--src/plugins/python/wee-python.c1
-rw-r--r--src/plugins/ruby/Makefile.am23
-rw-r--r--src/plugins/ruby/wee-ruby.c607
-rw-r--r--src/plugins/ruby/wee-ruby.h34
7 files changed, 751 insertions, 43 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index b52375faf..002747671 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -25,12 +25,11 @@ if PLUGIN_PYTHON
python_dir = python
endif
-# if PLUGIN_RUBY
-# ruby_dir = ruby
-# endif
+if PLUGIN_RUBY
+ruby_dir = ruby
+endif
-# SUBDIRS = $(perl_dir) $(python_dir) $(ruby_dir)
-SUBDIRS = $(perl_dir) $(python_dir)
+SUBDIRS = $(perl_dir) $(python_dir) $(ruby_dir)
noinst_LIBRARIES = lib_weechat_plugins.a
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c
index 7a7f194d7..089b34191 100644
--- a/src/plugins/plugins.c
+++ b/src/plugins/plugins.c
@@ -43,6 +43,10 @@
#include "python/wee-python.h"
#endif
+#ifdef PLUGIN_RUBY
+#include "ruby/wee-ruby.h"
+#endif
+
char *plugin_name[3] = { "Perl", "Python", "Ruby" };
@@ -115,15 +119,20 @@ plugin_auto_load (int plugin_type, char *directory)
void
plugin_init ()
{
- #ifdef PLUGIN_PERL
+#ifdef PLUGIN_PERL
wee_perl_init();
plugin_auto_load (PLUGIN_TYPE_PERL, "perl/autoload");
- #endif
+#endif
- #ifdef PLUGIN_PYTHON
+#ifdef PLUGIN_PYTHON
wee_python_init();
plugin_auto_load (PLUGIN_TYPE_PYTHON, "python/autoload");
- #endif
+#endif
+
+#ifdef PLUGIN_RUBY
+ wee_ruby_init();
+ plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload");
+#endif
}
/*
@@ -133,28 +142,30 @@ plugin_init ()
void
plugin_load (int plugin_type, char *filename)
{
- #ifdef PLUGINS
+#ifdef PLUGINS
switch (plugin_type)
{
case PLUGIN_TYPE_PERL:
- #ifdef PLUGIN_PERL
+#ifdef PLUGIN_PERL
wee_perl_load (filename);
- #endif
+#endif
break;
case PLUGIN_TYPE_PYTHON:
- #ifdef PLUGIN_PYTHON
+#ifdef PLUGIN_PYTHON
wee_python_load (filename);
- #endif
+#endif
break;
case PLUGIN_TYPE_RUBY:
- /* TODO: load Ruby script */
+#ifdef PLUGIN_RUBY
+ wee_ruby_load (filename);
+#endif
break;
}
- #else
+#else
/* make gcc happy */
(void) plugin_type;
(void) filename;
- #endif
+#endif /* PLUGINS */
}
/*
@@ -292,7 +303,7 @@ plugin_handler_free_all_type (t_plugin_handler **plugin_handlers,
void
plugin_event_msg (char *irc_command, char *server, char *arguments)
{
- #ifdef PLUGINS
+#ifdef PLUGINS
t_plugin_handler *ptr_plugin_handler;
for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler;
@@ -300,7 +311,7 @@ plugin_event_msg (char *irc_command, char *server, char *arguments)
{
if (strcasecmp (ptr_plugin_handler->name, irc_command) == 0)
{
- #ifdef PLUGIN_PERL
+#ifdef PLUGIN_PERL
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
{
if (ptr_plugin_handler->running == 0)
@@ -310,8 +321,8 @@ plugin_event_msg (char *irc_command, char *server, char *arguments)
ptr_plugin_handler->running = 0;
}
}
- #endif
- #ifdef PLUGIN_PYTHON
+#endif
+#ifdef PLUGIN_PYTHON
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON)
{
if (ptr_plugin_handler->running == 0)
@@ -321,15 +332,26 @@ plugin_event_msg (char *irc_command, char *server, char *arguments)
ptr_plugin_handler->running = 0;
}
}
- #endif
+#endif
+#ifdef PLUGIN_RUBY
+ if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_RUBY)
+ {
+ if (ptr_plugin_handler->running == 0)
+ {
+ ptr_plugin_handler->running = 1;
+ wee_ruby_exec (ptr_plugin_handler->function_name, server, arguments);
+ ptr_plugin_handler->running = 0;
+ }
+ }
+#endif
}
}
- #else
+#else
/* make gcc happy */
(void) irc_command;
(void) arguments;
(void) server;
- #endif
+#endif /* PLUGINS */
}
/*
@@ -339,7 +361,7 @@ plugin_event_msg (char *irc_command, char *server, char *arguments)
int
plugin_exec_command (char *user_command, char *server, char *arguments)
{
- #ifdef PLUGINS
+#ifdef PLUGINS
t_plugin_handler *ptr_plugin_handler;
for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler;
@@ -347,7 +369,7 @@ plugin_exec_command (char *user_command, char *server, char *arguments)
{
if (strcasecmp (ptr_plugin_handler->name, user_command) == 0)
{
- #ifdef PLUGIN_PERL
+#ifdef PLUGIN_PERL
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PERL)
{
if (ptr_plugin_handler->running == 0)
@@ -357,8 +379,8 @@ plugin_exec_command (char *user_command, char *server, char *arguments)
ptr_plugin_handler->running = 0;
}
}
- #endif
- #ifdef PLUGIN_PYTHON
+#endif
+#ifdef PLUGIN_PYTHON
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON)
{
if (ptr_plugin_handler->running == 0)
@@ -368,18 +390,29 @@ plugin_exec_command (char *user_command, char *server, char *arguments)
ptr_plugin_handler->running = 0;
}
}
- #endif
+#endif
+#ifdef PLUGIN_RUBY
+ if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_RUBY)
+ {
+ if (ptr_plugin_handler->running == 0)
+ {
+ ptr_plugin_handler->running = 1;
+ wee_ruby_exec (ptr_plugin_handler->function_name, server, arguments);
+ ptr_plugin_handler->running = 0;
+ }
+ }
+#endif
/* command executed */
return 1;
}
}
- #else
+#else
/* make gcc happy */
(void) user_command;
(void) arguments;
(void) server;
- #endif
+#endif /* PLUGINS */
/* no command executed */
return 0;
@@ -453,30 +486,33 @@ plugin_unload (int plugin_type, char *scriptname)
/* make gcc happy */
(void) scriptname;
- #ifdef PLUGINS
+#ifdef PLUGINS
switch (plugin_type)
{
case PLUGIN_TYPE_PERL:
- #ifdef PLUGIN_PERL
+#ifdef PLUGIN_PERL
/* unload one Perl script is not allowed */
wee_perl_end ();
wee_perl_init ();
- #endif
+#endif
break;
case PLUGIN_TYPE_PYTHON:
- #ifdef PLUGIN_PYTHON
+#ifdef PLUGIN_PYTHON
wee_python_end ();
wee_python_init ();
- #endif
+#endif
break;
case PLUGIN_TYPE_RUBY:
- /* TODO: unload Ruby scripts */
+#ifdef PLUGIN_RUBY
+ wee_ruby_end ();
+ wee_ruby_init ();
+#endif
break;
}
- #else
+#else
/* make gcc happy */
(void) plugin_type;
- #endif
+#endif /* PLUGINS */
}
/*
@@ -489,11 +525,15 @@ plugin_end ()
plugin_handler_free_all (&plugin_msg_handlers, &last_plugin_msg_handler);
plugin_handler_free_all (&plugin_cmd_handlers, &last_plugin_cmd_handler);
- #ifdef PLUGIN_PERL
+#ifdef PLUGIN_PERL
wee_perl_end();
- #endif
+#endif
- #ifdef PLUGIN_PYTHON
+#ifdef PLUGIN_PYTHON
wee_python_end();
- #endif
+#endif
+
+#ifdef PLUGIN_RUBY
+ wee_ruby_end();
+#endif
}
diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h
index 3a5bc64b5..c729d0480 100644
--- a/src/plugins/plugins.h
+++ b/src/plugins/plugins.h
@@ -67,6 +67,10 @@ extern t_plugin_script *perl_scripts;
extern t_plugin_script *python_scripts;
#endif
+#ifdef PLUGIN_RUBY
+extern t_plugin_script *ruby_scripts;
+#endif
+
extern void plugin_auto_load (int, char *);
extern void plugin_init ();
extern void plugin_load (int, char *);
diff --git a/src/plugins/python/wee-python.c b/src/plugins/python/wee-python.c
index 8b3f9927a..d1fd2d901 100644
--- a/src/plugins/python/wee-python.c
+++ b/src/plugins/python/wee-python.c
@@ -330,6 +330,7 @@ wee_python_get_info (PyObject *self, PyObject *args)
gui_printf (NULL,
_("%s error: server not found for \"%s\" function\n"),
"Python", "get_info");
+ return NULL;
}
}
diff --git a/src/plugins/ruby/Makefile.am b/src/plugins/ruby/Makefile.am
new file mode 100644
index 000000000..6fe8f4560
--- /dev/null
+++ b/src/plugins/ruby/Makefile.am
@@ -0,0 +1,23 @@
+# Copyright (c) 2003-2005 FlashCode <flashcode@flashtux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(RUBY_CFLAGS)
+
+noinst_LIBRARIES = lib_weechat_ruby.a
+
+lib_weechat_ruby_a_SOURCES = wee-ruby.h \
+ wee-ruby.c
diff --git a/src/plugins/ruby/wee-ruby.c b/src/plugins/ruby/wee-ruby.c
new file mode 100644
index 000000000..449b9b003
--- /dev/null
+++ b/src/plugins/ruby/wee-ruby.c
@@ -0,0 +1,607 @@
+/*
+ * Copyright (c) 2003-2005 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* wee-ruby.c: Ruby plugin support for WeeChat */
+
+
+#include <ruby.h>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#undef _
+#include "../../common/weechat.h"
+#include "../plugins.h"
+#include "wee-ruby.h"
+#include "../../common/command.h"
+#include "../../irc/irc.h"
+#include "../../gui/gui.h"
+
+
+t_plugin_script *ruby_scripts = NULL;
+t_plugin_script *last_ruby_script = NULL;
+
+
+/*
+ * register: startup function for all WeeChat Ruby scripts
+ */
+
+static VALUE
+wee_ruby_register (VALUE class, VALUE name, VALUE version, VALUE shutdown_func, VALUE description)
+{
+ char *c_name, *c_version, *c_shutdown_func, *c_description;
+ t_plugin_script *ptr_ruby_script, *ruby_script_found, *new_ruby_script;
+
+ if (NIL_P (name) || NIL_P (version) || NIL_P (shutdown_func) || NIL_P (description))
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: wrong parameters for \"%s\" function\n"),
+ "Ruby", "register");
+ return Qnil;
+ }
+
+ Check_Type (name, T_STRING);
+ Check_Type (version, T_STRING);
+ Check_Type (shutdown_func, T_STRING);
+ Check_Type (description, T_STRING);
+
+ c_name = STR2CSTR (name);
+ c_version = STR2CSTR (version);
+ c_shutdown_func = STR2CSTR (shutdown_func);
+ c_description = STR2CSTR (description);
+
+ ruby_script_found = NULL;
+ for (ptr_ruby_script = ruby_scripts; ptr_ruby_script;
+ ptr_ruby_script = ptr_ruby_script->next_script)
+ {
+ if (strcasecmp (ptr_ruby_script->name, c_name) == 0)
+ {
+ ruby_script_found = ptr_ruby_script;
+ break;
+ }
+ }
+
+ if (ruby_script_found)
+ {
+ /* error: another script already exists with this name! */
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: unable to register \"%s\" script (another script "
+ "already exists with this name)\n"),
+ "Ruby", name);
+ }
+ else
+ {
+ /* registering script */
+ new_ruby_script = (t_plugin_script *)malloc (sizeof (t_plugin_script));
+ if (new_ruby_script)
+ {
+ new_ruby_script->name = strdup (c_name);
+ new_ruby_script->version = strdup (c_version);
+ new_ruby_script->shutdown_func = strdup (c_shutdown_func);
+ new_ruby_script->description = strdup (c_description);
+
+ /* add new script to list */
+ new_ruby_script->prev_script = last_ruby_script;
+ new_ruby_script->next_script = NULL;
+ if (ruby_scripts)
+ last_ruby_script->next_script = new_ruby_script;
+ else
+ ruby_scripts = new_ruby_script;
+ last_ruby_script = new_ruby_script;
+
+ wee_log_printf (_("Registered %s script: \"%s\", version %s (%s)\n"),
+ "Ruby", c_name, c_version, c_description);
+ }
+ else
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: unable to load script \"%s\" (not enough memory)\n"),
+ "Ruby", c_name);
+ }
+ }
+
+ return Qnil;
+}
+
+/*
+ * print: print message into a buffer (current or specified one)
+ */
+
+static VALUE
+wee_ruby_print (VALUE class, VALUE message, VALUE channel_name, VALUE server_name)
+{
+ char *c_message, *c_channel_name, *c_server_name;
+ t_gui_buffer *ptr_buffer;
+
+ c_message = NULL;
+ c_channel_name = NULL;
+ c_server_name = NULL;
+
+ if (NIL_P (message))
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: wrong parameters for \"%s\" function\n"),
+ "Ruby", "print");
+ return Qnil;
+ }
+
+ Check_Type (message, T_STRING);
+ if (!NIL_P (channel_name))
+ Check_Type (channel_name, T_STRING);
+ if (!NIL_P (server_name))
+ Check_Type (server_name, T_STRING);
+
+ c_message = STR2CSTR (message);
+ if (!NIL_P (channel_name))
+ c_channel_name = STR2CSTR (channel_name);
+ if (!NIL_P (server_name))
+ c_server_name = STR2CSTR (server_name);
+
+ ptr_buffer = plugin_find_buffer (c_server_name, c_channel_name);
+ if (ptr_buffer)
+ {
+ irc_display_prefix (ptr_buffer, PREFIX_PLUGIN);
+ gui_printf (ptr_buffer, "%s\n", c_message);
+ return INT2FIX (1);
+ }
+
+ /* buffer not found */
+ return INT2FIX (0);
+}
+
+/*
+ * print_infobar: print message to infobar
+ */
+
+static VALUE
+wee_ruby_print_infobar (VALUE class, VALUE delay, VALUE message)
+{
+ int c_delay;
+ char *c_message;
+
+ c_delay = 1;
+ c_message = NULL;
+
+ if (NIL_P (delay) || NIL_P (message))
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: wrong parameters for \"%s\" function\n"),
+ "Ruby", "print_infobar");
+ return Qfalse;
+ }
+
+ Check_Type (delay, T_FIXNUM);
+ Check_Type (message, T_STRING);
+
+ c_delay = FIX2INT (delay);
+ c_message = STR2CSTR (message);
+
+ gui_infobar_printf (delay, COLOR_WIN_INFOBAR, c_message);
+
+ return Qtrue;
+}
+
+/*
+ * command: send command to server
+ */
+
+static VALUE
+wee_ruby_command (VALUE class, VALUE command, VALUE channel_name, VALUE server_name)
+{
+ char *c_command, *c_channel_name, *c_server_name;
+ t_gui_buffer *ptr_buffer;
+
+ c_command = NULL;
+ c_channel_name = NULL;
+ c_server_name = NULL;
+
+ if (NIL_P (command))
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: wrong parameters for \"%s\" function\n"),
+ "Ruby", "command");
+ return Qnil;
+ }
+
+ Check_Type (command, T_STRING);
+ if (!NIL_P (channel_name))
+ Check_Type (channel_name, T_STRING);
+ if (!NIL_P (server_name))
+ Check_Type (server_name, T_STRING);
+
+ c_command = STR2CSTR (command);
+ if (!NIL_P (channel_name))
+ c_channel_name = STR2CSTR (channel_name);
+ if (!NIL_P (server_name))
+ c_server_name = STR2CSTR (server_name);
+
+ ptr_buffer = plugin_find_buffer (c_server_name, c_channel_name);
+ if (ptr_buffer)
+ {
+ user_command (SERVER(ptr_buffer), ptr_buffer, c_command);
+ return INT2FIX (1);
+ }
+
+ /* buffer not found */
+ return INT2FIX (0);
+}
+
+/*
+ * add_message_handler: add handler for messages
+ */
+
+static VALUE
+wee_ruby_add_message_handler (VALUE class, VALUE message, VALUE function)
+{
+ char *c_message, *c_function;
+
+ if (NIL_P (message) || NIL_P (function))
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: wrong parameters for \"%s\" function\n"),
+ "Ruby", "add_message_handler");
+ return Qnil;
+ }
+
+ Check_Type (message, T_STRING);
+ Check_Type (function, T_STRING);
+
+ c_message = STR2CSTR (message);
+ c_function = STR2CSTR (function);
+
+ plugin_handler_add (&plugin_msg_handlers, &last_plugin_msg_handler,
+ PLUGIN_TYPE_RUBY, c_message, c_function);
+
+ return Qtrue;
+}
+
+/*
+ * add_command_handler: define/redefines commands
+ */
+
+static VALUE
+wee_ruby_add_command_handler (VALUE class, VALUE name, VALUE function)
+{
+ char *c_name, *c_function;
+ t_plugin_handler *ptr_plugin_handler;
+
+ if (NIL_P (name) || NIL_P (function))
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: wrong parameters for \"%s\" function\n"),
+ "Ruby", "add_command_handler");
+ return Qnil;
+ }
+
+ Check_Type (name, T_STRING);
+ Check_Type (function, T_STRING);
+
+ c_name = STR2CSTR (name);
+ c_function = STR2CSTR (function);
+
+ if (!weelist_search (index_commands, c_name))
+ weelist_add (&index_commands, &last_index_command, c_name);
+
+ ptr_plugin_handler = plugin_handler_search (plugin_cmd_handlers, c_name);
+ if (ptr_plugin_handler)
+ {
+ free (ptr_plugin_handler->function_name);
+ ptr_plugin_handler->function_name = strdup (c_function);
+ }
+ else
+ plugin_handler_add (&plugin_cmd_handlers, &last_plugin_cmd_handler,
+ PLUGIN_TYPE_PYTHON, c_name, c_function);
+
+ return Qtrue;
+}
+
+/*
+ * get_info: get various infos
+ */
+
+static VALUE
+wee_ruby_get_info (VALUE class, VALUE arg, VALUE server_name)
+{
+ char *c_arg, *info, *c_server_name;
+ t_irc_server *ptr_server;
+
+ if (NIL_P (arg))
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: wrong parameters for \"%s\" function\n"),
+ "Ruby", "get_info");
+ return Qnil;
+ }
+
+ Check_Type (arg, T_STRING);
+ if (!NIL_P (server_name))
+ Check_Type (server_name, T_STRING);
+
+ c_arg = STR2CSTR (arg);
+ if (!NIL_P (server_name))
+ c_server_name = STR2CSTR (server_name);
+
+ if (c_server_name == NULL)
+ {
+ ptr_server = SERVER(gui_current_window->buffer);
+ }
+ else
+ {
+ for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
+ {
+ if (strcasecmp (ptr_server->name, c_server_name) == 0)
+ break;
+ }
+ if (!ptr_server)
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: server not found for \"%s\" function\n"),
+ "Ruby", "get_info");
+ return Qnil;
+ }
+ }
+
+ if (ptr_server && c_arg)
+ {
+ if ( (strcasecmp (c_arg, "0") == 0) || (strcasecmp (c_arg, "version") == 0) )
+ {
+ info = PACKAGE_STRING;
+ }
+ else if ( (strcasecmp (c_arg, "1") == 0) || (strcasecmp (c_arg, "nick") == 0) )
+ {
+ if (ptr_server->nick)
+ info = ptr_server->nick;
+ }
+ else if ( (strcasecmp (c_arg, "2") == 0) || (strcasecmp (c_arg, "channel") == 0) )
+ {
+ if (BUFFER_IS_CHANNEL (gui_current_window->buffer))
+ info = CHANNEL (gui_current_window->buffer)->name;
+ }
+ else if ( (strcasecmp (c_arg, "3") == 0) || (strcasecmp (c_arg, "server") == 0) )
+ {
+ if (ptr_server->name)
+ info = ptr_server->name;
+ }
+ else if ( (strcasecmp (c_arg, "4") == 0) || (strcasecmp (c_arg, "weechatdir") == 0) )
+ {
+ info = weechat_home;
+ }
+ else if ( (strcasecmp (c_arg, "5") == 0) || (strcasecmp (c_arg, "away") == 0) )
+ {
+ return INT2FIX (SERVER(gui_current_window->buffer)->is_away);
+ }
+ else if ( (strcasecmp (c_arg, "100") == 0) || (strcasecmp (c_arg, "dccs") == 0) )
+ {
+ /* TODO: build dcc list */
+ }
+
+ if (info)
+ return rb_str_new2 (info);
+ else
+ return rb_str_new2 ("");
+ }
+
+ return INT2FIX (1);
+}
+
+/*
+ * Ruby subroutines
+ */
+
+/*
+ * wee_ruby_init: initialize Ruby interface for WeeChat
+ */
+
+void
+wee_ruby_init ()
+{
+
+ /* TODO: init Ruby environment */
+ /* ruby_init ();
+ if ()
+ {
+ irc_display_prefix (NULL, PREFIX_PLUGIN);
+ gui_printf (NULL, _("%s error: error while launching interpreter\n"),
+ "Ruby");
+ }
+ else
+ {
+ wee_log_printf (_("Loading %s module \"weechat\"\n"), "Ruby");
+ }*/
+}
+
+/*
+ * wee_ruby_search: search a (loaded) Ruby script by name
+ */
+
+t_plugin_script *
+wee_ruby_search (char *name)
+{
+ t_plugin_script *ptr_ruby_script;
+
+ for (ptr_ruby_script = ruby_scripts; ptr_ruby_script;
+ ptr_ruby_script = ptr_ruby_script->next_script)
+ {
+ if (strcmp (ptr_ruby_script->name, name) == 0)
+ return ptr_ruby_script;
+ }
+
+ /* script not found */
+ return NULL;
+}
+
+/*
+ * wee_ruby_exec: execute a Ruby script
+ */
+
+int
+wee_ruby_exec (char *function, char *server, char *arguments)
+{
+ /* TODO: exec Ruby script */
+}
+
+/*
+ * wee_ruby_load: load a Ruby script
+ */
+
+int
+wee_ruby_load (char *filename)
+{
+ FILE *fp;
+
+ /* TODO: load & exec Ruby script */
+ gui_printf (NULL, "Ruby scripts not developed!\n");
+ /* execute Ruby script */
+ /*wee_log_printf (_("Loading %s script \"%s\"\n"), "Ruby", filename);
+ irc_display_prefix (NULL, PREFIX_PLUGIN);
+ gui_printf (NULL, _("Loading %s script \"%s\"\n"), "Ruby", filename);
+
+ if ((fp = fopen (filename, "r")) == NULL)
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: error while opening file \"%s\"\n"),
+ "Ruby", filename);
+ return 1;
+ }
+
+ if (xxxxxxx (fp, filename) != 0)
+ {
+ irc_display_prefix (NULL, PREFIX_ERROR);
+ gui_printf (NULL,
+ _("%s error: error while parsing file \"%s\"\n"),
+ "Ruby", filename);
+ return 1;
+ }
+
+ fclose (fp);
+ return 0;*/
+}
+
+/*
+ * wee_ruby_script_free: free a Ruby script
+ */
+
+void
+wee_ruby_script_free (t_plugin_script *ptr_ruby_script)
+{
+ t_plugin_script *new_ruby_scripts;
+
+ /* remove script from list */
+ if (last_ruby_script == ptr_ruby_script)
+ last_ruby_script = ptr_ruby_script->prev_script;
+ if (ptr_ruby_script->prev_script)
+ {
+ (ptr_ruby_script->prev_script)->next_script = ptr_ruby_script->next_script;
+ new_ruby_scripts = ruby_scripts;
+ }
+ else
+ new_ruby_scripts = ptr_ruby_script->next_script;
+
+ if (ptr_ruby_script->next_script)
+ (ptr_ruby_script->next_script)->prev_script = ptr_ruby_script->prev_script;
+
+ /* free data */
+ if (ptr_ruby_script->name)
+ free (ptr_ruby_script->name);
+ if (ptr_ruby_script->version)
+ free (ptr_ruby_script->version);
+ if (ptr_ruby_script->shutdown_func)
+ free (ptr_ruby_script->shutdown_func);
+ if (ptr_ruby_script->description)
+ free (ptr_ruby_script->description);
+ free (ptr_ruby_script);
+ ruby_scripts = new_ruby_scripts;
+}
+
+/*
+ * wee_ruby_unload: unload a Ruby script
+ */
+
+void
+wee_ruby_unload (t_plugin_script *ptr_ruby_script)
+{
+ if (ptr_ruby_script)
+ {
+ wee_log_printf (_("Unloading %s script \"%s\"\n"),
+ "Ruby", ptr_ruby_script->name);
+
+ /* call shutdown callback function */
+ if (ptr_ruby_script->shutdown_func[0])
+ wee_ruby_exec (ptr_ruby_script->shutdown_func, "", "");
+ wee_ruby_script_free (ptr_ruby_script);
+ }
+}
+
+/*
+ * wee_ruby_unload_all: unload all Ruby scripts
+ */
+
+void
+wee_ruby_unload_all ()
+{
+ wee_log_printf (_("Unloading all %s scripts...\n"), "Ruby");
+ while (ruby_scripts)
+ wee_ruby_unload (ruby_scripts);
+
+ irc_display_prefix (NULL, PREFIX_PLUGIN);
+ gui_printf (NULL, _("%s scripts unloaded\n"), "Ruby");
+}
+
+/*
+ * wee_ruby_end: shutdown Ruby interface
+ */
+
+void
+wee_ruby_end ()
+{
+ /* unload all scripts */
+ wee_ruby_unload_all ();
+
+ /* free all handlers */
+ plugin_handler_free_all_type (&plugin_msg_handlers,
+ &last_plugin_msg_handler,
+ PLUGIN_TYPE_RUBY);
+ plugin_handler_free_all_type (&plugin_cmd_handlers,
+ &last_plugin_cmd_handler,
+ PLUGIN_TYPE_RUBY);
+
+ /* TODO: free Ruby interpreter */
+ /* free Ruby interpreter */
+ /* xxxxx ();
+ if ()
+ {
+ irc_display_prefix (NULL, PREFIX_PLUGIN);
+ gui_printf (NULL, _("%s error: error while freeing interpreter\n"),
+ "Ruby");
+ }*/
+}
diff --git a/src/plugins/ruby/wee-ruby.h b/src/plugins/ruby/wee-ruby.h
new file mode 100644
index 000000000..3fdc9b932
--- /dev/null
+++ b/src/plugins/ruby/wee-ruby.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2003-2005 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef __WEECHAT_RUBY_H
+#define __WEECHAT_RUBY_H 1
+
+#include "../plugins.h"
+
+extern void wee_ruby_init ();
+extern t_plugin_script *wee_ruby_search (char *);
+extern int wee_ruby_exec (char *, char *, char *);
+extern int wee_ruby_load (char *);
+extern void wee_ruby_unload (t_plugin_script *);
+extern void wee_ruby_unload_all ();
+extern void wee_ruby_end ();
+
+#endif /* wee-ruby.h */