From 7621939a7a40a0e535b5b2ef67c2cb60e12208e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Tue, 30 May 2017 20:26:19 +0200 Subject: [PATCH] api: add function hdata_compare --- ChangeLog.adoc | 2 +- doc/en/weechat_plugin_api.en.adoc | 53 ++++++++++++ doc/fr/weechat_plugin_api.fr.adoc | 53 ++++++++++++ doc/it/weechat_plugin_api.it.adoc | 54 +++++++++++++ doc/ja/weechat_plugin_api.ja.adoc | 54 +++++++++++++ src/core/wee-hdata.c | 99 +++++++++++++++++++++++ src/core/wee-hdata.h | 3 + src/plugins/guile/weechat-guile-api.c | 22 +++++ src/plugins/javascript/weechat-js-api.cpp | 23 ++++++ src/plugins/lua/weechat-lua-api.c | 25 ++++++ src/plugins/perl/weechat-perl-api.c | 26 ++++++ src/plugins/plugin.c | 1 + src/plugins/python/weechat-python-api.c | 25 ++++++ src/plugins/ruby/weechat-ruby-api.c | 35 ++++++++ src/plugins/tcl/weechat-tcl-api.c | 28 +++++++ src/plugins/weechat-plugin.h | 9 ++- 16 files changed, 510 insertions(+), 2 deletions(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index a071f9ee6..d7744fc79 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -20,7 +20,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] New features:: - * api: add function config_option_get_string() + * api: add functions config_option_get_string() and hdata_compare() * buflist: add keys kbd:[F1]/kbd:[F2], kbd:[Alt+F1]/kbd:[Alt+F2] to scroll the buflist bar Improvements:: diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index f2929d3b2..4fb28a02c 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -16034,6 +16034,59 @@ for key in hash: weechat.prnt("", " %s == %s" % (key, hash[key])) ---- +==== hdata_compare + +_WeeChat ≥ 1.9._ + +Compare a hdata variable of two objects. + +Prototype: + +[source,C] +---- +int weechat_hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2, const char *name, int case_sensitive); +---- + +Arguments: + +* _hdata_: hdata pointer +* _pointer1_: pointer to first WeeChat/plugin object +* _pointer2_: pointer to second WeeChat/plugin object +* _name_: variable name; for arrays, the name can be "N|name" where N is + the index in array (starting at 0), for example: "2|name" +* _case_sensitive_: 1 for case sensitive comparison of strings, otherwise 0 + +Return value: + +* -1 if variable1 < variable2 +* 0 if variable1 == variable2 +* 1 if variable1 > variable2 + +C example: + +[source,C] +---- +struct t_hdata *hdata = weechat_hdata_get ("buffer"); +struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "freenode.#weechat"); +struct t_gui_buffer *buffer2 = weechat_buffer_search ("irc", "freenode.#weechat-fr"); +weechat_printf (NULL, "number comparison = %d", + weechat_hdata_compare (hdata, buffer1, buffer2, "number", 0)); +---- + +Script (Python): + +[source,python] +---- +# prototype +rc = weechat.hdata_compare(hdata, pointer1, pointer2, name, case_sensitive) + +# example +hdata = weechat.hdata_get("buffer") +buffer1 = weechat.buffer_search("irc", "freenode.#weechat") +buffer2 = weechat.buffer_search("irc", "freenode.#weechat-fr") +weechat.prnt("", "number comparison = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0)) +---- + ==== hdata_set _WeeChat ≥ 0.3.9._ diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index 67b27a493..792f66001 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -16371,6 +16371,59 @@ for key in hash: weechat.prnt("", " %s == %s" % (key, hash[key])) ---- +==== hdata_compare + +_WeeChat ≥ 1.9._ + +Comparer une variable hdata de deux objets. + +Prototype : + +[source,C] +---- +int weechat_hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2, const char *name, int case_sensitive); +---- + +Paramètres : + +* _hdata_ : pointeur vers le hdata +* _pointer1_ : pointeur vers le premier objet WeeChat ou d'une extension +* _pointer2_ : pointeur vers le second objet WeeChat ou d'une extension +* _name_ : nom de la variable ; pour les tableaux, le nom peut être "N|name" où N + est un index dans le tableau (démarrant à 0), par exemple : "2|name" +* _case_sensitive_ : 1 pour une comparaison tenant compte de la casse pour les chaînes, + sinon 0 + +Valeur de retour : + +* -1 si variable1 < variable2 +* 0 si variable1 == variable2 +* 1 si variable1 > variable2 + +Exemple en C : + +[source,C] +---- +struct t_hdata *hdata = weechat_hdata_get ("buffer"); +struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "freenode.#weechat"); +struct t_gui_buffer *buffer2 = weechat_buffer_search ("irc", "freenode.#weechat-fr"); +weechat_printf (NULL, "comparaison de numéro = %d", weechat_hdata_compare (hdata, buffer1, buffer2, "number", 0)); +---- + +Script (Python) : + +[source,python] +---- +# prototype +rc = weechat.hdata_compare(hdata, pointer1, pointer2, name, case_sensitive) + +# exemple +hdata = weechat.hdata_get("buffer") +buffer1 = weechat.buffer_search("irc", "freenode.#weechat") +buffer2 = weechat.buffer_search("irc", "freenode.#weechat-fr") +weechat.prnt("", "comparaison de numéro = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0)) +---- + ==== hdata_set _WeeChat ≥ 0.3.9._ diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 795aa9cbd..1ceeff90d 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -16631,6 +16631,60 @@ for key in hash: weechat.prnt("", " %s == %s" % (key, hash[key])) ---- +// TRANSLATION MISSING +==== hdata_compare + +_WeeChat ≥ 1.9._ + +Compare a hdata variable of two objects. + +Prototipo: + +[source,C] +---- +int weechat_hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2, const char *name, int case_sensitive); +---- + +Argomenti: + +* _hdata_: hdata pointer +* _pointer1_: pointer to first WeeChat/plugin object +* _pointer2_: pointer to second WeeChat/plugin object +* _name_: variable name; for arrays, the name can be "N|name" where N is + the index in array (starting at 0), for example: "2|name" +* _case_sensitive_: 1 for case sensitive comparison of strings, otherwise 0 + +Valore restituito: + +* -1 if variable1 < variable2 +* 0 if variable1 == variable2 +* 1 if variable1 > variable2 + +Esempio in C: + +[source,C] +---- +struct t_hdata *hdata = weechat_hdata_get ("buffer"); +struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "freenode.#weechat"); +struct t_gui_buffer *buffer2 = weechat_buffer_search ("irc", "freenode.#weechat-fr"); +weechat_printf (NULL, "number comparison = %d", + weechat_hdata_compare (hdata, buffer1, buffer2, "number", 0)); +---- + +Script (Python): + +[source,python] +---- +# prototype +rc = weechat.hdata_compare(hdata, pointer1, pointer2, name, case_sensitive) + +# example +hdata = weechat.hdata_get("buffer") +buffer1 = weechat.buffer_search("irc", "freenode.#weechat") +buffer2 = weechat.buffer_search("irc", "freenode.#weechat-fr") +weechat.prnt("", "number comparison = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0)) +---- + // TRANSLATION MISSING ==== hdata_set diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 3109f8e89..d6be49278 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -16039,6 +16039,60 @@ for key in hash: weechat.prnt("", " %s == %s" % (key, hash[key])) ---- +// TRANSLATION MISSING +==== hdata_compare + +_WeeChat バージョン 1.9 以上で利用可。_ + +Compare a hdata variable of two objects. + +プロトタイプ: + +[source,C] +---- +int weechat_hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2, const char *name, int case_sensitive); +---- + +引数: + +* _hdata_: hdata へのポインタ +* _pointer1_: pointer to first WeeChat/plugin object +* _pointer2_: pointer to second WeeChat/plugin object +* _name_: variable name; for arrays, the name can be "N|name" where N is + the index in array (starting at 0), for example: "2|name" +* _case_sensitive_: 1 for case sensitive comparison of strings, otherwise 0 + +戻り値: + +* -1 if variable1 < variable2 +* 0 if variable1 == variable2 +* 1 if variable1 > variable2 + +C 言語での使用例: + +[source,C] +---- +struct t_hdata *hdata = weechat_hdata_get ("buffer"); +struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "freenode.#weechat"); +struct t_gui_buffer *buffer2 = weechat_buffer_search ("irc", "freenode.#weechat-fr"); +weechat_printf (NULL, "number comparison = %d", + weechat_hdata_compare (hdata, buffer1, buffer2, "number", 0)); +---- + +スクリプト (Python) での使用例: + +[source,python] +---- +# プロトタイプ +rc = weechat.hdata_compare(hdata, pointer1, pointer2, name, case_sensitive) + +# 例 +hdata = weechat.hdata_get("buffer") +buffer1 = weechat.buffer_search("irc", "freenode.#weechat") +buffer2 = weechat.buffer_search("irc", "freenode.#weechat-fr") +weechat.prnt("", "number comparison = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0)) +---- + ==== hdata_set _WeeChat バージョン 0.3.9 以上で利用可。_ diff --git a/src/core/wee-hdata.c b/src/core/wee-hdata.c index be5bc4d6a..4631b8de9 100644 --- a/src/core/wee-hdata.c +++ b/src/core/wee-hdata.c @@ -876,6 +876,105 @@ hdata_hashtable (struct t_hdata *hdata, void *pointer, const char *name) return NULL; } +/* + * Compares a hdata variable of two objects. + * + * If case_sensitive == 1, the comparison of strings is case sensitive. + * + * Returns: + * -1: variable1 < variable2 + * 0: variable1 == variable2 + * 1: variable1 > variable2 + */ + +int +hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2, + const char *name, int case_sensitive) +{ + int rc, int_value1, int_value2; + long long_value1, long_value2; + char char_value1, char_value2; + const char *ptr_name, *str_value1, *str_value2; + void *ptr_value1, *ptr_value2; + time_t time_value1, time_value2; + + if (!pointer1 && pointer2) + return -1; + if (pointer1 && !pointer2) + return 1; + if (!pointer1 && !pointer2) + return 0; + + rc = 0; + + hdata_get_index_and_name (name, NULL, &ptr_name); + switch (hdata_get_var_type (hdata, ptr_name)) + { + case WEECHAT_HDATA_CHAR: + char_value1 = hdata_char (hdata, pointer1, name); + char_value2 = hdata_char (hdata, pointer2, name); + rc = (char_value1 < char_value2) ? + -1 : ((char_value1 > char_value2) ? 1 : 0); + break; + case WEECHAT_HDATA_INTEGER: + int_value1 = hdata_integer (hdata, pointer1, name); + int_value2 = hdata_integer (hdata, pointer2, name); + rc = (int_value1 < int_value2) ? + -1 : ((int_value1 > int_value2) ? 1 : 0); + break; + case WEECHAT_HDATA_LONG: + long_value1 = hdata_long (hdata, pointer1, name); + long_value2 = hdata_long (hdata, pointer2, name); + rc = (long_value1 < long_value2) ? + -1 : ((long_value1 > long_value2) ? 1 : 0); + break; + case WEECHAT_HDATA_STRING: + case WEECHAT_HDATA_SHARED_STRING: + str_value1 = hdata_string (hdata, pointer1, name); + str_value2 = hdata_string (hdata, pointer2, name); + if (!str_value1 && !str_value2) + rc = 0; + else if (str_value1 && !str_value2) + rc = 1; + else if (!str_value1 && str_value2) + rc = -1; + else + { + if (case_sensitive) + rc = strcmp (str_value1, str_value2); + else + rc = string_strcasecmp (str_value1, str_value2); + if (rc < 0) + rc = -1; + else if (rc > 0) + rc = 1; + } + break; + case WEECHAT_HDATA_POINTER: + ptr_value1 = hdata_pointer (hdata, pointer1, name); + ptr_value2 = hdata_pointer (hdata, pointer2, name); + rc = (ptr_value1 < ptr_value2) ? + -1 : ((ptr_value1 > ptr_value2) ? 1 : 0); + break; + case WEECHAT_HDATA_TIME: + time_value1 = hdata_time (hdata, pointer1, name); + time_value2 = hdata_time (hdata, pointer2, name); + rc = (time_value1 < time_value2) ? + -1 : ((time_value1 > time_value2) ? 1 : 0); + break; + case WEECHAT_HDATA_HASHTABLE: + /* no comparison for hashtables */ + rc = 0; + break; + case WEECHAT_HDATA_OTHER: + /* no comparison for other types */ + rc = 0; + break; + } + + return rc; +} + /* * Sets value for a variable in hdata. * diff --git a/src/core/wee-hdata.h b/src/core/wee-hdata.h index c6cde0503..eaa2a3431 100644 --- a/src/core/wee-hdata.h +++ b/src/core/wee-hdata.h @@ -126,6 +126,9 @@ extern time_t hdata_time (struct t_hdata *hdata, void *pointer, const char *name); extern struct t_hashtable *hdata_hashtable (struct t_hdata *hdata, void *pointer, const char *name); +extern int hdata_compare (struct t_hdata *hdata, void *pointer1, + void *pointer2, const char *name, + int case_sensitive); extern int hdata_set (struct t_hdata *hdata, void *pointer, const char *name, const char *value); extern int hdata_update (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 425d60a43..2842b39ae 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -4631,6 +4631,27 @@ weechat_guile_api_hdata_hashtable (SCM hdata, SCM pointer, SCM name) API_RETURN_OTHER(result_alist); } +SCM +weechat_guile_api_hdata_compare (SCM hdata, SCM pointer1, SCM pointer2, + SCM name, SCM case_sensitive) +{ + int rc; + + API_INIT_FUNC(1, "hdata_compare", API_RETURN_INT(0)); + if (!scm_is_string (hdata) || !scm_is_string (pointer1) + || !scm_is_string (pointer2) || !scm_is_string (name) + || !scm_is_integer (case_sensitive)) + API_WRONG_ARGS(API_RETURN_INT(0)); + + rc = weechat_hdata_compare (API_STR2PTR(API_SCM_TO_STRING(hdata)), + API_STR2PTR(API_SCM_TO_STRING(pointer1)), + API_STR2PTR(API_SCM_TO_STRING(pointer2)), + API_SCM_TO_STRING(name), + scm_to_int (case_sensitive)); + + API_RETURN_INT(rc); +} + SCM weechat_guile_api_hdata_update (SCM hdata, SCM pointer, SCM hashtable) { @@ -4991,6 +5012,7 @@ weechat_guile_api_module_init (void *data) API_DEF_FUNC(hdata_pointer, 3); API_DEF_FUNC(hdata_time, 3); API_DEF_FUNC(hdata_hashtable, 3); + API_DEF_FUNC(hdata_compare, 5); API_DEF_FUNC(hdata_update, 3); API_DEF_FUNC(hdata_get_string, 2); API_DEF_FUNC(upgrade_new, 3); diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp index dcf62e1b4..ee3cfdbbf 100644 --- a/src/plugins/javascript/weechat-js-api.cpp +++ b/src/plugins/javascript/weechat-js-api.cpp @@ -4572,6 +4572,28 @@ API_FUNC(hdata_hashtable) return result_obj; } +API_FUNC(hdata_compare) +{ + int case_sensitive, rc; + + API_INIT_FUNC(1, "hdata_compare", "ssssi", API_RETURN_INT(0)); + + v8::String::Utf8Value hdata(args[0]); + v8::String::Utf8Value pointer1(args[1]); + v8::String::Utf8Value pointer2(args[2]); + v8::String::Utf8Value name(args[3]); + case_sensitive = args[4]->IntegerValue(); + + rc = weechat_hdata_compare ( + (struct t_hdata *)API_STR2PTR(*hdata), + API_STR2PTR(*pointer1), + API_STR2PTR(*pointer2), + *name, + case_sensitive); + + API_RETURN_INT(rc); +} + API_FUNC(hdata_update) { struct t_hashtable *hashtable; @@ -4966,6 +4988,7 @@ WeechatJsV8::loadLibs() API_DEF_FUNC(hdata_pointer); API_DEF_FUNC(hdata_time); API_DEF_FUNC(hdata_hashtable); + API_DEF_FUNC(hdata_compare); API_DEF_FUNC(hdata_update); API_DEF_FUNC(hdata_get_string); API_DEF_FUNC(upgrade_new); diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index 372f01905..c09f09676 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -4933,6 +4933,30 @@ API_FUNC(hdata_hashtable) return 1; } +API_FUNC(hdata_compare) +{ + const char *hdata, *pointer1, *pointer2, *name; + int case_sensitive, rc; + + API_INIT_FUNC(1, "hdata_compare", API_RETURN_INT(0)); + if (lua_gettop (L) < 5) + API_WRONG_ARGS(API_RETURN_INT(0)); + + hdata = lua_tostring (L, -5); + pointer1 = lua_tostring (L, -4); + pointer2 = lua_tostring (L, -3); + name = lua_tostring (L, -2); + case_sensitive = lua_tonumber (L, -1); + + rc = weechat_hdata_compare (API_STR2PTR(hdata), + API_STR2PTR(pointer1), + API_STR2PTR(pointer2), + name, + case_sensitive); + + API_RETURN_INT(rc); +} + API_FUNC(hdata_update) { const char *hdata, *pointer; @@ -5289,6 +5313,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = { API_DEF_FUNC(hdata_pointer), API_DEF_FUNC(hdata_time), API_DEF_FUNC(hdata_hashtable), + API_DEF_FUNC(hdata_compare), API_DEF_FUNC(hdata_update), API_DEF_FUNC(hdata_get_string), API_DEF_FUNC(upgrade_new), diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c index eae85f275..8e7b19569 100644 --- a/src/plugins/perl/weechat-perl-api.c +++ b/src/plugins/perl/weechat-perl-api.c @@ -4861,6 +4861,31 @@ API_FUNC(hdata_hashtable) API_RETURN_OBJ(result_hash); } +API_FUNC(hdata_compare) +{ + char *hdata, *pointer1, *pointer2, *name; + int case_sensitive, rc; + dXSARGS; + + API_INIT_FUNC(1, "hdata_compare", API_RETURN_INT(0)); + if (items < 5) + API_WRONG_ARGS(API_RETURN_INT(0)); + + hdata = SvPV_nolen (ST (0)); + pointer1 = SvPV_nolen (ST (1)); + pointer2 = SvPV_nolen (ST (2)); + name = SvPV_nolen (ST (3)); + case_sensitive = SvIV(ST (4)); + + rc = weechat_hdata_compare (API_STR2PTR(hdata), + API_STR2PTR(pointer1), + API_STR2PTR(pointer2), + name, + case_sensitive); + + API_RETURN_INT(rc); +} + API_FUNC(hdata_update) { char *hdata, *pointer; @@ -5229,6 +5254,7 @@ weechat_perl_api_init (pTHX) API_DEF_FUNC(hdata_pointer); API_DEF_FUNC(hdata_time); API_DEF_FUNC(hdata_hashtable); + API_DEF_FUNC(hdata_compare); API_DEF_FUNC(hdata_update); API_DEF_FUNC(hdata_get_string); API_DEF_FUNC(upgrade_new); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index bb2c25e7d..7065dfcca 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -891,6 +891,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv) new_plugin->hdata_pointer = &hdata_pointer; new_plugin->hdata_time = &hdata_time; new_plugin->hdata_hashtable = &hdata_hashtable; + new_plugin->hdata_compare = &hdata_compare; new_plugin->hdata_set = &hdata_set; new_plugin->hdata_update = &hdata_update; new_plugin->hdata_get_string = &hdata_get_string; diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c index 4d02445cb..93e932a31 100644 --- a/src/plugins/python/weechat-python-api.c +++ b/src/plugins/python/weechat-python-api.c @@ -4851,6 +4851,30 @@ API_FUNC(hdata_hashtable) return result_dict; } +API_FUNC(hdata_compare) +{ + char *hdata, *pointer1, *pointer2, *name; + int case_sensitive, rc; + + API_INIT_FUNC(1, "hdata_compare", API_RETURN_INT(0)); + hdata = NULL; + pointer1 = NULL; + pointer2 = NULL; + name = NULL; + case_sensitive = 0; + if (!PyArg_ParseTuple (args, "ssssi", &hdata, &pointer1, &pointer2, &name, + &case_sensitive)) + API_WRONG_ARGS(API_RETURN_INT(0)); + + rc = weechat_hdata_compare (API_STR2PTR(hdata), + API_STR2PTR(pointer1), + API_STR2PTR(pointer2), + name, + case_sensitive); + + API_RETURN_INT(rc); +} + API_FUNC(hdata_update) { char *hdata, *pointer; @@ -5205,6 +5229,7 @@ PyMethodDef weechat_python_funcs[] = API_DEF_FUNC(hdata_pointer), API_DEF_FUNC(hdata_time), API_DEF_FUNC(hdata_hashtable), + API_DEF_FUNC(hdata_compare), API_DEF_FUNC(hdata_update), API_DEF_FUNC(hdata_get_string), API_DEF_FUNC(upgrade_new), diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index e78a5cf5c..639ec9eca 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -5916,6 +5916,40 @@ weechat_ruby_api_hdata_hashtable (VALUE class, VALUE hdata, VALUE pointer, return result_hash; } +static VALUE +weechat_ruby_api_hdata_compare (VALUE class, VALUE hdata, + VALUE pointer1, VALUE pointer2, VALUE name, + VALUE case_sensitive) +{ + char *c_hdata, *c_pointer1, *c_pointer2, *c_name; + int c_case_sensitive, rc; + + API_INIT_FUNC(1, "hdata_compare", API_RETURN_INT(0)); + if (NIL_P (hdata) || NIL_P (pointer1) || NIL_P (pointer2) || NIL_P (name) + || NIL_P (case_sensitive)) + API_WRONG_ARGS(API_RETURN_INT(0)); + + Check_Type (hdata, T_STRING); + Check_Type (pointer1, T_STRING); + Check_Type (pointer2, T_STRING); + Check_Type (name, T_STRING); + Check_Type (case_sensitive, T_FIXNUM); + + c_hdata = StringValuePtr (hdata); + c_pointer1 = StringValuePtr (pointer1); + c_pointer2 = StringValuePtr (pointer2); + c_name = StringValuePtr (name); + c_case_sensitive = FIX2INT (case_sensitive); + + rc = weechat_hdata_compare (API_STR2PTR(c_hdata), + API_STR2PTR(c_pointer1), + API_STR2PTR(c_pointer2), + c_name, + c_case_sensitive); + + API_RETURN_INT(rc); +} + static VALUE weechat_ruby_api_hdata_update (VALUE class, VALUE hdata, VALUE pointer, VALUE hashtable) @@ -6351,6 +6385,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) API_DEF_FUNC(hdata_pointer, 3); API_DEF_FUNC(hdata_time, 3); API_DEF_FUNC(hdata_hashtable, 3); + API_DEF_FUNC(hdata_compare, 5); API_DEF_FUNC(hdata_update, 3); API_DEF_FUNC(hdata_get_string, 2); API_DEF_FUNC(upgrade_new, 3); diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c index a53f1f970..a7de9b353 100644 --- a/src/plugins/tcl/weechat-tcl-api.c +++ b/src/plugins/tcl/weechat-tcl-api.c @@ -5221,6 +5221,33 @@ API_FUNC(hdata_hashtable) API_RETURN_OBJ(result_dict); } +API_FUNC(hdata_compare) +{ + Tcl_Obj *objp; + char *hdata, *pointer1, *pointer2, *name; + int case_sensitive, rc, i; + + API_INIT_FUNC(1, "hdata_compare", API_RETURN_INT(0)); + if (objc < 6) + API_WRONG_ARGS(API_RETURN_INT(0)); + + hdata = Tcl_GetStringFromObj (objv[1], &i); + pointer1 = Tcl_GetStringFromObj (objv[2], &i); + pointer2 = Tcl_GetStringFromObj (objv[3], &i); + name = Tcl_GetStringFromObj (objv[4], &i); + + if (Tcl_GetIntFromObj (interp, objv[5], &case_sensitive) != TCL_OK) + API_WRONG_ARGS(API_RETURN_INT(0)); + + rc = weechat_hdata_compare (API_STR2PTR(hdata), + API_STR2PTR(pointer1), + API_STR2PTR(pointer2), + name, + case_sensitive); + + API_RETURN_INT(rc); +} + API_FUNC(hdata_update) { Tcl_Obj *objp; @@ -5692,6 +5719,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp) API_DEF_FUNC(hdata_pointer); API_DEF_FUNC(hdata_time); API_DEF_FUNC(hdata_hashtable); + API_DEF_FUNC(hdata_compare); API_DEF_FUNC(hdata_update); API_DEF_FUNC(hdata_get_string); API_DEF_FUNC(upgrade_new); diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 9d3fe101c..6d0019e2e 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -59,7 +59,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 "20170530-01" +#define WEECHAT_PLUGIN_API_VERSION "20170530-02" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -1065,6 +1065,9 @@ struct t_weechat_plugin const char *name); struct t_hashtable *(*hdata_hashtable) (struct t_hdata *hdata, void *pointer, const char *name); + int (*hdata_compare) (struct t_hdata *hdata, + void *pointer1, void *pointer2, const char *name, + int case_sensitive); int (*hdata_set) (struct t_hdata *hdata, void *pointer, const char *name, const char *value); int (*hdata_update) (struct t_hdata *hdata, void *pointer, @@ -1988,6 +1991,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); (weechat_plugin->hdata_time)(__hdata, __pointer, __name) #define weechat_hdata_hashtable(__hdata, __pointer, __name) \ (weechat_plugin->hdata_hashtable)(__hdata, __pointer, __name) +#define weechat_hdata_compare(__hdata, __pointer1, __pointer2, __name, \ + __case_sensitive) \ + (weechat_plugin->hdata_compare)(__hdata, __pointer1, __pointer2, \ + __name, __case_sensitive) #define weechat_hdata_set(__hdata, __pointer, __name, __value) \ (weechat_plugin->hdata_set)(__hdata, __pointer, __name, __value) #define weechat_hdata_update(__hdata, __pointer, __hashtable) \