diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/plugin.c | 2 | ||||
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua-api.c | 129 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl-api.c | 104 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python-api.c | 107 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python.c | 1 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby-api.c | 118 | ||||
-rw-r--r-- | src/plugins/scripts/script-api.c | 39 | ||||
-rw-r--r-- | src/plugins/scripts/script-api.h | 7 | ||||
-rw-r--r-- | src/plugins/scripts/tcl/weechat-tcl-api.c | 113 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 13 |
10 files changed, 633 insertions, 0 deletions
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index e7538beb2..277283a13 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -350,6 +350,7 @@ plugin_load (const char *filename) new_plugin->string_split_command = &string_split_command; new_plugin->string_free_splitted_command = &string_free_splitted_command; new_plugin->string_format_size = &string_format_size; + new_plugin->string_remove_color = &string_remove_color; new_plugin->utf8_has_8bits = &utf8_has_8bits; new_plugin->utf8_is_valid = &utf8_is_valid; @@ -435,6 +436,7 @@ plugin_load (const char *filename) new_plugin->log_printf = &log_printf; new_plugin->hook_command = &hook_command; + new_plugin->hook_command_run = &hook_command_run; new_plugin->hook_timer = &hook_timer; new_plugin->hook_fd = &hook_fd; new_plugin->hook_connect = &hook_connect; diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 1b8508e65..dac75ab02 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -362,6 +362,43 @@ weechat_lua_api_ngettext (lua_State *L) } /* + * weechat_lua_api_string_remove_color: remove WeeChat color codes from string + */ + +static int +weechat_lua_api_string_remove_color (lua_State *L) +{ + const char *string; + char *result; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("string_remove_color"); + LUA_RETURN_EMPTY; + } + + string = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color"); + LUA_RETURN_EMPTY; + } + + string = lua_tostring (lua_current_interpreter, -1); + + result = weechat_string_remove_color (string); + + LUA_RETURN_STRING_FREE(result); +} + +/* * weechat_lua_api_mkdir_home: create a directory in WeeChat home */ @@ -2740,6 +2777,85 @@ weechat_lua_api_hook_command (lua_State *L) } /* + * weechat_lua_api_hook_command_run_cb: callback for command_run hooked + */ + +int +weechat_lua_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer, + const char *command) +{ + struct t_script_callback *script_callback; + char *lua_argv[3]; + int *rc, ret; + + script_callback = (struct t_script_callback *)data; + + lua_argv[0] = script_ptr2str (buffer); + lua_argv[1] = (char *)command; + lua_argv[2] = NULL; + + rc = (int *) weechat_lua_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + lua_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (lua_argv[0]) + free (lua_argv[0]); + + return ret; +} + +/* + * weechat_lua_api_hook_command_run: hook a command_run + */ + +static int +weechat_lua_api_hook_command_run (lua_State *L) +{ + const char *command, *function; + char *result; + int n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command_run"); + LUA_RETURN_EMPTY; + } + + command = NULL; + function = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command_run"); + LUA_RETURN_EMPTY; + } + + command = lua_tostring (lua_current_interpreter, -2); + function = lua_tostring (lua_current_interpreter, -1); + + result = script_ptr2str (script_api_hook_command_run (weechat_lua_plugin, + lua_current_script, + command, + &weechat_lua_api_hook_command_run_cb, + function)); + + LUA_RETURN_STRING_FREE(result); +} + +/* * weechat_lua_api_hook_timer_cb: callback for timer hooked */ @@ -5690,6 +5806,16 @@ weechat_lua_api_constant_weechat_rc_ok (lua_State *L) } static int +weechat_lua_api_constant_weechat_rc_ok_eat (lua_State *L) +{ + /* make C compiler happy */ + (void) L; + + lua_pushnumber (lua_current_interpreter, WEECHAT_RC_OK_EAT); + return 1; +} + +static int weechat_lua_api_constant_weechat_rc_error (lua_State *L) { /* make C compiler happy */ @@ -6041,6 +6167,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = { { "iconv_from_internal", &weechat_lua_api_iconv_from_internal }, { "gettext", &weechat_lua_api_gettext }, { "ngettext", &weechat_lua_api_ngettext }, + { "string_remove_color", &weechat_lua_api_string_remove_color }, { "mkdir_home", &weechat_lua_api_mkdir_home }, { "mkdir", &weechat_lua_api_mkdir }, { "mkdir_parents", &weechat_lua_api_mkdir_parents }, @@ -6091,6 +6218,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = { { "print_y", &weechat_lua_api_print_y }, { "log_print", &weechat_lua_api_log_print }, { "hook_command", &weechat_lua_api_hook_command }, + { "hook_command_run", &weechat_lua_api_hook_command_run }, { "hook_timer", &weechat_lua_api_hook_timer }, { "hook_fd", &weechat_lua_api_hook_fd }, { "hook_connect", &weechat_lua_api_hook_connect }, @@ -6155,6 +6283,7 @@ 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_OK_EAT", &weechat_lua_api_constant_weechat_rc_ok_eat }, { "WEECHAT_RC_ERROR", &weechat_lua_api_constant_weechat_rc_error }, { "WEECHAT_CONFIG_READ_OK", &weechat_lua_api_constant_weechat_config_read_ok }, diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index f1fe74c6b..348ca0d8c 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -308,6 +308,36 @@ static XS (XS_weechat_api_ngettext) } /* + * weechat::string_remove_color: remove WeeChat color codes from string + */ + +static XS (XS_weechat_api_string_remove_color) +{ + char *result, *string; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("string_remove_color"); + PERL_RETURN_EMPTY; + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color"); + PERL_RETURN_EMPTY; + } + + string = SvPV (ST (0), PL_na); + result = weechat_string_remove_color (string); + + PERL_RETURN_STRING_FREE(result); +} + +/* * weechat::mkdir_home: create a directory in WeeChat home */ @@ -2282,6 +2312,77 @@ static XS (XS_weechat_api_hook_command) } /* + * weechat_perl_api_hook_command_run_cb: callback for command_run hooked + */ + +int +weechat_perl_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer, + const char *command) +{ + struct t_script_callback *script_callback; + char *perl_argv[3]; + int *rc, ret; + + script_callback = (struct t_script_callback *)data; + + perl_argv[0] = script_ptr2str (buffer); + perl_argv[1] = (char *)command; + perl_argv[2] = NULL; + + 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 = *rc; + free (rc); + } + if (perl_argv[0]) + free (perl_argv[0]); + + return ret; +} + +/* + * weechat::hook_command_run: hook a command_run + */ + +static XS (XS_weechat_api_hook_command_run) +{ + char *result, *command, *function; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command_run"); + PERL_RETURN_EMPTY; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command_run"); + PERL_RETURN_EMPTY; + } + + command = SvPV (ST (0), PL_na); + function = SvPV (ST (1), PL_na); + result = script_ptr2str (script_api_hook_command_run (weechat_perl_plugin, + perl_current_script, + command, + &weechat_perl_api_hook_command_run_cb, + function)); + + PERL_RETURN_STRING_FREE(result); +} + +/* * weechat_perl_api_hook_timer_cb: callback for timer hooked */ @@ -4750,6 +4851,7 @@ weechat_perl_api_init (pTHX) newXS ("weechat::iconv_from_internal", XS_weechat_api_iconv_from_internal, "weechat"); newXS ("weechat::gettext", XS_weechat_api_gettext, "weechat"); newXS ("weechat::ngettext", XS_weechat_api_ngettext, "weechat"); + newXS ("weechat::string_remove_color", XS_weechat_api_string_remove_color, "weechat"); newXS ("weechat::mkdir_home", XS_weechat_api_mkdir_home, "weechat"); newXS ("weechat::mkdir", XS_weechat_api_mkdir, "weechat"); newXS ("weechat::mkdir_parents", XS_weechat_api_mkdir_parents, "weechat"); @@ -4800,6 +4902,7 @@ weechat_perl_api_init (pTHX) newXS ("weechat::print_y", XS_weechat_api_print_y, "weechat"); newXS ("weechat::log_print", XS_weechat_api_log_print, "weechat"); newXS ("weechat::hook_command", XS_weechat_api_hook_command, "weechat"); + newXS ("weechat::hook_command_run", XS_weechat_api_hook_command_run, "weechat"); newXS ("weechat::hook_timer", XS_weechat_api_hook_timer, "weechat"); newXS ("weechat::hook_fd", XS_weechat_api_hook_fd, "weechat"); newXS ("weechat::hook_connect", XS_weechat_api_hook_connect, "weechat"); @@ -4864,6 +4967,7 @@ weechat_perl_api_init (pTHX) /* interface constants */ stash = gv_stashpv ("weechat", TRUE); newCONSTSUB (stash, "weechat::WEECHAT_RC_OK", newSViv (WEECHAT_RC_OK)); + newCONSTSUB (stash, "weechat::WEECHAT_RC_OK_EAT", newSViv (WEECHAT_RC_OK_EAT)); newCONSTSUB (stash, "weechat::WEECHAT_RC_ERROR", newSViv (WEECHAT_RC_ERROR)); newCONSTSUB (stash, "weechat::WEECHAT_CONFIG_READ_OK", newSViv (WEECHAT_CONFIG_READ_OK)); diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 33c047c45..95807c41a 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -315,6 +315,38 @@ weechat_python_api_ngettext (PyObject *self, PyObject *args) } /* + * weechat_python_api_string_remove_color: remove WeeChat color codes from string + */ + +static PyObject * +weechat_python_api_string_remove_color (PyObject *self, PyObject *args) +{ + char *string, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("string_remove_color"); + PYTHON_RETURN_EMPTY; + } + + string = NULL; + + if (!PyArg_ParseTuple (args, "s", &string)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color"); + PYTHON_RETURN_EMPTY; + } + + result = weechat_string_remove_color (string); + + PYTHON_RETURN_STRING_FREE(result); +} + +/* * weechat_python_api_mkdir_home: create a directory in WeeChat home */ @@ -2430,6 +2462,79 @@ weechat_python_api_hook_command (PyObject *self, PyObject *args) } /* + * weechat_python_api_hook_command_run_cb: callback for command_run hooked + */ + +int +weechat_python_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer, + const char *command) +{ + struct t_script_callback *script_callback; + char *python_argv[3]; + int *rc, ret; + + script_callback = (struct t_script_callback *)data; + + python_argv[0] = script_ptr2str (buffer); + python_argv[1] = (char *)command; + python_argv[2] = NULL; + + rc = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (python_argv[0]) + free (python_argv[0]); + + return ret; +} + +/* + * weechat_python_api_hook_command_run: hook a command_run + */ + +static PyObject * +weechat_python_api_hook_command_run (PyObject *self, PyObject *args) +{ + char *command, *function, *result; + PyObject *object; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command_run"); + PYTHON_RETURN_EMPTY; + } + + command = NULL; + function = NULL; + + if (!PyArg_ParseTuple (args, "ss", &command, &function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command_run"); + PYTHON_RETURN_EMPTY; + } + + result = script_ptr2str (script_api_hook_command_run (weechat_python_plugin, + python_current_script, + command, + &weechat_python_api_hook_command_run_cb, + function)); + + PYTHON_RETURN_STRING_FREE(result); +} + +/* * weechat_python_api_hook_timer_cb: callback for timer hooked */ @@ -5049,6 +5154,7 @@ PyMethodDef weechat_python_funcs[] = { "iconv_from_internal", &weechat_python_api_iconv_from_internal, METH_VARARGS, "" }, { "gettext", &weechat_python_api_gettext, METH_VARARGS, "" }, { "ngettext", &weechat_python_api_ngettext, METH_VARARGS, "" }, + { "string_remove_color", &weechat_python_api_string_remove_color, METH_VARARGS, "" }, { "mkdir_home", &weechat_python_api_mkdir_home, METH_VARARGS, "" }, { "mkdir", &weechat_python_api_mkdir, METH_VARARGS, "" }, { "mkdir_parents", &weechat_python_api_mkdir_parents, METH_VARARGS, "" }, @@ -5099,6 +5205,7 @@ PyMethodDef weechat_python_funcs[] = { "prnt_y", &weechat_python_api_prnt_y, METH_VARARGS, "" }, { "log_print", &weechat_python_api_log_print, METH_VARARGS, "" }, { "hook_command", &weechat_python_api_hook_command, METH_VARARGS, "" }, + { "hook_command_run", &weechat_python_api_hook_command_run, METH_VARARGS, "" }, { "hook_timer", &weechat_python_api_hook_timer, METH_VARARGS, "" }, { "hook_fd", &weechat_python_api_hook_fd, METH_VARARGS, "" }, { "hook_connect", &weechat_python_api_hook_connect, METH_VARARGS, "" }, diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index 8865532c9..f923d5cbf 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -356,6 +356,7 @@ weechat_python_load (const char *filename) /* define some constants */ 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_OK_EAT", PyInt_FromLong((long) WEECHAT_RC_OK_EAT)); PyDict_SetItemString(weechat_dict, "WEECHAT_RC_ERROR", PyInt_FromLong((long) WEECHAT_RC_ERROR)); PyDict_SetItemString(weechat_dict, "WEECHAT_CONFIG_READ_OK", PyInt_FromLong((long) WEECHAT_CONFIG_READ_OK)); diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index 8645a88b1..3bd217fa3 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -365,6 +365,42 @@ weechat_ruby_api_ngettext (VALUE class, VALUE single, VALUE plural, } /* + * weechat_ruby_api_string_remove_color: remove WeeChat color codes from string + */ + +static VALUE +weechat_ruby_api_string_remove_color (VALUE class, VALUE string) +{ + char *c_string, *result; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("string_remove_color"); + RUBY_RETURN_EMPTY; + } + + c_string = NULL; + + if (NIL_P (string)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color"); + RUBY_RETURN_EMPTY; + } + + Check_Type (string, T_STRING); + + c_string = STR2CSTR (string); + + result = weechat_string_remove_color (c_string); + + RUBY_RETURN_STRING_FREE(result); +} + +/* * weechat_ruby_api_mkdir_home: create a directory in WeeChat home */ @@ -2796,6 +2832,85 @@ weechat_ruby_api_hook_command (VALUE class, VALUE command, VALUE description, } /* + * weechat_ruby_api_hook_command_run_cb: callback for command_run hooked + */ + +int +weechat_ruby_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer, + const char *command) +{ + struct t_script_callback *script_callback; + char *ruby_argv[3]; + int *rc, ret; + + script_callback = (struct t_script_callback *)data; + + ruby_argv[0] = script_ptr2str (buffer); + ruby_argv[1] = (char *)command; + ruby_argv[2] = NULL; + + rc = (int *) weechat_ruby_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + ruby_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (ruby_argv[0]) + free (ruby_argv[0]); + + return ret; +} + +/* + * weechat_ruby_api_hook_command_run: hook a command_run + */ + +static VALUE +weechat_ruby_api_hook_command_run (VALUE class, VALUE command, VALUE function) +{ + char *c_command, *c_function, *result; + VALUE return_value; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command_run"); + RUBY_RETURN_EMPTY; + } + + c_command = NULL; + c_function = NULL; + + if (NIL_P (command) || NIL_P (function)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command_run"); + RUBY_RETURN_EMPTY; + } + + Check_Type (command, T_STRING); + Check_Type (function, T_STRING); + + c_command = STR2CSTR (command); + c_function = STR2CSTR (function); + + result = script_ptr2str (script_api_hook_command_run (weechat_ruby_plugin, + ruby_current_script, + c_command, + &weechat_ruby_api_hook_command_run_cb, + c_function)); + + RUBY_RETURN_STRING_FREE(result); +} + +/* * weechat_ruby_api_hook_timer_cb: callback for timer hooked */ @@ -5757,6 +5872,7 @@ void 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_OK_EAT", INT2NUM(WEECHAT_RC_OK_EAT)); rb_define_const(ruby_mWeechat, "WEECHAT_RC_ERROR", INT2NUM(WEECHAT_RC_ERROR)); rb_define_const(ruby_mWeechat, "WEECHAT_CONFIG_READ_OK", INT2NUM(WEECHAT_CONFIG_READ_OK)); @@ -5804,6 +5920,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "iconv_from_internal", &weechat_ruby_api_iconv_from_internal, 2); rb_define_module_function (ruby_mWeechat, "gettext", &weechat_ruby_api_gettext, 1); rb_define_module_function (ruby_mWeechat, "ngettext", &weechat_ruby_api_ngettext, 3); + rb_define_module_function (ruby_mWeechat, "string_remove_color", &weechat_ruby_api_string_remove_color, 1); rb_define_module_function (ruby_mWeechat, "mkdir_home", &weechat_ruby_api_mkdir_home, 2); rb_define_module_function (ruby_mWeechat, "mkdir", &weechat_ruby_api_mkdir, 2); rb_define_module_function (ruby_mWeechat, "mkdir_parents", &weechat_ruby_api_mkdir_parents, 2); @@ -5854,6 +5971,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "print_y", &weechat_ruby_api_print_y, 3); rb_define_module_function (ruby_mWeechat, "log_print", &weechat_ruby_api_log_print, 1); rb_define_module_function (ruby_mWeechat, "hook_command", &weechat_ruby_api_hook_command, 6); + rb_define_module_function (ruby_mWeechat, "hook_command_run", &weechat_ruby_api_hook_command_run, 2); 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_connect", &weechat_ruby_api_hook_connect, 7); diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c index 911f1acb0..1e39e5649 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -664,6 +664,45 @@ script_api_hook_command (struct t_weechat_plugin *weechat_plugin, } /* + * script_api_hook_command_run: hook a command_run + * return new hook, NULL if error + */ + +struct t_hook * +script_api_hook_command_run (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + const char *command, + int (*callback)(void *data, + struct t_gui_buffer *buffer, + const char *command), + const 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_command_run (command, + callback, new_script_callback); + if (!new_hook) + { + script_callback_free_data (new_script_callback); + 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_hook_timer: hook a timer * return new hook, NULL if error */ diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h index 15122b96a..bd8822664 100644 --- a/src/plugins/scripts/script-api.h +++ b/src/plugins/scripts/script-api.h @@ -108,6 +108,13 @@ extern struct t_hook *script_api_hook_command (struct t_weechat_plugin *weechat_ int argc, char **argv, char **argv_eol), const char *function); +extern struct t_hook *script_api_hook_command_run (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + const char *command, + int (*callback)(void *data, + struct t_gui_buffer *buffer, + const char *command), + const char *function); extern struct t_hook *script_api_hook_timer (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, int interval, int align_second, diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index cf68dc255..1a778426f 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -432,6 +432,39 @@ weechat_tcl_api_ngettext (ClientData clientData, Tcl_Interp *interp, } /* + * weechat_tcl_api_string_remove_color: remove WeeChat color codes from string + */ + +static int +weechat_tcl_api_string_remove_color (ClientData clientData, Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj* objp; + char *result, *string; + int i; + + /* make C compiler happy */ + (void) clientData; + + if (!tcl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("string_remove_color"); + TCL_RETURN_EMPTY; + } + + if (objc < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color"); + TCL_RETURN_EMPTY; + } + + string = Tcl_GetStringFromObj (objv[1], &i); + result = weechat_string_remove_color (string); + + TCL_RETURN_STRING_FREE(result); +} + +/* * weechat_tcl_api_mkdir_home: create a directory in WeeChat home */ @@ -2636,6 +2669,80 @@ weechat_tcl_api_hook_command (ClientData clientData, Tcl_Interp *interp, } /* + * weechat_tcl_api_hook_command_run_cb: callback for command_run hooked + */ + +int +weechat_tcl_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer, + const char *command) +{ + struct t_script_callback *script_callback; + char *tcl_argv[3]; + int *rc, ret; + + script_callback = (struct t_script_callback *)data; + + tcl_argv[0] = script_ptr2str (buffer); + tcl_argv[1] = (char *)command; + tcl_argv[2] = NULL; + + rc = (int *) weechat_tcl_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + tcl_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (tcl_argv[0]) + free (tcl_argv[0]); + + return ret; +} + +/* + * weechat_tcl_api_hook_command_run: hook a command_run + */ + +static int +weechat_tcl_api_hook_command_run (ClientData clientData, Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj *objp; + char *result, *command, *function; + int i; + + /* make C compiler happy */ + (void) clientData; + + if (!tcl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_command_run"); + TCL_RETURN_EMPTY; + } + + if (objc < 3) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command_run"); + TCL_RETURN_EMPTY; + } + + command = Tcl_GetStringFromObj (objv[1], &i); + function = Tcl_GetStringFromObj (objv[2], &i); + result = script_ptr2str (script_api_hook_command_run (weechat_tcl_plugin, + tcl_current_script, + command, + &weechat_tcl_api_hook_command_run_cb, + function)); + + TCL_RETURN_STRING_FREE(result); +} + +/* * weechat_tcl_api_hook_timer_cb: callback for timer hooked */ @@ -5353,6 +5460,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) { Tcl_IncrRefCount (objp); Tcl_SetVar (interp, "weechat::WEECHAT_RC_OK", Tcl_GetStringFromObj (objp, &i),0); + Tcl_SetIntObj (objp,WEECHAT_RC_OK_EAT); + Tcl_SetVar (interp, "weechat::WEECHAT_RC_OK_EAT", Tcl_GetStringFromObj (objp, &i),0); Tcl_SetIntObj (objp,WEECHAT_RC_ERROR); Tcl_SetVar (interp, "weechat::WEECHAT_RC_ERROR", Tcl_GetStringFromObj (objp, &i),0); @@ -5444,6 +5553,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) { weechat_tcl_api_gettext, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::ngettext", weechat_tcl_api_ngettext, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); + Tcl_CreateObjCommand (interp,"weechat::string_remove_color", + weechat_tcl_api_string_remove_color, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::mkdir_home", weechat_tcl_api_mkdir_home, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::mkdir", @@ -5544,6 +5655,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) { weechat_tcl_api_log_print, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::hook_command", weechat_tcl_api_hook_command, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); + Tcl_CreateObjCommand (interp,"weechat::hook_command_run", + weechat_tcl_api_hook_command_run, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::hook_timer", weechat_tcl_api_hook_timer, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::hook_fd", diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index e3b0bb8e5..d84f8457f 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -48,6 +48,7 @@ struct t_weelist; /* return codes for plugin functions */ #define WEECHAT_RC_OK 0 +#define WEECHAT_RC_OK_EAT 1 #define WEECHAT_RC_ERROR -1 /* return codes for config read functions/callbacks */ @@ -159,6 +160,7 @@ struct t_weechat_plugin char **(*string_split_command) (const char *command, char separator); void (*string_free_splitted_command) (char **splitted_command); char *(*string_format_size) (unsigned long size); + char *(*string_remove_color) (const char *string); /* UTF-8 strings */ int (*utf8_has_8bits) (const char *string); @@ -345,6 +347,12 @@ struct t_weechat_plugin int argc, char **argv, char **argv_eol), void *callback_data); + struct t_hook *(*hook_command_run) (struct t_weechat_plugin *plugin, + const char *command, + int (*callback)(void *data, + struct t_gui_buffer *buffer, + const char *command), + void *callback_data); struct t_hook *(*hook_timer) (struct t_weechat_plugin *plugin, long interval, int align_second, @@ -667,6 +675,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->string_free_splitted_command(__splitted_command) #define weechat_string_format_size(__size) \ weechat_plugin->string_format_size(__size) +#define weechat_string_remove_color(__string) \ + weechat_plugin->string_remove_color(__string) /* UTF-8 strings */ #define weechat_utf8_has_8bits(__string) \ @@ -901,6 +911,9 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->hook_command(weechat_plugin, __command, \ __description, __args, __args_desc, \ __completion, __callback, __data) +#define weechat_hook_command_run(__command, __callback, __data) \ + weechat_plugin->hook_command_run(weechat_plugin, __command, \ + __callback, __data) #define weechat_hook_timer(__interval, __align_second, __max_calls, \ __callback, __data) \ weechat_plugin->hook_timer(weechat_plugin, __interval, \ |