mirror of
https://github.com/weechat/weechat.git
synced 2026-07-08 18:53:12 +02:00
Add function to get plugin name (return "core" for WeeChat core)
This commit is contained in:
@@ -443,15 +443,12 @@ charset_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
plugin_name = weechat_buffer_get_string (buffer, "plugin");
|
||||
name = weechat_buffer_get_string (buffer, "name");
|
||||
|
||||
length = ((plugin_name) ? strlen (plugin_name) : strlen ("core")) + 1 +
|
||||
strlen (name) + 1;
|
||||
length = strlen (plugin_name) + 1 + strlen (name) + 1;
|
||||
option_name = malloc (length);
|
||||
if (!option_name)
|
||||
return WEECHAT_RC_ERROR;
|
||||
|
||||
snprintf (option_name, length, "%s.%s",
|
||||
(plugin_name) ? plugin_name : "core",
|
||||
name);
|
||||
snprintf (option_name, length, "%s.%s", plugin_name, name);
|
||||
|
||||
if ((argc > 1) && (weechat_strcasecmp (argv[1], "reset") == 0))
|
||||
{
|
||||
|
||||
@@ -131,7 +131,7 @@ logger_get_filename (struct t_gui_buffer *buffer)
|
||||
{
|
||||
plugin_name = weechat_infolist_string (ptr_infolist, "plugin_name");
|
||||
plugin_name2 = (plugin_name) ?
|
||||
weechat_string_replace (plugin_name, dir_separator, "_") : strdup ("core");
|
||||
weechat_string_replace (plugin_name, dir_separator, "_") : NULL;
|
||||
name = weechat_infolist_string (ptr_infolist, "name");
|
||||
name2 = (name) ?
|
||||
weechat_string_replace (name, dir_separator, "_") : NULL;
|
||||
|
||||
@@ -84,15 +84,12 @@ notify_build_option_name (struct t_gui_buffer *buffer)
|
||||
plugin_name = weechat_buffer_get_string (buffer, "plugin");
|
||||
name = weechat_buffer_get_string (buffer, "name");
|
||||
|
||||
length = ((plugin_name) ? strlen (plugin_name) : strlen ("core")) + 1 +
|
||||
strlen (name) + 1;
|
||||
length = strlen (plugin_name) + 1 + strlen (name) + 1;
|
||||
option_name = malloc (length);
|
||||
if (!option_name)
|
||||
return NULL;
|
||||
|
||||
snprintf (option_name, length, "%s.%s",
|
||||
(plugin_name) ? plugin_name : "core",
|
||||
name);
|
||||
snprintf (option_name, length, "%s.%s", plugin_name, name);
|
||||
|
||||
return option_name;
|
||||
}
|
||||
|
||||
@@ -85,6 +85,18 @@ plugin_search (const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_get_name: get name of plugin with a pointer
|
||||
*/
|
||||
|
||||
char *
|
||||
plugin_get_name (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
static char *plugin_core = PLUGIN_CORE;
|
||||
|
||||
return (plugin) ? plugin->name : plugin_core;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_load: load a WeeChat plugin (a dynamic library)
|
||||
* return: pointer to new WeeChat plugin, NULL if error
|
||||
@@ -281,6 +293,8 @@ plugin_load (const char *filename)
|
||||
new_plugin->charset = (charset) ? strdup (charset) : NULL;
|
||||
|
||||
/* functions */
|
||||
new_plugin->plugin_get_name = &plugin_get_name;
|
||||
|
||||
new_plugin->charset_set = &plugin_api_charset_set;
|
||||
new_plugin->iconv_to_internal = &string_iconv_to_internal;
|
||||
new_plugin->iconv_from_internal = &string_iconv_from_internal;
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
#include "weechat-plugin.h"
|
||||
|
||||
#define PLUGIN_CORE "core"
|
||||
|
||||
typedef int (t_weechat_init_func) (struct t_weechat_plugin *plugin,
|
||||
int argc, char *argv[]);
|
||||
typedef int (t_weechat_end_func) (struct t_weechat_plugin *plugin);
|
||||
@@ -32,6 +34,7 @@ extern struct t_weechat_plugin *last_weechat_plugin;
|
||||
//extern t_plugin_irc_color plugins_irc_colors[GUI_NUM_IRC_COLORS];
|
||||
|
||||
extern struct t_weechat_plugin *plugin_search (const char *name);
|
||||
extern char *plugin_get_name (struct t_weechat_plugin *plugin);
|
||||
extern struct t_weechat_plugin *plugin_load (const char *filename);
|
||||
extern void plugin_auto_load ();
|
||||
extern void plugin_remove (struct t_weechat_plugin *plugin);
|
||||
|
||||
@@ -132,6 +132,44 @@ weechat_lua_api_register (lua_State *L)
|
||||
LUA_RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_plugin_get_name: get name of plugin (return "core" for
|
||||
* WeeChat core)
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_plugin_get_name (lua_State *L)
|
||||
{
|
||||
const char *plugin;
|
||||
char *result;
|
||||
int n;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("plugin_get_name");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
plugin = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 1)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("plugin_get_name");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
plugin = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
result = weechat_plugin_get_name (script_str2ptr (plugin));
|
||||
|
||||
LUA_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_charset_set: set script charset
|
||||
*/
|
||||
@@ -5554,6 +5592,7 @@ weechat_lua_api_constant_weechat_hook_signal_pointer (lua_State *L)
|
||||
|
||||
const struct luaL_reg weechat_lua_api_funcs[] = {
|
||||
{ "register", &weechat_lua_api_register },
|
||||
{ "plugin_get_name", &weechat_lua_api_plugin_get_name },
|
||||
{ "charset_set", &weechat_lua_api_charset_set },
|
||||
{ "iconv_to_internal", &weechat_lua_api_iconv_to_internal },
|
||||
{ "iconv_from_internal", &weechat_lua_api_iconv_from_internal },
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -115,6 +115,38 @@ weechat_python_api_register (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_plugin_get_name: get name of plugin (return "core" for
|
||||
* WeeChat core)
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_api_plugin_get_name (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *plugin, *result;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("plugin_get_name");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
plugin = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &plugin))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("plugin_get_name");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
result = weechat_plugin_get_name (script_str2ptr (plugin));
|
||||
|
||||
PYTHON_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_charset_set: set script charset
|
||||
*/
|
||||
@@ -4588,6 +4620,7 @@ weechat_python_api_infolist_free (PyObject *self, PyObject *args)
|
||||
PyMethodDef weechat_python_funcs[] =
|
||||
{
|
||||
{ "register", &weechat_python_api_register, METH_VARARGS, "" },
|
||||
{ "plugin_get_name", &weechat_python_api_plugin_get_name, METH_VARARGS, "" },
|
||||
{ "charset_set", &weechat_python_api_charset_set, METH_VARARGS, "" },
|
||||
{ "iconv_to_internal", &weechat_python_api_iconv_to_internal, METH_VARARGS, "" },
|
||||
{ "iconv_from_internal", &weechat_python_api_iconv_from_internal, METH_VARARGS, "" },
|
||||
|
||||
@@ -133,6 +133,42 @@ weechat_ruby_api_register (VALUE class, VALUE name, VALUE author,
|
||||
RUBY_RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_plugin_get_name: get name of plugin (return "core" for
|
||||
* WeeChat core)
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_plugin_get_name (VALUE class, VALUE plugin)
|
||||
{
|
||||
char *c_plugin, *result;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("plugin_get_name");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
c_plugin = NULL;
|
||||
|
||||
if (NIL_P (plugin))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("plugin_get_name");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
Check_Type (plugin, T_STRING);
|
||||
|
||||
c_plugin = STR2CSTR (plugin);
|
||||
|
||||
result = weechat_plugin_get_name (script_str2ptr (c_plugin));
|
||||
|
||||
RUBY_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_charset_set: set script charset
|
||||
*/
|
||||
@@ -5294,6 +5330,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
rb_define_const(ruby_mWeechat, "WEECHAT_HOOK_SIGNAL_POINTER", rb_str_new2(WEECHAT_HOOK_SIGNAL_POINTER));
|
||||
|
||||
rb_define_module_function (ruby_mWeechat, "register", &weechat_ruby_api_register, 7);
|
||||
rb_define_module_function (ruby_mWeechat, "plugin_get_name", &weechat_ruby_api_plugin_get_name, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "charset_set", &weechat_ruby_api_charset_set, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "iconv_to_internal", &weechat_ruby_api_iconv_to_internal, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "iconv_from_internal", &weechat_ruby_api_iconv_from_internal, 2);
|
||||
|
||||
@@ -219,6 +219,40 @@ weechat_tcl_api_register (ClientData clientData, Tcl_Interp *interp, int objc,
|
||||
TCL_RETURN_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::plugin_get_name: get name of plugin (return "core" for WeeChat core)
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_tcl_api_plugin_get_name (ClientData clientData, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj* objp;
|
||||
char *result, *plugin;
|
||||
int i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) clientData;
|
||||
|
||||
if (!tcl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("plugin_get_name");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (objc < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("plugin_get_name");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
plugin = Tcl_GetStringFromObj (objv[1], &i);
|
||||
|
||||
result = weechat_plugin_get_name (script_str2ptr (plugin));
|
||||
|
||||
TCL_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::charset_set: set script charset
|
||||
*/
|
||||
@@ -4951,6 +4985,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) {
|
||||
/* interface functions */
|
||||
Tcl_CreateObjCommand (interp,"weechat::register",
|
||||
weechat_tcl_api_register, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp,"weechat::plugin_get_name",
|
||||
weechat_tcl_api_plugin_get_name, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp,"weechat::charset_set",
|
||||
weechat_tcl_api_charset_set, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp,"weechat::iconv_to_internal",
|
||||
|
||||
@@ -119,6 +119,9 @@ struct t_weechat_plugin
|
||||
at the END of functions, for keeping backward compatibility with
|
||||
existing plugins */
|
||||
|
||||
/* plugins */
|
||||
char *(*plugin_get_name) (struct t_weechat_plugin *plugin);
|
||||
|
||||
/* strings */
|
||||
void (*charset_set) (struct t_weechat_plugin *plugin, const char *charset);
|
||||
char *(*iconv_to_internal) (const char *charset, const char *string);
|
||||
@@ -552,6 +555,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
|
||||
|
||||
/* macros for easy call to plugin API */
|
||||
|
||||
/* plugins */
|
||||
#define weechat_plugin_get_name(__plugin) \
|
||||
weechat_plugin->plugin_get_name(__plugin)
|
||||
|
||||
/* strings */
|
||||
#define weechat_charset_set(__charset) \
|
||||
weechat_plugin->charset_set(weechat_plugin, __charset)
|
||||
|
||||
Reference in New Issue
Block a user