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

Added preliminary support of new buffer type, with free content

This commit is contained in:
Sebastien Helleu
2008-03-28 18:57:10 +01:00
parent 34a3c8637d
commit 868bc6b63d
30 changed files with 1252 additions and 337 deletions
+94
View File
@@ -1831,6 +1831,98 @@ weechat_lua_api_print (lua_State *L)
LUA_RETURN_OK;
}
/*
* 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 },
+76 -1
View File
@@ -1505,6 +1505,79 @@ static XS (XS_weechat_print)
PERL_RETURN_OK;
}
/*
* 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");
+41 -41
View File
@@ -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);
}
@@ -1598,6 +1598,85 @@ weechat_python_api_prnt (PyObject *self, PyObject *args)
PYTHON_RETURN_OK;
}
/*
* 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, "" },
+100
View File
@@ -1844,6 +1844,104 @@ weechat_ruby_api_print (VALUE class, VALUE buffer, VALUE message)
RUBY_RETURN_OK;
}
/*
* 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);
+135 -32
View File
@@ -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);
@@ -308,6 +332,57 @@ script_api_printf (struct t_weechat_plugin *weechat_plugin,
free (buf2);
}
/*
* 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);
}
+9
View File
@@ -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,
+23 -14
View File
@@ -68,6 +68,17 @@ script_callback_add (struct t_plugin_script *script,
script->callbacks = callback;
}
/*
* 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);
}
+1
View File
@@ -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);
+2
View File
@@ -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);