1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 06:16:40 +02:00

Add function config_unset_plugin in API, fix return code of config_set_plugin

This commit is contained in:
Sebastien Helleu
2009-02-01 13:31:20 +01:00
parent 33e733cb0a
commit 5205be4b87
12 changed files with 340 additions and 56 deletions
+47 -9
View File
@@ -2336,7 +2336,7 @@ static int
weechat_lua_api_config_set_plugin (lua_State *L)
{
const char *option, *value;
int n;
int n, rc;
/* make C compiler happy */
(void) L;
@@ -2344,7 +2344,7 @@ weechat_lua_api_config_set_plugin (lua_State *L)
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_set_plugin");
LUA_RETURN_ERROR;
LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
}
option = NULL;
@@ -2355,19 +2355,56 @@ weechat_lua_api_config_set_plugin (lua_State *L)
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_set_plugin");
LUA_RETURN_ERROR;
LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
}
option = lua_tostring (lua_current_interpreter, -2);
value = lua_tostring (lua_current_interpreter, -1);
if (script_api_config_set_plugin (weechat_lua_plugin,
lua_current_script,
option,
value))
LUA_RETURN_OK;
rc = script_api_config_set_plugin (weechat_lua_plugin,
lua_current_script,
option,
value);
LUA_RETURN_ERROR;
LUA_RETURN_INT(rc);
}
/*
* weechat_lua_api_config_unset_plugin: unset plugin option
*/
static int
weechat_lua_api_config_unset_plugin (lua_State *L)
{
const char *option;
int n, rc;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_unset_plugin");
LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
}
option = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_unset_plugin");
LUA_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
}
option = lua_tostring (lua_current_interpreter, -1);
rc = script_api_config_unset_plugin (weechat_lua_plugin,
lua_current_script,
option);
LUA_RETURN_INT(rc);
}
/*
@@ -6053,6 +6090,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "config_get", &weechat_lua_api_config_get },
{ "config_get_plugin", &weechat_lua_api_config_get_plugin },
{ "config_set_plugin", &weechat_lua_api_config_set_plugin },
{ "config_unset_plugin", &weechat_lua_api_config_unset_plugin },
{ "prefix", &weechat_lua_api_prefix },
{ "color", &weechat_lua_api_color },
{ "print", &weechat_lua_api_print },
+43 -9
View File
@@ -1948,6 +1948,7 @@ static XS (XS_weechat_api_config_get_plugin)
static XS (XS_weechat_api_config_set_plugin)
{
char *option, *value;
int rc;
dXSARGS;
/* make C compiler happy */
@@ -1956,24 +1957,56 @@ static XS (XS_weechat_api_config_set_plugin)
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_set_plugin");
PERL_RETURN_ERROR;
PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_set_plugin");
PERL_RETURN_ERROR;
PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
}
option = SvPV (ST (0), PL_na);
value = SvPV (ST (1), PL_na);
if (script_api_config_set_plugin (weechat_perl_plugin,
perl_current_script,
option,
value))
PERL_RETURN_OK;
rc = script_api_config_set_plugin (weechat_perl_plugin,
perl_current_script,
option,
value);
PERL_RETURN_ERROR;
PERL_RETURN_INT(rc);
}
/*
* weechat::config_unset_plugin: unset a plugin option
*/
static XS (XS_weechat_api_config_unset_plugin)
{
char *option;
int rc;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_unset_plugin");
PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
}
if (items < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_unset_plugin");
PERL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
}
option = SvPV (ST (0), PL_na);
rc = script_api_config_unset_plugin (weechat_perl_plugin,
perl_current_script,
option);
PERL_RETURN_INT(rc);
}
/*
@@ -4766,6 +4799,7 @@ weechat_perl_api_init (pTHX)
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_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");
newXS ("weechat::color", XS_weechat_api_color, "weechat");
newXS ("weechat::print", XS_weechat_api_print, "weechat");
@@ -2076,6 +2076,7 @@ static PyObject *
weechat_python_api_config_set_plugin (PyObject *self, PyObject *args)
{
char *option, *value;
int rc;
/* make C compiler happy */
(void) self;
@@ -2083,7 +2084,7 @@ weechat_python_api_config_set_plugin (PyObject *self, PyObject *args)
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_set_plugin");
PYTHON_RETURN_ERROR;
PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
}
option = NULL;
@@ -2092,16 +2093,49 @@ weechat_python_api_config_set_plugin (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple (args, "ss", &option, &value))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_set_plugin");
PYTHON_RETURN_ERROR;
PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
}
if (script_api_config_set_plugin (weechat_python_plugin,
python_current_script,
option,
value))
PYTHON_RETURN_OK;
rc = script_api_config_set_plugin (weechat_python_plugin,
python_current_script,
option,
value);
PYTHON_RETURN_ERROR;
PYTHON_RETURN_INT(rc);
}
/*
* weechat_python_api_config_unset_plugin: unset plugin option
*/
static PyObject *
weechat_python_api_config_unset_plugin (PyObject *self, PyObject *args)
{
char *option;
int rc;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_unset_plugin");
PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
}
option = NULL;
if (!PyArg_ParseTuple (args, "s", &option))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_unset_plugin");
PYTHON_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
}
rc = script_api_config_unset_plugin (weechat_python_plugin,
python_current_script,
option);
PYTHON_RETURN_INT(rc);
}
/*
@@ -5064,6 +5098,7 @@ PyMethodDef weechat_python_funcs[] =
{ "config_get", &weechat_python_api_config_get, METH_VARARGS, "" },
{ "config_get_plugin", &weechat_python_api_config_get_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, "" },
{ "color", &weechat_python_api_color, METH_VARARGS, "" },
{ "prnt", &weechat_python_api_prnt, METH_VARARGS, "" },
+45 -8
View File
@@ -2384,6 +2384,7 @@ static VALUE
weechat_ruby_api_config_set_plugin (VALUE class, VALUE option, VALUE value)
{
char *c_option, *c_value;
int rc;
/* make C compiler happy */
(void) class;
@@ -2391,13 +2392,13 @@ weechat_ruby_api_config_set_plugin (VALUE class, VALUE option, VALUE value)
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_set_plugin");
RUBY_RETURN_ERROR;
RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
}
if (NIL_P (option) || NIL_P (value))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_set_plugin");
RUBY_RETURN_ERROR;
RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
}
Check_Type (option, T_STRING);
@@ -2406,13 +2407,48 @@ weechat_ruby_api_config_set_plugin (VALUE class, VALUE option, VALUE value)
c_option = STR2CSTR (option);
c_value = STR2CSTR (value);
if (script_api_config_set_plugin (weechat_ruby_plugin,
ruby_current_script,
c_option,
c_value))
RUBY_RETURN_OK;
rc = script_api_config_set_plugin (weechat_ruby_plugin,
ruby_current_script,
c_option,
c_value);
RUBY_RETURN_ERROR;
RUBY_RETURN_INT(rc);
}
/*
* weechat_ruby_api_config_unset_plugin: unset plugin option
*/
static VALUE
weechat_ruby_api_config_unset_plugin (VALUE class, VALUE option)
{
char *c_option;
int rc;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_unset_plugin");
RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
}
if (NIL_P (option))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_unset_plugin");
RUBY_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
}
Check_Type (option, T_STRING);
c_option = STR2CSTR (option);
rc = script_api_config_unset_plugin (weechat_ruby_plugin,
ruby_current_script,
c_option);
RUBY_RETURN_INT(rc);
}
/*
@@ -5817,6 +5853,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
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_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);
rb_define_module_function (ruby_mWeechat, "color", &weechat_ruby_api_color, 1);
rb_define_module_function (ruby_mWeechat, "print", &weechat_ruby_api_print, 2);
+30 -2
View File
@@ -1314,7 +1314,7 @@ script_api_command (struct t_weechat_plugin *weechat_plugin,
/*
* script_api_config_get_plugin: get a value of a script option
* format in file is: plugin.script.option = value
* format in file is "plugin.script.option"
*/
const char *
@@ -1342,7 +1342,7 @@ script_api_config_get_plugin (struct t_weechat_plugin *weechat_plugin,
/*
* script_api_config_set_plugin: set value of a script config option
* format in file is: plugin.script.option = value
* format in file is "plugin.script.option"
*/
int
@@ -1367,3 +1367,31 @@ script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin,
return return_code;
}
/*
* script_api_config_unset_plugin: unset script config option
* format in file is "plugin.script.option"
*/
int
script_api_config_unset_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_unset_plugin (option_fullname);
free (option_fullname);
return return_code;
}
+3
View File
@@ -236,5 +236,8 @@ extern const char *script_api_config_get_plugin (struct t_weechat_plugin *weecha
extern int script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *option, const char *value);
extern int script_api_config_unset_plugin (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *option);
#endif /* script-api.h */
+48 -10
View File
@@ -2260,7 +2260,7 @@ weechat_tcl_api_config_set_plugin (ClientData clientData, Tcl_Interp *interp,
{
Tcl_Obj *objp;
char *option, *value;
int i;
int i, rc;
/* make C compiler happy */
(void) clientData;
@@ -2268,24 +2268,60 @@ weechat_tcl_api_config_set_plugin (ClientData clientData, Tcl_Interp *interp,
if (!tcl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_set_plugin");
TCL_RETURN_ERROR;
TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
}
if (objc < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_set_plugin");
TCL_RETURN_ERROR;
TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_SET_ERROR);
}
option = Tcl_GetStringFromObj (objv[1], &i);
value = Tcl_GetStringFromObj (objv[2], &i);
if (script_api_config_set_plugin (weechat_tcl_plugin,
tcl_current_script,
option,
value))
TCL_RETURN_OK;
TCL_RETURN_ERROR;
rc = script_api_config_set_plugin (weechat_tcl_plugin,
tcl_current_script,
option,
value);
TCL_RETURN_INT(rc);
}
/*
* weechat_tcl_api_config_set_plugin: unset plugin option
*/
static int
weechat_tcl_api_config_unset_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_INITIALIZED("config_unset_plugin");
TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
}
if (objc < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_unset_plugin");
TCL_RETURN_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR);
}
option = Tcl_GetStringFromObj (objv[1], &i);
rc = script_api_config_unset_plugin (weechat_tcl_plugin,
tcl_current_script,
option);
TCL_RETURN_INT(rc);
}
/*
@@ -5499,6 +5535,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) {
weechat_tcl_api_config_get_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",
weechat_tcl_api_config_unset_plugin, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::prefix",
weechat_tcl_api_prefix, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp,"weechat::color",