mirror of
https://github.com/weechat/weechat.git
synced 2026-06-26 12:56:37 +02:00
Added charset plugin (WeeChat is now full UTF-8 for internal data storage), fixed compilation problems with FreeBSD, fixed status bar display bug
This commit is contained in:
@@ -224,7 +224,7 @@ weechat_lua_modifier (t_weechat_plugin *plugin,
|
||||
static int
|
||||
weechat_lua_register (lua_State *L)
|
||||
{
|
||||
const char *name, *version, *shutdown_func, *description;
|
||||
const char *name, *version, *shutdown_func, *description, *charset;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
@@ -236,10 +236,11 @@ weechat_lua_register (lua_State *L)
|
||||
version = NULL;
|
||||
shutdown_func = NULL;
|
||||
description = NULL;
|
||||
charset = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n != 4)
|
||||
if ((n < 4) || (n > 5))
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
@@ -247,12 +248,24 @@ weechat_lua_register (lua_State *L)
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
name = lua_tostring (lua_current_interpreter, -4);
|
||||
version = lua_tostring (lua_current_interpreter, -3);
|
||||
shutdown_func = lua_tostring (lua_current_interpreter, -2);
|
||||
description = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
switch (n)
|
||||
{
|
||||
case 4:
|
||||
name = lua_tostring (lua_current_interpreter, -4);
|
||||
version = lua_tostring (lua_current_interpreter, -3);
|
||||
shutdown_func = lua_tostring (lua_current_interpreter, -2);
|
||||
description = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 5:
|
||||
name = lua_tostring (lua_current_interpreter, -5);
|
||||
version = lua_tostring (lua_current_interpreter, -4);
|
||||
shutdown_func = lua_tostring (lua_current_interpreter, -3);
|
||||
description = lua_tostring (lua_current_interpreter, -2);
|
||||
charset = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
}
|
||||
|
||||
if (weechat_script_search (lua_plugin, &lua_scripts, (char *) name))
|
||||
{
|
||||
/* error: another scripts already exists with this name! */
|
||||
@@ -273,7 +286,8 @@ weechat_lua_register (lua_State *L)
|
||||
(char *) name,
|
||||
(char *) version,
|
||||
(char *) shutdown_func,
|
||||
(char *) description);
|
||||
(char *) description,
|
||||
(char *) charset);
|
||||
if (lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
@@ -291,6 +305,51 @@ weechat_lua_register (lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_set_charset: set script charset
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_set_charset (lua_State *L)
|
||||
{
|
||||
const char *charset;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: unable to set charset, "
|
||||
"script not initialized");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
charset = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n != 1)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"set_charset\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
charset = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
weechat_script_set_charset (lua_plugin,
|
||||
lua_current_script,
|
||||
(char *) charset);
|
||||
|
||||
lua_pushnumber (lua_current_interpreter, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
@@ -1531,18 +1590,6 @@ weechat_lua_get_server_info (lua_State *L)
|
||||
lua_pushstring (lua_current_interpreter, ptr_server->notify_levels);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "charset_decode_iso");
|
||||
lua_pushstring (lua_current_interpreter, ptr_server->charset_decode_iso);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "charset_decode_utf");
|
||||
lua_pushstring (lua_current_interpreter, ptr_server->charset_decode_utf);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "charset_encode");
|
||||
lua_pushstring (lua_current_interpreter, ptr_server->charset_encode);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "is_connected");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_server->is_connected);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
@@ -2062,6 +2109,7 @@ weechat_lua_constant_plugin_rc_ok_ignore_all (lua_State *L)
|
||||
static
|
||||
const struct luaL_reg weechat_lua_funcs[] = {
|
||||
{ "register", weechat_lua_register },
|
||||
{ "set_charset", weechat_lua_set_charset },
|
||||
{ "print", weechat_lua_print },
|
||||
{ "print_server", weechat_lua_print_server },
|
||||
{ "print_infobar", weechat_lua_print_infobar },
|
||||
|
||||
@@ -271,11 +271,11 @@ weechat_perl_timer_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
int *r, ret;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
int *r;
|
||||
int ret;
|
||||
|
||||
r = (int *) weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
SCRIPT_EXEC_INT,
|
||||
@@ -343,7 +343,7 @@ weechat_perl_modifier (t_weechat_plugin *plugin,
|
||||
|
||||
static XS (XS_weechat_register)
|
||||
{
|
||||
char *name, *version, *shutdown_func, *description;
|
||||
char *name, *version, *shutdown_func, *description, *charset;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@@ -352,7 +352,7 @@ static XS (XS_weechat_register)
|
||||
|
||||
perl_current_script = NULL;
|
||||
|
||||
if (items != 4)
|
||||
if ((items < 4) || (items > 5))
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
@@ -364,6 +364,7 @@ static XS (XS_weechat_register)
|
||||
version = SvPV (ST (1), PL_na);
|
||||
shutdown_func = SvPV (ST (2), PL_na);
|
||||
description = SvPV (ST (3), PL_na);
|
||||
charset = (items == 5) ? SvPV (ST (4), PL_na) : NULL;
|
||||
|
||||
if (weechat_script_search (perl_plugin, &perl_scripts, name))
|
||||
{
|
||||
@@ -382,7 +383,7 @@ static XS (XS_weechat_register)
|
||||
(perl_current_script_filename) ?
|
||||
perl_current_script_filename : "",
|
||||
name, version, shutdown_func,
|
||||
description);
|
||||
description, charset);
|
||||
if (perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
@@ -398,6 +399,40 @@ static XS (XS_weechat_register)
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::set_charset: set script charset
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_set_charset)
|
||||
{
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to set charset, "
|
||||
"script not initialized");
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"set_charset\" function");
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
weechat_script_set_charset (perl_plugin,
|
||||
perl_current_script,
|
||||
SvPV (ST (0), PL_na));
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
@@ -438,9 +473,9 @@ static XS (XS_weechat_print)
|
||||
server_name = SvPV (ST (2), PL_na);
|
||||
}
|
||||
|
||||
perl_plugin->print (perl_plugin,
|
||||
server_name, channel_name,
|
||||
"%s", message);
|
||||
weechat_script_print (perl_plugin, perl_current_script,
|
||||
server_name, channel_name,
|
||||
"%s", message);
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
@@ -475,7 +510,8 @@ static XS (XS_weechat_print_server)
|
||||
|
||||
message = SvPV (ST (0), PL_na);
|
||||
|
||||
perl_plugin->print_server (perl_plugin, "%s", message);
|
||||
weechat_script_print_server (perl_plugin, perl_current_script,
|
||||
"%s", message);
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
@@ -507,10 +543,9 @@ static XS (XS_weechat_print_infobar)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
perl_plugin->print_infobar (perl_plugin,
|
||||
SvIV (ST (0)),
|
||||
"%s",
|
||||
SvPV (ST (1), PL_na));
|
||||
weechat_script_print_infobar (perl_plugin, perl_current_script,
|
||||
SvIV (ST (0)),
|
||||
"%s", SvPV (ST (1), PL_na));
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
@@ -580,9 +615,9 @@ static XS (XS_weechat_log)
|
||||
server_name = SvPV (ST (2), PL_na);
|
||||
}
|
||||
|
||||
perl_plugin->log (perl_plugin,
|
||||
server_name, channel_name,
|
||||
"%s", message);
|
||||
weechat_script_log (perl_plugin, perl_current_script,
|
||||
server_name, channel_name,
|
||||
"%s", message);
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
@@ -625,9 +660,9 @@ static XS (XS_weechat_command)
|
||||
server_name = SvPV (ST (2), PL_na);
|
||||
}
|
||||
|
||||
perl_plugin->exec_command (perl_plugin,
|
||||
server_name, channel_name,
|
||||
SvPV (ST (0), PL_na));
|
||||
weechat_script_exec_command (perl_plugin, perl_current_script,
|
||||
server_name, channel_name,
|
||||
SvPV (ST (0), PL_na));
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
@@ -1338,9 +1373,6 @@ static XS (XS_weechat_get_server_info)
|
||||
hv_store (server_hash_member, "autojoin", 8, newSVpv (ptr_server->autojoin, 0), 0);
|
||||
hv_store (server_hash_member, "autorejoin", 10, newSViv (ptr_server->autorejoin), 0);
|
||||
hv_store (server_hash_member, "notify_levels", 13, newSVpv (ptr_server->notify_levels, 0), 0);
|
||||
hv_store (server_hash_member, "charset_decode_iso", 18, newSVpv (ptr_server->charset_decode_iso, 0), 0);
|
||||
hv_store (server_hash_member, "charset_decode_utf", 18, newSVpv (ptr_server->charset_decode_utf, 0), 0);
|
||||
hv_store (server_hash_member, "charset_encode", 14, newSVpv (ptr_server->charset_encode, 0), 0);
|
||||
hv_store (server_hash_member, "is_connected", 12, newSViv (ptr_server->is_connected), 0);
|
||||
hv_store (server_hash_member, "ssl_connected", 13, newSViv (ptr_server->ssl_connected), 0);
|
||||
hv_store (server_hash_member, "nick", 4, newSVpv (ptr_server->nick, 0), 0);
|
||||
@@ -1755,6 +1787,7 @@ weechat_perl_xs_init (pTHX)
|
||||
|
||||
/* interface functions */
|
||||
newXS ("weechat::register", XS_weechat_register, "weechat");
|
||||
newXS ("weechat::set_charset", XS_weechat_set_charset, "weechat");
|
||||
newXS ("weechat::print", XS_weechat_print, "weechat");
|
||||
newXS ("weechat::print_server", XS_weechat_print_server, "weechat");
|
||||
newXS ("weechat::print_infobar", XS_weechat_print_infobar, "weechat");
|
||||
|
||||
@@ -266,7 +266,7 @@ weechat_python_modifier (t_weechat_plugin *plugin,
|
||||
static PyObject *
|
||||
weechat_python_register (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *name, *version, *shutdown_func, *description;
|
||||
char *name, *version, *shutdown_func, *description, *charset;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
@@ -277,8 +277,10 @@ weechat_python_register (PyObject *self, PyObject *args)
|
||||
version = NULL;
|
||||
shutdown_func = NULL;
|
||||
description = NULL;
|
||||
charset = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ssss", &name, &version, &shutdown_func, &description))
|
||||
if (!PyArg_ParseTuple (args, "ssss|s", &name, &version, &shutdown_func,
|
||||
&description, &charset))
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
@@ -303,7 +305,7 @@ weechat_python_register (PyObject *self, PyObject *args)
|
||||
(python_current_script_filename) ?
|
||||
python_current_script_filename : "",
|
||||
name, version, shutdown_func,
|
||||
description);
|
||||
description, charset);
|
||||
if (python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
@@ -317,6 +319,46 @@ weechat_python_register (PyObject *self, PyObject *args)
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_set_charset: set script charset
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_set_charset (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *charset;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to set charset, "
|
||||
"script not initialized");
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
charset = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &charset))
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"set_charset\" function");
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
if (charset)
|
||||
weechat_script_set_charset (python_plugin,
|
||||
python_current_script,
|
||||
charset);
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
@@ -1303,12 +1345,6 @@ weechat_python_get_server_info (PyObject *self, PyObject *args)
|
||||
Py_BuildValue("i", ptr_server->autorejoin));
|
||||
PyDict_SetItem(server_hash_member, Py_BuildValue("s", "notify_levels"),
|
||||
Py_BuildValue("s", ptr_server->notify_levels));
|
||||
PyDict_SetItem(server_hash_member, Py_BuildValue("s", "charset_decode_iso"),
|
||||
Py_BuildValue("s", ptr_server->charset_decode_iso));
|
||||
PyDict_SetItem(server_hash_member, Py_BuildValue("s", "charset_decode_utf"),
|
||||
Py_BuildValue("s", ptr_server->charset_decode_utf));
|
||||
PyDict_SetItem(server_hash_member, Py_BuildValue("s", "charset_encode"),
|
||||
Py_BuildValue("s", ptr_server->charset_encode));
|
||||
PyDict_SetItem(server_hash_member, Py_BuildValue("s", "is_connected"),
|
||||
Py_BuildValue("i", ptr_server->is_connected));
|
||||
PyDict_SetItem(server_hash_member, Py_BuildValue("s", "ssl_connected"),
|
||||
@@ -1714,6 +1750,7 @@ weechat_python_get_buffer_data (PyObject *self, PyObject *args)
|
||||
static
|
||||
PyMethodDef weechat_python_funcs[] = {
|
||||
{ "register", weechat_python_register, METH_VARARGS, "" },
|
||||
{ "set_charset", weechat_python_set_charset, METH_VARARGS, "" },
|
||||
{ "prnt", weechat_python_print, METH_VARARGS, "" },
|
||||
{ "print_server", weechat_python_print_server, METH_VARARGS, "" },
|
||||
{ "print_infobar", weechat_python_print_infobar, METH_VARARGS, "" },
|
||||
|
||||
@@ -303,15 +303,28 @@ weechat_ruby_modifier (t_weechat_plugin *plugin,
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_register (VALUE class, VALUE name, VALUE version,
|
||||
VALUE shutdown_func, VALUE description)
|
||||
weechat_ruby_register (int argc, VALUE *argv, VALUE class)
|
||||
{
|
||||
char *c_name, *c_version, *c_shutdown_func, *c_description;
|
||||
VALUE name, version, shutdown_func, description, charset;
|
||||
char *c_name, *c_version, *c_shutdown_func, *c_description, *c_charset;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
ruby_current_script = NULL;
|
||||
|
||||
name = Qnil;
|
||||
version = Qnil;
|
||||
shutdown_func = Qnil;
|
||||
description = Qnil;
|
||||
charset = Qnil;
|
||||
c_name = NULL;
|
||||
c_version = NULL;
|
||||
c_shutdown_func = NULL;
|
||||
c_description = NULL;
|
||||
c_charset = NULL;
|
||||
|
||||
rb_scan_args (argc, argv, "41", &name, &version, &shutdown_func, &description, &charset);
|
||||
|
||||
if (NIL_P (name) || NIL_P (version) || NIL_P (shutdown_func) || NIL_P (description))
|
||||
{
|
||||
@@ -331,6 +344,12 @@ weechat_ruby_register (VALUE class, VALUE name, VALUE version,
|
||||
c_shutdown_func = STR2CSTR (shutdown_func);
|
||||
c_description = STR2CSTR (description);
|
||||
|
||||
if (!NIL_P (charset))
|
||||
{
|
||||
Check_Type (charset, T_STRING);
|
||||
c_charset = STR2CSTR (charset);
|
||||
}
|
||||
|
||||
if (weechat_script_search (ruby_plugin, &ruby_scripts, c_name))
|
||||
{
|
||||
/* error: another scripts already exists with this name! */
|
||||
@@ -348,7 +367,7 @@ weechat_ruby_register (VALUE class, VALUE name, VALUE version,
|
||||
(ruby_current_script_filename) ?
|
||||
ruby_current_script_filename : "",
|
||||
c_name, c_version, c_shutdown_func,
|
||||
c_description);
|
||||
c_description, c_charset);
|
||||
if (ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
@@ -362,6 +381,47 @@ weechat_ruby_register (VALUE class, VALUE name, VALUE version,
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_set_charset: set script charset
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_set_charset (VALUE class, VALUE charset)
|
||||
{
|
||||
char *c_charset;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: unable to set charset, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_charset = NULL;
|
||||
|
||||
if (NIL_P (c_charset))
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"set_charset\" function");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (charset, T_STRING);
|
||||
c_charset = STR2CSTR (charset);
|
||||
|
||||
if (c_charset)
|
||||
weechat_script_set_charset (ruby_plugin,
|
||||
ruby_current_script,
|
||||
c_charset);
|
||||
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_print: print message into a buffer (current or specified one)
|
||||
*/
|
||||
@@ -1523,12 +1583,6 @@ weechat_ruby_get_server_info (VALUE class)
|
||||
INT2FIX(ptr_server->autorejoin));
|
||||
rb_hash_aset (server_hash_member, rb_str_new2("notify_levels"),
|
||||
rb_str_new2(ptr_server->notify_levels));
|
||||
rb_hash_aset (server_hash_member, rb_str_new2("charset_decode_iso"),
|
||||
rb_str_new2(ptr_server->charset_decode_iso));
|
||||
rb_hash_aset (server_hash_member, rb_str_new2("charset_decode_utf"),
|
||||
rb_str_new2(ptr_server->charset_decode_utf));
|
||||
rb_hash_aset (server_hash_member, rb_str_new2("charset_encode"),
|
||||
rb_str_new2(ptr_server->charset_encode));
|
||||
rb_hash_aset (server_hash_member, rb_str_new2("is_connected"),
|
||||
INT2FIX(ptr_server->is_connected));
|
||||
rb_hash_aset (server_hash_member, rb_str_new2("ssl_connected"),
|
||||
@@ -2420,7 +2474,8 @@ weechat_plugin_init (t_weechat_plugin *plugin)
|
||||
rb_define_const(ruby_mWeechat, "PLUGIN_RC_OK_IGNORE_WEECHAT", INT2NUM(PLUGIN_RC_OK_IGNORE_WEECHAT));
|
||||
rb_define_const(ruby_mWeechat, "PLUGIN_RC_OK_IGNORE_PLUGINS", INT2NUM(PLUGIN_RC_OK_IGNORE_PLUGINS));
|
||||
rb_define_const(ruby_mWeechat, "PLUGIN_RC_OK_IGNORE_ALL", INT2NUM(PLUGIN_RC_OK_IGNORE_ALL));
|
||||
rb_define_module_function (ruby_mWeechat, "register", weechat_ruby_register, 4);
|
||||
rb_define_module_function (ruby_mWeechat, "register", weechat_ruby_register, -1);
|
||||
rb_define_module_function (ruby_mWeechat, "set_charset", weechat_ruby_set_charset, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "print", weechat_ruby_print, -1);
|
||||
rb_define_module_function (ruby_mWeechat, "print_server", weechat_ruby_print_server, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "print_infobar", weechat_ruby_print_infobar, 2);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
@@ -199,7 +200,8 @@ weechat_script_add (t_weechat_plugin *plugin,
|
||||
t_plugin_script **script_list,
|
||||
char *filename,
|
||||
char *name, char *version,
|
||||
char *shutdown_func, char *description)
|
||||
char *shutdown_func, char *description,
|
||||
char *charset)
|
||||
{
|
||||
t_plugin_script *new_script;
|
||||
|
||||
@@ -221,6 +223,7 @@ weechat_script_add (t_weechat_plugin *plugin,
|
||||
new_script->version = strdup (version);
|
||||
new_script->shutdown_func = strdup (shutdown_func);
|
||||
new_script->description = strdup (description);
|
||||
new_script->charset = (charset) ? strdup (charset) : NULL;
|
||||
|
||||
/* add new script to list */
|
||||
if ((*script_list))
|
||||
@@ -288,6 +291,8 @@ weechat_script_remove (t_weechat_plugin *plugin,
|
||||
free (script->version);
|
||||
if (script->shutdown_func)
|
||||
free (script->shutdown_func);
|
||||
if (script->charset)
|
||||
free (script->charset);
|
||||
|
||||
/* remove script from list */
|
||||
if (script->prev_script)
|
||||
@@ -301,6 +306,122 @@ weechat_script_remove (t_weechat_plugin *plugin,
|
||||
free (script);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_print: print a message on a server or channel buffer
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_print (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *server, char *channel,
|
||||
char *message, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
static char buf[8192];
|
||||
char *buf2;
|
||||
|
||||
va_start (argptr, message);
|
||||
vsnprintf (buf, sizeof (buf) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
buf2 = (script->charset && script->charset[0]) ?
|
||||
plugin->iconv_to_internal (plugin, script->charset, buf) : NULL;
|
||||
plugin->print (plugin, server, channel, (buf2) ? buf2 : buf);
|
||||
if (buf2)
|
||||
free (buf2);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_print_server: print a message on server buffer
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_print_server (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *message, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
static char buf[8192];
|
||||
char *buf2;
|
||||
|
||||
va_start (argptr, message);
|
||||
vsnprintf (buf, sizeof (buf) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
buf2 = (script->charset && script->charset[0]) ?
|
||||
plugin->iconv_to_internal (plugin, script->charset, buf) : NULL;
|
||||
plugin->print_server (plugin, (buf2) ? buf2 : buf);
|
||||
if (buf2)
|
||||
free (buf2);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_print_infobar: print a message in infobar
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_print_infobar (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
int time_displayed, char *message, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
static char buf[1024];
|
||||
char *buf2;
|
||||
|
||||
va_start (argptr, message);
|
||||
vsnprintf (buf, sizeof (buf) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
buf2 = (script->charset && script->charset[0]) ?
|
||||
plugin->iconv_to_internal (plugin, script->charset, buf) : NULL;
|
||||
plugin->print_infobar (plugin, time_displayed, (buf2) ? buf2 : buf);
|
||||
if (buf2)
|
||||
free (buf2);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_log: add a message in buffer log file
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_log (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *server, char *channel, char *message, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
static char buf[1024];
|
||||
char *buf2;
|
||||
|
||||
va_start (argptr, message);
|
||||
vsnprintf (buf, sizeof (buf) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
buf2 = (script->charset && script->charset[0]) ?
|
||||
plugin->iconv_to_internal (plugin, script->charset, buf) : NULL;
|
||||
plugin->log (plugin, server, channel, (buf2) ? buf2 : buf);
|
||||
if (buf2)
|
||||
free (buf2);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_exec_command: execute a command (simulate user entry)
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_exec_command (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *server, char *channel, char *command)
|
||||
{
|
||||
char *command2;
|
||||
|
||||
command2 = (script->charset && script->charset[0]) ?
|
||||
plugin->iconv_to_internal (plugin, script->charset, command) : NULL;
|
||||
plugin->exec_command (plugin, server, channel,
|
||||
(command2) ? command2 : command);
|
||||
if (command2)
|
||||
free (command2);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_remove_handler: remove a handler for a script
|
||||
* for a msg handler, arg1=irc command, arg2=function
|
||||
@@ -494,3 +615,21 @@ weechat_script_set_plugin_config (t_weechat_plugin *plugin,
|
||||
|
||||
return return_code;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_set_charset: set charset for script
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_set_charset (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *charset)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) plugin;
|
||||
|
||||
if (script->charset)
|
||||
free (script->charset);
|
||||
|
||||
script->charset = (charset) ? strdup (charset) : NULL;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ struct t_plugin_script
|
||||
char *description; /* plugin description */
|
||||
char *version; /* plugin version */
|
||||
char *shutdown_func; /* function when script is unloaded */
|
||||
char *charset; /* script charset */
|
||||
|
||||
t_plugin_script *prev_script; /* link to previous script */
|
||||
t_plugin_script *next_script; /* link to next script */
|
||||
@@ -51,9 +52,24 @@ extern char *weechat_script_search_full_name (t_weechat_plugin *,
|
||||
char *, char *);
|
||||
extern t_plugin_script *weechat_script_add (t_weechat_plugin *,
|
||||
t_plugin_script **, char *, char *,
|
||||
char *, char *, char *);
|
||||
char *, char *, char *, char *);
|
||||
extern void weechat_script_remove (t_weechat_plugin *,
|
||||
t_plugin_script **, t_plugin_script *);
|
||||
extern void weechat_script_print (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *, char *, char *, ...);
|
||||
extern void weechat_script_print_server (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *, ...);
|
||||
extern void weechat_script_print_infobar (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
int, char *, ...);
|
||||
extern void weechat_script_log (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *, char *, char *, ...);
|
||||
extern void weechat_script_exec_command (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *, char *, char *);
|
||||
extern void weechat_script_remove_handler (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *, char *);
|
||||
@@ -72,5 +88,8 @@ extern char *weechat_script_get_plugin_config (t_weechat_plugin *,
|
||||
extern int weechat_script_set_plugin_config (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *, char *);
|
||||
extern void weechat_script_set_charset (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *);
|
||||
|
||||
#endif /* weechat-script.h */
|
||||
|
||||
Reference in New Issue
Block a user