summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/plugin-api.c56
-rw-r--r--src/plugins/plugin.c3
-rw-r--r--src/plugins/scripts/lua/weechat-lua-api.c94
-rw-r--r--src/plugins/scripts/perl/weechat-perl-api.c77
-rw-r--r--src/plugins/scripts/perl/weechat-perl.c82
-rw-r--r--src/plugins/scripts/python/weechat-python-api.c81
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby-api.c100
-rw-r--r--src/plugins/scripts/script-api.c167
-rw-r--r--src/plugins/scripts/script-api.h9
-rw-r--r--src/plugins/scripts/script-callback.c37
-rw-r--r--src/plugins/scripts/script-callback.h1
-rw-r--r--src/plugins/scripts/script.c2
-rw-r--r--src/plugins/weechat-plugin.h4
13 files changed, 621 insertions, 92 deletions
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index 76b8dee7b..ac99a3f59 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -220,16 +220,66 @@ plugin_api_prefix (char *prefix)
char *
plugin_api_color (char *color_name)
{
- int num_color;
+ int num_color, fg, bg;
+ static char color[20][16];
+ static int index_color = 0;
+ char *pos_comma, *str_fg, *pos_bg;
if (!color_name)
return GUI_NO_COLOR;
-
+
+ /* name is a weechat color option ? => then return this color */
num_color = gui_color_search_config (color_name);
if (num_color >= 0)
return GUI_COLOR(num_color);
- return GUI_NO_COLOR;
+ /* custom color name (GUI dependent) */
+ pos_comma = strchr (color_name, ',');
+ if (pos_comma)
+ {
+ if (pos_comma == color_name)
+ str_fg = NULL;
+ else
+ str_fg = string_strndup (color_name, pos_comma - color_name);
+ pos_bg = pos_comma + 1;
+ }
+ else
+ {
+ str_fg = strdup (color_name);
+ pos_bg = NULL;
+ }
+
+ index_color = (index_color + 1) % 20;
+
+ color[index_color][0] = '\0';
+
+ if (str_fg && pos_bg)
+ {
+ fg = gui_color_search (str_fg);
+ bg = gui_color_search (pos_bg);
+ snprintf (color[index_color], sizeof (color[index_color]),
+ "%s*%02d,%02d",
+ GUI_COLOR_COLOR_STR, fg, bg);
+ }
+ else if (str_fg && !pos_bg)
+ {
+ fg = gui_color_search (str_fg);
+ snprintf (color[index_color], sizeof (color[index_color]),
+ "%sF%02d",
+ GUI_COLOR_COLOR_STR, fg);
+ }
+ else if (!str_fg && pos_bg)
+ {
+ bg = gui_color_search (pos_bg);
+ snprintf (color[index_color], sizeof (color[index_color]),
+ "%sB%02d",
+ GUI_COLOR_COLOR_STR, bg);
+ }
+
+ if (str_fg)
+ free (str_fg);
+
+ return color[index_color];
}
/*
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 89f7cbadf..64039dcab 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -339,10 +339,11 @@ plugin_load (char *filename)
new_plugin->config_get_weechat = &plugin_api_config_get_weechat;
new_plugin->config_get_plugin = &plugin_api_config_get_plugin;
new_plugin->config_set_plugin = &plugin_api_config_set_plugin;
-
+
new_plugin->prefix = &plugin_api_prefix;
new_plugin->color = &plugin_api_color;
new_plugin->printf_date_tags = &gui_chat_printf_date_tags;
+ new_plugin->printf_y = &gui_chat_printf_y;
new_plugin->infobar_printf = &plugin_api_infobar_printf;
new_plugin->infobar_remove = &plugin_api_infobar_remove;
new_plugin->log_printf = &log_printf;
diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c
index 57800afa9..cb41daa2c 100644
--- a/src/plugins/scripts/lua/weechat-lua-api.c
+++ b/src/plugins/scripts/lua/weechat-lua-api.c
@@ -1832,6 +1832,98 @@ weechat_lua_api_print (lua_State *L)
}
/*
+ * weechat_lua_api_print_date_tags: print message in a buffer with optional
+ * date and tags
+ */
+
+static int
+weechat_lua_api_print_date_tags (lua_State *L)
+{
+ const char *buffer, *tags, *message;
+ int n, date;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("print_date_tags");
+ LUA_RETURN_ERROR;
+ }
+
+ buffer = NULL;
+ date = 0;
+ tags = NULL;
+ message = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 4)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("print_date_tags");
+ LUA_RETURN_ERROR;
+ }
+
+ buffer = lua_tostring (lua_current_interpreter, -4);
+ date = lua_tonumber (lua_current_interpreter, -3);
+ tags = lua_tostring (lua_current_interpreter, -2);
+ message = lua_tostring (lua_current_interpreter, -1);
+
+ script_api_printf_date_tags (weechat_lua_plugin,
+ lua_current_script,
+ script_str2ptr ((char *)buffer),
+ date,
+ (char *)tags,
+ "%s", (char *)message);
+
+ LUA_RETURN_OK;
+}
+
+/*
+ * weechat_lua_api_print_y: print message in a buffer with free content
+ */
+
+static int
+weechat_lua_api_print_y (lua_State *L)
+{
+ const char *buffer, *message;
+ int n, y;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("print_y");
+ LUA_RETURN_ERROR;
+ }
+
+ buffer = NULL;
+ y = 0;
+ message = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("print_y");
+ LUA_RETURN_ERROR;
+ }
+
+ buffer = lua_tostring (lua_current_interpreter, -3);
+ y = lua_tonumber (lua_current_interpreter, -2);
+ message = lua_tostring (lua_current_interpreter, -1);
+
+ script_api_printf_y (weechat_lua_plugin,
+ lua_current_script,
+ script_str2ptr ((char *)buffer),
+ y,
+ "%s", (char *)message);
+
+ LUA_RETURN_OK;
+}
+
+/*
* weechat_lua_api_infobar_print: print message to infobar
*/
@@ -4366,6 +4458,8 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "prefix", &weechat_lua_api_prefix },
{ "color", &weechat_lua_api_color },
{ "print", &weechat_lua_api_print },
+ { "print_date_tags", &weechat_lua_api_print_date_tags },
+ { "print_y", &weechat_lua_api_print_y },
{ "infobar_print", &weechat_lua_api_infobar_print },
{ "infobar_remove", &weechat_lua_api_infobar_remove },
{ "log_print", &weechat_lua_api_log_print },
diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c
index 9cce80803..2b2064bab 100644
--- a/src/plugins/scripts/perl/weechat-perl-api.c
+++ b/src/plugins/scripts/perl/weechat-perl-api.c
@@ -1506,6 +1506,79 @@ static XS (XS_weechat_print)
}
/*
+ * weechat::print_date_tags: print message in a buffer with optional date and
+ * tags
+ */
+
+static XS (XS_weechat_print_date_tags)
+{
+ char *buffer, *tags, *message;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("print_date_tags");
+ PERL_RETURN_ERROR;
+ }
+
+ if (items < 4)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("print_date_tags");
+ PERL_RETURN_ERROR;
+ }
+
+ buffer = SvPV (ST (0), PL_na);
+ tags = SvPV (ST (2), PL_na);
+ message = SvPV (ST (3), PL_na);
+ script_api_printf_date_tags (weechat_perl_plugin,
+ perl_current_script,
+ script_str2ptr (buffer),
+ SvIV (ST (1)),
+ tags,
+ "%s", message);
+
+ PERL_RETURN_OK;
+}
+
+/*
+ * weechat::print_y: print message in a buffer with free content
+ */
+
+static XS (XS_weechat_print_y)
+{
+ char *buffer, *message;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("print_y");
+ PERL_RETURN_ERROR;
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("print_y");
+ PERL_RETURN_ERROR;
+ }
+
+ buffer = SvPV (ST (0), PL_na);
+ message = SvPV (ST (2), PL_na);
+ script_api_printf_y (weechat_perl_plugin,
+ perl_current_script,
+ script_str2ptr (buffer),
+ SvIV (ST (1)),
+ "%s", message);
+
+ PERL_RETURN_OK;
+}
+
+/*
* weechat::infobar_print: print message to infobar
*/
@@ -2413,7 +2486,7 @@ static XS (XS_weechat_buffer_new)
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_new");
- PERL_RETURN_EMPTY;
+ PERL_RETURN_EMPTY;
}
if (items < 4)
@@ -3512,6 +3585,8 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::prefix", XS_weechat_prefix, "weechat");
newXS ("weechat::color", XS_weechat_color, "weechat");
newXS ("weechat::print", XS_weechat_print, "weechat");
+ newXS ("weechat::print_date_tags", XS_weechat_print_date_tags, "weechat");
+ newXS ("weechat::print_y", XS_weechat_print_y, "weechat");
newXS ("weechat::infobar_print", XS_weechat_infobar_print, "weechat");
newXS ("weechat::infobar_remove", XS_weechat_infobar_remove, "weechat");
newXS ("weechat::log_print", XS_weechat_log_print, "weechat");
diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c
index 2ab653233..6766f94f2 100644
--- a/src/plugins/scripts/perl/weechat-perl.c
+++ b/src/plugins/scripts/perl/weechat-perl.c
@@ -70,20 +70,20 @@ char *perl_weechat_code =
"}"
"sub weechat_perl_load_eval_file"
"{"
-#ifndef MULTIPLICITY
- " my ($filename, $package) = @_;"
-#else
+#ifdef MULTIPLICITY
" my $filename = shift;"
+#else
+ " my ($filename, $package) = @_;"
#endif
" my $content = weechat_perl_load_file ($filename);"
" if ($content eq \"__WEECHAT_PERL_ERROR__\")"
" {"
" return 1;"
" }"
-#ifndef MULTIPLICITY
- " my $eval = qq{package $package; $content;};"
-#else
+#ifdef MULTIPLICITY
" my $eval = $content;"
+#else
+ " my $eval = qq{package $package; $content;};"
#endif
" {"
" eval $eval;"
@@ -117,16 +117,16 @@ weechat_perl_exec (struct t_plugin_script *script,
/* this code is placed here to conform ISO C90 */
dSP;
-#ifndef MULTIPLICITY
+#ifdef MULTIPLICITY
+ (void) length;
+ func = function;
+ PERL_SET_CONTEXT (script->interpreter);
+#else
length = strlen (script->interpreter) + strlen (function) + 3;
func = malloc (length);
if (!func)
return NULL;
snprintf (func, length, "%s::%s", (char *) script->interpreter, function);
-#else
- (void) length;
- func = function;
- PERL_SET_CONTEXT (script->interpreter);
#endif
ENTER;
@@ -220,11 +220,11 @@ weechat_perl_load (char *filename)
struct stat buf;
char *perl_argv[2];
-#ifndef MULTIPLICITY
- char pkgname[64];
-#else
+#ifdef MULTIPLICITY
PerlInterpreter *perl_current_interpreter;
- char *perl_args[] = { "", "-e", "0" };
+ char *perl_args[] = { "", "-e", "0" };
+#else
+ char pkgname[64];
#endif
if (stat (filename, &buf) != 0)
@@ -241,16 +241,9 @@ weechat_perl_load (char *filename)
perl_current_script = NULL;
-#ifndef MULTIPLICITY
- snprintf (pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, perl_num);
- perl_num++;
- tempscript.interpreter = "WeechatPerlScriptLoader";
- perl_argv[0] = filename;
- perl_argv[1] = pkgname;
- perl_argv[2] = NULL;
-#else
+#ifdef MULTIPLICITY
perl_current_interpreter = perl_alloc();
-
+
if (!perl_current_interpreter)
{
weechat_printf (NULL,
@@ -261,7 +254,7 @@ weechat_perl_load (char *filename)
}
perl_current_script_filename = filename;
-
+
PERL_SET_CONTEXT (perl_current_interpreter);
perl_construct (perl_current_interpreter);
tempscript.interpreter = (PerlInterpreter *) perl_current_interpreter;
@@ -271,6 +264,13 @@ weechat_perl_load (char *filename)
eval_pv (perl_weechat_code, TRUE);
perl_argv[0] = filename;
perl_argv[1] = NULL;
+#else
+ snprintf (pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, perl_num);
+ perl_num++;
+ tempscript.interpreter = "WeechatPerlScriptLoader";
+ perl_argv[0] = filename;
+ perl_argv[1] = pkgname;
+ perl_argv[2] = NULL;
#endif
eval = weechat_perl_exec (&tempscript,
WEECHAT_SCRIPT_EXEC_INT,
@@ -285,7 +285,7 @@ weechat_perl_load (char *filename)
return 0;
}
- if ( *eval != 0)
+ if (*eval != 0)
{
if (*eval == 2)
{
@@ -296,12 +296,12 @@ weechat_perl_load (char *filename)
weechat_printf (NULL,
weechat_gettext ("%s%s: error: %s"),
weechat_prefix ("error"), "perl",
-#ifndef MULTIPLICITY
- SvPV(perl_get_sv("WeechatPerlScriptLoader::"
- "weechat_perl_load_eval_file_error",
+#ifdef MULTIPLICITY
+ SvPV(perl_get_sv("weechat_perl_load_eval_file_error",
FALSE), len)
#else
- SvPV(perl_get_sv("weechat_perl_load_eval_file_error",
+ SvPV(perl_get_sv("WeechatPerlScriptLoader::"
+ "weechat_perl_load_eval_file_error",
FALSE), len)
#endif
);
@@ -348,10 +348,10 @@ weechat_perl_load (char *filename)
return 0;
}
-#ifndef MULTIPLICITY
- perl_current_script->interpreter = strdup (pkgname);
-#else
+#ifdef MULTIPLICITY
perl_current_script->interpreter = (PerlInterpreter *)perl_current_interpreter;
+#else
+ perl_current_script->interpreter = strdup (pkgname);
#endif
return 1;
@@ -384,10 +384,10 @@ weechat_perl_unload (struct t_plugin_script *script)
weechat_gettext ("%s%s: unloading script \"%s\""),
weechat_prefix ("info"), "perl", script->name);
-#ifndef MULTIPLICITY
- eval_pv (script->interpreter, TRUE);
-#else
+#ifdef MULTIPLICITY
PERL_SET_CONTEXT (script->interpreter);
+#else
+ eval_pv (script->interpreter, TRUE);
#endif
if (script->shutdown_func && script->shutdown_func[0])
@@ -400,14 +400,14 @@ weechat_perl_unload (struct t_plugin_script *script)
free (r);
}
-#ifndef MULTIPLICITY
- if (script->interpreter)
- free (script->interpreter);
-#else
+#ifdef MULTIPLICITY
perl_destruct (script->interpreter);
perl_free (script->interpreter);
+#else
+ if (script->interpreter)
+ free (script->interpreter);
#endif
-
+
script_remove (weechat_perl_plugin, &perl_scripts, script);
}
diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c
index 20b80882a..39691c1e9 100644
--- a/src/plugins/scripts/python/weechat-python-api.c
+++ b/src/plugins/scripts/python/weechat-python-api.c
@@ -1599,6 +1599,85 @@ weechat_python_api_prnt (PyObject *self, PyObject *args)
}
/*
+ * weechat_python_api_prnt_date_tags: print message in a buffer with optional
+ * date and tags
+ */
+
+static PyObject *
+weechat_python_api_prnt_date_tags (PyObject *self, PyObject *args)
+{
+ char *buffer, *tags, *message;
+ int date;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("prnt_date_tags");
+ PYTHON_RETURN_ERROR;
+ }
+
+ buffer = NULL;
+ date = 0;
+ tags = NULL;
+ message = NULL;
+
+ if (!PyArg_ParseTuple (args, "siss", &buffer, &time, &tags, &message))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("prnt_date_tags");
+ PYTHON_RETURN_ERROR;
+ }
+
+ script_api_printf_date_tags (weechat_python_plugin,
+ python_current_script,
+ script_str2ptr (buffer),
+ date,
+ tags,
+ "%s", message);
+
+ PYTHON_RETURN_OK;
+}
+
+/*
+ * weechat_python_api_prnt_y: print message in a buffer with free content
+ */
+
+static PyObject *
+weechat_python_api_prnt_y (PyObject *self, PyObject *args)
+{
+ char *buffer, *message;
+ int y;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("prnt_y");
+ PYTHON_RETURN_ERROR;
+ }
+
+ buffer = NULL;
+ y = 0;
+ message = NULL;
+
+ if (!PyArg_ParseTuple (args, "sis", &buffer, &y, &message))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("prnt_y");
+ PYTHON_RETURN_ERROR;
+ }
+
+ script_api_printf_y (weechat_python_plugin,
+ python_current_script,
+ script_str2ptr (buffer),
+ y,
+ "%s", message);
+
+ PYTHON_RETURN_OK;
+}
+
+/*
* weechat_python_api_infobar_print: print message to infobar
*/
@@ -3735,6 +3814,8 @@ PyMethodDef weechat_python_funcs[] =
{ "prefix", &weechat_python_api_prefix, METH_VARARGS, "" },
{ "color", &weechat_python_api_color, METH_VARARGS, "" },
{ "prnt", &weechat_python_api_prnt, METH_VARARGS, "" },
+ { "prnt_date_tags", &weechat_python_api_prnt_date_tags, METH_VARARGS, "" },
+ { "prnt_y", &weechat_python_api_prnt_y, METH_VARARGS, "" },
{ "infobar_print", &weechat_python_api_infobar_print, METH_VARARGS, "" },
{ "infobar_remove", &weechat_python_api_infobar_remove, METH_VARARGS, "" },
{ "log_print", &weechat_python_api_log_print, METH_VARARGS, "" },
diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c
index bc727e142..d9ecbb013 100644
--- a/src/plugins/scripts/ruby/weechat-ruby-api.c
+++ b/src/plugins/scripts/ruby/weechat-ruby-api.c
@@ -1845,6 +1845,104 @@ weechat_ruby_api_print (VALUE class, VALUE buffer, VALUE message)
}
/*
+ * weechat_ruby_api_print_date_tags: print message in a buffer with optional
+ * date and tags
+ */
+
+static VALUE
+weechat_ruby_api_print_date_tags (VALUE class, VALUE buffer, VALUE date,
+ VALUE tags, VALUE message)
+{
+ char *c_buffer, *c_tags, *c_message;
+ int c_date;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("print_date_tags");
+ RUBY_RETURN_ERROR;
+ }
+
+ c_buffer = NULL;
+ c_date = 0;
+ c_tags = NULL;
+ c_message = NULL;
+
+ if (NIL_P (buffer) || NIL_P (date) || NIL_P (tags) || NIL_P (message))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("print_date_tags");
+ RUBY_RETURN_ERROR;
+ }
+
+ Check_Type (buffer, T_STRING);
+ Check_Type (date, T_FIXNUM);
+ Check_Type (tags, T_STRING);
+ Check_Type (message, T_STRING);
+
+ c_buffer = STR2CSTR (buffer);
+ c_date = FIX2INT (date);
+ c_tags = STR2CSTR (tags);
+ c_message = STR2CSTR (message);
+
+ script_api_printf_date_tags (weechat_ruby_plugin,
+ ruby_current_script,
+ script_str2ptr (c_buffer),
+ c_date,
+ c_tags,
+ "%s", c_message);
+
+ RUBY_RETURN_OK;
+}
+
+/*
+ * weechat_ruby_api_print_y: print message in a buffer with free content
+ */
+
+static VALUE
+weechat_ruby_api_print_y (VALUE class, VALUE buffer, VALUE y, VALUE message)
+{
+ char *c_buffer, *c_message;
+ int c_y;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("print_y");
+ RUBY_RETURN_ERROR;
+ }
+
+ c_buffer = NULL;
+ c_y = 0;
+ c_message = NULL;
+
+ if (NIL_P (buffer) || NIL_P (message))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("print_y");
+ RUBY_RETURN_ERROR;
+ }
+
+ Check_Type (buffer, T_STRING);
+ Check_Type (y, T_FIXNUM);
+ Check_Type (message, T_STRING);
+
+ c_buffer = STR2CSTR (buffer);
+ c_y = FIX2INT (y);
+ c_message = STR2CSTR (message);
+
+ script_api_printf_y (weechat_ruby_plugin,
+ ruby_current_script,
+ script_str2ptr (c_buffer),
+ c_y,
+ "%s", c_message);
+
+ RUBY_RETURN_OK;
+}
+
+/*
* weechat_ruby_api_infobar_print: print message to infobar
*/
@@ -4269,6 +4367,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "prefix", &weechat_ruby_api_prefix, 1);
rb_define_module_function (ruby_mWeechat, "color", &weechat_ruby_api_color, 1);
rb_define_module_function (ruby_mWeechat, "print", &weechat_ruby_api_print, 2);
+ rb_define_module_function (ruby_mWeechat, "print_date_tags", &weechat_ruby_api_print_date_tags, 4);
+ rb_define_module_function (ruby_mWeechat, "print_y", &weechat_ruby_api_print_y, 3);
rb_define_module_function (ruby_mWeechat, "infobar_print", &weechat_ruby_api_infobar_print, 3);
rb_define_module_function (ruby_mWeechat, "infobar_remove", &weechat_ruby_api_infobar_remove, -1);
rb_define_module_function (ruby_mWeechat, "log_print", &weechat_ruby_api_log_print, 1);
diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c
index 52bb09df3..f12caa768 100644
--- a/src/plugins/scripts/script-api.c
+++ b/src/plugins/scripts/script-api.c
@@ -69,6 +69,7 @@ script_api_config_new (struct t_weechat_plugin *weechat_plugin,
new_script_callback);
if (!new_config_file)
{
+ script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
@@ -137,7 +138,10 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
if (!new_script_callback2)
{
if (new_script_callback1)
+ {
+ script_callback_free_data (new_script_callback1);
free (new_script_callback1);
+ }
return NULL;
}
callback2 = callback_write;
@@ -149,9 +153,15 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
if (!new_script_callback3)
{
if (new_script_callback1)
+ {
+ script_callback_free_data (new_script_callback1);
free (new_script_callback1);
+ }
if (new_script_callback2)
+ {
+ script_callback_free_data (new_script_callback2);
free (new_script_callback2);
+ }
return NULL;
}
callback3 = callback_write_default;
@@ -168,11 +178,20 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
if (!new_section)
{
if (new_script_callback1)
+ {
+ script_callback_free_data (new_script_callback1);
free (new_script_callback1);
+ }
if (new_script_callback2)
+ {
+ script_callback_free_data (new_script_callback2);
free (new_script_callback2);
+ }
if (new_script_callback3)
+ {
+ script_callback_free_data (new_script_callback3);
free (new_script_callback3);
+ }
return NULL;
}
@@ -193,7 +212,7 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
new_script_callback2->config_section = new_section;
script_callback_add (script, new_script_callback2);
}
-
+
if (new_script_callback3)
{
new_script_callback3->script = script;
@@ -238,6 +257,7 @@ script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
new_script_callback);
if (!new_option)
{
+ script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
@@ -269,18 +289,22 @@ script_api_config_free (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file)
{
- struct t_script_callback *ptr_script_callback;
+ struct t_script_callback *ptr_script_callback, *next_callback;
if (!weechat_plugin || !script || !config_file)
return;
weechat_config_free (config_file);
-
- for (ptr_script_callback = script->callbacks; ptr_script_callback;
- ptr_script_callback = ptr_script_callback->next_callback)
+
+ ptr_script_callback = script->callbacks;
+ while (ptr_script_callback)
{
+ next_callback = ptr_script_callback->next_callback;
+
if (ptr_script_callback->config_file == config_file)
script_callback_remove (script, ptr_script_callback);
+
+ ptr_script_callback = next_callback;
}
}
@@ -294,7 +318,7 @@ script_api_printf (struct t_weechat_plugin *weechat_plugin,
struct t_gui_buffer *buffer, char *format, ...)
{
va_list argptr;
- static char buf[8192];
+ char buf[8192];
char *buf2;
va_start (argptr, format);
@@ -309,6 +333,57 @@ script_api_printf (struct t_weechat_plugin *weechat_plugin,
}
/*
+ * script_api_printf_date_tags: print a message with optional date and tags
+ */
+
+void
+script_api_printf_date_tags (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer,
+ time_t date, char *tags, char *format, ...)
+{
+ va_list argptr;
+ char buf[8192];
+ char *buf2;
+
+ va_start (argptr, format);
+ vsnprintf (buf, sizeof (buf) - 1, format, argptr);
+ va_end (argptr);
+
+ buf2 = (script->charset && script->charset[0]) ?
+ weechat_iconv_to_internal (script->charset, buf) : NULL;
+ weechat_printf_date_tags (buffer, date, tags,
+ "%s", (buf2) ? buf2 : buf);
+ if (buf2)
+ free (buf2);
+}
+
+/*
+ * script_api_printf_y: print a message on a buffer with free content
+ */
+
+void
+script_api_printf_y (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer, int y,
+ char *format, ...)
+{
+ va_list argptr;
+ char buf[8192];
+ char *buf2;
+
+ va_start (argptr, format);
+ vsnprintf (buf, sizeof (buf) - 1, format, argptr);
+ va_end (argptr);
+
+ buf2 = (script->charset && script->charset[0]) ?
+ weechat_iconv_to_internal (script->charset, buf) : NULL;
+ weechat_printf_y (buffer, y, "%s", (buf2) ? buf2 : buf);
+ if (buf2)
+ free (buf2);
+}
+
+/*
* script_api_infobar_printf: print a message in infobar
*/
@@ -319,7 +394,7 @@ script_api_infobar_printf (struct t_weechat_plugin *weechat_plugin,
char *format, ...)
{
va_list argptr;
- static char buf[1024];
+ char buf[1024];
char *buf2;
va_start (argptr, format);
@@ -343,7 +418,7 @@ script_api_log_printf (struct t_weechat_plugin *weechat_plugin,
char *format, ...)
{
va_list argptr;
- static char buf[1024];
+ char buf[1024];
char *buf2;
va_start (argptr, format);
@@ -386,6 +461,7 @@ script_api_hook_command (struct t_weechat_plugin *weechat_plugin,
callback, new_script_callback);
if (!new_hook)
{
+ script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
@@ -422,6 +498,7 @@ script_api_hook_timer (struct t_weechat_plugin *weechat_plugin,
callback, new_script_callback);
if (!new_hook)
{
+ script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
@@ -429,7 +506,7 @@ script_api_hook_timer (struct t_weechat_plugin *weechat_plugin,
new_script_callback->script = script;
new_script_callback->function = strdup (function);
new_script_callback->hook = new_hook;
-
+
script_callback_add (script, new_script_callback);
return new_hook;
@@ -459,6 +536,7 @@ script_api_hook_fd (struct t_weechat_plugin *weechat_plugin,
callback, new_script_callback);
if (!new_hook)
{
+ script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
@@ -500,6 +578,7 @@ script_api_hook_print (struct t_weechat_plugin *weechat_plugin,
callback, new_script_callback);
if (!new_hook)
{
+ script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
@@ -537,6 +616,7 @@ script_api_hook_signal (struct t_weechat_plugin *weechat_plugin,
new_hook = weechat_hook_signal (signal, callback, new_script_callback);
if (!new_hook)
{
+ script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
@@ -573,6 +653,7 @@ script_api_hook_config (struct t_weechat_plugin *weechat_plugin,
new_hook = weechat_hook_config (type, option, callback, new_script_callback);
if (!new_hook)
{
+ script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
@@ -610,6 +691,7 @@ script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
new_hook = weechat_hook_completion (completion, callback, new_script_callback);
if (!new_hook)
{
+ script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
@@ -646,6 +728,7 @@ script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
new_hook = weechat_hook_modifier (modifier, callback, new_script_callback);
if (!new_hook)
{
+ script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
@@ -668,18 +751,22 @@ script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook)
{
- struct t_script_callback *ptr_script_callback;
+ struct t_script_callback *ptr_script_callback, *next_callback;
if (!weechat_plugin || !script || !hook)
return;
weechat_unhook (hook);
- for (ptr_script_callback = script->callbacks; ptr_script_callback;
- ptr_script_callback = ptr_script_callback->next_callback)
+ ptr_script_callback = script->callbacks;
+ while (ptr_script_callback)
{
+ next_callback = ptr_script_callback->next_callback;
+
if (ptr_script_callback->hook == hook)
script_callback_remove (script, ptr_script_callback);
+
+ ptr_script_callback = next_callback;
}
}
@@ -743,7 +830,10 @@ script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
if (!new_script_callback_close)
{
if (new_script_callback_input)
+ {
+ script_callback_free_data (new_script_callback_input);
free (new_script_callback_input);
+ }
return NULL;
}
}
@@ -752,20 +842,26 @@ script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
(new_script_callback_input) ?
input_callback : NULL,
(new_script_callback_input) ?
- function_input : NULL,
+ new_script_callback_input : NULL,
(new_script_callback_close) ?
close_callback : NULL,
(new_script_callback_close) ?
- function_close : NULL);
+ new_script_callback_close : NULL);
if (!new_buffer)
{
if (new_script_callback_input)
+ {
+ script_callback_free_data (new_script_callback_input);
free (new_script_callback_input);
+ }
if (new_script_callback_close)
+ {
+ script_callback_free_data (new_script_callback_close);
free (new_script_callback_close);
+ }
return NULL;
}
-
+
if (new_script_callback_input)
{
new_script_callback_input->script = script;
@@ -773,7 +869,7 @@ script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
new_script_callback_input->buffer = new_buffer;
script_callback_add (script, new_script_callback_input);
}
-
+
if (new_script_callback_close)
{
new_script_callback_close->script = script;
@@ -795,23 +891,22 @@ script_api_buffer_close (struct t_weechat_plugin *weechat_plugin,
struct t_gui_buffer *buffer,
int switch_to_another)
{
- struct t_script_callback *ptr_script_callback;
+ struct t_script_callback *ptr_script_callback, *next_callback;
if (!weechat_plugin || !script || !buffer)
return;
weechat_buffer_close (buffer, switch_to_another);
- for (ptr_script_callback = script->callbacks; ptr_script_callback;
- ptr_script_callback = ptr_script_callback->next_callback)
+ ptr_script_callback = script->callbacks;
+ while (ptr_script_callback)
{
+ next_callback = ptr_script_callback->next_callback;
+
if (ptr_script_callback->buffer == buffer)
- break;
- }
-
- if (ptr_script_callback)
- {
- script_callback_remove (script, ptr_script_callback);
+ script_callback_remove (script, ptr_script_callback);
+
+ ptr_script_callback = next_callback;
}
}
@@ -837,6 +932,10 @@ script_api_bar_item_new (struct t_weechat_plugin *weechat_plugin,
if (!new_script_callback)
return NULL;
+ new_script_callback->script = script;
+ new_script_callback->function = (function_build && function_build[0]) ?
+ strdup (function_build) : NULL;
+
new_item = weechat_bar_item_new (name,
(function_build && function_build[0]) ?
build_callback : NULL,
@@ -844,13 +943,11 @@ script_api_bar_item_new (struct t_weechat_plugin *weechat_plugin,
new_script_callback : NULL);
if (!new_item)
{
+ script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
- new_script_callback->script = script;
- new_script_callback->function = (function_build && function_build[0]) ?
- strdup (function_build) : NULL;
new_script_callback->bar_item = new_item;
script_callback_add (script, new_script_callback);
@@ -866,18 +963,22 @@ script_api_bar_item_remove (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_bar_item *item)
{
- struct t_script_callback *ptr_script_callback;
+ struct t_script_callback *ptr_script_callback, *next_callback;
if (!weechat_plugin || !script || !item)
return;
weechat_bar_item_remove (item);
-
- for (ptr_script_callback = script->callbacks; ptr_script_callback;
- ptr_script_callback = ptr_script_callback->next_callback)
+
+ ptr_script_callback = script->callbacks;
+ while (ptr_script_callback)
{
+ next_callback = ptr_script_callback->next_callback;
+
if (ptr_script_callback->bar_item == item)
script_callback_remove (script, ptr_script_callback);
+
+ ptr_script_callback = next_callback;
}
}
@@ -894,7 +995,9 @@ script_api_command (struct t_weechat_plugin *weechat_plugin,
command2 = (script->charset && script->charset[0]) ?
weechat_iconv_to_internal (script->charset, command) : NULL;
+
weechat_command (buffer, (command2) ? command2 : command);
+
if (command2)
free (command2);
}
diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h
index 50fa7254c..98217549a 100644
--- a/src/plugins/scripts/script-api.h
+++ b/src/plugins/scripts/script-api.h
@@ -63,6 +63,15 @@ extern void script_api_printf (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
char *format, ...);
+extern void script_api_printf_date_tags (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer,
+ time_t date, char *tags,
+ char *format, ...);
+extern void script_api_printf_y (struct t_weechat_plugin *weechat_plugin,
+ struct t_plugin_script *script,
+ struct t_gui_buffer *buffer,
+ int y, char *format, ...);
extern void script_api_infobar_printf (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
int delay, char *color_name,
diff --git a/src/plugins/scripts/script-callback.c b/src/plugins/scripts/script-callback.c
index fb9ae66ca..a7f89e22e 100644
--- a/src/plugins/scripts/script-callback.c
+++ b/src/plugins/scripts/script-callback.c
@@ -69,6 +69,17 @@ script_callback_add (struct t_plugin_script *script,
}
/*
+ * script_callback_free_data: free data of a script callback
+ */
+
+void
+script_callback_free_data (struct t_script_callback *script_callback)
+{
+ if (script_callback->function)
+ free (script_callback->function);
+}
+
+/*
* script_callback_remove: remove a callback from a script
*/
@@ -86,9 +97,7 @@ script_callback_remove (struct t_plugin_script *script,
if (script->callbacks == script_callback)
script->callbacks = script_callback->next_callback;
- /* free data */
- if (script_callback->function)
- free (script_callback->function);
+ script_callback_free_data (script_callback);
free (script_callback);
}
@@ -115,15 +124,15 @@ script_callback_print_log (struct t_weechat_plugin *weechat_plugin,
struct t_script_callback *script_callback)
{
weechat_log_printf ("");
- weechat_log_printf ("[callback (addr:0x%x)]", script_callback);
- weechat_log_printf (" script. . . . . . . : 0x%x", script_callback->script);
- weechat_log_printf (" function. . . . . . : '%s'", script_callback->function);
- weechat_log_printf (" config_file . . . . : '%s'", script_callback->config_file);
- weechat_log_printf (" config_section. . . : '%s'", script_callback->config_section);
- weechat_log_printf (" config_option . . . : '%s'", script_callback->config_option);
- weechat_log_printf (" hook. . . . . . . . : 0x%x", script_callback->hook);
- weechat_log_printf (" buffer. . . . . . . : 0x%x", script_callback->buffer);
- weechat_log_printf (" bar_item. . . . . . : 0x%x", script_callback->bar_item);
- weechat_log_printf (" prev_callback . . . : 0x%x", script_callback->prev_callback);
- weechat_log_printf (" next_callback . . . : 0x%x", script_callback->next_callback);
+ weechat_log_printf (" [callback (addr:0x%x)]", script_callback);
+ weechat_log_printf (" script. . . . . . . : 0x%x", script_callback->script);
+ weechat_log_printf (" function. . . . . . : '%s'", script_callback->function);
+ weechat_log_printf (" config_file . . . . : 0x%x", script_callback->config_file);
+ weechat_log_printf (" config_section. . . : 0x%x", script_callback->config_section);
+ weechat_log_printf (" config_option . . . : 0x%x", script_callback->config_option);
+ weechat_log_printf (" hook. . . . . . . . : 0x%x", script_callback->hook);
+ weechat_log_printf (" buffer. . . . . . . : 0x%x", script_callback->buffer);
+ weechat_log_printf (" bar_item. . . . . . : 0x%x", script_callback->bar_item);
+ weechat_log_printf (" prev_callback . . . : 0x%x", script_callback->prev_callback);
+ weechat_log_printf (" next_callback . . . : 0x%x", script_callback->next_callback);
}
diff --git a/src/plugins/scripts/script-callback.h b/src/plugins/scripts/script-callback.h
index a9db3db49..947887ef0 100644
--- a/src/plugins/scripts/script-callback.h
+++ b/src/plugins/scripts/script-callback.h
@@ -36,6 +36,7 @@ struct t_script_callback
extern struct t_script_callback *script_callback_alloc ();
extern void script_callback_add (struct t_plugin_script *script,
struct t_script_callback *callback);
+extern void script_callback_free_data (struct t_script_callback *script_callback);
extern void script_callback_remove (struct t_plugin_script *script,
struct t_script_callback *script_callback);
extern void script_callback_remove_all (struct t_plugin_script *script);
diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c
index c7c5d507f..94dbf42bf 100644
--- a/src/plugins/scripts/script.c
+++ b/src/plugins/scripts/script.c
@@ -421,6 +421,7 @@ script_remove (struct t_weechat_plugin *weechat_plugin,
{
weechat_unhook (ptr_script_callback->hook);
}
+
/* free config file */
if (ptr_script_callback->config_file
&& !ptr_script_callback->config_section
@@ -430,6 +431,7 @@ script_remove (struct t_weechat_plugin *weechat_plugin,
weechat_config_write (ptr_script_callback->config_file);
weechat_config_free (ptr_script_callback->config_file);
}
+
/* remove bar item */
if (ptr_script_callback->bar_item)
weechat_bar_item_remove (ptr_script_callback->bar_item);
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index df041462d..6a5c039da 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -216,6 +216,8 @@ struct t_weechat_plugin
char *(*color) (char *color_name);
void (*printf_date_tags) (struct t_gui_buffer *buffer, time_t date,
char *tags, char *message, ...);
+ void (*printf_y) (struct t_gui_buffer *buffer, int y,
+ char *message, ...);
void (*infobar_printf) (struct t_weechat_plugin *plugin, int delay,
char *color_name, char *format, ...);
void (*infobar_remove) (int how_many);
@@ -567,6 +569,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
#define weechat_printf(__buffer, __message, __argz...) \
weechat_plugin->printf_date_tags(__buffer, 0, NULL, __message, \
##__argz)
+#define weechat_printf_y(__buffer, __y, __message, __argz...) \
+ weechat_plugin->printf_y(__buffer, __y, __message, ##__argz)
#define weechat_printf_date(__buffer, __date, __message, __argz...) \
weechat_plugin->printf_date_tags(__buffer, __date, NULL, \
__message, ##__argz)