diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2021-11-06 15:59:18 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2021-11-06 15:59:18 +0100 |
commit | 2da21725937cfa6ea5bee911175a0cc82f478cdf (patch) | |
tree | e610418233289b61bfffd7ebb7f88acdfad2cee7 /src | |
parent | 018a4bda53cd7abca7c13dc07422c40511626a4f (diff) | |
download | weechat-2da21725937cfa6ea5bee911175a0cc82f478cdf.zip |
api: add parameters pointers, extra_vars and options in function hdata_search
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-hdata.c | 97 | ||||
-rw-r--r-- | src/core/wee-hdata.h | 4 | ||||
-rw-r--r-- | src/plugins/guile/weechat-guile-api.c | 34 | ||||
-rw-r--r-- | src/plugins/javascript/weechat-js-api.cpp | 30 | ||||
-rw-r--r-- | src/plugins/lua/weechat-lua-api.c | 31 | ||||
-rw-r--r-- | src/plugins/perl/weechat-perl-api.c | 27 | ||||
-rw-r--r-- | src/plugins/php/weechat-php-api.c | 38 | ||||
-rw-r--r-- | src/plugins/python/weechat-python-api.c | 33 | ||||
-rw-r--r-- | src/plugins/python/weechat.pyi | 4 | ||||
-rw-r--r-- | src/plugins/ruby/weechat-ruby-api.c | 36 | ||||
-rw-r--r-- | src/plugins/tcl/weechat-tcl-api.c | 27 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 11 |
12 files changed, 291 insertions, 81 deletions
diff --git a/src/core/wee-hdata.c b/src/core/wee-hdata.c index d1b800473..8b8636196 100644 --- a/src/core/wee-hdata.c +++ b/src/core/wee-hdata.c @@ -37,11 +37,6 @@ struct t_hashtable *weechat_hdata = NULL; -/* hashtables used in hdata_search() for evaluating expression */ -struct t_hashtable *hdata_search_pointers = NULL; -struct t_hashtable *hdata_search_extra_vars = NULL; -struct t_hashtable *hdata_search_options = NULL; - char *hdata_type_string[9] = { "other", "char", "integer", "long", "string", "pointer", "time", "hashtable", "shared_string" }; @@ -587,72 +582,78 @@ hdata_move (struct t_hdata *hdata, void *pointer, int count) */ void * -hdata_search (struct t_hdata *hdata, void *pointer, const char *search, int move) +hdata_search (struct t_hdata *hdata, + void *pointer, + const char *search, + struct t_hashtable *pointers, + struct t_hashtable *extra_vars, + struct t_hashtable *options, + int move) { + struct t_hashtable *pointers2, *options2; char *result; + void *ret_pointer; int rc; if (!hdata || !pointer || !search || !search[0] || (move == 0)) return NULL; - /* clear or create hashtable with pointer for search */ - if (hdata_search_pointers) + ret_pointer = NULL; + + /* duplicate or create hashtable with pointers */ + if (pointers) { - hashtable_remove_all (hdata_search_pointers); + pointers2 = hashtable_dup (pointers); } else { - hdata_search_pointers = hashtable_new (32, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_POINTER, - NULL, - NULL); + pointers2 = hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER, + NULL, + NULL); } - /* - * create hashtable with extra vars (empty hashtable) - * (hashtable would be created in eval_expression(), but it's created here - * so it will not be created for each call to eval_expression()) - */ - if (!hdata_search_extra_vars) + /* duplicate or create hashtable with options */ + if (options) { - hdata_search_extra_vars = hashtable_new (32, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); + options2 = hashtable_dup (options); } - - if (!hdata_search_options) + else { - hdata_search_options = hashtable_new (32, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); - if (hdata_search_options) - hashtable_set (hdata_search_options, "type", "condition"); + options2 = hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER, + NULL, + NULL); } + if (options2) + hashtable_set (options2, "type", "condition"); while (pointer) { /* set pointer in hashtable (used for evaluating expression) */ - hashtable_set (hdata_search_pointers, hdata->name, pointer); + if (pointers2) + hashtable_set (pointers2, hdata->name, pointer); /* evaluate expression */ - result = eval_expression (search, hdata_search_pointers, - hdata_search_extra_vars, - hdata_search_options); + result = eval_expression (search, pointers2, extra_vars, options2); rc = eval_is_true (result); if (result) free (result); if (rc) - return pointer; + { + ret_pointer = pointer; + goto end; + } pointer = hdata_move (hdata, pointer, move); } - return NULL; +end: + hashtable_free (pointers2); + hashtable_free (options2); + return ret_pointer; } /* @@ -1399,20 +1400,4 @@ hdata_end () hdata_free_all (); hashtable_free (weechat_hdata); weechat_hdata = NULL; - - if (hdata_search_pointers) - { - hashtable_free (hdata_search_pointers); - hdata_search_pointers = NULL; - } - if (hdata_search_extra_vars) - { - hashtable_free (hdata_search_extra_vars); - hdata_search_extra_vars = NULL; - } - if (hdata_search_options) - { - hashtable_free (hdata_search_options); - hdata_search_options = NULL; - } } diff --git a/src/core/wee-hdata.h b/src/core/wee-hdata.h index 24eb6eb8a..c84e00562 100644 --- a/src/core/wee-hdata.h +++ b/src/core/wee-hdata.h @@ -111,7 +111,9 @@ extern int hdata_check_pointer (struct t_hdata *hdata, void *list, void *pointer); extern void *hdata_move (struct t_hdata *hdata, void *pointer, int count); extern void *hdata_search (struct t_hdata *hdata, void *pointer, - const char *search, int move); + const char *search, struct t_hashtable *pointers, + struct t_hashtable *extra_vars, + struct t_hashtable *options, int move); extern void hdata_get_index_and_name (const char *name, int *index, const char **ptr_name); extern char hdata_char (struct t_hdata *hdata, void *pointer, diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index 214f5cc2c..3bedb04d4 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -4667,21 +4667,49 @@ weechat_guile_api_hdata_move (SCM hdata, SCM pointer, SCM count) } SCM -weechat_guile_api_hdata_search (SCM hdata, SCM pointer, SCM search, SCM move) +weechat_guile_api_hdata_search (SCM hdata, SCM pointer, SCM search, + SCM pointers, SCM extra_vars, SCM options, + SCM move) { const char *result; SCM return_value; + struct t_hashtable *c_pointers, *c_extra_vars, *c_options; API_INIT_FUNC(1, "hdata_search", API_RETURN_EMPTY); if (!scm_is_string (hdata) || !scm_is_string (pointer) - || !scm_is_string (search) || !scm_is_integer (move)) + || !scm_is_string (search) || !scm_list_p (pointers) + || !scm_list_p (extra_vars) || !scm_list_p (options) + || !scm_is_integer (move)) API_WRONG_ARGS(API_RETURN_EMPTY); + c_pointers = weechat_guile_alist_to_hashtable (pointers, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER); + c_extra_vars = weechat_guile_alist_to_hashtable (extra_vars, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); + c_options = weechat_guile_alist_to_hashtable (options, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); + result = API_PTR2STR(weechat_hdata_search (API_STR2PTR(API_SCM_TO_STRING(hdata)), API_STR2PTR(API_SCM_TO_STRING(pointer)), API_SCM_TO_STRING(search), + c_pointers, + c_extra_vars, + c_options, scm_to_int (move))); + if (c_pointers) + weechat_hashtable_free (c_pointers); + if (c_extra_vars) + weechat_hashtable_free (c_extra_vars); + if (c_options) + weechat_hashtable_free (c_options); + API_RETURN_STRING(result); } @@ -5199,7 +5227,7 @@ weechat_guile_api_module_init (void *data) API_DEF_FUNC(hdata_get_list, 2); API_DEF_FUNC(hdata_check_pointer, 3); API_DEF_FUNC(hdata_move, 3); - API_DEF_FUNC(hdata_search, 4); + API_DEF_FUNC(hdata_search, 7); API_DEF_FUNC(hdata_char, 3); API_DEF_FUNC(hdata_integer, 3); API_DEF_FUNC(hdata_long, 3); diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp index f4f973a1f..d233cf380 100644 --- a/src/plugins/javascript/weechat-js-api.cpp +++ b/src/plugins/javascript/weechat-js-api.cpp @@ -4569,23 +4569,49 @@ API_FUNC(hdata_move) API_FUNC(hdata_search) { + struct t_hashtable *pointers, *extra_vars, *options; int move; const char *result; - API_INIT_FUNC(1, "hdata_search", "sssi", API_RETURN_EMPTY); + API_INIT_FUNC(1, "hdata_search", "ssshhhi", API_RETURN_EMPTY); v8::String::Utf8Value hdata(args[0]); v8::String::Utf8Value pointer(args[1]); v8::String::Utf8Value search(args[2]); - move = args[3]->IntegerValue(); + pointers = weechat_js_object_to_hashtable ( + args[3]->ToObject(), + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER); + extra_vars = weechat_js_object_to_hashtable ( + args[4]->ToObject(), + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); + options = weechat_js_object_to_hashtable ( + args[5]->ToObject(), + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); + move = args[6]->IntegerValue(); result = API_PTR2STR( weechat_hdata_search ( (struct t_hdata *)API_STR2PTR(*hdata), API_STR2PTR(*pointer), *search, + pointers, + extra_vars, + options, move)); + if (pointers) + weechat_hashtable_free (pointers); + if (extra_vars) + weechat_hashtable_free (extra_vars); + if (options) + weechat_hashtable_free (options); + API_RETURN_STRING(result); } diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index 1f3846735..bde9fbb78 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -4961,22 +4961,45 @@ API_FUNC(hdata_search) { const char *hdata, *pointer, *search; const char *result; + struct t_hashtable *pointers, *extra_vars, *options; int move; API_INIT_FUNC(1, "hdata_search", API_RETURN_EMPTY); - if (lua_gettop (L) < 4) + if (lua_gettop (L) < 7) API_WRONG_ARGS(API_RETURN_EMPTY); - hdata = lua_tostring (L, -4); - pointer = lua_tostring (L, -3); - search = lua_tostring (L, -2); + hdata = lua_tostring (L, -7); + pointer = lua_tostring (L, -6); + search = lua_tostring (L, -5); + pointers = weechat_lua_tohashtable (L, -4, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER); + extra_vars = weechat_lua_tohashtable (L, -3, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); + options = weechat_lua_tohashtable (L, -2, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); move = lua_tonumber (L, -1); result = API_PTR2STR(weechat_hdata_search (API_STR2PTR(hdata), API_STR2PTR(pointer), search, + pointers, + extra_vars, + options, move)); + if (pointers) + weechat_hashtable_free (pointers); + if (extra_vars) + weechat_hashtable_free (extra_vars); + if (options) + weechat_hashtable_free (options); + API_RETURN_STRING(result); } diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c index e47ea9010..5a76e204f 100644 --- a/src/plugins/perl/weechat-perl-api.c +++ b/src/plugins/perl/weechat-perl-api.c @@ -4894,23 +4894,46 @@ API_FUNC(hdata_search) { char *hdata, *pointer, *search; const char *result; + struct t_hashtable *pointers, *extra_vars, *options; int move; dXSARGS; API_INIT_FUNC(1, "hdata_search", API_RETURN_EMPTY); - if (items < 4) + if (items < 7) API_WRONG_ARGS(API_RETURN_EMPTY); hdata = SvPV_nolen (ST (0)); pointer = SvPV_nolen (ST (1)); search = SvPV_nolen (ST (2)); - move = SvIV(ST (3)); + pointers = weechat_perl_hash_to_hashtable (ST (3), + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER); + extra_vars = weechat_perl_hash_to_hashtable (ST (4), + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); + options = weechat_perl_hash_to_hashtable (ST (5), + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); + move = SvIV(ST (6)); result = API_PTR2STR(weechat_hdata_search (API_STR2PTR(hdata), API_STR2PTR(pointer), search, + pointers, + extra_vars, + options, move)); + if (pointers) + weechat_hashtable_free (pointers); + if (extra_vars) + weechat_hashtable_free (extra_vars); + if (options) + weechat_hashtable_free (options); + API_RETURN_STRING(result); } diff --git a/src/plugins/php/weechat-php-api.c b/src/plugins/php/weechat-php-api.c index 394b306e9..3267e3583 100644 --- a/src/plugins/php/weechat-php-api.c +++ b/src/plugins/php/weechat-php-api.c @@ -4975,25 +4975,57 @@ API_FUNC(hdata_move) API_FUNC(hdata_search) { zend_string *z_hdata, *z_pointer, *z_search; + zval *z_pointers, *z_extra_vars, *z_options; zend_long z_move; struct t_hdata *hdata; void *pointer; char *search; int move; const char *result; + struct t_hashtable *pointers, *extra_vars, *options; API_INIT_FUNC(1, "hdata_search", API_RETURN_EMPTY); - if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSSl", &z_hdata, &z_pointer, - &z_search, &z_move) == FAILURE) + if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSSaaal", &z_hdata, + &z_pointer, &z_search, &z_pointers, + &z_extra_vars, &z_options, &z_move) == FAILURE) API_WRONG_ARGS(API_RETURN_EMPTY); hdata = (struct t_hdata *)API_STR2PTR(ZSTR_VAL(z_hdata)); pointer = (void *)API_STR2PTR(ZSTR_VAL(z_pointer)); search = ZSTR_VAL(z_search); + pointers = weechat_php_array_to_hashtable ( + z_pointers, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER); + extra_vars = weechat_php_array_to_hashtable ( + z_extra_vars, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); + options = weechat_php_array_to_hashtable ( + z_options, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); move = (int)z_move; result = API_PTR2STR( - weechat_hdata_search (hdata, pointer, (const char *)search, move)); + weechat_hdata_search ( + hdata, + pointer, + (const char *)search, + pointers, + extra_vars, + options, + move)); + + if (pointers) + weechat_hashtable_free (pointers); + if (extra_vars) + weechat_hashtable_free (extra_vars); + if (options) + weechat_hashtable_free (options); API_RETURN_STRING(result); } diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c index c2e204fbb..d2c421663 100644 --- a/src/plugins/python/weechat-python-api.c +++ b/src/plugins/python/weechat-python-api.c @@ -4877,21 +4877,52 @@ API_FUNC(hdata_search) { char *hdata, *pointer, *search; const char *result; + struct t_hashtable *pointers, *extra_vars, *options; + PyObject *dict, *dict2, *dict3; int move; API_INIT_FUNC(1, "hdata_search", API_RETURN_EMPTY); hdata = NULL; pointer = NULL; search = NULL; + pointers = NULL; + extra_vars = NULL; + options = NULL; move = 0; - if (!PyArg_ParseTuple (args, "sssi", &hdata, &pointer, &search, &move)) + if (!PyArg_ParseTuple (args, "sssOOOi", &hdata, &pointer, &search, + &dict, &dict2, &dict3, &move)) + { API_WRONG_ARGS(API_RETURN_EMPTY); + } + + pointers = weechat_python_dict_to_hashtable (dict, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER); + extra_vars = weechat_python_dict_to_hashtable (dict2, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); + options = weechat_python_dict_to_hashtable (dict3, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); result = API_PTR2STR(weechat_hdata_search (API_STR2PTR(hdata), API_STR2PTR(pointer), search, + pointers, + extra_vars, + options, move)); + if (pointers) + weechat_hashtable_free (pointers); + if (extra_vars) + weechat_hashtable_free (extra_vars); + if (options) + weechat_hashtable_free (options); + API_RETURN_STRING(result); } diff --git a/src/plugins/python/weechat.pyi b/src/plugins/python/weechat.pyi index 1223f5f8e..5bfbc8c8b 100644 --- a/src/plugins/python/weechat.pyi +++ b/src/plugins/python/weechat.pyi @@ -973,7 +973,9 @@ def hdata_move(hdata: str, pointer: str, count: int) -> str: ... -def hdata_search(hdata: str, pointer: str, search: str, count: int) -> str: +def hdata_search(hdata: str, pointer: str, search: str, + pointers: Dict[str, str], extra_vars: Dict[str, str], options: Dict[str, str], + count: int) -> str: """`hdata_search in WeeChat plugin API reference <https://weechat.org/doc/api#_hdata_search>`_""" ... diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index dfd67d7f8..2d2c15cfd 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -5938,31 +5938,61 @@ weechat_ruby_api_hdata_move (VALUE class, VALUE hdata, VALUE pointer, static VALUE weechat_ruby_api_hdata_search (VALUE class, VALUE hdata, VALUE pointer, - VALUE search, VALUE move) + VALUE search, VALUE pointers, VALUE extra_vars, + VALUE options, VALUE move) { char *c_hdata, *c_pointer, *c_search; const char *result; + struct t_hashtable *c_pointers, *c_extra_vars, *c_options; int c_move; API_INIT_FUNC(1, "hdata_search", API_RETURN_EMPTY); - if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (search) || NIL_P (move)) + if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (search) || NIL_P (pointers) + || NIL_P (extra_vars) || NIL_P (options) || NIL_P (move)) + { API_WRONG_ARGS(API_RETURN_EMPTY); + } Check_Type (hdata, T_STRING); Check_Type (pointer, T_STRING); Check_Type (search, T_STRING); + Check_Type (pointers, T_HASH); + Check_Type (extra_vars, T_HASH); + Check_Type (options, T_HASH); CHECK_INTEGER(move); c_hdata = StringValuePtr (hdata); c_pointer = StringValuePtr (pointer); c_search = StringValuePtr (search); + c_pointers = weechat_ruby_hash_to_hashtable (pointers, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER); + c_extra_vars = weechat_ruby_hash_to_hashtable (extra_vars, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); + c_options = weechat_ruby_hash_to_hashtable (options, + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); c_move = NUM2INT (move); result = API_PTR2STR(weechat_hdata_search (API_STR2PTR(c_hdata), API_STR2PTR(c_pointer), c_search, + c_pointers, + c_extra_vars, + c_options, c_move)); + if (c_pointers) + weechat_hashtable_free (c_pointers); + if (c_extra_vars) + weechat_hashtable_free (c_extra_vars); + if (c_options) + weechat_hashtable_free (c_options); + API_RETURN_STRING(result); } @@ -6616,7 +6646,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) API_DEF_FUNC(hdata_get_list, 2); API_DEF_FUNC(hdata_check_pointer, 3); API_DEF_FUNC(hdata_move, 3); - API_DEF_FUNC(hdata_search, 4); + API_DEF_FUNC(hdata_search, 7); API_DEF_FUNC(hdata_char, 3); API_DEF_FUNC(hdata_integer, 3); API_DEF_FUNC(hdata_long, 3); diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c index 22aa9b258..0ac99bb37 100644 --- a/src/plugins/tcl/weechat-tcl-api.c +++ b/src/plugins/tcl/weechat-tcl-api.c @@ -5256,24 +5256,47 @@ API_FUNC(hdata_search) Tcl_Obj *objp; char *hdata, *pointer, *search; const char *result; + struct t_hashtable *pointers, *extra_vars, *options; int i, move; API_INIT_FUNC(1, "hdata_search", API_RETURN_EMPTY); - if (objc < 5) + if (objc < 8) API_WRONG_ARGS(API_RETURN_EMPTY); hdata = Tcl_GetStringFromObj (objv[1], &i); pointer = Tcl_GetStringFromObj (objv[2], &i); search = Tcl_GetStringFromObj (objv[3], &i); + pointers = weechat_tcl_dict_to_hashtable (interp, objv[4], + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER); + extra_vars = weechat_tcl_dict_to_hashtable (interp, objv[5], + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); + options = weechat_tcl_dict_to_hashtable (interp, objv[6], + WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING); - if (Tcl_GetIntFromObj (interp, objv[4], &move) != TCL_OK) + if (Tcl_GetIntFromObj (interp, objv[7], &move) != TCL_OK) API_WRONG_ARGS(API_RETURN_EMPTY); result = API_PTR2STR(weechat_hdata_search (API_STR2PTR(hdata), API_STR2PTR(pointer), search, + pointers, + extra_vars, + options, move)); + if (pointers) + weechat_hashtable_free (pointers); + if (extra_vars) + weechat_hashtable_free (extra_vars); + if (options) + weechat_hashtable_free (options); + API_RETURN_STRING(result); } diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 5802f2646..8b9a4bfa1 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -68,7 +68,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 "20210704-01" +#define WEECHAT_PLUGIN_API_VERSION "20211106-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -1119,7 +1119,10 @@ struct t_weechat_plugin void *pointer); void *(*hdata_move) (struct t_hdata *hdata, void *pointer, int count); void *(*hdata_search) (struct t_hdata *hdata, void *pointer, - const char *search, int move); + const char *search, struct t_hashtable *pointers, + struct t_hashtable *extra_vars, + struct t_hashtable *options, + int move); char (*hdata_char) (struct t_hdata *hdata, void *pointer, const char *name); int (*hdata_integer) (struct t_hdata *hdata, void *pointer, @@ -2112,8 +2115,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); (weechat_plugin->hdata_check_pointer)(__hdata, __list, __pointer) #define weechat_hdata_move(__hdata, __pointer, __count) \ (weechat_plugin->hdata_move)(__hdata, __pointer, __count) -#define weechat_hdata_search(__hdata, __pointer, __search, __move) \ +#define weechat_hdata_search(__hdata, __pointer, __search, __pointers, \ + __extra_vars, __options, __move) \ (weechat_plugin->hdata_search)(__hdata, __pointer, __search, \ + __pointers, __extra_vars, __options, \ __move) #define weechat_hdata_char(__hdata, __pointer, __name) \ (weechat_plugin->hdata_char)(__hdata, __pointer, __name) |