summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.adoc1
-rw-r--r--ReleaseNotes.adoc25
-rw-r--r--doc/en/weechat_plugin_api.en.adoc34
-rw-r--r--doc/fr/weechat_plugin_api.fr.adoc36
-rw-r--r--doc/it/weechat_plugin_api.it.adoc39
-rw-r--r--doc/ja/weechat_plugin_api.ja.adoc35
-rw-r--r--doc/sr/weechat_plugin_api.sr.adoc32
-rw-r--r--src/core/wee-hdata.c97
-rw-r--r--src/core/wee-hdata.h4
-rw-r--r--src/plugins/guile/weechat-guile-api.c34
-rw-r--r--src/plugins/javascript/weechat-js-api.cpp30
-rw-r--r--src/plugins/lua/weechat-lua-api.c31
-rw-r--r--src/plugins/perl/weechat-perl-api.c27
-rw-r--r--src/plugins/php/weechat-php-api.c38
-rw-r--r--src/plugins/python/weechat-python-api.c33
-rw-r--r--src/plugins/python/weechat.pyi4
-rw-r--r--src/plugins/ruby/weechat-ruby-api.c36
-rw-r--r--src/plugins/tcl/weechat-tcl-api.c27
-rw-r--r--src/plugins/weechat-plugin.h11
-rw-r--r--tests/scripts/test-scripts.cpp2
-rw-r--r--tests/unit/core/test-core-hdata.cpp363
21 files changed, 722 insertions, 217 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index 96cab16e8..c648a800c 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -22,6 +22,7 @@ New features::
* core: add support of static arrays in hdata
* core: add command /toggle
+ * api: add parameters pointers, extra_vars and options in function hdata_search
* api: add user variables in evaluation of expressions with "define:name,value"
* api: add IRC message parameters "param1" to "paramN" and "num_params" in output of irc_message_parse
* irc: allow quotes around IRC message in command /server fakerecv
diff --git a/ReleaseNotes.adoc b/ReleaseNotes.adoc
index e98ac3e13..c83ef58ba 100644
--- a/ReleaseNotes.adoc
+++ b/ReleaseNotes.adoc
@@ -20,6 +20,31 @@ https://weechat.org/files/changelog/ChangeLog-devel.html[ChangeLog]
[[v3.4]]
== Version 3.4 (under dev)
+[[v3.4_hdata_search]]
+=== New parameters in function hdata_search
+
+New parameters have been added in function
+link:weechat_plugin_api.en.html#_hdata_search[hdata_search], used for the
+evaluation of expression.
+
+New parameters are the same as function
+link:weechat_plugin_api.en.html#_string_eval_expression[string_eval_expression]:
+
+* pointers: hashtable with pointers (pointers)
+* extra_vars: hashtable with extra variables (strings)
+* options: hashtable with options (strings).
+
+The following scripts are updated consequently to be compatible with all
+WeeChat versions:
+
+* https://weechat.org/scripts/source/autoauth.py/[autoauth.py] 1.3
+* https://weechat.org/scripts/source/buffer_open.py/[buffer_open.py] 0.3
+* https://weechat.org/scripts/source/collapse_channel.py/[collapse_channel.py] 0.9
+* https://weechat.org/scripts/source/grep_filter.py/[grep_filter.py] 0.11
+* https://weechat.org/scripts/source/samechannel.rb/[samechannel.rb] 0.2
+* https://weechat.org/scripts/source/soju.py/[soju.py] 0.1.4
+* https://weechat.org/scripts/source/stalker.pl/[stalker.pl] 1.6.3
+
[[v3.4_hdata_arrays]]
=== Static array support in hdata
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc
index d6ff39a3c..ea953ffd7 100644
--- a/doc/en/weechat_plugin_api.en.adoc
+++ b/doc/en/weechat_plugin_api.en.adoc
@@ -17135,7 +17135,7 @@ if buffer:
==== hdata_search
-_WeeChat ≥ 0.4.1._
+_WeeChat ≥ 0.4.1, updated in 3.4._
Search element in a list: the expression _search_ is evaluated for each element
in list, until element is found (or end of list).
@@ -17144,7 +17144,9 @@ Prototype:
[source,C]
----
-void *weechat_hdata_search (struct t_hdata *hdata, void *pointer, const char *search, int move);
+void *weechat_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);
----
Arguments:
@@ -17155,9 +17157,20 @@ Arguments:
hdata (and this pointer changes for each element in list); for help on
expression, see the
link:weechat_user.en.html#command_weechat_eval[WeeChat user's guide / Command /eval]
+* _pointers_: hashtable for call to function
+ <<_string_eval_expression,string_eval_expression>>
+* _extra_vars_: hashtable for call to function
+ <<_string_eval_expression,string_eval_expression>>
+* _options_: hashtable for call to function
+ <<_string_eval_expression,string_eval_expression>>
* _move_: number of jump(s) to execute after unsuccessful search (negative or
positive integer, different from 0)
+[IMPORTANT]
+You must ensure the _search_ expression is safe and does not include any
+user data. Such unsafe data must be given in the hashtable _extra_vars_ and
+referenced by `${xxx}` in the _search_ expression (see the example below).
+
Return value:
* pointer to element found, NULL if not found
@@ -17168,13 +17181,21 @@ C example:
----
struct t_hdata *hdata = weechat_hdata_get ("irc_server");
void *servers = weechat_hdata_get_list (hdata, "irc_servers");
+struct t_hashtable *extra_vars = weechat_hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
/* search irc server with name "libera" */
-void *server = weechat_hdata_search (hdata, servers, "${irc_server.name} == libera", 1);
+weechat_hashtable_set (extra_vars, "name", "libera");
+void *server = weechat_hdata_search (hdata, servers, "${irc_server.name} == ${name}",
+ NULL, extra_vars, NULL, 1);
if (server)
{
/* ... */
}
+weechat_hashtable_free (extra_vars);
----
Script (Python):
@@ -17182,14 +17203,17 @@ Script (Python):
[source,python]
----
# prototype
-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: ...
# example
hdata = weechat.hdata_get("irc_server")
servers = weechat.hdata_get_list(hdata, "irc_servers")
# search irc server with name "libera"
-server = weechat.hdata_search(hdata, servers, "${irc_server.name} == libera", 1)
+server = weechat.hdata_search(hdata, servers, "${irc_server.name} == ${name}",
+ {}, {"name": "libera"}, {}, 1)
if server:
# ...
----
diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc
index 60e3c58f0..b263fdb68 100644
--- a/doc/fr/weechat_plugin_api.fr.adoc
+++ b/doc/fr/weechat_plugin_api.fr.adoc
@@ -17488,7 +17488,7 @@ if buffer:
==== hdata_search
-_WeeChat ≥ 0.4.1._
+_WeeChat ≥ 0.4.1, mis à jour dans la 3.4._
Chercher un élément dans la liste : l'expression _search_ est évaluée pour
chaque élément dans la liste, jusqu'à trouver l'élément (ou la fin de la liste).
@@ -17497,7 +17497,9 @@ Prototype :
[source,C]
----
-void *weechat_hdata_search (struct t_hdata *hdata, void *pointer, const char *search, int move);
+void *weechat_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);
----
Paramètres :
@@ -17508,9 +17510,22 @@ Paramètres :
le nom du hdata (et ce pointeur change pour chaque élément dans la liste);
pour l'aide sur l'expression, voir le
link:weechat_user.fr.html#command_weechat_eval[Guide utilisateur WeeChat / Commande /eval]
+* _pointers_ : table de hachage pour l'appel à la fonction
+ <<_string_eval_expression,string_eval_expression>>
+* _extra_vars_ : table de hachage pour l'appel à la fonction
+ <<_string_eval_expression,string_eval_expression>>
+* _options_ : table de hachage pour l'appel à la fonction
+ <<_string_eval_expression,string_eval_expression>>
* _move_ : nombre de saut(s) à exécuter après une recherche infructueuse (entier
négatif ou positif, différent de 0)
+// TRANSLATION MISSING
+[IMPORTANT]
+Vous devez vous assurer que l'expression _search_ est sûre et ne contient
+aucune donnée utilisateur. De telles données non sûres doivent être données
+dans la table de hachage _extra_vars_ et être référencées par `${xxx}` dans
+l'expression _search_ (voir l'exemple ci-dessous).
+
Valeur de retour :
* pointeur vers l'élément trouvé, ou NULL si non trouvé
@@ -17521,13 +17536,21 @@ Exemple en C :
----
struct t_hdata *hdata = weechat_hdata_get ("irc_server");
void *servers = weechat_hdata_get_list (hdata, "irc_servers");
+struct t_hashtable *extra_vars = weechat_hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
/* cherche un serveur irc avec le nom "libera" */
-void *server = weechat_hdata_search (hdata, servers, "${irc_server.name} == libera", 1);
+weechat_hashtable_set (extra_vars, "name", "libera");
+void *server = weechat_hdata_search (hdata, servers, "${irc_server.name} == ${name}",
+ NULL, extra_vars, NULL, 1);
if (server)
{
/* ... */
}
+weechat_hashtable_free (extra_vars);
----
Script (Python) :
@@ -17535,14 +17558,17 @@ Script (Python) :
[source,python]
----
# prototype
-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: ...
# exemple
hdata = weechat.hdata_get("irc_server")
servers = weechat.hdata_get_list(hdata, "irc_servers")
# cherche un serveur irc avec le nom "libera"
-server = weechat.hdata_search(hdata, servers, "${irc_server.name} == libera", 1)
+server = weechat.hdata_search(hdata, servers, "${irc_server.name} == ${name}",
+ {}, {"name": "libera"}, {}, 1)
if server:
# ...
----
diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc
index a2273eac5..b1e224b42 100644
--- a/doc/it/weechat_plugin_api.it.adoc
+++ b/doc/it/weechat_plugin_api.it.adoc
@@ -17822,7 +17822,8 @@ if buffer:
==== hdata_search
-_WeeChat ≥ 0.4.1._
+// TRANSLATION MISSING
+_WeeChat ≥ 0.4.1, updated in 3.4._
// TRANSLATION MISSING
Search element in a list: the expression _search_ is evaluated for each element
@@ -17832,7 +17833,9 @@ Prototipo:
[source,C]
----
-void *weechat_hdata_search (struct t_hdata *hdata, void *pointer, const char *search, int move);
+void *weechat_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);
----
Argomenti:
@@ -17845,9 +17848,24 @@ Argomenti:
expression, see the
link:weechat_user.it.html#command_weechat_eval[WeeChat user's guide / Command /eval]
// TRANSLATION MISSING
+* _pointers_: hashtable for call to function
+ <<_string_eval_expression,string_eval_expression>>
+// TRANSLATION MISSING
+* _extra_vars_: hashtable for call to function
+ <<_string_eval_expression,string_eval_expression>>
+// TRANSLATION MISSING
+* _options_: hashtable for call to function
+ <<_string_eval_expression,string_eval_expression>>
+// TRANSLATION MISSING
* _move_: number of jump(s) to execute after unsuccessful search (negative or
positive integer, different from 0)
+// TRANSLATION MISSING
+[IMPORTANT]
+You must ensure the _search_ expression is safe and does not include any
+user data. Such unsafe data must be given in the hashtable _extra_vars_ and
+referenced by `${xxx}` in the _search_ expression (see the example below).
+
Valore restituito:
// TRANSLATION MISSING
@@ -17859,13 +17877,21 @@ Esempio in C:
----
struct t_hdata *hdata = weechat_hdata_get ("irc_server");
void *servers = weechat_hdata_get_list (hdata, "irc_servers");
+struct t_hashtable *extra_vars = weechat_hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
/* search irc server with name "libera" */
-void *server = weechat_hdata_search (hdata, servers, "${irc_server.name} == libera", 1);
+weechat_hashtable_set (extra_vars, "name", "libera");
+void *server = weechat_hdata_search (hdata, servers, "${irc_server.name} == ${name}",
+ NULL, extra_vars, NULL, 1);
if (server)
{
/* ... */
}
+weechat_hashtable_free (extra_vars);
----
Script (Python):
@@ -17874,14 +17900,17 @@ Script (Python):
[source,python]
----
# prototipo
-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: ...
# esempio
hdata = weechat.hdata_get("irc_server")
servers = weechat.hdata_get_list(hdata, "irc_servers")
# search irc server with name "libera"
-server = weechat.hdata_search(hdata, servers, "${irc_server.name} == libera", 1)
+server = weechat.hdata_search(hdata, servers, "${irc_server.name} == ${name}",
+ {}, {"name": "libera"}, {}, 1)
if server:
# ...
----
diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc
index d50b93dcc..fd133b95c 100644
--- a/doc/ja/weechat_plugin_api.ja.adoc
+++ b/doc/ja/weechat_plugin_api.ja.adoc
@@ -17199,7 +17199,7 @@ if buffer:
==== hdata_search
-_WeeChat バージョン 0.4.1 以上で利用可。_
+_WeeChat バージョン 0.4.1 以上で利用可、バージョン 3.4 で更新。_
リストから要素を検索: リスト内の各要素に対して _search_
の内容を評価し、マッチする要素が見つかるかリストの最後に到達するまでこれを続ける。
@@ -17208,7 +17208,9 @@ _WeeChat バージョン 0.4.1 以上で利用可。_
[source,C]
----
-void *weechat_hdata_search (struct t_hdata *hdata, void *pointer, const char *search, int move);
+void *weechat_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);
----
引数:
@@ -17218,9 +17220,21 @@ void *weechat_hdata_search (struct t_hdata *hdata, void *pointer, const char *se
* _search_: 評価する式、式中のデフォルトポインタは hdata の名前
(デフォルトポインタはリストに含まれる各要素で置換されます); 式に関する詳細は
link:weechat_user.ja.html#command_weechat_eval[WeeChat ユーザーズガイド / WeeChat コマンド / eval] を参照してください
+* _pointers_: 関数に渡されるハッシュテーブル
+ <<_string_eval_expression,string_eval_expression>>
+* _extra_vars_: 関数に渡されるハッシュテーブル
+ <<_string_eval_expression,string_eval_expression>>
+* _options_: 関数に渡されるハッシュテーブル
+ <<_string_eval_expression,string_eval_expression>>
* _move_: 検索に失敗した後に移動を実行する回数
(負および正の整数、ゼロは禁止)
+// TRANSLATION MISSING
+[IMPORTANT]
+You must ensure the _search_ expression is safe and does not include any
+user data. Such unsafe data must be given in the hashtable _extra_vars_ and
+referenced by `${xxx}` in the _search_ expression (see the example below).
+
戻り値:
* 見つかった要素へのポインタ、見つからなかった場合は NULL
@@ -17231,13 +17245,21 @@ C 言語での使用例:
----
struct t_hdata *hdata = weechat_hdata_get ("irc_server");
void *servers = weechat_hdata_get_list (hdata, "irc_servers");
+struct t_hashtable *extra_vars = weechat_hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
/* search irc server with name "libera" */
-void *server = weechat_hdata_search (hdata, servers, "${irc_server.name} == libera", 1);
+weechat_hashtable_set (extra_vars, "name", "libera");
+void *server = weechat_hdata_search (hdata, servers, "${irc_server.name} == ${name}",
+ NULL, extra_vars, NULL, 1);
if (server)
{
/* ... */
}
+weechat_hashtable_free (extra_vars);
----
スクリプト (Python) での使用例:
@@ -17245,14 +17267,17 @@ if (server)
[source,python]
----
# プロトタイプ
-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 = weechat.hdata_get("irc_server")
servers = weechat.hdata_get_list(hdata, "irc_servers")
# search irc server with name "libera"
-server = weechat.hdata_search(hdata, servers, "${irc_server.name} == libera", 1)
+server = weechat.hdata_search(hdata, servers, "${irc_server.name} == ${name}",
+ {}, {"name": "libera"}, {}, 1)
if server:
# ...
----
diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc
index 85b5ceba2..e430584ce 100644
--- a/doc/sr/weechat_plugin_api.sr.adoc
+++ b/doc/sr/weechat_plugin_api.sr.adoc
@@ -16575,7 +16575,7 @@ if buffer:
==== hdata_search
-_WeeChat ≥ 0.4.1._
+_WeeChat ≥ 0.4.1, ажурирано у верзији 3.4._
Тражи елемент у листи: израз _search_ се тражи за сваки елемент у листи, све док се елемент не пронађе (или наиђе на крај листе).
@@ -16583,7 +16583,9 @@ _WeeChat ≥ 0.4.1._
[source, C]
----
-void *weechat_hdata_search (struct t_hdata *hdata, void *pointer, const char *search, int move);
+void *weechat_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);
----
Аргументи:
@@ -16591,8 +16593,17 @@ void *weechat_hdata_search (struct t_hdata *hdata, void *pointer, const char *se
* _hdata_: показивач на hdata
* _pointer_: показивач на објекат програма WeeChat/додатка
* _search_: израз који се израчунава, подразумевани показивач у изразу је име hdata (и овај показивач се мења за сваки елемент у листи); за помоћ у вези израза, погледајте link:weechat_user.sr.html#command_weechat_eval[WeeChat корисничко упутство / Команда /eval]
+* _pointers_: хеш табела за позив функције <<_string_eval_expression,string_eval_expression>>
+* _extra_vars_: хеш табела за позив функције <<_string_eval_expression,string_eval_expression>>
+* _options_: хеш табела за позив функције <<_string_eval_expression,string_eval_expression>>
* _move_: број скок(а/ова) који треба да се изврши након неуспешне претраге (негативни или позитивни цео број, различит од 0)
+// TRANSLATION MISSING
+[IMPORTANT]
+You must ensure the _search_ expression is safe and does not include any
+user data. Such unsafe data must be given in the hashtable _extra_vars_ and
+referenced by `${xxx}` in the _search_ expression (see the example below).
+
Повратна вредност:
* показивач на пронађени елемент, NULL у случају да се не пронађе
@@ -16603,13 +16614,21 @@ C пример:
----
struct t_hdata *hdata = weechat_hdata_get ("irc_server");
void *servers = weechat_hdata_get_list (hdata, "irc_servers");
+struct t_hashtable *extra_vars = weechat_hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
/* тражи irc сервер под именом „libera” */
-void *server = weechat_hdata_search (hdata, servers, "${irc_server.name} == libera", 1);
+weechat_hashtable_set (extra_vars, "name", "libera");
+void *server = weechat_hdata_search (hdata, servers, "${irc_server.name} == ${name}",
+ NULL, extra_vars, NULL, 1);
if (server)
{
/* ... */
}
+weechat_hashtable_free (extra_vars);
----
Скрипта (Python):
@@ -16617,14 +16636,17 @@ if (server)
[source, python]
----
# прототип
-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 = weechat.hdata_get("irc_server")
servers = weechat.hdata_get_list(hdata, "irc_servers")
# тражи irc сервер под именом „libera”
-server = weechat.hdata_search(hdata, servers, "${irc_server.name} == libera", 1)
+server = weechat.hdata_search(hdata, servers, "${irc_server.name} == ${name}",
+ {}, {"name": "libera"}, {}, 1)
if server:
# ...
----
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)
diff --git a/tests/scripts/test-scripts.cpp b/tests/scripts/test-scripts.cpp
index 604961c0f..cde0ae865 100644
--- a/tests/scripts/test-scripts.cpp
+++ b/tests/scripts/test-scripts.cpp
@@ -198,7 +198,7 @@ TEST(Scripts, API)
snprintf (str_condition, sizeof (str_condition),
"${plugin.name} == %s",
languages[i][0]);
- if (!hdata_search (hdata, plugins, str_condition, 1))
+ if (!hdata_search (hdata, plugins, str_condition, NULL, NULL, NULL, 1))
continue;
/*
diff --git a/tests/unit/core/test-core-hdata.cpp b/tests/unit/core/test-core-hdata.cpp
index 815434dd4..d6e76b7fb 100644
--- a/tests/unit/core/test-core-hdata.cpp
+++ b/tests/unit/core/test-core-hdata.cpp
@@ -1299,145 +1299,288 @@ TEST(CoreHdataWithList, Move)
TEST(CoreHdataWithList, Search)
{
- POINTERS_EQUAL(NULL, hdata_search (NULL, NULL, NULL, 0));
- POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, NULL, NULL, 0));
- POINTERS_EQUAL(NULL, hdata_search (NULL, items, NULL, 0));
- POINTERS_EQUAL(NULL, hdata_search (NULL, NULL, "${test_char} == A", 0));
- POINTERS_EQUAL(NULL, hdata_search (NULL, NULL, NULL, 1));
- POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, items, NULL, 0));
- POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, NULL, "${test_char} == A", 0));
- POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, NULL, NULL, 1));
- POINTERS_EQUAL(NULL, hdata_search (NULL, items, "${test_char} == A", 0));
- POINTERS_EQUAL(NULL, hdata_search (NULL, items, NULL, 1));
- POINTERS_EQUAL(NULL, hdata_search (NULL, NULL, "${test_char} == A", 1));
- POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, items, "${test_char} == A", 0));
- POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, items, NULL, 1));
- POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, NULL, "${test_char} == A", 1));
- POINTERS_EQUAL(NULL, hdata_search (NULL, items, "${test_char} == A", 1));
+ struct t_hashtable *pointers, *extra_vars;
+
+ pointers = hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_POINTER,
+ NULL,
+ NULL);
+
+ extra_vars = hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
+
+ POINTERS_EQUAL(NULL, hdata_search (NULL, NULL, NULL,
+ NULL, NULL, NULL, 0));
+ POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, NULL, NULL,
+ NULL, NULL, NULL, 0));
+ POINTERS_EQUAL(NULL, hdata_search (NULL, items, NULL,
+ NULL, NULL, NULL, 0));
+ POINTERS_EQUAL(NULL, hdata_search (NULL, NULL, "${test_char} == A",
+ NULL, NULL, NULL, 0));
+ POINTERS_EQUAL(NULL, hdata_search (NULL, NULL, NULL,
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, items, NULL,
+ NULL, NULL, NULL, 0));
+ POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, NULL, "${test_char} == A",
+ NULL, NULL, NULL, 0));
+ POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, NULL, NULL, NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(NULL, hdata_search (NULL, items, "${test_char} == A",
+ NULL, NULL, NULL, 0));
+ POINTERS_EQUAL(NULL, hdata_search (NULL, items, NULL, NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(NULL, hdata_search (NULL, NULL, "${test_char} == A",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, items, "${test_char} == A",
+ NULL, NULL, NULL, 0));
+ POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, items, NULL,
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(NULL, hdata_search (ptr_hdata, NULL, "${test_char} == A",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(NULL, hdata_search (NULL, items, "${test_char} == A",
+ NULL, NULL, NULL, 1));
/* search char */
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_char} == Z", 1));
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_char} == X", 2));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, items,
- "${test_item.test_char} == A", 1));
- POINTERS_EQUAL(ptr_item2,
- hdata_search (ptr_hdata, items,
- "${test_item.test_char} == a", 1));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, last_item,
- "${test_item.test_char} == A", -1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_char} == Z",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_char} == X",
+ NULL, NULL, NULL, 2));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_char} == A",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_char} == a",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, last_item,
+ "${test_item.test_char} == A",
+ NULL, NULL, NULL, -1));
+ hashtable_set (extra_vars, "value", "a");
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_char} == ${value}",
+ NULL, extra_vars, NULL, 1));
/* search integer */
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_int} == 999", 1));
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_int} == 456", 2));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, items,
- "${test_item.test_int} == 123", 1));
- POINTERS_EQUAL(ptr_item2,
- hdata_search (ptr_hdata, items,
- "${test_item.test_int} == 456", 1));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, last_item,
- "${test_item.test_int} == 123", -1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_int} == 999",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_int} == 456",
+ NULL, NULL, NULL, 2));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_int} == 123",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_int} == 456",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, last_item,
+ "${test_item.test_int} == 123",
+ NULL, NULL, NULL, -1));
+ hashtable_set (extra_vars, "value", "456");
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_int} == ${value}",
+ NULL, extra_vars, NULL, 1));
/* search long */
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_long} == 999", 1));
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_long} == 987654321", 2));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, items,
- "${test_item.test_long} == 123456789", 1));
- POINTERS_EQUAL(ptr_item2,
- hdata_search (ptr_hdata, items,
- "${test_item.test_long} == 987654321", 1));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, last_item,
- "${test_item.test_long} == 123456789", -1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_long} == 999",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_long} == 987654321",
+ NULL, NULL, NULL, 2));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_long} == 123456789",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_long} == 987654321",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, last_item,
+ "${test_item.test_long} == 123456789",
+ NULL, NULL, NULL, -1));
+ hashtable_set (extra_vars, "value", "987654321");
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_long} == ${value}",
+ NULL, extra_vars, NULL, 1));
/* search string */
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_string} == zzz", 1));
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_string} == item2", 2));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, items,
- "${test_item.test_string} == item1", 1));
- POINTERS_EQUAL(ptr_item2,
- hdata_search (ptr_hdata, items,
- "${test_item.test_string} == item2", 1));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, last_item,
- "${test_item.test_string} == item1", -1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_string} == zzz",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_string} == item2",
+ NULL, NULL, NULL, 2));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_string} == item1",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_string} == item2",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, last_item,
+ "${test_item.test_string} == item1",
+ NULL, NULL, NULL, -1));
+ hashtable_set (extra_vars, "value", "item2");
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_string} == item2",
+ NULL, extra_vars, NULL, 1));
/* search shared string */
POINTERS_EQUAL(
NULL,
hdata_search (ptr_hdata, items,
- "${test_item.test_shared_string} == zzz", 1));
+ "${test_item.test_shared_string} == zzz",
+ NULL, NULL, NULL, 1));
POINTERS_EQUAL(
NULL,
hdata_search (ptr_hdata, items,
- "${test_item.test_shared_string} == item2_shared", 2));
+ "${test_item.test_shared_string} == item2_shared",
+ NULL, NULL, NULL, 2));
POINTERS_EQUAL(
ptr_item1,
hdata_search (ptr_hdata, items,
- "${test_item.test_shared_string} == item1_shared", 1));
+ "${test_item.test_shared_string} == item1_shared",
+ NULL, NULL, NULL, 1));
POINTERS_EQUAL(
ptr_item2,
hdata_search (ptr_hdata, items,
- "${test_item.test_shared_string} == item2_shared", 1));
+ "${test_item.test_shared_string} == item2_shared",
+ NULL, NULL, NULL, 1));
POINTERS_EQUAL(
ptr_item1,
hdata_search (ptr_hdata, last_item,
- "${test_item.test_shared_string} == item1_shared", -1));
+ "${test_item.test_shared_string} == item1_shared",
+ NULL, NULL, NULL, -1));
+ hashtable_set (extra_vars, "value", "item2_shared");
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_shared_string} == item2_shared",
+ NULL, NULL, NULL, 1));
/* search pointer */
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_pointer} == 0x999", 1));
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_pointer} == 0x456", 2));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, items,
- "${test_item.test_pointer} == 0x123", 1));
- POINTERS_EQUAL(ptr_item2,
- hdata_search (ptr_hdata, items,
- "${test_item.test_pointer} == 0x456", 1));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, last_item,
- "${test_item.test_pointer} == 0x123", -1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_pointer} == 0x999",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_pointer} == 0x456",
+ NULL, NULL, NULL, 2));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_pointer} == 0x123",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_pointer} == 0x456",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, last_item,
+ "${test_item.test_pointer} == 0x123",
+ NULL, NULL, NULL, -1));
+ hashtable_set (extra_vars, "value", "0x456");
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_pointer} == ${value}",
+ NULL, extra_vars, NULL, 1));
+ hashtable_set (pointers, "value", (void *)0x456);
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_pointer} == ${value}",
+ pointers, NULL, NULL, 1));
/* search time */
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_time} == 999", 1));
- POINTERS_EQUAL(NULL,
- hdata_search (ptr_hdata, items,
- "${test_item.test_time} == 789123", 2));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, items,
- "${test_item.test_time} == 123456", 1));
- POINTERS_EQUAL(ptr_item2,
- hdata_search (ptr_hdata, items,
- "${test_item.test_time} == 789123", 1));
- POINTERS_EQUAL(ptr_item1,
- hdata_search (ptr_hdata, last_item,
- "${test_item.test_time} == 123456", -1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_time} == 999",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ NULL,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_time} == 789123",
+ NULL, NULL, NULL, 2));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_time} == 123456",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_time} == 789123",
+ NULL, NULL, NULL, 1));
+ POINTERS_EQUAL(
+ ptr_item1,
+ hdata_search (ptr_hdata, last_item,
+ "${test_item.test_time} == 123456",
+ NULL, NULL, NULL, -1));
+ hashtable_set (extra_vars, "value", "789123");
+ POINTERS_EQUAL(
+ ptr_item2,
+ hdata_search (ptr_hdata, items,
+ "${test_item.test_time} == ${value}",
+ NULL, extra_vars, NULL, 1));
+
+ hashtable_free (pointers);
+ hashtable_free (extra_vars);
}
/*