1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-25 20:36:38 +02:00

Added tags for lines and custom filtering by tags or regex (task #7674), fixed many memory leaks

This commit is contained in:
Sebastien Helleu
2008-03-22 23:36:12 +01:00
parent 8c4dc57d8e
commit 61ca929728
73 changed files with 4824 additions and 2603 deletions
+67 -58
View File
@@ -2208,22 +2208,27 @@ weechat_lua_api_hook_fd (lua_State *L)
int
weechat_lua_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
time_t date, char *prefix, char *message)
time_t date, int tags_count, char **tags,
char *prefix, char *message)
{
struct t_script_callback *script_callback;
char *lua_argv[5];
char *lua_argv[6];
static char timebuffer[64];
int *rc, ret;
/* make C compiler happy */
(void) tags_count;
script_callback = (struct t_script_callback *)data;
snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", date);
lua_argv[0] = script_ptr2str (buffer);
lua_argv[1] = timebuffer;
lua_argv[2] = prefix;
lua_argv[3] = message;
lua_argv[4] = NULL;
lua_argv[2] = weechat_string_build_with_exploded (tags, ",");
lua_argv[3] = prefix;
lua_argv[4] = message;
lua_argv[5] = NULL;
rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
@@ -2237,6 +2242,10 @@ weechat_lua_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
ret = *rc;
free (rc);
}
if (lua_argv[0])
free (lua_argv[0]);
if (lua_argv[2])
free (lua_argv[2]);
return ret;
}
@@ -2248,7 +2257,7 @@ weechat_lua_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
static int
weechat_lua_api_hook_print (lua_State *L)
{
const char *buffer, *message, *function;
const char *buffer, *tags, *message, *function;
char *result;
int n, strip_colors;
@@ -2262,6 +2271,7 @@ weechat_lua_api_hook_print (lua_State *L)
}
buffer = NULL;
tags = NULL;
message = NULL;
strip_colors = 0;
function = NULL;
@@ -2274,7 +2284,8 @@ weechat_lua_api_hook_print (lua_State *L)
LUA_RETURN_EMPTY;
}
buffer = lua_tostring (lua_current_interpreter, -4);
buffer = lua_tostring (lua_current_interpreter, -5);
tags = lua_tostring (lua_current_interpreter, -4);
message = lua_tostring (lua_current_interpreter, -3);
strip_colors = lua_tonumber (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
@@ -2282,6 +2293,7 @@ weechat_lua_api_hook_print (lua_State *L)
result = script_ptr2str (script_api_hook_print (weechat_lua_plugin,
lua_current_script,
script_str2ptr ((char *)buffer),
(char *)tags,
(char *)message,
strip_colors,
&weechat_lua_api_hook_print_cb,
@@ -2979,11 +2991,11 @@ weechat_lua_api_buffer_close (lua_State *L)
}
/*
* weechat_lua_api_buffer_get: get a buffer property
* weechat_lua_api_buffer_get_string: get a buffer property as string
*/
static int
weechat_lua_api_buffer_get (lua_State *L)
weechat_lua_api_buffer_get_string (lua_State *L)
{
const char *buffer, *property;
char *value;
@@ -2994,7 +3006,7 @@ weechat_lua_api_buffer_get (lua_State *L)
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get");
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get_string");
LUA_RETURN_EMPTY;
}
@@ -3005,19 +3017,59 @@ weechat_lua_api_buffer_get (lua_State *L)
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get");
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get_string");
LUA_RETURN_EMPTY;
}
buffer = lua_tostring (lua_current_interpreter, -2);
property = lua_tostring (lua_current_interpreter, -1);
value = weechat_buffer_get (script_str2ptr ((char *)buffer),
(char *)property);
value = weechat_buffer_get_string (script_str2ptr ((char *)buffer),
(char *)property);
LUA_RETURN_STRING(value);
}
/*
* weechat_lua_api_buffer_get_pointer: get a buffer property as pointer
*/
static int
weechat_lua_api_buffer_get_pointer (lua_State *L)
{
const char *buffer, *property;
char *value;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get_pointer");
LUA_RETURN_EMPTY;
}
buffer = NULL;
property = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get_pointer");
LUA_RETURN_EMPTY;
}
buffer = lua_tostring (lua_current_interpreter, -2);
property = lua_tostring (lua_current_interpreter, -1);
value = script_ptr2str (weechat_buffer_get_string (script_str2ptr ((char *)buffer),
(char *)property));
LUA_RETURN_STRING_FREE(value);
}
/*
* weechat_lua_api_buffer_set: set a buffer property
*/
@@ -4169,46 +4221,6 @@ weechat_lua_api_constant_weechat_rc_error (lua_State *L)
return 1;
}
static int
weechat_lua_api_constant_weechat_rc_ok_ignore_weechat (lua_State *L)
{
/* make C compiler happy */
(void) L;
lua_pushnumber (lua_current_interpreter, WEECHAT_RC_OK_IGNORE_WEECHAT);
return 1;
}
static int
weechat_lua_api_constant_weechat_rc_ok_ignore_plugins (lua_State *L)
{
/* make C compiler happy */
(void) L;
lua_pushnumber (lua_current_interpreter, WEECHAT_RC_OK_IGNORE_PLUGINS);
return 1;
}
static int
weechat_lua_api_constant_weechat_rc_ok_ignore_all (lua_State *L)
{
/* make C compiler happy */
(void) L;
lua_pushnumber (lua_current_interpreter, WEECHAT_RC_OK_IGNORE_ALL);
return 1;
}
static int
weechat_lua_api_constant_weechat_rc_ok_with_highlight (lua_State *L)
{
/* make C compiler happy */
(void) L;
lua_pushnumber (lua_current_interpreter, WEECHAT_RC_OK_WITH_HIGHLIGHT);
return 1;
}
static int
weechat_lua_api_constant_weechat_list_pos_sort (lua_State *L)
{
@@ -4372,7 +4384,8 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "buffer_new", &weechat_lua_api_buffer_new },
{ "buffer_search", &weechat_lua_api_buffer_search },
{ "buffer_close", &weechat_lua_api_buffer_close },
{ "buffer_get", &weechat_lua_api_buffer_get },
{ "buffer_get_string", &weechat_lua_api_buffer_get_string },
{ "buffer_get_pointer", &weechat_lua_api_buffer_get_pointer },
{ "buffer_set", &weechat_lua_api_buffer_set },
{ "nicklist_add_group", &weechat_lua_api_nicklist_add_group },
{ "nicklist_search_group", &weechat_lua_api_nicklist_search_group },
@@ -4403,10 +4416,6 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
/* define constants as function which returns values */
{ "WEECHAT_RC_OK", &weechat_lua_api_constant_weechat_rc_ok },
{ "WEECHAT_RC_ERROR", &weechat_lua_api_constant_weechat_rc_error },
{ "WEECHAT_RC_OK_IGNORE_WEECHAT", &weechat_lua_api_constant_weechat_rc_ok_ignore_weechat },
{ "WEECHAT_RC_OK_IGNORE_PLUGINS", &weechat_lua_api_constant_weechat_rc_ok_ignore_plugins },
{ "WEECHAT_RC_OK_IGNORE_ALL", &weechat_lua_api_constant_weechat_rc_ok_ignore_all },
{ "WEECHAT_RC_OK_WITH_HIGHLIGHT", &weechat_lua_api_constant_weechat_rc_ok_with_highlight },
{ "WEECHAT_LIST_POS_SORT", &weechat_lua_api_constant_weechat_list_pos_sort },
{ "WEECHAT_LIST_POS_BEGINNING", &weechat_lua_api_constant_weechat_list_pos_beginning },
{ "WEECHAT_LIST_POS_END", &weechat_lua_api_constant_weechat_list_pos_end },
+58 -20
View File
@@ -1815,22 +1815,27 @@ static XS (XS_weechat_hook_fd)
int
weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
time_t date, char *prefix, char *message)
time_t date, int tags_count, char **tags,
char *prefix, char *message)
{
struct t_script_callback *script_callback;
char *perl_argv[5];
char *perl_argv[6];
static char timebuffer[64];
int *rc, ret;
/* make C compiler happy */
(void) tags_count;
script_callback = (struct t_script_callback *)data;
snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", date);
perl_argv[0] = script_ptr2str (buffer);
perl_argv[1] = timebuffer;
perl_argv[2] = prefix;
perl_argv[3] = message;
perl_argv[4] = NULL;
perl_argv[2] = weechat_string_build_with_exploded (tags, ",");
perl_argv[3] = prefix;
perl_argv[4] = message;
perl_argv[5] = NULL;
rc = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
@@ -1846,6 +1851,8 @@ weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
}
if (perl_argv[0])
free (perl_argv[0]);
if (perl_argv[2])
free (perl_argv[2]);
return ret;
}
@@ -1856,7 +1863,7 @@ weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
static XS (XS_weechat_hook_print)
{
char *result, *buffer, *message, *function;
char *result, *buffer, *tags, *message, *function;
dXSARGS;
/* make C compiler happy */
@@ -1868,20 +1875,22 @@ static XS (XS_weechat_hook_print)
PERL_RETURN_EMPTY;
}
if (items < 4)
if (items < 5)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_print");
PERL_RETURN_EMPTY;
}
buffer = SvPV (ST (0), PL_na);
message = SvPV (ST (1), PL_na);
function = SvPV (ST (3), PL_na);
tags = SvPV (ST (1), PL_na);
message = SvPV (ST (2), PL_na);
function = SvPV (ST (4), PL_na);
result = script_ptr2str (script_api_hook_print (weechat_perl_plugin,
perl_current_script,
script_str2ptr (buffer),
tags,
message,
SvIV (ST (2)), /* strip_colors */
SvIV (ST (3)), /* strip_colors */
&weechat_perl_api_hook_print_cb,
function));
@@ -2492,10 +2501,10 @@ static XS (XS_weechat_buffer_close)
}
/*
* weechat::buffer_get: get a buffer property
* weechat::buffer_get_string: get a buffer property as string
*/
static XS (XS_weechat_buffer_get)
static XS (XS_weechat_buffer_get_string)
{
char *value, *buffer, *property;
dXSARGS;
@@ -2505,23 +2514,55 @@ static XS (XS_weechat_buffer_get)
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get");
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get_string");
PERL_RETURN_EMPTY;
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get");
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get_string");
PERL_RETURN_EMPTY;
}
buffer = SvPV (ST (0), PL_na);
property = SvPV (ST (1), PL_na);
value = weechat_buffer_get (script_str2ptr (buffer), property);
value = weechat_buffer_get_string (script_str2ptr (buffer), property);
PERL_RETURN_STRING(value);
}
/*
* weechat::buffer_get_pointer: get a buffer property as pointer
*/
static XS (XS_weechat_buffer_get_pointer)
{
char *value, *buffer, *property;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get_pointer");
PERL_RETURN_EMPTY;
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get_pointer");
PERL_RETURN_EMPTY;
}
buffer = SvPV (ST (0), PL_na);
property = SvPV (ST (1), PL_na);
value = script_ptr2str (weechat_buffer_get_pointer (script_str2ptr (buffer),
property));
PERL_RETURN_STRING_FREE(value);
}
/*
* weechat::buffer_set: set a buffer property
*/
@@ -3489,7 +3530,8 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::buffer_new", XS_weechat_buffer_new, "weechat");
newXS ("weechat::buffer_search", XS_weechat_buffer_search, "weechat");
newXS ("weechat::buffer_close", XS_weechat_buffer_close, "weechat");
newXS ("weechat::buffer_get", XS_weechat_buffer_get, "weechat");
newXS ("weechat::buffer_get_string", XS_weechat_buffer_get_string, "weechat");
newXS ("weechat::buffer_get_pointer", XS_weechat_buffer_get_pointer, "weechat");
newXS ("weechat::buffer_set", XS_weechat_buffer_set, "weechat");
newXS ("weechat::nicklist_add_group", XS_weechat_nicklist_add_group, "weechat");
newXS ("weechat::nicklist_search_group", XS_weechat_nicklist_search_group, "weechat");
@@ -3522,10 +3564,6 @@ weechat_perl_api_init (pTHX)
stash = gv_stashpv ("weechat", TRUE);
newCONSTSUB (stash, "weechat::WEECHAT_RC_OK", newSViv (WEECHAT_RC_OK));
newCONSTSUB (stash, "weechat::WEECHAT_RC_ERROR", newSViv (WEECHAT_RC_ERROR));
newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_IGNORE_WEECHAT", newSViv (WEECHAT_RC_OK_IGNORE_WEECHAT));
newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_IGNORE_PLUGINS", newSViv (WEECHAT_RC_OK_IGNORE_PLUGINS));
newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_IGNORE_ALL", newSViv (WEECHAT_RC_OK_IGNORE_ALL));
newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_WITH_HIGHLIGHT", newSViv (WEECHAT_RC_OK_WITH_HIGHLIGHT));
newCONSTSUB (stash, "weechat::WEECHAT_LIST_POS_SORT", newSVpv (WEECHAT_LIST_POS_SORT, PL_na));
newCONSTSUB (stash, "weechat::WEECHAT_LIST_POS_BEGINNING", newSVpv (WEECHAT_LIST_POS_BEGINNING, PL_na));
newCONSTSUB (stash, "weechat::WEECHAT_LIST_POS_END", newSVpv (WEECHAT_LIST_POS_END, PL_na));
+59 -15
View File
@@ -1939,22 +1939,27 @@ weechat_python_api_hook_fd (PyObject *self, PyObject *args)
int
weechat_python_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
time_t date, char *prefix, char *message)
time_t date, int tags_count, char **tags,
char *prefix, char *message)
{
struct t_script_callback *script_callback;
char *python_argv[5];
char *python_argv[6];
static char timebuffer[64];
int *rc, ret;
/* make C compiler happy */
(void) tags_count;
script_callback = (struct t_script_callback *)data;
snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", date);
python_argv[0] = script_ptr2str (buffer);
python_argv[1] = timebuffer;
python_argv[2] = prefix;
python_argv[3] = message;
python_argv[4] = NULL;
python_argv[2] = weechat_string_build_with_exploded (tags, ",");
python_argv[3] = prefix;
python_argv[4] = message;
python_argv[5] = NULL;
rc = (int *) weechat_python_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
@@ -1970,6 +1975,8 @@ weechat_python_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
}
if (python_argv[0])
free (python_argv[0]);
if (python_argv[2])
free (python_argv[2]);
return ret;
}
@@ -1981,7 +1988,7 @@ weechat_python_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
static PyObject *
weechat_python_api_hook_print (PyObject *self, PyObject *args)
{
char *buffer, *message, *function, *result;
char *buffer, *tags, *message, *function, *result;
int strip_colors;
PyObject *object;
@@ -1995,12 +2002,13 @@ weechat_python_api_hook_print (PyObject *self, PyObject *args)
}
buffer = NULL;
tags = NULL;
message = NULL;
strip_colors = 0;
function = NULL;
if (!PyArg_ParseTuple (args, "ssis", &buffer, &message, &strip_colors,
&function))
if (!PyArg_ParseTuple (args, "sssis", &buffer, &tags, &message,
&strip_colors, &function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_print");
PYTHON_RETURN_EMPTY;
@@ -2009,6 +2017,7 @@ weechat_python_api_hook_print (PyObject *self, PyObject *args)
result = script_ptr2str(script_api_hook_print (weechat_python_plugin,
python_current_script,
script_str2ptr (buffer),
tags,
message,
strip_colors,
&weechat_python_api_hook_print_cb,
@@ -2146,7 +2155,7 @@ weechat_python_api_hook_signal_send (PyObject *self, PyObject *args)
{
error = NULL;
number = (int)strtol (signal_data, &error, 10);
if (error && (error[0] == '\0'))
if (error && !error[0])
{
weechat_hook_signal_send (signal, type_data, &number);
}
@@ -2645,11 +2654,11 @@ weechat_python_api_buffer_close (PyObject *self, PyObject *args)
}
/*
* weechat_python_api_buffer_get: get a buffer property
* weechat_python_api_buffer_get_string: get a buffer property as string
*/
static PyObject *
weechat_python_api_buffer_get (PyObject *self, PyObject *args)
weechat_python_api_buffer_get_string (PyObject *self, PyObject *args)
{
char *buffer, *property, *value;
@@ -2658,7 +2667,7 @@ weechat_python_api_buffer_get (PyObject *self, PyObject *args)
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get");
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get_string");
PYTHON_RETURN_ERROR;
}
@@ -2667,15 +2676,49 @@ weechat_python_api_buffer_get (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple (args, "ss", &buffer, &property))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get");
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get_string");
PYTHON_RETURN_EMPTY;
}
value = weechat_buffer_get (script_str2ptr (buffer), property);
value = weechat_buffer_get_string (script_str2ptr (buffer), property);
PYTHON_RETURN_STRING(value);
}
/*
* weechat_python_api_buffer_get_pointer: get a buffer property as pointer
*/
static PyObject *
weechat_python_api_buffer_get_pointer (PyObject *self, PyObject *args)
{
char *buffer, *property, *value;
PyObject *object;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get_pointer");
PYTHON_RETURN_ERROR;
}
buffer = NULL;
property = NULL;
if (!PyArg_ParseTuple (args, "ss", &buffer, &property))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get_pointer");
PYTHON_RETURN_EMPTY;
}
value = script_ptr2str (weechat_buffer_get_pointer (script_str2ptr (buffer),
property));
PYTHON_RETURN_STRING_FREE(value);
}
/*
* weechat_python_api_buffer_set: set a buffer property
*/
@@ -3710,7 +3753,8 @@ PyMethodDef weechat_python_funcs[] =
{ "buffer_new", &weechat_python_api_buffer_new, METH_VARARGS, "" },
{ "buffer_search", &weechat_python_api_buffer_search, METH_VARARGS, "" },
{ "buffer_close", &weechat_python_api_buffer_close, METH_VARARGS, "" },
{ "buffer_get", &weechat_python_api_buffer_get, METH_VARARGS, "" },
{ "buffer_get_string", &weechat_python_api_buffer_get_string, METH_VARARGS, "" },
{ "buffer_get_pointer", &weechat_python_api_buffer_get_pointer, METH_VARARGS, "" },
{ "buffer_set", &weechat_python_api_buffer_set, METH_VARARGS, "" },
{ "nicklist_add_group", &weechat_python_api_nicklist_add_group, METH_VARARGS, "" },
{ "nicklist_search_group", &weechat_python_api_nicklist_search_group, METH_VARARGS, "" },
+10 -7
View File
@@ -87,9 +87,16 @@ weechat_python_exec (struct t_plugin_script *script,
{
if (argv[4])
{
rc = PyObject_CallFunction (evFunc, "sssss", argv[0],
argv[1], argv[2], argv[3],
argv[4]);
if (argv[5])
{
rc = PyObject_CallFunction (evFunc, "ssssss", argv[0],
argv[1], argv[2], argv[3],
argv[4], argv[5]);
}
else
rc = PyObject_CallFunction (evFunc, "sssss", argv[0],
argv[1], argv[2], argv[3],
argv[4]);
}
else
rc = PyObject_CallFunction (evFunc, "ssss", argv[0],
@@ -315,10 +322,6 @@ weechat_python_load (char *filename)
weechat_dict = PyModule_GetDict(weechat_module);
PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK", PyInt_FromLong((long) WEECHAT_RC_OK));
PyDict_SetItemString(weechat_dict, "WEECHAT_RC_ERROR", PyInt_FromLong((long) WEECHAT_RC_ERROR));
PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK_IGNORE_WEECHAT", PyInt_FromLong((long) WEECHAT_RC_OK_IGNORE_WEECHAT));
PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK_IGNORE_PLUGINS", PyInt_FromLong((long) WEECHAT_RC_OK_IGNORE_PLUGINS));
PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK_IGNORE_ALL", PyInt_FromLong((long) WEECHAT_RC_OK_IGNORE_ALL));
PyDict_SetItemString(weechat_dict, "WEECHAT_RC_OK_WITH_HIGHLIGHT", PyInt_FromLong((long) WEECHAT_RC_OK_WITH_HIGHLIGHT));
PyDict_SetItemString(weechat_dict, "WEECHAT_LIST_POS_SORT", PyString_FromString(WEECHAT_LIST_POS_SORT));
PyDict_SetItemString(weechat_dict, "WEECHAT_LIST_POS_BEGINNING", PyString_FromString(WEECHAT_LIST_POS_BEGINNING));
PyDict_SetItemString(weechat_dict, "WEECHAT_LIST_POS_END", PyString_FromString(WEECHAT_LIST_POS_END));
+68 -23
View File
@@ -2244,22 +2244,27 @@ weechat_ruby_api_hook_fd (VALUE class, VALUE fd, VALUE read, VALUE write,
int
weechat_ruby_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
time_t date, char *prefix, char *message)
time_t date, int tags_count, char **tags,
char *prefix, char *message)
{
struct t_script_callback *script_callback;
char *ruby_argv[5];
char *ruby_argv[6];
static char timebuffer[64];
int *rc, ret;
/* make C compiler happy */
(void) tags_count;
script_callback = (struct t_script_callback *)data;
snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", date);
ruby_argv[0] = script_ptr2str (buffer);
ruby_argv[1] = timebuffer;
ruby_argv[2] = prefix;
ruby_argv[3] = message;
ruby_argv[4] = NULL;
ruby_argv[2] = weechat_string_build_with_exploded (tags, ",");
ruby_argv[3] = prefix;
ruby_argv[4] = message;
ruby_argv[5] = NULL;
rc = (int *) weechat_ruby_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
@@ -2275,6 +2280,8 @@ weechat_ruby_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
}
if (ruby_argv[0])
free (ruby_argv[0]);
if (ruby_argv[2])
free (ruby_argv[2]);
return ret;
}
@@ -2284,10 +2291,10 @@ weechat_ruby_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
*/
static VALUE
weechat_ruby_api_hook_print (VALUE class, VALUE buffer, VALUE message,
VALUE strip_colors, VALUE function)
weechat_ruby_api_hook_print (VALUE class, VALUE buffer, VALUE tags,
VALUE message, VALUE strip_colors, VALUE function)
{
char *c_buffer, *c_message, *c_function, *result;
char *c_buffer, *c_tags, *c_message, *c_function, *result;
int c_strip_colors;
VALUE return_value;
@@ -2301,23 +2308,26 @@ weechat_ruby_api_hook_print (VALUE class, VALUE buffer, VALUE message,
}
c_buffer = NULL;
c_tags = NULL;
c_message = NULL;
c_strip_colors = 0;
c_function = NULL;
if (NIL_P (buffer) || NIL_P (message) || NIL_P (strip_colors)
|| NIL_P (function))
if (NIL_P (buffer) || NIL_P (tags) || NIL_P (message)
|| NIL_P (strip_colors) || NIL_P (function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_print");
RUBY_RETURN_EMPTY;
}
Check_Type (buffer, T_STRING);
Check_Type (tags, T_STRING);
Check_Type (message, T_STRING);
Check_Type (strip_colors, T_FIXNUM);
Check_Type (function, T_STRING);
c_buffer = STR2CSTR (buffer);
c_tags = STR2CSTR (tags);
c_message = STR2CSTR (message);
c_strip_colors = FIX2INT (strip_colors);
c_function = STR2CSTR (function);
@@ -2325,6 +2335,7 @@ weechat_ruby_api_hook_print (VALUE class, VALUE buffer, VALUE message,
result = script_ptr2str (script_api_hook_print (weechat_ruby_plugin,
ruby_current_script,
script_str2ptr (c_buffer),
c_tags,
c_message,
c_strip_colors,
&weechat_ruby_api_hook_print_cb,
@@ -3034,11 +3045,11 @@ weechat_ruby_api_buffer_close (VALUE class, VALUE buffer,
}
/*
* weechat_ruby_api_buffer_get: get a buffer property
* weechat_ruby_api_buffer_get_string: get a buffer property as string
*/
static VALUE
weechat_ruby_api_buffer_get (VALUE class, VALUE buffer, VALUE property)
weechat_ruby_api_buffer_get_string (VALUE class, VALUE buffer, VALUE property)
{
char *c_buffer, *c_property, *value;
@@ -3047,13 +3058,13 @@ weechat_ruby_api_buffer_get (VALUE class, VALUE buffer, VALUE property)
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get");
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get_string");
RUBY_RETURN_EMPTY;
}
if (NIL_P (buffer) || NIL_P (property))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get");
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get_string");
RUBY_RETURN_EMPTY;
}
@@ -3063,12 +3074,49 @@ weechat_ruby_api_buffer_get (VALUE class, VALUE buffer, VALUE property)
c_buffer = STR2CSTR (buffer);
c_property = STR2CSTR (property);
value = weechat_buffer_get (script_str2ptr (c_buffer),
c_property);
value = weechat_buffer_get_string (script_str2ptr (c_buffer),
c_property);
RUBY_RETURN_STRING(value);
}
/*
* weechat_ruby_api_buffer_get_pointer: get a buffer property as pointer
*/
static VALUE
weechat_ruby_api_buffer_get_pointer (VALUE class, VALUE buffer, VALUE property)
{
char *c_buffer, *c_property, *value;
VALUE return_value;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_get_pointer");
RUBY_RETURN_EMPTY;
}
if (NIL_P (buffer) || NIL_P (property))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get_pointer");
RUBY_RETURN_EMPTY;
}
Check_Type (buffer, T_STRING);
Check_Type (property, T_STRING);
c_buffer = STR2CSTR (buffer);
c_property = STR2CSTR (property);
value = script_ptr2str (weechat_buffer_get_string (script_str2ptr (c_buffer),
c_property));
RUBY_RETURN_STRING_FREE(value);
}
/*
* weechat_ruby_api_buffer_set: set a buffer property
*/
@@ -4171,10 +4219,6 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
{
rb_define_const(ruby_mWeechat, "WEECHAT_RC_OK", INT2NUM(WEECHAT_RC_OK));
rb_define_const(ruby_mWeechat, "WEECHAT_RC_ERROR", INT2NUM(WEECHAT_RC_ERROR));
rb_define_const(ruby_mWeechat, "WEECHAT_RC_OK_IGNORE_WEECHAT", INT2NUM(WEECHAT_RC_OK_IGNORE_WEECHAT));
rb_define_const(ruby_mWeechat, "WEECHAT_RC_OK_IGNORE_PLUGINS", INT2NUM(WEECHAT_RC_OK_IGNORE_PLUGINS));
rb_define_const(ruby_mWeechat, "WEECHAT_RC_OK_IGNORE_ALL", INT2NUM(WEECHAT_RC_OK_IGNORE_ALL));
rb_define_const(ruby_mWeechat, "WEECHAT_RC_OK_WITH_HIGHLIGHT", INT2NUM(WEECHAT_RC_OK_WITH_HIGHLIGHT));
rb_define_const(ruby_mWeechat, "WEECHAT_LIST_POS_SORT", rb_str_new2(WEECHAT_LIST_POS_SORT));
rb_define_const(ruby_mWeechat, "WEECHAT_LIST_POS_BEGINNING", rb_str_new2(WEECHAT_LIST_POS_BEGINNING));
rb_define_const(ruby_mWeechat, "WEECHAT_LIST_POS_END", rb_str_new2(WEECHAT_LIST_POS_END));
@@ -4231,7 +4275,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "hook_command", &weechat_ruby_api_hook_command, 6);
rb_define_module_function (ruby_mWeechat, "hook_timer", &weechat_ruby_api_hook_timer, 4);
rb_define_module_function (ruby_mWeechat, "hook_fd", &weechat_ruby_api_hook_fd, 5);
rb_define_module_function (ruby_mWeechat, "hook_print", &weechat_ruby_api_hook_print, 4);
rb_define_module_function (ruby_mWeechat, "hook_print", &weechat_ruby_api_hook_print, 5);
rb_define_module_function (ruby_mWeechat, "hook_signal", &weechat_ruby_api_hook_signal, 2);
rb_define_module_function (ruby_mWeechat, "hook_signal_send", &weechat_ruby_api_hook_signal_send, 3);
rb_define_module_function (ruby_mWeechat, "hook_config", &weechat_ruby_api_hook_config, 3);
@@ -4243,7 +4287,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "buffer_new", &weechat_ruby_api_buffer_new, 4);
rb_define_module_function (ruby_mWeechat, "buffer_search", &weechat_ruby_api_buffer_search, 2);
rb_define_module_function (ruby_mWeechat, "buffer_close", &weechat_ruby_api_buffer_close, 1);
rb_define_module_function (ruby_mWeechat, "buffer_get", &weechat_ruby_api_buffer_get, 2);
rb_define_module_function (ruby_mWeechat, "buffer_get_string", &weechat_ruby_api_buffer_get_string, 2);
rb_define_module_function (ruby_mWeechat, "buffer_get_pointer", &weechat_ruby_api_buffer_get_pointer, 2);
rb_define_module_function (ruby_mWeechat, "buffer_set", &weechat_ruby_api_buffer_set, 3);
rb_define_module_function (ruby_mWeechat, "nicklist_add_group", &weechat_ruby_api_nicklist_add_group, 5);
rb_define_module_function (ruby_mWeechat, "nicklist_search_group", &weechat_ruby_api_nicklist_search_group, 3);
+19 -7
View File
@@ -124,13 +124,25 @@ weechat_ruby_exec (struct t_plugin_script *script,
{
if (argv[4])
{
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
&ruby_error, 5,
rb_str_new2(argv[0]),
rb_str_new2(argv[1]),
rb_str_new2(argv[2]),
rb_str_new2(argv[3]),
rb_str_new2(argv[4]));
if (argv[5])
{
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
&ruby_error, 6,
rb_str_new2(argv[0]),
rb_str_new2(argv[1]),
rb_str_new2(argv[2]),
rb_str_new2(argv[3]),
rb_str_new2(argv[4]),
rb_str_new2(argv[5]));
}
else
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
&ruby_error, 5,
rb_str_new2(argv[0]),
rb_str_new2(argv[1]),
rb_str_new2(argv[2]),
rb_str_new2(argv[3]),
rb_str_new2(argv[4]));
}
else
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
+5 -4
View File
@@ -481,11 +481,12 @@ struct t_hook *
script_api_hook_print (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
char *message, int strip_colors,
char *tags, char *message, int strip_colors,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
time_t date, char *prefix,
char *message),
time_t date,
int tags_count, char **tags,
char *prefix, char *message),
char *function)
{
struct t_script_callback *new_script_callback;
@@ -495,7 +496,7 @@ script_api_hook_print (struct t_weechat_plugin *weechat_plugin,
if (!new_script_callback)
return NULL;
new_hook = weechat_hook_print (buffer, message, strip_colors,
new_hook = weechat_hook_print (buffer, tags, message, strip_colors,
callback, new_script_callback);
if (!new_hook)
{
+5 -1
View File
@@ -95,10 +95,14 @@ extern struct t_hook *script_api_hook_fd (struct t_weechat_plugin *weechat_plugi
extern struct t_hook *script_api_hook_print (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
char *message, int strip_colors,
char *tags,
char *message,
int strip_colors,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
time_t date,
int tags_count,
char **tags,
char *prefix,
char *message),
char *function);