mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 16:23:14 +02:00
Improved /set command, added /unset command, new name for config files (*.conf)
This commit is contained in:
@@ -119,10 +119,9 @@ weechat_lua_api_register (lua_State *L)
|
||||
if (lua_current_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: registered script \"%s\", "
|
||||
weechat_gettext ("%s: registered script \"%s\", "
|
||||
"version %s (%s)"),
|
||||
weechat_prefix ("info"), "lua",
|
||||
name, version, description);
|
||||
"lua", name, version, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -934,7 +933,7 @@ weechat_lua_api_config_reload_cb (void *data,
|
||||
static int
|
||||
weechat_lua_api_config_new (lua_State *L)
|
||||
{
|
||||
const char *filename, *function;
|
||||
const char *name, *function;
|
||||
char *result;
|
||||
int n;
|
||||
|
||||
@@ -947,7 +946,7 @@ weechat_lua_api_config_new (lua_State *L)
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
filename = NULL;
|
||||
name = NULL;
|
||||
function = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
@@ -958,12 +957,12 @@ weechat_lua_api_config_new (lua_State *L)
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
filename = lua_tostring (lua_current_interpreter, -2);
|
||||
name = lua_tostring (lua_current_interpreter, -2);
|
||||
function = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
result = script_ptr2str (script_api_config_new (weechat_lua_plugin,
|
||||
lua_current_script,
|
||||
(char *)filename,
|
||||
(char *)name,
|
||||
&weechat_lua_api_config_reload_cb,
|
||||
(char *)function));
|
||||
|
||||
@@ -1071,6 +1070,54 @@ weechat_lua_api_config_section_write_default_cb (void *data,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_config_section_create_option_cb: callback to create an option
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_api_config_section_create_option_cb (void *data,
|
||||
struct t_config_file *config_file,
|
||||
struct t_config_section *section,
|
||||
char *option_name,
|
||||
char *value)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *lua_argv[5];
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
if (script_callback->function && script_callback->function[0])
|
||||
{
|
||||
lua_argv[0] = script_ptr2str (config_file);
|
||||
lua_argv[1] = script_ptr2str (section);
|
||||
lua_argv[2] = option_name;
|
||||
lua_argv[3] = value;
|
||||
lua_argv[4] = 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]);
|
||||
if (lua_argv[1])
|
||||
free (lua_argv[1]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_config_new_section: create a new section in configuration file
|
||||
*/
|
||||
@@ -1079,7 +1126,7 @@ static int
|
||||
weechat_lua_api_config_new_section (lua_State *L)
|
||||
{
|
||||
const char *config_file, *name, *function_read, *function_write;
|
||||
const char *function_write_default;
|
||||
const char *function_write_default, *function_create_option;
|
||||
char *result;
|
||||
int n;
|
||||
|
||||
@@ -1097,20 +1144,22 @@ weechat_lua_api_config_new_section (lua_State *L)
|
||||
function_read = NULL;
|
||||
function_write = NULL;
|
||||
function_write_default = NULL;
|
||||
function_create_option = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 5)
|
||||
if (n < 6)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
config_file = lua_tostring (lua_current_interpreter, -5);
|
||||
name = lua_tostring (lua_current_interpreter, -4);
|
||||
function_read = lua_tostring (lua_current_interpreter, -3);
|
||||
function_write = lua_tostring (lua_current_interpreter, -2);
|
||||
function_write_default = lua_tostring (lua_current_interpreter, -1);
|
||||
config_file = lua_tostring (lua_current_interpreter, -6);
|
||||
name = lua_tostring (lua_current_interpreter, -5);
|
||||
function_read = lua_tostring (lua_current_interpreter, -4);
|
||||
function_write = lua_tostring (lua_current_interpreter, -3);
|
||||
function_write_default = lua_tostring (lua_current_interpreter, -2);
|
||||
function_create_option = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
result = script_ptr2str (script_api_config_new_section (weechat_lua_plugin,
|
||||
lua_current_script,
|
||||
@@ -1120,8 +1169,10 @@ weechat_lua_api_config_new_section (lua_State *L)
|
||||
(char *)function_read,
|
||||
&weechat_lua_api_config_section_write_cb,
|
||||
(char *)function_write,
|
||||
&weechat_lua_api_config_section_write_cb,
|
||||
(char *)function_write_default));
|
||||
&weechat_lua_api_config_section_write_default_cb,
|
||||
(char *)function_write_default,
|
||||
&weechat_lua_api_config_section_create_option_cb,
|
||||
(char *)function_create_option));
|
||||
|
||||
LUA_RETURN_STRING_FREE(result);
|
||||
}
|
||||
@@ -2553,19 +2604,17 @@ weechat_lua_api_hook_signal_send (lua_State *L)
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_api_hook_config_cb (void *data, char *type, char *option,
|
||||
char *value)
|
||||
weechat_lua_api_hook_config_cb (void *data, char *option, char *value)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *lua_argv[4];
|
||||
char *lua_argv[3];
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
lua_argv[0] = type;
|
||||
lua_argv[1] = option;
|
||||
lua_argv[2] = value;
|
||||
lua_argv[3] = NULL;
|
||||
lua_argv[0] = option;
|
||||
lua_argv[1] = value;
|
||||
lua_argv[2] = NULL;
|
||||
|
||||
rc = (int *) weechat_lua_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
@@ -2596,7 +2645,7 @@ weechat_lua_api_hook_config (lua_State *L)
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_config");
|
||||
@@ -2609,19 +2658,17 @@ weechat_lua_api_hook_config (lua_State *L)
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 3)
|
||||
if (n < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_config");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
type = lua_tostring (lua_current_interpreter, -3);
|
||||
option = lua_tostring (lua_current_interpreter, -2);
|
||||
function = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
result = script_ptr2str (script_api_hook_config (weechat_lua_plugin,
|
||||
lua_current_script,
|
||||
(char *)type,
|
||||
(char *)option,
|
||||
&weechat_lua_api_hook_config_cb,
|
||||
(char *)function));
|
||||
|
||||
@@ -37,7 +37,7 @@ WEECHAT_PLUGIN_DESCRIPTION("Lua plugin for WeeChat");
|
||||
WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>");
|
||||
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
|
||||
WEECHAT_PLUGIN_WEECHAT_VERSION(WEECHAT_VERSION);
|
||||
WEECHAT_PLUGIN_LICENSE("GPL");
|
||||
WEECHAT_PLUGIN_LICENSE("GPL3");
|
||||
|
||||
struct t_weechat_plugin *weechat_lua_plugin;
|
||||
|
||||
@@ -142,8 +142,8 @@ weechat_lua_load (char *filename)
|
||||
}
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: loading script \"%s\""),
|
||||
weechat_prefix ("info"), "lua", filename);
|
||||
weechat_gettext ("%s: loading script \"%s\""),
|
||||
"lua", filename);
|
||||
|
||||
lua_current_script = NULL;
|
||||
|
||||
@@ -259,8 +259,8 @@ weechat_lua_unload (struct t_plugin_script *script)
|
||||
char *lua_argv[1] = { NULL };
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unloading script \"%s\""),
|
||||
weechat_prefix ("info"), "lua", script->name);
|
||||
weechat_gettext ("%s: unloading script \"%s\""),
|
||||
"lua", script->name);
|
||||
|
||||
if (script->shutdown_func && script->shutdown_func[0])
|
||||
{
|
||||
@@ -291,8 +291,8 @@ weechat_lua_unload_name (char *name)
|
||||
{
|
||||
weechat_lua_unload (ptr_script);
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: script \"%s\" unloaded"),
|
||||
weechat_prefix ("info"), "lua", name);
|
||||
weechat_gettext ("%s: script \"%s\" unloaded"),
|
||||
"lua", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -110,10 +110,9 @@ static XS (XS_weechat_register)
|
||||
if (perl_current_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: registered script \"%s\", "
|
||||
weechat_gettext ("%s: registered script \"%s\", "
|
||||
"version %s (%s)"),
|
||||
weechat_prefix ("info"), "perl",
|
||||
name, version, description);
|
||||
"perl", name, version, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -768,7 +767,7 @@ weechat_perl_api_config_reload_cb (void *data,
|
||||
|
||||
static XS (XS_weechat_config_new)
|
||||
{
|
||||
char *result, *filename, *function;
|
||||
char *result, *name, *function;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -786,11 +785,11 @@ static XS (XS_weechat_config_new)
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
filename = SvPV (ST (0), PL_na);
|
||||
name = SvPV (ST (0), PL_na);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
result = script_ptr2str (script_api_config_new (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
filename,
|
||||
name,
|
||||
&weechat_perl_api_config_reload_cb,
|
||||
function));
|
||||
|
||||
@@ -898,13 +897,62 @@ weechat_perl_api_config_section_write_default_cb (void *data,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_api_config_section_create_option_cb: callback to create an option
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_api_config_section_create_option_cb (void *data,
|
||||
struct t_config_file *config_file,
|
||||
struct t_config_section *section,
|
||||
char *option_name,
|
||||
char *value)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *perl_argv[5];
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
if (script_callback->function && script_callback->function[0])
|
||||
{
|
||||
perl_argv[0] = script_ptr2str (config_file);
|
||||
perl_argv[1] = script_ptr2str (section);
|
||||
perl_argv[2] = option_name;
|
||||
perl_argv[3] = value;
|
||||
perl_argv[4] = 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]);
|
||||
if (perl_argv[1])
|
||||
free (perl_argv[1]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::config_new_section: create a new section in configuration file
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_config_new_section)
|
||||
{
|
||||
char *result, *cfg_file, *name, *read_cb, *write_cb, *write_default_db;
|
||||
char *result, *cfg_file, *name, *function_read, *function_write;
|
||||
char *function_write_default, *function_create_option;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -916,7 +964,7 @@ static XS (XS_weechat_config_new_section)
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 5)
|
||||
if (items < 6)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section");
|
||||
PERL_RETURN_EMPTY;
|
||||
@@ -924,19 +972,22 @@ static XS (XS_weechat_config_new_section)
|
||||
|
||||
cfg_file = SvPV (ST (0), PL_na);
|
||||
name = SvPV (ST (1), PL_na);
|
||||
read_cb = SvPV (ST (2), PL_na);
|
||||
write_cb = SvPV (ST (3), PL_na);
|
||||
write_default_db = SvPV (ST (4), PL_na);
|
||||
function_read = SvPV (ST (2), PL_na);
|
||||
function_write = SvPV (ST (3), PL_na);
|
||||
function_write_default = SvPV (ST (4), PL_na);
|
||||
function_create_option = SvPV (ST (5), PL_na);
|
||||
result = script_ptr2str (script_api_config_new_section (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
script_str2ptr (cfg_file),
|
||||
name,
|
||||
&weechat_perl_api_config_section_read_cb,
|
||||
read_cb,
|
||||
function_read,
|
||||
&weechat_perl_api_config_section_write_cb,
|
||||
write_cb,
|
||||
function_write,
|
||||
&weechat_perl_api_config_section_write_default_cb,
|
||||
write_default_db));
|
||||
function_write_default,
|
||||
&weechat_perl_api_config_section_create_option_cb,
|
||||
function_create_option));
|
||||
|
||||
PERL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
@@ -2117,19 +2168,17 @@ static XS (XS_weechat_hook_signal_send)
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_api_hook_config_cb (void *data, char *type, char *option,
|
||||
char *value)
|
||||
weechat_perl_api_hook_config_cb (void *data, char *option, char *value)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *perl_argv[4];
|
||||
char *perl_argv[3];
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
perl_argv[0] = type;
|
||||
perl_argv[1] = option;
|
||||
perl_argv[2] = value;
|
||||
perl_argv[3] = NULL;
|
||||
perl_argv[0] = option;
|
||||
perl_argv[1] = value;
|
||||
perl_argv[2] = NULL;
|
||||
|
||||
rc = (int *) weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
@@ -2153,7 +2202,7 @@ weechat_perl_api_hook_config_cb (void *data, char *type, char *option,
|
||||
|
||||
static XS (XS_weechat_hook_config)
|
||||
{
|
||||
char *result, *type, *option, *function;
|
||||
char *result, *option, *function;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -2165,18 +2214,16 @@ static XS (XS_weechat_hook_config)
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 3)
|
||||
if (items < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_config");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
type = SvPV (ST (0), PL_na);
|
||||
option = SvPV (ST (1), PL_na);
|
||||
function = SvPV (ST (2), PL_na);
|
||||
option = SvPV (ST (0), PL_na);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
result = script_ptr2str (script_api_hook_config (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
type,
|
||||
option,
|
||||
&weechat_perl_api_hook_config_cb,
|
||||
function));
|
||||
|
||||
@@ -35,7 +35,7 @@ WEECHAT_PLUGIN_DESCRIPTION("Perl plugin for WeeChat");
|
||||
WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>");
|
||||
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
|
||||
WEECHAT_PLUGIN_WEECHAT_VERSION(WEECHAT_VERSION);
|
||||
WEECHAT_PLUGIN_LICENSE("GPL");
|
||||
WEECHAT_PLUGIN_LICENSE("GPL3");
|
||||
|
||||
struct t_weechat_plugin *weechat_perl_plugin = NULL;
|
||||
|
||||
@@ -236,8 +236,8 @@ weechat_perl_load (char *filename)
|
||||
}
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: loading script \"%s\""),
|
||||
weechat_prefix ("info"), "perl", filename);
|
||||
weechat_gettext ("%s: loading script \"%s\""),
|
||||
"perl", filename);
|
||||
|
||||
perl_current_script = NULL;
|
||||
|
||||
@@ -381,8 +381,8 @@ weechat_perl_unload (struct t_plugin_script *script)
|
||||
char *perl_argv[1] = { NULL };
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unloading script \"%s\""),
|
||||
weechat_prefix ("info"), "perl", script->name);
|
||||
weechat_gettext ("%s: unloading script \"%s\""),
|
||||
"perl", script->name);
|
||||
|
||||
#ifdef MULTIPLICITY
|
||||
PERL_SET_CONTEXT (script->interpreter);
|
||||
@@ -425,8 +425,8 @@ weechat_perl_unload_name (char *name)
|
||||
{
|
||||
weechat_perl_unload (ptr_script);
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: script \"%s\" unloaded"),
|
||||
weechat_prefix ("info"), "perl", name);
|
||||
weechat_gettext ("%s: script \"%s\" unloaded"),
|
||||
"perl", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -101,10 +101,9 @@ weechat_python_api_register (PyObject *self, PyObject *args)
|
||||
if (python_current_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: registered script \"%s\", "
|
||||
weechat_gettext ("%s: registered script \"%s\", "
|
||||
"version %s (%s)"),
|
||||
weechat_prefix ("info"), "python",
|
||||
name, version, description);
|
||||
"python", name, version, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -811,7 +810,7 @@ weechat_python_api_config_reload_cb (void *data,
|
||||
static PyObject *
|
||||
weechat_python_api_config_new (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *filename, *function, *result;
|
||||
char *name, *function, *result;
|
||||
PyObject *object;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -823,10 +822,10 @@ weechat_python_api_config_new (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
filename = NULL;
|
||||
name = NULL;
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &filename, &function))
|
||||
if (!PyArg_ParseTuple (args, "ss", &name, &function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
@@ -834,7 +833,7 @@ weechat_python_api_config_new (PyObject *self, PyObject *args)
|
||||
|
||||
result = script_ptr2str (script_api_config_new (weechat_python_plugin,
|
||||
python_current_script,
|
||||
filename,
|
||||
name,
|
||||
&weechat_python_api_config_reload_cb,
|
||||
function));
|
||||
|
||||
@@ -942,6 +941,54 @@ weechat_python_api_config_section_write_default_cb (void *data,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_config_section_create_option_cb: callback to create an option
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_api_config_section_create_option_cb (void *data,
|
||||
struct t_config_file *config_file,
|
||||
struct t_config_section *section,
|
||||
char *option_name,
|
||||
char *value)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *python_argv[5];
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
if (script_callback->function && script_callback->function[0])
|
||||
{
|
||||
python_argv[0] = script_ptr2str (config_file);
|
||||
python_argv[1] = script_ptr2str (section);
|
||||
python_argv[2] = option_name;
|
||||
python_argv[3] = value;
|
||||
python_argv[4] = 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]);
|
||||
if (python_argv[1])
|
||||
free (python_argv[1]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_config_new_section: create a new section in configuration file
|
||||
*/
|
||||
@@ -950,7 +997,8 @@ static PyObject *
|
||||
weechat_python_api_config_new_section (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *config_file, *name, *function_read, *function_write;
|
||||
char *function_write_default, *result;
|
||||
char *function_write_default, *function_create_option;
|
||||
char *result;
|
||||
PyObject *object;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -967,9 +1015,11 @@ weechat_python_api_config_new_section (PyObject *self, PyObject *args)
|
||||
function_read = NULL;
|
||||
function_write = NULL;
|
||||
function_write_default = NULL;
|
||||
function_create_option = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "sssss", &config_file, &name, &function_read,
|
||||
&function_write, &function_write_default))
|
||||
if (!PyArg_ParseTuple (args, "ssssss", &config_file, &name,
|
||||
&function_read, &function_write,
|
||||
&function_write_default, &function_create_option))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
@@ -984,7 +1034,9 @@ weechat_python_api_config_new_section (PyObject *self, PyObject *args)
|
||||
&weechat_python_api_config_section_write_cb,
|
||||
function_write,
|
||||
&weechat_python_api_config_section_write_default_cb,
|
||||
function_write_default));
|
||||
function_write_default,
|
||||
&weechat_python_api_config_section_create_option_cb,
|
||||
function_create_option));
|
||||
|
||||
PYTHON_RETURN_STRING_FREE(result);
|
||||
}
|
||||
@@ -2255,19 +2307,17 @@ weechat_python_api_hook_signal_send (PyObject *self, PyObject *args)
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_api_hook_config_cb (void *data, char *type, char *option,
|
||||
char *value)
|
||||
weechat_python_api_hook_config_cb (void *data, char *option, char *value)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *python_argv[4];
|
||||
char *python_argv[3];
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
python_argv[0] = type;
|
||||
python_argv[1] = option;
|
||||
python_argv[2] = value;
|
||||
python_argv[3] = NULL;
|
||||
python_argv[0] = option;
|
||||
python_argv[1] = value;
|
||||
python_argv[2] = NULL;
|
||||
|
||||
rc = (int *) weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
@@ -2292,7 +2342,7 @@ weechat_python_api_hook_config_cb (void *data, char *type, char *option,
|
||||
static PyObject *
|
||||
weechat_python_api_hook_config (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *type, *option, *function, *result;
|
||||
char *option, *function, *result;
|
||||
PyObject *object;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -2304,11 +2354,10 @@ weechat_python_api_hook_config (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
type = NULL;
|
||||
option = NULL;
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "sss", &type, &option, &function))
|
||||
if (!PyArg_ParseTuple (args, "ss", &option, &function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_config");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
@@ -2316,7 +2365,6 @@ weechat_python_api_hook_config (PyObject *self, PyObject *args)
|
||||
|
||||
result = script_ptr2str(script_api_hook_config (weechat_python_plugin,
|
||||
python_current_script,
|
||||
type,
|
||||
option,
|
||||
&weechat_python_api_hook_config_cb,
|
||||
function));
|
||||
|
||||
@@ -33,7 +33,7 @@ WEECHAT_PLUGIN_DESCRIPTION("Python plugin for WeeChat");
|
||||
WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>");
|
||||
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
|
||||
WEECHAT_PLUGIN_WEECHAT_VERSION(WEECHAT_VERSION);
|
||||
WEECHAT_PLUGIN_LICENSE("GPL");
|
||||
WEECHAT_PLUGIN_LICENSE("GPL3");
|
||||
|
||||
struct t_weechat_plugin *weechat_python_plugin = NULL;
|
||||
|
||||
@@ -261,8 +261,8 @@ weechat_python_load (char *filename)
|
||||
}
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: loading script \"%s\""),
|
||||
weechat_prefix ("info"), "python", filename);
|
||||
weechat_gettext ("%s: loading script \"%s\""),
|
||||
"python", filename);
|
||||
|
||||
python_current_script = NULL;
|
||||
|
||||
@@ -428,8 +428,8 @@ weechat_python_unload (struct t_plugin_script *script)
|
||||
int *r;
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unloading script \"%s\""),
|
||||
weechat_prefix ("info"), "python", script->name);
|
||||
weechat_gettext ("%s: unloading script \"%s\""),
|
||||
"python", script->name);
|
||||
|
||||
if (script->shutdown_func && script->shutdown_func[0])
|
||||
{
|
||||
@@ -459,8 +459,8 @@ weechat_python_unload_name (char *name)
|
||||
{
|
||||
weechat_python_unload (ptr_script);
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: script \"%s\" unloaded"),
|
||||
weechat_prefix ("info"), "python", name);
|
||||
weechat_gettext ("%s: script \"%s\" unloaded"),
|
||||
"python", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -119,10 +119,9 @@ weechat_ruby_api_register (VALUE class, VALUE name, VALUE author,
|
||||
if (ruby_current_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: registered script \"%s\", "
|
||||
weechat_gettext ("%s: registered script \"%s\", "
|
||||
"version %s (%s)"),
|
||||
weechat_prefix ("info"), "ruby",
|
||||
c_name, c_version, c_description);
|
||||
"ruby", c_name, c_version, c_description);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -922,9 +921,9 @@ weechat_ruby_api_config_reload_cb (void *data,
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_config_new (VALUE class, VALUE filename, VALUE function)
|
||||
weechat_ruby_api_config_new (VALUE class, VALUE name, VALUE function)
|
||||
{
|
||||
char *c_filename, *c_function, *result;
|
||||
char *c_name, *c_function, *result;
|
||||
VALUE return_value;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -936,24 +935,24 @@ weechat_ruby_api_config_new (VALUE class, VALUE filename, VALUE function)
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
c_filename = NULL;
|
||||
c_name = NULL;
|
||||
c_function = NULL;
|
||||
|
||||
if (NIL_P (filename) || NIL_P (function))
|
||||
if (NIL_P (name) || NIL_P (function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
Check_Type (filename, T_STRING);
|
||||
Check_Type (name, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_filename = STR2CSTR (filename);
|
||||
c_name = STR2CSTR (name);
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
result = script_ptr2str (script_api_config_new (weechat_ruby_plugin,
|
||||
ruby_current_script,
|
||||
c_filename,
|
||||
c_name,
|
||||
&weechat_ruby_api_config_reload_cb,
|
||||
c_function));
|
||||
|
||||
@@ -1061,6 +1060,54 @@ weechat_ruby_api_config_section_write_default_cb (void *data,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_config_section_create_option_cb: callback to create an option
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_api_config_section_create_option_cb (void *data,
|
||||
struct t_config_file *config_file,
|
||||
struct t_config_section *section,
|
||||
char *option_name,
|
||||
char *value)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *ruby_argv[5];
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
if (script_callback->function && script_callback->function[0])
|
||||
{
|
||||
ruby_argv[0] = script_ptr2str (config_file);
|
||||
ruby_argv[1] = script_ptr2str (section);
|
||||
ruby_argv[2] = option_name;
|
||||
ruby_argv[3] = value;
|
||||
ruby_argv[4] = 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]);
|
||||
if (ruby_argv[1])
|
||||
free (ruby_argv[1]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_config_new_section: create a new section in configuration file
|
||||
*/
|
||||
@@ -1069,10 +1116,12 @@ static VALUE
|
||||
weechat_ruby_api_config_new_section (VALUE class, VALUE config_file,
|
||||
VALUE name, VALUE function_read,
|
||||
VALUE function_write,
|
||||
VALUE function_write_default)
|
||||
VALUE function_write_default,
|
||||
VALUE function_create_option)
|
||||
{
|
||||
char *c_config_file, *c_name, *c_function_read, *c_function_write;
|
||||
char *c_function_write_default, *result;
|
||||
char *c_function_write_default, *c_function_create_option;
|
||||
char *result;
|
||||
VALUE return_value;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -1089,9 +1138,11 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file,
|
||||
c_function_read = NULL;
|
||||
c_function_write = NULL;
|
||||
c_function_write_default = NULL;
|
||||
c_function_create_option = NULL;
|
||||
|
||||
if (NIL_P (config_file) || NIL_P (name) || NIL_P (function_read)
|
||||
|| NIL_P (function_write) || NIL_P (function_write_default))
|
||||
|| NIL_P (function_write) || NIL_P (function_write_default)
|
||||
|| NIL_P (function_create_option))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section");
|
||||
RUBY_RETURN_EMPTY;
|
||||
@@ -1102,12 +1153,14 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file,
|
||||
Check_Type (function_read, T_STRING);
|
||||
Check_Type (function_write, T_STRING);
|
||||
Check_Type (function_write_default, T_STRING);
|
||||
Check_Type (function_create_option, T_STRING);
|
||||
|
||||
c_config_file = STR2CSTR (config_file);
|
||||
c_name = STR2CSTR (name);
|
||||
c_function_read = STR2CSTR (function_read);
|
||||
c_function_write = STR2CSTR (function_write);
|
||||
c_function_write_default = STR2CSTR (function_write_default);
|
||||
c_function_create_option = STR2CSTR (function_create_option);
|
||||
|
||||
result = script_ptr2str (script_api_config_new_section (weechat_ruby_plugin,
|
||||
ruby_current_script,
|
||||
@@ -1118,7 +1171,9 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file,
|
||||
&weechat_ruby_api_config_section_write_cb,
|
||||
c_function_write,
|
||||
&weechat_ruby_api_config_section_write_default_cb,
|
||||
c_function_write_default));
|
||||
c_function_write_default,
|
||||
&weechat_ruby_api_config_section_create_option_cb,
|
||||
c_function_create_option));
|
||||
|
||||
RUBY_RETURN_STRING_FREE(result);
|
||||
}
|
||||
@@ -2606,19 +2661,17 @@ weechat_ruby_api_hook_signal_send (VALUE class, VALUE signal, VALUE type_data,
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_api_hook_config_cb (void *data, char *type, char *option,
|
||||
char *value)
|
||||
weechat_ruby_api_hook_config_cb (void *data, char *option, char *value)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *ruby_argv[4];
|
||||
char *ruby_argv[3];
|
||||
int *rc, ret;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
ruby_argv[0] = type;
|
||||
ruby_argv[1] = option;
|
||||
ruby_argv[2] = value;
|
||||
ruby_argv[3] = NULL;
|
||||
ruby_argv[0] = option;
|
||||
ruby_argv[1] = value;
|
||||
ruby_argv[2] = NULL;
|
||||
|
||||
rc = (int *) weechat_ruby_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
@@ -2641,10 +2694,9 @@ weechat_ruby_api_hook_config_cb (void *data, char *type, char *option,
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_hook_config (VALUE class, VALUE type, VALUE option,
|
||||
VALUE function)
|
||||
weechat_ruby_api_hook_config (VALUE class, VALUE option, VALUE function)
|
||||
{
|
||||
char *c_type, *c_option, *c_function, *result;
|
||||
char *c_option, *c_function, *result;
|
||||
VALUE return_value;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -2656,27 +2708,23 @@ weechat_ruby_api_hook_config (VALUE class, VALUE type, VALUE option,
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
c_type = NULL;
|
||||
c_option = NULL;
|
||||
c_function = NULL;
|
||||
|
||||
if (NIL_P (type) || NIL_P (option) || NIL_P (function))
|
||||
if (NIL_P (option) || NIL_P (function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_config");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
Check_Type (type, T_STRING);
|
||||
Check_Type (option, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_type = STR2CSTR (type);
|
||||
c_option = STR2CSTR (option);
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
result = script_ptr2str (script_api_hook_config (weechat_ruby_plugin,
|
||||
ruby_current_script,
|
||||
c_type,
|
||||
c_option,
|
||||
&weechat_ruby_api_hook_config_cb,
|
||||
c_function));
|
||||
@@ -4388,7 +4436,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
rb_define_module_function (ruby_mWeechat, "list_remove_all", &weechat_ruby_api_list_remove_all, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "list_free", &weechat_ruby_api_list_free, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "config_new", &weechat_ruby_api_config_new, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "config_new_section", &weechat_ruby_api_config_new_section, 5);
|
||||
rb_define_module_function (ruby_mWeechat, "config_new_section", &weechat_ruby_api_config_new_section, 6);
|
||||
rb_define_module_function (ruby_mWeechat, "config_search_section", &weechat_ruby_api_config_search_section, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "config_new_option", &weechat_ruby_api_config_new_option, 10);
|
||||
rb_define_module_function (ruby_mWeechat, "config_search_option", &weechat_ruby_api_config_search_option, 3);
|
||||
@@ -4417,7 +4465,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
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);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_config", &weechat_ruby_api_hook_config, 2);
|
||||
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);
|
||||
|
||||
@@ -36,7 +36,7 @@ WEECHAT_PLUGIN_DESCRIPTION("Ruby plugin for WeeChat");
|
||||
WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>");
|
||||
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
|
||||
WEECHAT_PLUGIN_WEECHAT_VERSION(WEECHAT_VERSION);
|
||||
WEECHAT_PLUGIN_LICENSE("GPL");
|
||||
WEECHAT_PLUGIN_LICENSE("GPL3");
|
||||
|
||||
struct t_weechat_plugin *weechat_ruby_plugin = NULL;
|
||||
|
||||
@@ -306,8 +306,8 @@ weechat_ruby_load (char *filename)
|
||||
}
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: loading script \"%s\""),
|
||||
weechat_prefix ("info"), "ruby", filename);
|
||||
weechat_gettext ("%s: loading script \"%s\""),
|
||||
"ruby", filename);
|
||||
|
||||
ruby_current_script = NULL;
|
||||
|
||||
@@ -435,8 +435,8 @@ weechat_ruby_unload (struct t_plugin_script *script)
|
||||
char *ruby_argv[1] = { NULL };
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unloading script \"%s\""),
|
||||
weechat_prefix ("info"), "ruby", script->name);
|
||||
weechat_gettext ("%s: unloading script \"%s\""),
|
||||
"ruby", script->name);
|
||||
|
||||
if (script->shutdown_func && script->shutdown_func[0])
|
||||
{
|
||||
@@ -468,8 +468,8 @@ weechat_ruby_unload_name (char *name)
|
||||
{
|
||||
weechat_ruby_unload (ptr_script);
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: script \"%s\" unloaded"),
|
||||
weechat_prefix ("info"), "ruby", name);
|
||||
weechat_gettext ("%s: script \"%s\" unloaded"),
|
||||
"ruby", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ script_api_charset_set (struct t_plugin_script *script,
|
||||
struct t_config_file *
|
||||
script_api_config_new (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
char *filename,
|
||||
char *name,
|
||||
int (*callback_reload)(void *data,
|
||||
struct t_config_file *config_file),
|
||||
char *function)
|
||||
@@ -65,7 +65,7 @@ script_api_config_new (struct t_weechat_plugin *weechat_plugin,
|
||||
if (!new_script_callback)
|
||||
return NULL;
|
||||
|
||||
new_config_file = weechat_config_new (filename, callback_reload,
|
||||
new_config_file = weechat_config_new (name, callback_reload,
|
||||
new_script_callback);
|
||||
if (!new_config_file)
|
||||
{
|
||||
@@ -82,7 +82,7 @@ script_api_config_new (struct t_weechat_plugin *weechat_plugin,
|
||||
}
|
||||
else
|
||||
{
|
||||
new_config_file = weechat_config_new (filename, NULL, NULL);
|
||||
new_config_file = weechat_config_new (name, NULL, NULL);
|
||||
}
|
||||
|
||||
return new_config_file;
|
||||
@@ -110,19 +110,27 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
|
||||
void (*callback_write_default)(void *data,
|
||||
struct t_config_file *config_file,
|
||||
char *section_name),
|
||||
char *function_write_default)
|
||||
char *function_write_default,
|
||||
int (*callback_create_option)(void *data,
|
||||
struct t_config_file *config_file,
|
||||
struct t_config_section *section,
|
||||
char *option_name,
|
||||
char *value),
|
||||
char *function_create_option)
|
||||
{
|
||||
struct t_script_callback *new_script_callback1, *new_script_callback2;
|
||||
struct t_script_callback *new_script_callback3;
|
||||
struct t_script_callback *new_script_callback3, *new_script_callback4;
|
||||
struct t_config_section *new_section;
|
||||
void *callback1, *callback2, *callback3;
|
||||
void *callback1, *callback2, *callback3, *callback4;
|
||||
|
||||
new_script_callback1 = NULL;
|
||||
new_script_callback2 = NULL;
|
||||
new_script_callback3 = NULL;
|
||||
new_script_callback4 = NULL;
|
||||
callback1 = NULL;
|
||||
callback2 = NULL;
|
||||
callback3 = NULL;
|
||||
callback4 = NULL;
|
||||
|
||||
if (function_read && function_read[0])
|
||||
{
|
||||
@@ -167,6 +175,31 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
|
||||
callback3 = callback_write_default;
|
||||
}
|
||||
|
||||
if (function_create_option && function_create_option[0])
|
||||
{
|
||||
new_script_callback4 = script_callback_alloc ();
|
||||
if (!new_script_callback4)
|
||||
{
|
||||
if (new_script_callback1)
|
||||
{
|
||||
script_callback_free_data (new_script_callback1);
|
||||
free (new_script_callback1);
|
||||
}
|
||||
if (new_script_callback2)
|
||||
{
|
||||
script_callback_free_data (new_script_callback2);
|
||||
free (new_script_callback2);
|
||||
}
|
||||
if (new_script_callback3)
|
||||
{
|
||||
script_callback_free_data (new_script_callback3);
|
||||
free (new_script_callback3);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
callback4 = callback_create_option;
|
||||
}
|
||||
|
||||
new_section = weechat_config_new_section (config_file,
|
||||
name,
|
||||
callback1,
|
||||
@@ -174,7 +207,9 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
|
||||
callback2,
|
||||
new_script_callback2,
|
||||
callback3,
|
||||
new_script_callback3);
|
||||
new_script_callback3,
|
||||
callback4,
|
||||
new_script_callback4);
|
||||
if (!new_section)
|
||||
{
|
||||
if (new_script_callback1)
|
||||
@@ -192,6 +227,11 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
|
||||
script_callback_free_data (new_script_callback3);
|
||||
free (new_script_callback3);
|
||||
}
|
||||
if (new_script_callback4)
|
||||
{
|
||||
script_callback_free_data (new_script_callback4);
|
||||
free (new_script_callback4);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -222,6 +262,15 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
|
||||
script_callback_add (script, new_script_callback3);
|
||||
}
|
||||
|
||||
if (new_script_callback4)
|
||||
{
|
||||
new_script_callback4->script = script;
|
||||
new_script_callback4->function = strdup (function_create_option);
|
||||
new_script_callback4->config_file = config_file;
|
||||
new_script_callback4->config_section = new_section;
|
||||
script_callback_add (script, new_script_callback4);
|
||||
}
|
||||
|
||||
return new_section;
|
||||
}
|
||||
|
||||
@@ -238,43 +287,126 @@ script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
|
||||
char *name, char *type,
|
||||
char *description, char *string_values,
|
||||
int min, int max, char *default_value,
|
||||
void (*callback_change)(void *data),
|
||||
char *function)
|
||||
void (*callback_check_value)(void *data,
|
||||
struct t_config_option *option,
|
||||
char *value),
|
||||
char *function_check_value,
|
||||
void (*callback_change)(void *data,
|
||||
struct t_config_option *option),
|
||||
char *function_change,
|
||||
void (*callback_delete)(void *data,
|
||||
struct t_config_option *option),
|
||||
char *function_delete)
|
||||
{
|
||||
struct t_script_callback *new_script_callback;
|
||||
struct t_script_callback *new_script_callback1, *new_script_callback2;
|
||||
struct t_script_callback *new_script_callback3;
|
||||
void *callback1, *callback2, *callback3;
|
||||
struct t_config_option *new_option;
|
||||
|
||||
if (function && function[0])
|
||||
|
||||
new_script_callback1 = NULL;
|
||||
new_script_callback2 = NULL;
|
||||
new_script_callback3 = NULL;
|
||||
callback1 = NULL;
|
||||
callback2 = NULL;
|
||||
callback3 = NULL;
|
||||
|
||||
if (function_check_value && function_check_value[0])
|
||||
{
|
||||
new_script_callback = script_callback_alloc ();
|
||||
if (!new_script_callback)
|
||||
new_script_callback1 = script_callback_alloc ();
|
||||
if (!new_script_callback1)
|
||||
return NULL;
|
||||
|
||||
new_option = weechat_config_new_option (config_file, section, name, type,
|
||||
description, string_values, min,
|
||||
max, default_value,
|
||||
callback_change,
|
||||
new_script_callback);
|
||||
if (!new_option)
|
||||
callback1 = callback_check_value;
|
||||
}
|
||||
|
||||
if (function_change && function_change[0])
|
||||
{
|
||||
new_script_callback2 = script_callback_alloc ();
|
||||
if (!new_script_callback2)
|
||||
{
|
||||
script_callback_free_data (new_script_callback);
|
||||
free (new_script_callback);
|
||||
if (new_script_callback1)
|
||||
{
|
||||
script_callback_free_data (new_script_callback1);
|
||||
free (new_script_callback1);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new_script_callback->script = script;
|
||||
new_script_callback->function = strdup (function);
|
||||
new_script_callback->config_file = config_file;
|
||||
new_script_callback->config_section = section;
|
||||
new_script_callback->config_option = new_option;
|
||||
|
||||
script_callback_add (script, new_script_callback);
|
||||
callback2 = callback_change;
|
||||
}
|
||||
else
|
||||
|
||||
if (function_delete && function_delete[0])
|
||||
{
|
||||
new_option = weechat_config_new_option (config_file, section, name, type,
|
||||
description, string_values, min,
|
||||
max, default_value, NULL, NULL);
|
||||
new_script_callback3 = script_callback_alloc ();
|
||||
if (!new_script_callback3)
|
||||
{
|
||||
if (new_script_callback1)
|
||||
{
|
||||
script_callback_free_data (new_script_callback1);
|
||||
free (new_script_callback1);
|
||||
}
|
||||
if (new_script_callback2)
|
||||
{
|
||||
script_callback_free_data (new_script_callback2);
|
||||
free (new_script_callback2);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
callback3 = callback_delete;
|
||||
}
|
||||
|
||||
new_option = weechat_config_new_option (config_file, section, name, type,
|
||||
description, string_values, min,
|
||||
max, default_value,
|
||||
callback1, new_script_callback1,
|
||||
callback2, new_script_callback2,
|
||||
callback3, new_script_callback3);
|
||||
if (!new_option)
|
||||
{
|
||||
if (new_script_callback1)
|
||||
{
|
||||
script_callback_free_data (new_script_callback1);
|
||||
free (new_script_callback1);
|
||||
}
|
||||
if (new_script_callback2)
|
||||
{
|
||||
script_callback_free_data (new_script_callback2);
|
||||
free (new_script_callback2);
|
||||
}
|
||||
if (new_script_callback3)
|
||||
{
|
||||
script_callback_free_data (new_script_callback3);
|
||||
free (new_script_callback3);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (new_script_callback1)
|
||||
{
|
||||
new_script_callback1->script = script;
|
||||
new_script_callback1->function = strdup (function_check_value);
|
||||
new_script_callback1->config_file = config_file;
|
||||
new_script_callback1->config_section = section;
|
||||
new_script_callback1->config_option = new_option;
|
||||
script_callback_add (script, new_script_callback1);
|
||||
}
|
||||
|
||||
if (new_script_callback2)
|
||||
{
|
||||
new_script_callback2->script = script;
|
||||
new_script_callback2->function = strdup (function_check_value);
|
||||
new_script_callback2->config_file = config_file;
|
||||
new_script_callback2->config_section = section;
|
||||
new_script_callback2->config_option = new_option;
|
||||
script_callback_add (script, new_script_callback2);
|
||||
}
|
||||
|
||||
if (new_script_callback3)
|
||||
{
|
||||
new_script_callback3->script = script;
|
||||
new_script_callback3->function = strdup (function_check_value);
|
||||
new_script_callback3->config_file = config_file;
|
||||
new_script_callback3->config_section = section;
|
||||
new_script_callback3->config_option = new_option;
|
||||
script_callback_add (script, new_script_callback3);
|
||||
}
|
||||
|
||||
return new_option;
|
||||
@@ -638,9 +770,9 @@ script_api_hook_signal (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_hook *
|
||||
script_api_hook_config (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
char *type, char *option,
|
||||
int (*callback)(void *data, char *type,
|
||||
char *option, char *value),
|
||||
char *option,
|
||||
int (*callback)(void *data, char *option,
|
||||
char *value),
|
||||
char *function)
|
||||
{
|
||||
struct t_script_callback *new_script_callback;
|
||||
@@ -650,7 +782,7 @@ script_api_hook_config (struct t_weechat_plugin *weechat_plugin,
|
||||
if (!new_script_callback)
|
||||
return NULL;
|
||||
|
||||
new_hook = weechat_hook_config (type, option, callback, new_script_callback);
|
||||
new_hook = weechat_hook_config (option, callback, new_script_callback);
|
||||
if (!new_hook)
|
||||
{
|
||||
script_callback_free_data (new_script_callback);
|
||||
|
||||
@@ -23,7 +23,7 @@ extern void script_api_charset_set (struct t_plugin_script *script,
|
||||
char *charset);
|
||||
extern struct t_config_file *script_api_config_new (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
char *filename,
|
||||
char *name,
|
||||
int (*callback_reload)(void *data,
|
||||
struct t_config_file *config_file),
|
||||
char *function);
|
||||
@@ -43,7 +43,13 @@ extern struct t_config_section *script_api_config_new_section (struct t_weechat_
|
||||
void (*callback_write_default)(void *data,
|
||||
struct t_config_file *config_file,
|
||||
char *section_name),
|
||||
char *function_write_default);
|
||||
char *function_write_default,
|
||||
int (*callback_create_option)(void *data,
|
||||
struct t_config_file *config_file,
|
||||
struct t_config_section *section,
|
||||
char *option_name,
|
||||
char *value),
|
||||
char *function_create_option);
|
||||
extern struct t_config_option *script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
struct t_config_file *config_file,
|
||||
@@ -125,8 +131,8 @@ extern struct t_hook *script_api_hook_signal (struct t_weechat_plugin *weechat_p
|
||||
char *function);
|
||||
extern struct t_hook *script_api_hook_config (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
char *type, char *option,
|
||||
int (*callback)(void *data, char *type,
|
||||
char *option,
|
||||
int (*callback)(void *data,
|
||||
char *option,
|
||||
char *value),
|
||||
char *function);
|
||||
|
||||
@@ -63,10 +63,9 @@ script_config_read (struct t_weechat_plugin *weechat_plugin)
|
||||
*/
|
||||
|
||||
int
|
||||
script_config_cb (void *data, char *type, char *option, char *value)
|
||||
script_config_cb (void *data, char *option, char *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) type;
|
||||
(void) option;
|
||||
(void) value;
|
||||
|
||||
@@ -100,14 +99,13 @@ script_init (struct t_weechat_plugin *weechat_plugin,
|
||||
script_config_read (weechat_plugin);
|
||||
|
||||
/* add hook for config option */
|
||||
length = strlen (weechat_plugin->name) + 32;
|
||||
length = strlen (weechat_plugin->name) + 64;
|
||||
string = malloc (length);
|
||||
if (string)
|
||||
{
|
||||
snprintf (string, length, "%s.%s",
|
||||
snprintf (string, length, "plugins.var.%s.%s",
|
||||
weechat_plugin->name, SCRIPT_OPTION_CHECK_LICENSE);
|
||||
weechat_hook_config ("plugin", string,
|
||||
&script_config_cb, weechat_plugin);
|
||||
weechat_hook_config (string, &script_config_cb, weechat_plugin);
|
||||
free (string);
|
||||
}
|
||||
|
||||
@@ -427,7 +425,7 @@ script_remove (struct t_weechat_plugin *weechat_plugin,
|
||||
&& !ptr_script_callback->config_section
|
||||
&& !ptr_script_callback->config_option)
|
||||
{
|
||||
if (weechat_config_boolean (weechat_config_get_weechat ("plugins_save_config_on_unload")))
|
||||
if (weechat_config_boolean (weechat_config_get_weechat ("plugin_save_config_on_unload")))
|
||||
weechat_config_write (ptr_script_callback->config_file);
|
||||
weechat_config_free (ptr_script_callback->config_file);
|
||||
}
|
||||
@@ -509,9 +507,9 @@ script_display_list (struct t_weechat_plugin *weechat_plugin,
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
" %s%s%s v%s - %s",
|
||||
weechat_color ("color_chat_buffer"),
|
||||
weechat_color ("chat_buffer"),
|
||||
ptr_script->name,
|
||||
weechat_color ("color_chat"),
|
||||
weechat_color ("chat"),
|
||||
ptr_script->version,
|
||||
ptr_script->description);
|
||||
if (full)
|
||||
|
||||
Reference in New Issue
Block a user