1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 14:56:39 +02:00

api: add function command_options (issue #928)

This commit is contained in:
Sébastien Helleu
2019-02-28 00:14:38 +01:00
parent 64043d5a6c
commit 80b980b2af
43 changed files with 693 additions and 165 deletions
+29
View File
@@ -4076,6 +4076,34 @@ weechat_guile_api_command (SCM buffer, SCM command)
API_RETURN_INT(rc);
}
SCM
weechat_guile_api_command_options (SCM buffer, SCM command, SCM options)
{
struct t_hashtable *c_options;
int rc;
API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
if (!scm_is_string (buffer) || !scm_is_string (command)
|| !scm_list_p (options))
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));
c_options = weechat_guile_alist_to_hashtable (options,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
rc = plugin_script_api_command_options (weechat_guile_plugin,
guile_current_script,
API_STR2PTR(API_SCM_TO_STRING(buffer)),
API_SCM_TO_STRING(command),
c_options);
if (c_options)
weechat_hashtable_free (c_options);
API_RETURN_INT(rc);
}
SCM
weechat_guile_api_info_get (SCM info_name, SCM arguments)
{
@@ -5016,6 +5044,7 @@ weechat_guile_api_module_init (void *data)
API_DEF_FUNC(bar_update, 1);
API_DEF_FUNC(bar_remove, 1);
API_DEF_FUNC(command, 2);
API_DEF_FUNC(command_options, 3);
API_DEF_FUNC(info_get, 2);
API_DEF_FUNC(info_get_hashtable, 2);
API_DEF_FUNC(infolist_new, 0);
+28
View File
@@ -3976,6 +3976,33 @@ API_FUNC(command)
API_RETURN_INT(rc);
}
API_FUNC(command_options)
{
struct t_hashtable *options;
int rc;
API_INIT_FUNC(1, "command_options", "ssh", API_RETURN_INT(WEECHAT_RC_ERROR));
v8::String::Utf8Value buffer(args[0]);
v8::String::Utf8Value command(args[1]);
options = weechat_js_object_to_hashtable (
args[2]->ToObject(),
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
rc = plugin_script_api_command_options (weechat_js_plugin,
js_current_script,
(struct t_gui_buffer *)API_STR2PTR(*buffer),
*command,
options);
if (options)
weechat_hashtable_free (options);
API_RETURN_INT(rc);
}
API_FUNC(info_get)
{
const char *result;
@@ -4967,6 +4994,7 @@ WeechatJsV8::loadLibs()
API_DEF_FUNC(bar_update);
API_DEF_FUNC(bar_remove);
API_DEF_FUNC(command);
API_DEF_FUNC(command_options);
API_DEF_FUNC(info_get);
API_DEF_FUNC(info_get_hashtable);
API_DEF_FUNC(infolist_new);
+30
View File
@@ -4312,6 +4312,35 @@ API_FUNC(command)
API_RETURN_INT(rc);
}
API_FUNC(command_options)
{
const char *buffer, *command;
struct t_hashtable *options;
int rc;
API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
if (lua_gettop (L) < 3)
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));
buffer = lua_tostring (L, -3);
command = lua_tostring (L, -2);
options = weechat_lua_tohashtable (L, -1,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
rc = plugin_script_api_command_options (weechat_lua_plugin,
lua_current_script,
API_STR2PTR(buffer),
command,
options);
if (options)
weechat_hashtable_free (options);
API_RETURN_INT(rc);
}
API_FUNC(info_get)
{
const char *info_name, *arguments, *result;
@@ -5318,6 +5347,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(bar_update),
API_DEF_FUNC(bar_remove),
API_DEF_FUNC(command),
API_DEF_FUNC(command_options),
API_DEF_FUNC(info_get),
API_DEF_FUNC(info_get_hashtable),
API_DEF_FUNC(infolist_new),
+30
View File
@@ -4233,6 +4233,35 @@ API_FUNC(command)
API_RETURN_INT(rc);
}
API_FUNC(command_options)
{
char *buffer, *command;
struct t_hashtable *options;
int rc;
dXSARGS;
API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
if (items < 3)
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));
buffer = SvPV_nolen (ST (0));
command = SvPV_nolen (ST (1));
options = weechat_perl_hash_to_hashtable (ST (2),
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
rc = plugin_script_api_command_options (weechat_perl_plugin,
perl_current_script,
API_STR2PTR(buffer),
command,
options);
if (options)
weechat_hashtable_free (options);
API_RETURN_INT(rc);
}
API_FUNC(info_get)
{
char *info_name, *arguments;
@@ -5277,6 +5306,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(bar_update);
API_DEF_FUNC(bar_remove);
API_DEF_FUNC(command);
API_DEF_FUNC(command_options);
API_DEF_FUNC(info_get);
API_DEF_FUNC(info_get_hashtable);
API_DEF_FUNC(infolist_new);
+34
View File
@@ -4144,6 +4144,40 @@ API_FUNC(command)
API_RETURN_INT(result);
}
API_FUNC(command_options)
{
zend_string *z_buffer, *z_command;
zval *z_options;
struct t_gui_buffer *buffer;
char *command;
struct t_hashtable *options;
int result;
API_INIT_FUNC(1, "command", API_RETURN_INT(WEECHAT_RC_ERROR));
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSa", &z_buffer,
&z_command, &z_options) == FAILURE)
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));
buffer = (struct t_gui_buffer *)API_STR2PTR(ZSTR_VAL(z_buffer));
command = ZSTR_VAL(z_command);
options = weechat_php_array_to_hashtable (
z_options,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
result = plugin_script_api_command_options (weechat_php_plugin,
php_current_script,
buffer,
(const char *)command,
options);
if (options)
weechat_hashtable_free (options);
API_RETURN_INT(result);
}
API_FUNC(info_get)
{
zend_string *z_info_name, *z_arguments;
+1
View File
@@ -197,6 +197,7 @@ PHP_FUNCTION(weechat_bar_set);
PHP_FUNCTION(weechat_bar_update);
PHP_FUNCTION(weechat_bar_remove);
PHP_FUNCTION(weechat_command);
PHP_FUNCTION(weechat_command_options);
PHP_FUNCTION(weechat_info_get);
PHP_FUNCTION(weechat_info_get_hashtable);
PHP_FUNCTION(weechat_infolist_new);
+1
View File
@@ -251,6 +251,7 @@ const zend_function_entry weechat_functions[] = {
PHP_FE(weechat_bar_update, NULL)
PHP_FE(weechat_bar_remove, NULL)
PHP_FE(weechat_command, NULL)
PHP_FE(weechat_command_options, NULL)
PHP_FE(weechat_info_get, NULL)
PHP_FE(weechat_info_get_hashtable, NULL)
PHP_FE(weechat_infolist_new, NULL)
+36 -4
View File
@@ -28,6 +28,7 @@
#include "../core/weechat.h"
#include "../core/wee-config.h"
#include "../core/wee-hashtable.h"
#include "../core/wee-hook.h"
#include "../core/wee-infolist.h"
#include "../core/wee-input.h"
@@ -294,19 +295,35 @@ plugin_api_color (const char *color_name)
}
/*
* Executes a command on a buffer (simulates user entry).
* Executes a command on a buffer (simulates user entry) with options.
*/
int
plugin_api_command (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer, const char *command)
plugin_api_command_options (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer, const char *command,
struct t_hashtable *options)
{
char *command2;
char *command2, **old_commands_allowed, **new_commands_allowed;
const char *ptr_commands;
int rc;
if (!plugin || !command)
return WEECHAT_RC_ERROR;
old_commands_allowed = input_commands_allowed;
new_commands_allowed = NULL;
if (options)
{
ptr_commands = hashtable_get (options, "commands");
if (ptr_commands)
{
new_commands_allowed = string_split (ptr_commands, ",", 0, 0,
NULL);
input_commands_allowed = new_commands_allowed;
}
}
command2 = string_iconv_to_internal (plugin->charset, command);
if (!buffer)
buffer = gui_current_window->buffer;
@@ -314,9 +331,24 @@ plugin_api_command (struct t_weechat_plugin *plugin,
if (command2)
free (command2);
if (new_commands_allowed)
string_free_split (new_commands_allowed);
input_commands_allowed = old_commands_allowed;
return rc;
}
/*
* Executes a command on a buffer (simulates user entry).
*/
int
plugin_api_command (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer, const char *command)
{
return plugin_api_command_options (plugin, buffer, command, NULL);
}
/*
* Modifier to decode ANSI colors.
*/
+4
View File
@@ -54,6 +54,10 @@ extern const char *plugin_api_prefix (const char *prefix);
extern const char *plugin_api_color (const char *color_name);
/* command */
extern int plugin_api_command_options (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer,
const char *command,
struct t_hashtable *options);
extern int plugin_api_command (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer,
const char *command);
+29 -12
View File
@@ -1278,6 +1278,33 @@ plugin_script_api_bar_item_new (struct t_weechat_plugin *weechat_plugin,
return new_item;
}
/*
* Executes a command on a buffer (simulates user entry) with options.
*/
int
plugin_script_api_command_options (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
const char *command,
struct t_hashtable *options)
{
char *command2;
int rc;
command2 = (script && script->charset && script->charset[0]) ?
weechat_iconv_to_internal (script->charset, command) : NULL;
rc = weechat_command_options (buffer,
(command2) ? command2 : command,
options);
if (command2)
free (command2);
return rc;
}
/*
* Executes a command on a buffer (simulates user entry).
*/
@@ -1287,18 +1314,8 @@ plugin_script_api_command (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer, const char *command)
{
char *command2;
int rc;
command2 = (script && script->charset && script->charset[0]) ?
weechat_iconv_to_internal (script->charset, command) : NULL;
rc = weechat_command (buffer, (command2) ? command2 : command);
if (command2)
free (command2);
return rc;
return plugin_script_api_command_options (weechat_plugin, script, buffer,
command, NULL);
}
/*
+5
View File
@@ -353,6 +353,11 @@ extern struct t_gui_bar_item *plugin_script_api_bar_item_new (struct t_weechat_p
struct t_hashtable *extra_info),
const char *function,
const char *data);
extern int plugin_script_api_command_options (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
const char *command,
struct t_hashtable *options);
extern int plugin_script_api_command (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
+1
View File
@@ -828,6 +828,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->bar_remove = &gui_bar_free;
new_plugin->command = &plugin_api_command;
new_plugin->command_options = &plugin_api_command_options;
new_plugin->network_pass_proxy = &network_pass_proxy;
new_plugin->network_connect_to = &network_connect_to;
+30
View File
@@ -4247,6 +4247,35 @@ API_FUNC(command)
API_RETURN_INT(rc);
}
API_FUNC(command_options)
{
char *buffer, *command;
struct t_hashtable *options;
int rc;
PyObject *dict;
API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
buffer = NULL;
command = NULL;
options = NULL;
if (!PyArg_ParseTuple (args, "ssO", &buffer, &command, &dict))
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));
options = weechat_python_dict_to_hashtable (dict,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
rc = plugin_script_api_command_options (weechat_python_plugin,
python_current_script,
API_STR2PTR(buffer),
command,
options);
if (options)
weechat_hashtable_free (options);
API_RETURN_INT(rc);
}
API_FUNC(info_get)
{
char *info_name, *arguments;
@@ -5227,6 +5256,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(bar_update),
API_DEF_FUNC(bar_remove),
API_DEF_FUNC(command),
API_DEF_FUNC(command_options),
API_DEF_FUNC(info_get),
API_DEF_FUNC(info_get_hashtable),
API_DEF_FUNC(infolist_new),
+36
View File
@@ -5118,6 +5118,41 @@ weechat_ruby_api_command (VALUE class, VALUE buffer, VALUE command)
API_RETURN_INT(rc);
}
static VALUE
weechat_ruby_api_command_options (VALUE class, VALUE buffer, VALUE command,
VALUE options)
{
char *c_buffer, *c_command;
struct t_hashtable *c_options;
int rc;
API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
if (NIL_P (buffer) || NIL_P (command) || NIL_P (options))
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));
Check_Type (buffer, T_STRING);
Check_Type (command, T_STRING);
Check_Type (options, T_HASH);
c_buffer = StringValuePtr (buffer);
c_command = StringValuePtr (command);
c_options = weechat_ruby_hash_to_hashtable (options,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
rc = plugin_script_api_command_options (weechat_ruby_plugin,
ruby_current_script,
API_STR2PTR(c_buffer),
c_command,
c_options);
if (c_options)
weechat_hashtable_free (c_options);
API_RETURN_INT(rc);
}
static VALUE
weechat_ruby_api_info_get (VALUE class, VALUE info_name, VALUE arguments)
{
@@ -6388,6 +6423,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
API_DEF_FUNC(bar_update, 1);
API_DEF_FUNC(bar_remove, 1);
API_DEF_FUNC(command, 2);
API_DEF_FUNC(command_options, 3);
API_DEF_FUNC(info_get, 2);
API_DEF_FUNC(info_get_hashtable, 2);
API_DEF_FUNC(infolist_new, 0);
+31
View File
@@ -4598,6 +4598,36 @@ API_FUNC(command)
API_RETURN_INT(rc);
}
API_FUNC(command_options)
{
Tcl_Obj *objp;
char *buffer, *command;
struct t_hashtable *options;
int i, rc;
API_INIT_FUNC(1, "command_options", API_RETURN_INT(WEECHAT_RC_ERROR));
if (objc < 4)
API_WRONG_ARGS(API_RETURN_INT(WEECHAT_RC_ERROR));
buffer = Tcl_GetStringFromObj (objv[1], &i);
command = Tcl_GetStringFromObj (objv[2], &i);
options = weechat_tcl_dict_to_hashtable (interp, objv[3],
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
rc = plugin_script_api_command_options (weechat_tcl_plugin,
tcl_current_script,
API_STR2PTR(buffer),
command,
options);
if (options)
weechat_hashtable_free (options);
API_RETURN_INT(rc);
}
API_FUNC(info_get)
{
Tcl_Obj *objp;
@@ -5753,6 +5783,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(bar_update);
API_DEF_FUNC(bar_remove);
API_DEF_FUNC(command);
API_DEF_FUNC(command_options);
API_DEF_FUNC(info_get);
API_DEF_FUNC(info_get_hashtable);
API_DEF_FUNC(infolist_new);
+7 -1
View File
@@ -67,7 +67,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
#define WEECHAT_PLUGIN_API_VERSION "20190226-01"
#define WEECHAT_PLUGIN_API_VERSION "20190228-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -985,6 +985,9 @@ struct t_weechat_plugin
/* command */
int (*command) (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer, const char *command);
int (*command_options) (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer, const char *command,
struct t_hashtable *options);
/* network */
int (*network_pass_proxy) (const char *proxy, int sock,
@@ -1899,6 +1902,9 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
/* command */
#define weechat_command(__buffer, __command) \
(weechat_plugin->command)(weechat_plugin, __buffer, __command)
#define weechat_command_options(__buffer, __command, __options) \
(weechat_plugin->command_options)(weechat_plugin, __buffer, \
__command, __options)
/* network */
#define weechat_network_pass_proxy(__proxy, __sock, __address, __port) \