From 353538e3d80a1f90c2f3149b82d4be680ede0cdb Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sun, 17 May 2009 15:49:58 +0200 Subject: [PATCH] Add function "config_is_set_plugin" in plugin/script API --- doc/de/dev/plugin_c_api.de.xml | 71 ++++++++++++++----- doc/en/dev/plugin_c_api.en.xml | 71 ++++++++++++++----- doc/fr/dev/plugin_c_api.fr.xml | 71 ++++++++++++++----- src/plugins/plugin-api.c | 20 ++++++ src/plugins/plugin-api.h | 2 + src/plugins/plugin.c | 1 + src/plugins/scripts/lua/weechat-lua-api.c | 39 ++++++++++ src/plugins/scripts/perl/weechat-perl-api.c | 35 +++++++++ .../scripts/python/weechat-python-api.c | 35 +++++++++ src/plugins/scripts/ruby/weechat-ruby-api.c | 37 ++++++++++ src/plugins/scripts/script-api.c | 27 +++++++ src/plugins/scripts/script-api.h | 3 + src/plugins/scripts/tcl/weechat-tcl-api.c | 38 ++++++++++ src/plugins/weechat-plugin.h | 4 ++ 14 files changed, 403 insertions(+), 51 deletions(-) diff --git a/doc/de/dev/plugin_c_api.de.xml b/doc/de/dev/plugin_c_api.de.xml index 9e6151850..83f1e26d8 100644 --- a/doc/de/dev/plugin_c_api.de.xml +++ b/doc/de/dev/plugin_c_api.de.xml @@ -4546,6 +4546,43 @@ char *value = weechat_config_get_plugin ("option"); +
+ weechat_config_is_set_plugin + + + Prototype: + +int weechat_config_is_set_plugin (const char *option_name); + + + + Check if option is set in plugins configuration file (plugins.conf). + + + Arguments: + + + + : option name, WeeChat will add + prefix "plugins.var.xxxx." (where xxxx is current plugin name). + + + + + + Return value: 1 if option is set, 0 if option does not exist. + + + Example: + +if (weechat_config_is_set_plugin ("option")) +{ + /* ... */ +} + + +
+
weechat_config_set_plugin @@ -5138,7 +5175,7 @@ struct t_hook *weechat_hook_command ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5250,7 +5287,7 @@ struct t_hook *weechat_hook_command_run ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5349,7 +5386,7 @@ struct t_hook *weechat_hook_timer ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5450,7 +5487,7 @@ struct t_hook *weechat_hook_fd ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5555,7 +5592,7 @@ struct t_hook *weechat_hook_process ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5718,7 +5755,7 @@ struct t_hook *weechat_hook_connect ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5893,7 +5930,7 @@ struct t_hook *weechat_hook_print ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6350,7 +6387,7 @@ struct t_hook *weechat_hook_signal ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6484,7 +6521,7 @@ struct t_hook *weechat_hook_config ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6586,7 +6623,7 @@ struct t_hook *weechat_hook_completion ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6836,7 +6873,7 @@ struct t_hook *weechat_hook_modifier ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6992,7 +7029,7 @@ struct t_hook *weechat_hook_info ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -7095,7 +7132,7 @@ struct t_hook *weechat_hook_infolist ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -7250,7 +7287,7 @@ struct t_gui_buffer *weechat_buffer_new ( : pointer given to input - callback when it is called by WeeeChat + callback when it is called by WeeChat @@ -7285,7 +7322,7 @@ struct t_gui_buffer *weechat_buffer_new ( : pointer given to close - callback when it is called by WeeeChat + callback when it is called by WeeChat @@ -7749,7 +7786,7 @@ void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property, display "1", "auto" - swtich to this buffer in current window (if value is + switch to this buffer in current window (if value is "auto", then it's considered as auto-switch and read marker is not reset for current buffer) @@ -7823,7 +7860,7 @@ void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property, "-" or comma separated list of words "-" is a special value to disable any highlight on this - buffer, or comma separated list of words to higlkight + buffer, or comma separated list of words to highlight in this buffer, for example: "abc,def,ghi" diff --git a/doc/en/dev/plugin_c_api.en.xml b/doc/en/dev/plugin_c_api.en.xml index 9dedc5718..caa5c8f02 100644 --- a/doc/en/dev/plugin_c_api.en.xml +++ b/doc/en/dev/plugin_c_api.en.xml @@ -4545,6 +4545,43 @@ char *value = weechat_config_get_plugin ("option");
+
+ weechat_config_is_set_plugin + + + Prototype: + +int weechat_config_is_set_plugin (const char *option_name); + + + + Check if option is set in plugins configuration file (plugins.conf). + + + Arguments: + + + + : option name, WeeChat will add + prefix "plugins.var.xxxx." (where xxxx is current plugin name). + + + + + + Return value: 1 if option is set, 0 if option does not exist. + + + Example: + +if (weechat_config_is_set_plugin ("option")) +{ + /* ... */ +} + + +
+
weechat_config_set_plugin @@ -5137,7 +5174,7 @@ struct t_hook *weechat_hook_command ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5249,7 +5286,7 @@ struct t_hook *weechat_hook_command_run ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5348,7 +5385,7 @@ struct t_hook *weechat_hook_timer ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5449,7 +5486,7 @@ struct t_hook *weechat_hook_fd ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5554,7 +5591,7 @@ struct t_hook *weechat_hook_process ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5717,7 +5754,7 @@ struct t_hook *weechat_hook_connect ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5892,7 +5929,7 @@ struct t_hook *weechat_hook_print ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6349,7 +6386,7 @@ struct t_hook *weechat_hook_signal ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6483,7 +6520,7 @@ struct t_hook *weechat_hook_config ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6585,7 +6622,7 @@ struct t_hook *weechat_hook_completion ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6835,7 +6872,7 @@ struct t_hook *weechat_hook_modifier ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6991,7 +7028,7 @@ struct t_hook *weechat_hook_info ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -7094,7 +7131,7 @@ struct t_hook *weechat_hook_infolist ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -7249,7 +7286,7 @@ struct t_gui_buffer *weechat_buffer_new ( : pointer given to input - callback when it is called by WeeeChat + callback when it is called by WeeChat @@ -7284,7 +7321,7 @@ struct t_gui_buffer *weechat_buffer_new ( : pointer given to close - callback when it is called by WeeeChat + callback when it is called by WeeChat @@ -7748,7 +7785,7 @@ void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property, display "1", "auto" - swtich to this buffer in current window (if value is + switch to this buffer in current window (if value is "auto", then it's considered as auto-switch and read marker is not reset for current buffer) @@ -7822,7 +7859,7 @@ void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property, "-" or comma separated list of words "-" is a special value to disable any highlight on this - buffer, or comma separated list of words to higlkight + buffer, or comma separated list of words to highlight in this buffer, for example: "abc,def,ghi" diff --git a/doc/fr/dev/plugin_c_api.fr.xml b/doc/fr/dev/plugin_c_api.fr.xml index 33863c102..325b25dd0 100644 --- a/doc/fr/dev/plugin_c_api.fr.xml +++ b/doc/fr/dev/plugin_c_api.fr.xml @@ -4546,6 +4546,43 @@ char *value = weechat_config_get_plugin ("option");
+
+ weechat_config_is_set_plugin + + + Prototype: + +int weechat_config_is_set_plugin (const char *option_name); + + + + Check if option is set in plugins configuration file (plugins.conf). + + + Arguments: + + + + : option name, WeeChat will add + prefix "plugins.var.xxxx." (where xxxx is current plugin name). + + + + + + Return value: 1 if option is set, 0 if option does not exist. + + + Example: + +if (weechat_config_is_set_plugin ("option")) +{ + /* ... */ +} + + +
+
weechat_config_set_plugin @@ -5138,7 +5175,7 @@ struct t_hook *weechat_hook_command ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5250,7 +5287,7 @@ struct t_hook *weechat_hook_command_run ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5349,7 +5386,7 @@ struct t_hook *weechat_hook_timer ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5450,7 +5487,7 @@ struct t_hook *weechat_hook_fd ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5555,7 +5592,7 @@ struct t_hook *weechat_hook_process ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5718,7 +5755,7 @@ struct t_hook *weechat_hook_connect ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -5893,7 +5930,7 @@ struct t_hook *weechat_hook_print ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6350,7 +6387,7 @@ struct t_hook *weechat_hook_signal ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6484,7 +6521,7 @@ struct t_hook *weechat_hook_config ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6586,7 +6623,7 @@ struct t_hook *weechat_hook_completion ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6836,7 +6873,7 @@ struct t_hook *weechat_hook_modifier ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -6992,7 +7029,7 @@ struct t_hook *weechat_hook_info ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -7095,7 +7132,7 @@ struct t_hook *weechat_hook_infolist ( : pointer given to callback when it - is called by WeeeChat + is called by WeeChat @@ -7250,7 +7287,7 @@ struct t_gui_buffer *weechat_buffer_new ( : pointer given to input - callback when it is called by WeeeChat + callback when it is called by WeeChat @@ -7285,7 +7322,7 @@ struct t_gui_buffer *weechat_buffer_new ( : pointer given to close - callback when it is called by WeeeChat + callback when it is called by WeeChat @@ -7749,7 +7786,7 @@ void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property, display "1", "auto" - swtich to this buffer in current window (if value is + switch to this buffer in current window (if value is "auto", then it's considered as auto-switch and read marker is not reset for current buffer) @@ -7823,7 +7860,7 @@ void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property, "-" or comma separated list of words "-" is a special value to disable any highlight on this - buffer, or comma separated list of words to higlkight + buffer, or comma separated list of words to highlight in this buffer, for example: "abc,def,ghi" diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index a9028e356..c7c867b46 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -124,6 +124,26 @@ plugin_api_config_get_plugin (struct t_weechat_plugin *plugin, return NULL; } +/* + * plugin_api_config_is_set_plugin: return 1 if plugin option is set, otherwise 0 + */ + +int +plugin_api_config_is_set_plugin (struct t_weechat_plugin *plugin, + const char *option_name) +{ + struct t_config_option *ptr_option; + + if (!plugin || !option_name) + return 0; + + ptr_option = plugin_config_search (plugin->name, option_name); + if (ptr_option) + return 1; + + return 0; +} + /* * plugin_api_config_set_plugin: set value of a plugin config option */ diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h index df1ba31dd..42e2a185f 100644 --- a/src/plugins/plugin-api.h +++ b/src/plugins/plugin-api.h @@ -31,6 +31,8 @@ extern const char *plugin_api_ngettext (const char *single, const char *plural, extern struct t_config_option *plugin_api_config_get (const char *option_name); extern const char *plugin_api_config_get_plugin (struct t_weechat_plugin *plugin, const char *option_name); +extern int plugin_api_config_is_set_plugin (struct t_weechat_plugin *plugin, + const char *option_name); extern int plugin_api_config_set_plugin (struct t_weechat_plugin *plugin, const char *option_name, const char *value); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 623e802cc..3f5f443e0 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -485,6 +485,7 @@ plugin_load (const char *filename) new_plugin->config_free = &config_file_free; new_plugin->config_get = &plugin_api_config_get; new_plugin->config_get_plugin = &plugin_api_config_get_plugin; + new_plugin->config_is_set_plugin = &plugin_api_config_is_set_plugin; new_plugin->config_set_plugin = &plugin_api_config_set_plugin; new_plugin->config_unset_plugin = &plugin_api_config_unset_plugin; diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index a19eb6b34..5f3852128 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -2691,6 +2691,44 @@ weechat_lua_api_config_get_plugin (lua_State *L) LUA_RETURN_STRING(result); } +/* + * weechat_lua_api_config_is_set_plugin: check if a plugin option is set + */ + +static int +weechat_lua_api_config_is_set_plugin (lua_State *L) +{ + const char *option; + int n, rc; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "config_is_set_plugin"); + LUA_RETURN_INT(0); + } + + option = NULL; + + n = lua_gettop (lua_current_interpreter); + + if (n < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "config_is_set_plugin"); + LUA_RETURN_INT(0); + } + + option = lua_tostring (lua_current_interpreter, -1); + + rc = script_api_config_is_set_plugin (weechat_lua_plugin, + lua_current_script, + option); + + LUA_RETURN_INT(rc); +} + /* * weechat_lua_api_config_set_plugin: set value of a plugin option */ @@ -7047,6 +7085,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = { { "config_free", &weechat_lua_api_config_free }, { "config_get", &weechat_lua_api_config_get }, { "config_get_plugin", &weechat_lua_api_config_get_plugin }, + { "config_is_set_plugin", &weechat_lua_api_config_is_set_plugin }, { "config_set_plugin", &weechat_lua_api_config_set_plugin }, { "config_unset_plugin", &weechat_lua_api_config_unset_plugin }, { "prefix", &weechat_lua_api_prefix }, diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index 419f8b45b..f3fe2fe37 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -2257,6 +2257,40 @@ static XS (XS_weechat_api_config_get_plugin) PERL_RETURN_STRING(result); } +/* + * weechat::config_is_set_plugin: check if a plugin option is set + */ + +static XS (XS_weechat_api_config_is_set_plugin) +{ + char *option; + int rc; + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "config_is_set_plugin"); + PERL_RETURN_INT(0); + } + + if (items < 1) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "config_is_set_plugin"); + PERL_RETURN_INT(0); + } + + option = SvPV (ST (0), PL_na); + + rc = script_api_config_is_set_plugin (weechat_perl_plugin, + perl_current_script, + option); + + PERL_RETURN_INT(rc); +} + /* * weechat::config_set_plugin: set value of a plugin option */ @@ -5646,6 +5680,7 @@ weechat_perl_api_init (pTHX) newXS ("weechat::config_free", XS_weechat_api_config_free, "weechat"); newXS ("weechat::config_get", XS_weechat_api_config_get, "weechat"); newXS ("weechat::config_get_plugin", XS_weechat_api_config_get_plugin, "weechat"); + newXS ("weechat::config_is_set_plugin", XS_weechat_api_config_is_set_plugin, "weechat"); newXS ("weechat::config_set_plugin", XS_weechat_api_config_set_plugin, "weechat"); newXS ("weechat::config_unset_plugin", XS_weechat_api_config_unset_plugin, "weechat"); newXS ("weechat::prefix", XS_weechat_api_prefix, "weechat"); diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 6cf94d2e3..0c58130b1 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -2386,6 +2386,40 @@ weechat_python_api_config_get_plugin (PyObject *self, PyObject *args) PYTHON_RETURN_STRING(result); } +/* + * weechat_python_api_config_is_set_plugin: check if a plugin option is set + */ + +static PyObject * +weechat_python_api_config_is_set_plugin (PyObject *self, PyObject *args) +{ + char *option; + int rc; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "config_is_set_plugin"); + PYTHON_RETURN_INT(0); + } + + option = NULL; + + if (!PyArg_ParseTuple (args, "s", &option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "config_is_set_plugin"); + PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR); + } + + rc = script_api_config_is_set_plugin (weechat_python_plugin, + python_current_script, + option); + + PYTHON_RETURN_INT(rc); +} + /* * weechat_python_api_config_set_plugin: set value of a plugin option */ @@ -5924,6 +5958,7 @@ PyMethodDef weechat_python_funcs[] = { "config_free", &weechat_python_api_config_free, METH_VARARGS, "" }, { "config_get", &weechat_python_api_config_get, METH_VARARGS, "" }, { "config_get_plugin", &weechat_python_api_config_get_plugin, METH_VARARGS, "" }, + { "config_is_set_plugin", &weechat_python_api_config_is_set_plugin, METH_VARARGS, "" }, { "config_set_plugin", &weechat_python_api_config_set_plugin, METH_VARARGS, "" }, { "config_unset_plugin", &weechat_python_api_config_unset_plugin, METH_VARARGS, "" }, { "prefix", &weechat_python_api_prefix, METH_VARARGS, "" }, diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index 082b918bb..266f45497 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -2760,6 +2760,42 @@ weechat_ruby_api_config_get_plugin (VALUE class, VALUE option) RUBY_RETURN_STRING(result); } +/* + * weechat_ruby_api_config_is_set_plugin: check if a plugin option is set + */ + +static VALUE +weechat_ruby_api_config_is_set_plugin (VALUE class, VALUE option) +{ + char *c_option; + int rc; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "config_is_set_plugin"); + RUBY_RETURN_INT(0); + } + + if (NIL_P (option)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "config_is_set_plugin"); + RUBY_RETURN_INT(0); + } + + Check_Type (option, T_STRING); + + c_option = STR2CSTR (option); + + rc = script_api_config_is_set_plugin (weechat_ruby_plugin, + ruby_current_script, + c_option); + + RUBY_RETURN_INT(rc); +} + /* * weechat_ruby_api_config_set_plugin: set value of a plugin option */ @@ -6837,6 +6873,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "config_free", &weechat_ruby_api_config_free, 1); rb_define_module_function (ruby_mWeechat, "config_get", &weechat_ruby_api_config_get, 1); rb_define_module_function (ruby_mWeechat, "config_get_plugin", &weechat_ruby_api_config_get_plugin, 1); + rb_define_module_function (ruby_mWeechat, "config_is_set_plugin", &weechat_ruby_api_config_is_set_plugin, 1); rb_define_module_function (ruby_mWeechat, "config_set_plugin", &weechat_ruby_api_config_set_plugin, 2); rb_define_module_function (ruby_mWeechat, "config_unset_plugin", &weechat_ruby_api_config_unset_plugin, 1); rb_define_module_function (ruby_mWeechat, "prefix", &weechat_ruby_api_prefix, 1); diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c index 38bbec75c..2eee67105 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -1535,6 +1535,33 @@ script_api_config_get_plugin (struct t_weechat_plugin *weechat_plugin, return return_value; } +/* + * script_api_config_is_set_plugin: check if a script option is set + */ + +int +script_api_config_is_set_plugin (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + const char *option) +{ + char *option_fullname; + int return_code; + + option_fullname = malloc ((strlen (script->name) + + strlen (option) + 2)); + if (!option_fullname) + return 0; + + strcpy (option_fullname, script->name); + strcat (option_fullname, "."); + strcat (option_fullname, option); + + return_code = weechat_config_is_set_plugin (option_fullname); + free (option_fullname); + + return return_code; +} + /* * script_api_config_set_plugin: set value of a script config option * format in file is "plugin.script.option" diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h index bfedeab4a..8d4622c56 100644 --- a/src/plugins/scripts/script-api.h +++ b/src/plugins/scripts/script-api.h @@ -286,6 +286,9 @@ extern void script_api_command (struct t_weechat_plugin *weechat_plugin, extern const char *script_api_config_get_plugin (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, const char *option); +extern int script_api_config_is_set_plugin (struct t_weechat_plugin *weechat_plugin, + struct t_plugin_script *script, + const char *option); extern int script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, const char *option, const char *value); diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index 9fc2e964b..afc4a388d 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -2583,6 +2583,42 @@ weechat_tcl_api_config_get_plugin (ClientData clientData, Tcl_Interp *interp, TCL_RETURN_STRING(result); } +/* + * weechat_tcl_api_config_is_set_plugin: check if a plugin option is set + */ + +static int +weechat_tcl_api_config_is_set_plugin (ClientData clientData, Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj *objp; + char *option; + int i, rc; + + /* make C compiler happy */ + (void) clientData; + + if (!tcl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "config_is_set_plugin"); + TCL_RETURN_INT(0); + } + + if (objc < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "config_is_set_plugin"); + TCL_RETURN_INT(0); + } + + option = Tcl_GetStringFromObj (objv[1], &i); + + rc = script_api_config_is_set_plugin (weechat_tcl_plugin, + tcl_current_script, + option); + + TCL_RETURN_INT(rc); +} + /* * weechat_tcl_api_config_set_plugin: set value of a plugin option */ @@ -6434,6 +6470,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) weechat_tcl_api_config_get, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp, "weechat::config_get_plugin", weechat_tcl_api_config_get_plugin, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); + Tcl_CreateObjCommand (interp, "weechat::config_is_set_plugin", + weechat_tcl_api_config_is_set_plugin, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp, "weechat::config_set_plugin", weechat_tcl_api_config_set_plugin, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp, "weechat::config_unset_plugin", diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 110d2fc8d..628de70b8 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -334,6 +334,8 @@ struct t_weechat_plugin struct t_config_option *(*config_get) (const char *option_name); const char *(*config_get_plugin) (struct t_weechat_plugin *plugin, const char *option_name); + int (*config_is_set_plugin) (struct t_weechat_plugin *plugin, + const char *option_name); int (*config_set_plugin) (struct t_weechat_plugin *plugin, const char *option_name, const char *value); int (*config_unset_plugin) (struct t_weechat_plugin *plugin, @@ -908,6 +910,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->config_get(__option) #define weechat_config_get_plugin(__option) \ weechat_plugin->config_get_plugin(weechat_plugin, __option) +#define weechat_config_is_set_plugin(__option) \ + weechat_plugin->config_is_set_plugin(weechat_plugin, __option) #define weechat_config_set_plugin(__option, __value) \ weechat_plugin->config_set_plugin(weechat_plugin, __option, \ __value)