1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-28 13:56:37 +02:00

Added Ruby plugins skeleton

This commit is contained in:
Sebastien Helleu
2005-08-21 16:32:48 +00:00
parent 84b1a27265
commit 11321acb96
28 changed files with 3242 additions and 1284 deletions
+16 -3
View File
@@ -66,6 +66,7 @@ AC_CHECK_FUNCS([gethostbyname gethostname getsockname gettimeofday inet_ntoa mem
AH_VERBATIM([PLUGINS], [#undef PLUGINS])
AH_VERBATIM([PLUGIN_PERL], [#undef PLUGIN_PERL])
AH_VERBATIM([PLUGIN_PYTHON], [#undef PLUGIN_PYTHON])
AH_VERBATIM([PLUGIN_RUBY], [#undef PLUGIN_RUBY])
AH_VERBATIM([HAVE_GNUTLS], [#undef HAVE_GNUTLS])
AH_VERBATIM([DEBUG], [#undef DEBUG])
@@ -75,12 +76,11 @@ AC_ARG_ENABLE(gtk, [ --enable-gtk Turn on Gtk+ interface (defau
AC_ARG_ENABLE(qt, [ --enable-qt Turn on Qt interface (default=no)],enable_qt=$enableval,enable_qt=no)
AC_ARG_ENABLE(perl, [ --enable-perl Turn on Perl plugins (default=no)],enable_perl=$enableval,enable_perl=no)
AC_ARG_ENABLE(python, [ --enable-python Turn on Python plugins (default=no)],enable_python=$enableval,enable_python=no)
AC_ARG_ENABLE(ruby, [ --enable-ruby Turn on Ruby plugins (default=no)],enable_ruby=$enableval,enable_ruby=no)
AC_ARG_ENABLE(gnutls, [ --disable-gnutls Turn off gnutls support (default=auto)],enable_gnutls=$enableval,enable_gnutls=yes)
AC_ARG_WITH(debug, [ --with-debug Debugging: 0=no debug, 1=debug compilation, 2=debug compilation + verbose msgs (default=0)],debug=$withval,debug=0)
enable_plugins="no"
enable_ruby="no"
RUBY_CFLAGS=
AM_CONDITIONAL(GUI_NCURSES, test "$enable_ncurses" = "yes")
AM_CONDITIONAL(GUI_WXWIDGETS, test "$enable_wxwidgets" = "yes")
@@ -88,7 +88,7 @@ AM_CONDITIONAL(GUI_GTK, test "$enable_gtk" = "yes")
AM_CONDITIONAL(GUI_QT, test "$enable_qt" = "yes")
AM_CONDITIONAL(PLUGIN_PERL, test "$enable_perl" = "yes")
AM_CONDITIONAL(PLUGIN_PYTHON, test "$enable_python" = "yes")
# AM_CONDITIONAL(PLUGIN_RUBY, test "$enable_ruby" = "yes")
AM_CONDITIONAL(PLUGIN_RUBY, test "$enable_ruby" = "yes")
AM_CONDITIONAL(HAVE_GNUTLS, test "$enable_gnutls" = "yes")
if test "x$enable_ncurses" = "xyes" ; then
@@ -225,6 +225,18 @@ if test "x$enable_python" = "xyes" ; then
AC_DEFINE(PLUGIN_PYTHON)
fi
if test "x$enable_ruby" = "xyes" ; then
enable_plugins="yes"
# TODO: check that ruby lib and headers are installed
RUBY_CFLAGS=-I`ruby -rrbconfig -e "puts Config::CONFIG[['archdir']]"`
RUBY_LFLAGS=-L`ruby -rrbconfig -e "puts Config::CONFIG[['archdir']]"` -lruby
PLUGINS_LIBS="$PLUGINS_LIBS ../../plugins/ruby/lib_weechat_ruby.a $RUBY_LFLAGS"
AC_SUBST(RUBY_CFLAGS)
AC_DEFINE(PLUGIN_RUBY)
fi
if test "x$enable_plugins" = "xyes" ; then
AC_DEFINE(PLUGINS)
fi
@@ -272,6 +284,7 @@ AC_OUTPUT([Makefile
src/plugins/Makefile
src/plugins/perl/Makefile
src/plugins/python/Makefile
src/plugins/ruby/Makefile
src/gui/Makefile
src/gui/curses/Makefile
src/gui/wxwidgets/Makefile
+2
View File
@@ -11,6 +11,8 @@
./src/plugins/perl/wee-perl.h
./src/plugins/python/wee-python.c
./src/plugins/python/wee-python.h
./src/plugins/ruby/wee-ruby.c
./src/plugins/ruby/wee-ruby.h
./src/plugins/plugins.c
./src/plugins/plugins.h
./src/gui/curses/gui-input.c
+233 -196
View File
File diff suppressed because it is too large Load Diff
+233 -196
View File
File diff suppressed because it is too large Load Diff
+231 -198
View File
File diff suppressed because it is too large Load Diff
+154 -6
View File
@@ -89,6 +89,11 @@ t_weechat_command weechat_commands[] =
N_("filename: Python script (file) to load\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"
"Without argument, /ruby command lists all loaded Ruby scripts."),
0, 2, weechat_cmd_ruby, NULL },
{ "server", N_("list, add or remove servers"),
N_("[servername] | "
"[servername hostname port [-auto | -noauto] [-ipv6] [-ssl] [-pwd password] [-nicks nick1 "
@@ -1486,7 +1491,7 @@ weechat_cmd_key (char *arguments)
int
weechat_cmd_perl (int argc, char **argv)
{
#ifdef PLUGIN_PERL
#ifdef PLUGIN_PERL
t_plugin_script *ptr_plugin_script;
t_plugin_handler *ptr_plugin_handler;
int handler_found, path_length;
@@ -1608,7 +1613,7 @@ weechat_cmd_perl (int argc, char **argv)
_("%s wrong argument count for \"%s\" command\n"),
WEECHAT_ERROR, "perl");
}
#else
#else
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("WeeChat was build without Perl support.\n"
@@ -1617,7 +1622,7 @@ weechat_cmd_perl (int argc, char **argv)
/* make gcc happy */
(void) argc;
(void) argv;
#endif /* PLUGIN_PERL */
#endif /* PLUGIN_PERL */
return 0;
}
@@ -1629,7 +1634,7 @@ weechat_cmd_perl (int argc, char **argv)
int
weechat_cmd_python (int argc, char **argv)
{
#ifdef PLUGIN_PYTHON
#ifdef PLUGIN_PYTHON
t_plugin_script *ptr_plugin_script;
t_plugin_handler *ptr_plugin_handler;
int handler_found, path_length;
@@ -1751,7 +1756,7 @@ weechat_cmd_python (int argc, char **argv)
_("%s wrong argument count for \"%s\" command\n"),
WEECHAT_ERROR, "python");
}
#else
#else
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("WeeChat was build without Python support.\n"
@@ -1760,7 +1765,150 @@ weechat_cmd_python (int argc, char **argv)
/* make gcc happy */
(void) argc;
(void) argv;
#endif /* PLUGIN_PYTHON */
#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 (strcasecmp (argv[0], "autoload") == 0)
plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload");
else if (strcasecmp (argv[0], "reload") == 0)
{
plugin_unload (PLUGIN_TYPE_RUBY, NULL);
plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload");
}
else if (strcasecmp (argv[0], "unload") == 0)
plugin_unload (PLUGIN_TYPE_RUBY, NULL);
break;
case 2:
if (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 */
return 0;
}
+1
View File
@@ -72,6 +72,7 @@ extern int weechat_cmd_help (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_save (int, char **);
extern int weechat_cmd_server (int, char **);
extern int weechat_cmd_set (char *);
+4 -5
View File
@@ -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
+78 -38
View File
@@ -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
}
+4
View File
@@ -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 *);
+1
View File
@@ -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;
}
}
+23
View File
@@ -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
+607
View File
@@ -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");
}*/
}
+34
View File
@@ -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 */
+16 -3
View File
@@ -66,6 +66,7 @@ AC_CHECK_FUNCS([gethostbyname gethostname getsockname gettimeofday inet_ntoa mem
AH_VERBATIM([PLUGINS], [#undef PLUGINS])
AH_VERBATIM([PLUGIN_PERL], [#undef PLUGIN_PERL])
AH_VERBATIM([PLUGIN_PYTHON], [#undef PLUGIN_PYTHON])
AH_VERBATIM([PLUGIN_RUBY], [#undef PLUGIN_RUBY])
AH_VERBATIM([HAVE_GNUTLS], [#undef HAVE_GNUTLS])
AH_VERBATIM([DEBUG], [#undef DEBUG])
@@ -75,12 +76,11 @@ AC_ARG_ENABLE(gtk, [ --enable-gtk Turn on Gtk+ interface (defau
AC_ARG_ENABLE(qt, [ --enable-qt Turn on Qt interface (default=no)],enable_qt=$enableval,enable_qt=no)
AC_ARG_ENABLE(perl, [ --enable-perl Turn on Perl plugins (default=no)],enable_perl=$enableval,enable_perl=no)
AC_ARG_ENABLE(python, [ --enable-python Turn on Python plugins (default=no)],enable_python=$enableval,enable_python=no)
AC_ARG_ENABLE(ruby, [ --enable-ruby Turn on Ruby plugins (default=no)],enable_ruby=$enableval,enable_ruby=no)
AC_ARG_ENABLE(gnutls, [ --disable-gnutls Turn off gnutls support (default=auto)],enable_gnutls=$enableval,enable_gnutls=yes)
AC_ARG_WITH(debug, [ --with-debug Debugging: 0=no debug, 1=debug compilation, 2=debug compilation + verbose msgs (default=0)],debug=$withval,debug=0)
enable_plugins="no"
enable_ruby="no"
RUBY_CFLAGS=
AM_CONDITIONAL(GUI_NCURSES, test "$enable_ncurses" = "yes")
AM_CONDITIONAL(GUI_WXWIDGETS, test "$enable_wxwidgets" = "yes")
@@ -88,7 +88,7 @@ AM_CONDITIONAL(GUI_GTK, test "$enable_gtk" = "yes")
AM_CONDITIONAL(GUI_QT, test "$enable_qt" = "yes")
AM_CONDITIONAL(PLUGIN_PERL, test "$enable_perl" = "yes")
AM_CONDITIONAL(PLUGIN_PYTHON, test "$enable_python" = "yes")
# AM_CONDITIONAL(PLUGIN_RUBY, test "$enable_ruby" = "yes")
AM_CONDITIONAL(PLUGIN_RUBY, test "$enable_ruby" = "yes")
AM_CONDITIONAL(HAVE_GNUTLS, test "$enable_gnutls" = "yes")
if test "x$enable_ncurses" = "xyes" ; then
@@ -225,6 +225,18 @@ if test "x$enable_python" = "xyes" ; then
AC_DEFINE(PLUGIN_PYTHON)
fi
if test "x$enable_ruby" = "xyes" ; then
enable_plugins="yes"
# TODO: check that ruby lib and headers are installed
RUBY_CFLAGS=-I`ruby -rrbconfig -e "puts Config::CONFIG[['archdir']]"`
RUBY_LFLAGS=-L`ruby -rrbconfig -e "puts Config::CONFIG[['archdir']]"` -lruby
PLUGINS_LIBS="$PLUGINS_LIBS ../../plugins/ruby/lib_weechat_ruby.a $RUBY_LFLAGS"
AC_SUBST(RUBY_CFLAGS)
AC_DEFINE(PLUGIN_RUBY)
fi
if test "x$enable_plugins" = "xyes" ; then
AC_DEFINE(PLUGINS)
fi
@@ -272,6 +284,7 @@ AC_OUTPUT([Makefile
src/plugins/Makefile
src/plugins/perl/Makefile
src/plugins/python/Makefile
src/plugins/ruby/Makefile
src/gui/Makefile
src/gui/curses/Makefile
src/gui/wxwidgets/Makefile
+2
View File
@@ -11,6 +11,8 @@
./src/plugins/perl/wee-perl.h
./src/plugins/python/wee-python.c
./src/plugins/python/wee-python.h
./src/plugins/ruby/wee-ruby.c
./src/plugins/ruby/wee-ruby.h
./src/plugins/plugins.c
./src/plugins/plugins.h
./src/gui/curses/gui-input.c
+233 -196
View File
File diff suppressed because it is too large Load Diff
+233 -196
View File
File diff suppressed because it is too large Load Diff
+231 -198
View File
File diff suppressed because it is too large Load Diff
+154 -6
View File
@@ -89,6 +89,11 @@ t_weechat_command weechat_commands[] =
N_("filename: Python script (file) to load\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"
"Without argument, /ruby command lists all loaded Ruby scripts."),
0, 2, weechat_cmd_ruby, NULL },
{ "server", N_("list, add or remove servers"),
N_("[servername] | "
"[servername hostname port [-auto | -noauto] [-ipv6] [-ssl] [-pwd password] [-nicks nick1 "
@@ -1486,7 +1491,7 @@ weechat_cmd_key (char *arguments)
int
weechat_cmd_perl (int argc, char **argv)
{
#ifdef PLUGIN_PERL
#ifdef PLUGIN_PERL
t_plugin_script *ptr_plugin_script;
t_plugin_handler *ptr_plugin_handler;
int handler_found, path_length;
@@ -1608,7 +1613,7 @@ weechat_cmd_perl (int argc, char **argv)
_("%s wrong argument count for \"%s\" command\n"),
WEECHAT_ERROR, "perl");
}
#else
#else
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("WeeChat was build without Perl support.\n"
@@ -1617,7 +1622,7 @@ weechat_cmd_perl (int argc, char **argv)
/* make gcc happy */
(void) argc;
(void) argv;
#endif /* PLUGIN_PERL */
#endif /* PLUGIN_PERL */
return 0;
}
@@ -1629,7 +1634,7 @@ weechat_cmd_perl (int argc, char **argv)
int
weechat_cmd_python (int argc, char **argv)
{
#ifdef PLUGIN_PYTHON
#ifdef PLUGIN_PYTHON
t_plugin_script *ptr_plugin_script;
t_plugin_handler *ptr_plugin_handler;
int handler_found, path_length;
@@ -1751,7 +1756,7 @@ weechat_cmd_python (int argc, char **argv)
_("%s wrong argument count for \"%s\" command\n"),
WEECHAT_ERROR, "python");
}
#else
#else
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("WeeChat was build without Python support.\n"
@@ -1760,7 +1765,150 @@ weechat_cmd_python (int argc, char **argv)
/* make gcc happy */
(void) argc;
(void) argv;
#endif /* PLUGIN_PYTHON */
#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 (strcasecmp (argv[0], "autoload") == 0)
plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload");
else if (strcasecmp (argv[0], "reload") == 0)
{
plugin_unload (PLUGIN_TYPE_RUBY, NULL);
plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload");
}
else if (strcasecmp (argv[0], "unload") == 0)
plugin_unload (PLUGIN_TYPE_RUBY, NULL);
break;
case 2:
if (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 */
return 0;
}
+1
View File
@@ -72,6 +72,7 @@ extern int weechat_cmd_help (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_save (int, char **);
extern int weechat_cmd_server (int, char **);
extern int weechat_cmd_set (char *);
+4 -5
View File
@@ -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
+78 -38
View File
@@ -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
}
+4
View File
@@ -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 *);
+1
View File
@@ -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;
}
}
+23
View File
@@ -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
+607
View File
@@ -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");
}*/
}
+34
View File
@@ -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 */