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

Add of "modifier" hook, migration of charset plugin to new API, SIGHUP signal catched (reload all config files), better config files reloading

This commit is contained in:
Sebastien Helleu
2008-01-24 16:50:20 +01:00
parent 25c5bc6421
commit ed26a0389c
48 changed files with 2335 additions and 1113 deletions
+111 -1
View File
@@ -1671,7 +1671,7 @@ weechat_lua_api_hook_config (lua_State *L)
}
/*
* weechat_lua_api_hook_completion_cb: callback for completion option hooked
* weechat_lua_api_hook_completion_cb: callback for completion hooked
*/
int
@@ -1752,6 +1752,114 @@ weechat_lua_api_hook_completion (lua_State *L)
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_hook_modifier_cb: callback for modifier hooked
*/
char *
weechat_lua_api_hook_modifier_cb (void *data, char *modifier,
char *modifier_data, char *string)
{
struct t_script_callback *script_callback;
char *lua_argv[4];
script_callback = (struct t_script_callback *)data;
lua_argv[0] = modifier;
lua_argv[1] = modifier_data;
lua_argv[2] = string;
lua_argv[3] = NULL;
return (char *)weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
lua_argv);
}
/*
* weechat_lua_api_hook_modifier: hook a modifier
*/
static int
weechat_lua_api_hook_modifier (lua_State *L)
{
const char *modifier, *function;
char *result;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier");
LUA_RETURN_EMPTY;
}
modifier = NULL;
function = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier");
LUA_RETURN_EMPTY;
}
modifier = lua_tostring (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
result = script_ptr2str (script_api_hook_modifier (weechat_lua_plugin,
lua_current_script,
(char *)modifier,
&weechat_lua_api_hook_modifier_cb,
(char *)function));
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_hook_modifier_exec: execute a modifier hook
*/
static int
weechat_lua_api_hook_modifier_exec (lua_State *L)
{
const char *modifier, *modifier_data, *string;
char *result;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier_exec");
LUA_RETURN_EMPTY;
}
modifier = NULL;
modifier_data = NULL;
string = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier_exec");
LUA_RETURN_ERROR;
}
modifier = lua_tostring (lua_current_interpreter, -3);
modifier_data = lua_tostring (lua_current_interpreter, -2);
string = lua_tostring (lua_current_interpreter, -1);
result = weechat_hook_modifier_exec ((char *)modifier,
(char *)modifier_data,
(char *)string);
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_unhook: unhook something
*/
@@ -3539,6 +3647,8 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "hook_signal_send", &weechat_lua_api_hook_signal_send },
{ "hook_config", &weechat_lua_api_hook_config },
{ "hook_completion", &weechat_lua_api_hook_completion },
{ "hook_modifier", &weechat_lua_api_hook_modifier },
{ "hook_modifier_exec", &weechat_lua_api_hook_modifier_exec },
{ "unhook", &weechat_lua_api_unhook },
{ "unhook_all", &weechat_lua_api_unhook_all },
{ "buffer_new", &weechat_lua_api_buffer_new },
+96 -8
View File
@@ -1422,6 +1422,92 @@ static XS (XS_weechat_hook_completion)
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat_perl_api_hook_modifier_cb: callback for modifier hooked
*/
char *
weechat_perl_api_hook_modifier_cb (void *data, char *modifier,
char *modifier_data, char *string)
{
struct t_script_callback *script_callback;
char *perl_argv[4];
script_callback = (struct t_script_callback *)data;
perl_argv[0] = modifier;
perl_argv[1] = modifier_data;
perl_argv[2] = string;
perl_argv[3] = NULL;
return (char *)weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
perl_argv);
}
/*
* weechat::hook_modifier: hook a modifier
*/
static XS (XS_weechat_hook_modifier)
{
char *result;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier");
PERL_RETURN_EMPTY;
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier");
PERL_RETURN_EMPTY;
}
result = script_ptr2str (script_api_hook_modifier (weechat_perl_plugin,
perl_current_script,
SvPV (ST (0), PL_na), /* modifier */
&weechat_perl_api_hook_modifier_cb,
SvPV (ST (1), PL_na))); /* perl function */
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat::hook_modifier_exec: execute a modifier hook
*/
static XS (XS_weechat_hook_modifier_exec)
{
char *result;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier_exec");
PERL_RETURN_EMPTY;
}
if (items < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier_exec");
PERL_RETURN_EMPTY;
}
result = weechat_hook_modifier_exec (SvPV (ST (0), PL_na), /* modifier */
SvPV (ST (1), PL_na), /* modifier_data */
SvPV (ST (2), PL_na)); /* string */
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat::unhook: unhook something
*/
@@ -1487,7 +1573,7 @@ weechat_perl_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
{
struct t_script_callback *script_callback;
char *perl_argv[3];
int *r, ret;
int *rc, ret;
script_callback = (struct t_script_callback *)data;
@@ -1495,16 +1581,16 @@ weechat_perl_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
perl_argv[1] = input_data;
perl_argv[2] = NULL;
r = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
perl_argv);
if (!r)
rc = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
perl_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *r;
free (r);
ret = *rc;
free (rc);
}
if (perl_argv[0])
free (perl_argv[0]);
@@ -2723,6 +2809,8 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::hook_signal_send", XS_weechat_hook_signal_send, "weechat");
newXS ("weechat::hook_config", XS_weechat_hook_config, "weechat");
newXS ("weechat::hook_completion", XS_weechat_hook_completion, "weechat");
newXS ("weechat::hook_modifier", XS_weechat_hook_modifier, "weechat");
newXS ("weechat::hook_modifier_exec", XS_weechat_hook_modifier_exec, "weechat");
newXS ("weechat::unhook", XS_weechat_unhook, "weechat");
newXS ("weechat::unhook_all", XS_weechat_unhook_all, "weechat");
newXS ("weechat::buffer_new", XS_weechat_buffer_new, "weechat");
+5 -4
View File
@@ -110,19 +110,20 @@ weechat_perl_exec (struct t_plugin_script *script,
char *func;
unsigned int count;
void *ret_value;
int *ret_i, mem_err;
int *ret_i, mem_err, length;
SV *ret_s;
/* this code is placed here to conform ISO C90 */
dSP;
#ifndef MULTIPLICITY
int size = strlen (script->interpreter) + strlen(function) + 3;
func = (char *)malloc (size * sizeof(char));
int length = strlen (script->interpreter) + strlen (function) + 3;
func = (char *)malloc (length * sizeof(char));
if (!func)
return NULL;
snprintf (func, size, "%s::%s", (char *) script->interpreter, function);
snprintf (func, length, "%s::%s", (char *) script->interpreter, function);
#else
(void) length;
func = function;
PERL_SET_CONTEXT (script->interpreter);
#endif
@@ -1551,6 +1551,99 @@ weechat_python_api_hook_completion (PyObject *self, PyObject *args)
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_hook_modifier_cb: callback for modifier hooked
*/
char *
weechat_python_api_hook_modifier_cb (void *data, char *modifier,
char *modifier_data, char *string)
{
struct t_script_callback *script_callback;
char *python_argv[4];
script_callback = (struct t_script_callback *)data;
python_argv[0] = modifier;
python_argv[1] = modifier_data;
python_argv[2] = string;
python_argv[3] = NULL;
return (char *)weechat_python_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
python_argv);
}
/*
* weechat_python_api_hook_modifier: hook a modifier
*/
static PyObject *
weechat_python_api_hook_modifier (PyObject *self, PyObject *args)
{
char *modifier, *function, *result;
PyObject *object;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier");
PYTHON_RETURN_EMPTY;
}
modifier = NULL;
function = NULL;
if (!PyArg_ParseTuple (args, "ss", &modifier, &function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier");
PYTHON_RETURN_EMPTY;
}
result = script_ptr2str(script_api_hook_modifier (weechat_python_plugin,
python_current_script,
modifier,
&weechat_python_api_hook_modifier_cb,
function));
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_hook_modifier_exec: execute a modifier hook
*/
static PyObject *
weechat_python_api_hook_modifier_exec (PyObject *self, PyObject *args)
{
char *modifier, *modifier_data, *string, *result;
PyObject *object;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier_exec");
PYTHON_RETURN_EMPTY;
}
modifier = NULL;
modifier_data = NULL;
string = NULL;
if (!PyArg_ParseTuple (args, "sss", &modifier, &modifier_data, &string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier_exec");
PYTHON_RETURN_EMPTY;
}
result = weechat_hook_modifier_exec (modifier, modifier_data, string);
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_unhook: unhook something
*/
@@ -3160,6 +3253,8 @@ PyMethodDef weechat_python_funcs[] =
{ "hook_signal_send", &weechat_python_api_hook_signal_send, METH_VARARGS, "" },
{ "hook_config", &weechat_python_api_hook_config, METH_VARARGS, "" },
{ "hook_completion", &weechat_python_api_hook_completion, METH_VARARGS, "" },
{ "hook_modifier", &weechat_python_api_hook_modifier, METH_VARARGS, "" },
{ "hook_modifier_exec", &weechat_python_api_hook_modifier_exec, METH_VARARGS, "" },
{ "unhook", &weechat_python_api_unhook, METH_VARARGS, "" },
{ "unhook_all", &weechat_python_api_unhook_all, METH_VARARGS, "" },
{ "buffer_new", &weechat_python_api_buffer_new, METH_VARARGS, "" },
+110
View File
@@ -1777,6 +1777,114 @@ weechat_ruby_api_hook_completion (VALUE class, VALUE completion,
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_hook_modifier_cb: callback for modifier hooked
*/
char *
weechat_ruby_api_hook_modifier_cb (void *data, char *modifier,
char *modifier_data, char *string)
{
struct t_script_callback *script_callback;
char *ruby_argv[4];
script_callback = (struct t_script_callback *)data;
ruby_argv[0] = modifier;
ruby_argv[1] = modifier_data;
ruby_argv[2] = string;
ruby_argv[3] = NULL;
return (char *)weechat_ruby_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
ruby_argv);
}
/*
* weechat_ruby_api_hook_modifier: hook a modifier
*/
static VALUE
weechat_ruby_api_hook_modifier (VALUE class, VALUE modifier, VALUE function)
{
char *c_modifier, *c_function, *result;
VALUE return_value;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier");
RUBY_RETURN_EMPTY;
}
c_modifier = NULL;
c_function = NULL;
if (NIL_P (modifier) || NIL_P (function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier");
RUBY_RETURN_EMPTY;
}
Check_Type (modifier, T_STRING);
Check_Type (function, T_STRING);
c_modifier = STR2CSTR (modifier);
c_function = STR2CSTR (function);
result = script_ptr2str (script_api_hook_modifier (weechat_ruby_plugin,
ruby_current_script,
c_modifier,
&weechat_ruby_api_hook_modifier_cb,
c_function));
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_hook_modifier_exec: execute a modifier hook
*/
static VALUE
weechat_ruby_api_hook_modifier_exec (VALUE class, VALUE modifier,
VALUE modifier_data, VALUE string)
{
char *c_modifier, *c_modifier_data, *c_string, *result;
VALUE return_value;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_modifier_exec");
RUBY_RETURN_EMPTY;
}
c_modifier = NULL;
c_modifier_data = NULL;
c_string = NULL;
if (NIL_P (modifier) || NIL_P (modifier_data) || NIL_P (string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_modifier_exec");
RUBY_RETURN_EMPTY;
}
Check_Type (modifier, T_STRING);
Check_Type (modifier_data, T_STRING);
Check_Type (string, T_STRING);
c_modifier = STR2CSTR (modifier);
c_modifier_data = STR2CSTR (modifier_data);
c_string = STR2CSTR (string);
result = weechat_hook_modifier_exec (c_modifier, c_modifier_data, c_string);
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_unhook: unhook something
*/
@@ -3300,6 +3408,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
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);
rb_define_module_function (ruby_mWeechat, "hook_completion", &weechat_ruby_api_hook_completion, 2);
rb_define_module_function (ruby_mWeechat, "hook_modifier", &weechat_ruby_api_hook_modifier, 2);
rb_define_module_function (ruby_mWeechat, "hook_modifier_exec", &weechat_ruby_api_hook_modifier_exec, 3);
rb_define_module_function (ruby_mWeechat, "unhook", &weechat_ruby_api_unhook, 1);
rb_define_module_function (ruby_mWeechat, "unhook_all", &weechat_ruby_api_unhook_all, 0);
rb_define_module_function (ruby_mWeechat, "buffer_new", &weechat_ruby_api_buffer_new, 3);
+36
View File
@@ -385,6 +385,42 @@ script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
return new_hook;
}
/*
* script_api_hook_modifier: hook a modifier
* return new hook, NULL if error
*/
struct t_hook *
script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *modifier,
char *(*callback)(void *data, char *modifier,
char *modifier_data, char *string),
char *function)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return NULL;
new_hook = weechat_hook_modifier (modifier, callback, new_script_callback);
if (!new_hook)
{
free (new_script_callback);
return NULL;
}
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;
}
/*
* script_api_unhook: unhook something
* return 1 if ok, 0 if error
+8
View File
@@ -87,6 +87,14 @@ extern struct t_hook *script_api_hook_completion (struct t_weechat_plugin *weech
struct t_gui_buffer *buffer,
struct t_weelist *list),
char *function);
extern struct t_hook *script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *modifier,
char *(*callback)(void *data,
char *modifier,
char *modifier_data,
char *string),
char *function);
extern int script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook);