mirror of
https://github.com/weechat/weechat.git
synced 2026-06-12 14:14:48 +02:00
api: add support of path to variable and hashtable comparison in function hdata_compare (closes #1066)
This commit is contained in:
@@ -24,6 +24,7 @@ New features::
|
||||
* core: add options weechat.buffer.* to save buffer properties set by user, add option `setauto` in command `/buffer` (issue #352)
|
||||
* core: add parameters and key bindings to move to edges of current area with commands `/cursor go` and `/cursor move` (issue #1282)
|
||||
* core: add variables "_chat_focused_line_bol" and "_chat_focused_line_eol" in focus data (issue #1955)
|
||||
* api: add support of path to variable and hashtable comparison in function hdata_compare (issue #1066)
|
||||
* api: add infos "nick_color_ignore_case" and "nick_color_name_ignore_case" (issue #194)
|
||||
* api: add info "buffer" (issue #1962)
|
||||
* buflist: increase max number of buflist items from 3 to 5 (issue #1703)
|
||||
|
||||
@@ -18589,7 +18589,7 @@ for key in hash:
|
||||
|
||||
==== hdata_compare
|
||||
|
||||
_WeeChat ≥ 1.9._
|
||||
_WeeChat ≥ 1.9, updated in 4.1.0._
|
||||
|
||||
Compare a hdata variable of two objects.
|
||||
|
||||
@@ -18605,8 +18605,8 @@ 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"
|
||||
* _name_: variable name or path to a 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:
|
||||
@@ -18622,8 +18622,12 @@ C example:
|
||||
struct t_hdata *hdata = weechat_hdata_get ("buffer");
|
||||
struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
|
||||
struct t_gui_buffer *buffer2 = weechat_buffer_search ("irc", "libera.#weechat-fr");
|
||||
weechat_printf (NULL, "number comparison = %d",
|
||||
weechat_printf (NULL, "comparison of buffer number = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "number", 0));
|
||||
weechat_printf (NULL, "comparison of number of lines = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "own_lines.lines_count", 0));
|
||||
weechat_printf (NULL, "comparison of local variable = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "local_variables.myvar", 0));
|
||||
----
|
||||
|
||||
Script (Python):
|
||||
@@ -18637,7 +18641,9 @@ def hdata_compare(hdata: str, pointer1: str, pointer2: str, name: str, case_sens
|
||||
hdata = weechat.hdata_get("buffer")
|
||||
buffer1 = weechat.buffer_search("irc", "libera.#weechat")
|
||||
buffer2 = weechat.buffer_search("irc", "libera.#weechat-fr")
|
||||
weechat.prnt("", "number comparison = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparison of buffer number = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparison of number of lines = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "own_lines.lines_count", 0))
|
||||
weechat.prnt("", "comparison of local variable = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "local_variables.myvar", 0))
|
||||
----
|
||||
|
||||
==== hdata_set
|
||||
|
||||
@@ -18982,7 +18982,7 @@ for key in hash:
|
||||
|
||||
==== hdata_compare
|
||||
|
||||
_WeeChat ≥ 1.9._
|
||||
_WeeChat ≥ 1.9, mis à jour dans la 4.1.0._
|
||||
|
||||
Comparer une variable hdata de deux objets.
|
||||
|
||||
@@ -18998,8 +18998,9 @@ 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"
|
||||
* _name_ : nom de la variable ou chemin vers le 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
|
||||
|
||||
@@ -19016,7 +19017,12 @@ Exemple en C :
|
||||
struct t_hdata *hdata = weechat_hdata_get ("buffer");
|
||||
struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
|
||||
struct t_gui_buffer *buffer2 = weechat_buffer_search ("irc", "libera.#weechat-fr");
|
||||
weechat_printf (NULL, "comparaison de numéro = %d", weechat_hdata_compare (hdata, buffer1, buffer2, "number", 0));
|
||||
weechat_printf (NULL, "comparaison de numéro de tampon = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "number", 0));
|
||||
weechat_printf (NULL, "comparaison du nombre de lignes = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "own_lines.lines_count", 0));
|
||||
weechat_printf (NULL, "comparaison de variable locale = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "local_variables.myvar", 0));
|
||||
----
|
||||
|
||||
Script (Python) :
|
||||
@@ -19030,7 +19036,9 @@ def hdata_compare(hdata: str, pointer1: str, pointer2: str, name: str, case_sens
|
||||
hdata = weechat.hdata_get("buffer")
|
||||
buffer1 = weechat.buffer_search("irc", "libera.#weechat")
|
||||
buffer2 = weechat.buffer_search("irc", "libera.#weechat-fr")
|
||||
weechat.prnt("", "comparaison de numéro = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparaison de numéro de tampon = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparaison du nombre de lignes = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "own_lines.lines_count", 0))
|
||||
weechat.prnt("", "comparaison de variable locale = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "local_variables.myvar", 0))
|
||||
----
|
||||
|
||||
==== hdata_set
|
||||
|
||||
@@ -19408,7 +19408,7 @@ for key in hash:
|
||||
// TRANSLATION MISSING
|
||||
==== hdata_compare
|
||||
|
||||
_WeeChat ≥ 1.9._
|
||||
_WeeChat ≥ 1.9, updated in 4.1.0._
|
||||
|
||||
Compare a hdata variable of two objects.
|
||||
|
||||
@@ -19424,8 +19424,8 @@ 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"
|
||||
* _name_: variable name or path to a 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:
|
||||
@@ -19441,8 +19441,12 @@ Esempio in C:
|
||||
struct t_hdata *hdata = weechat_hdata_get ("buffer");
|
||||
struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
|
||||
struct t_gui_buffer *buffer2 = weechat_buffer_search ("irc", "libera.#weechat-fr");
|
||||
weechat_printf (NULL, "number comparison = %d",
|
||||
weechat_printf (NULL, "comparison of buffer number = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "number", 0));
|
||||
weechat_printf (NULL, "comparison of number of lines = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "own_lines.lines_count", 0));
|
||||
weechat_printf (NULL, "comparison of local variable = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "local_variables.myvar", 0));
|
||||
----
|
||||
|
||||
Script (Python):
|
||||
@@ -19456,7 +19460,9 @@ def hdata_compare(hdata: str, pointer1: str, pointer2: str, name: str, case_sens
|
||||
hdata = weechat.hdata_get("buffer")
|
||||
buffer1 = weechat.buffer_search("irc", "libera.#weechat")
|
||||
buffer2 = weechat.buffer_search("irc", "libera.#weechat-fr")
|
||||
weechat.prnt("", "number comparison = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparison of buffer number = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparison of number of lines = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "own_lines.lines_count", 0))
|
||||
weechat.prnt("", "comparison of local variable = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "local_variables.myvar", 0))
|
||||
----
|
||||
|
||||
// TRANSLATION MISSING
|
||||
|
||||
@@ -18778,7 +18778,8 @@ for key in hash:
|
||||
|
||||
==== hdata_compare
|
||||
|
||||
_WeeChat バージョン 1.9 以上で利用可。_
|
||||
// TRANSLATION MISSING
|
||||
_WeeChat ≥ 1.9, updated in 4.1.0._
|
||||
|
||||
2 つのオブジェクトの hdata 変数を比較。
|
||||
|
||||
@@ -18794,8 +18795,9 @@ int weechat_hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2
|
||||
* _hdata_: hdata へのポインタ
|
||||
* _pointer1_: 1 番目の WeeChat およびプラグインオブジェクトへのポインタ
|
||||
* _pointer2_: 2 番目の WeeChat およびプラグインオブジェクトへのポインタ
|
||||
* _name_: 変数名; 配列の場合、変数名を "N|name" のように指定できます。ここで
|
||||
N は配列のインデックス番号です (番号は 0 から始まります)。例: "2|name"
|
||||
// TRANSLATION MISSING
|
||||
* _name_: variable name or path to a variable name; 配列の場合、変数名を "N|name"
|
||||
のように指定できます。ここで N は配列のインデックス番号です (番号は 0 から始まります)。例: "2|name"
|
||||
* _case_sensitive_: 大文字小文字を区別する場合 1、それ以外の場合 0
|
||||
|
||||
戻り値:
|
||||
@@ -18811,8 +18813,12 @@ C 言語での使用例:
|
||||
struct t_hdata *hdata = weechat_hdata_get ("buffer");
|
||||
struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
|
||||
struct t_gui_buffer *buffer2 = weechat_buffer_search ("irc", "libera.#weechat-fr");
|
||||
weechat_printf (NULL, "number comparison = %d",
|
||||
weechat_printf (NULL, "comparison of buffer number = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "number", 0));
|
||||
weechat_printf (NULL, "comparison of number of lines = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "own_lines.lines_count", 0));
|
||||
weechat_printf (NULL, "comparison of local variable = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "local_variables.myvar", 0));
|
||||
----
|
||||
|
||||
スクリプト (Python) での使用例:
|
||||
@@ -18826,7 +18832,9 @@ def hdata_compare(hdata: str, pointer1: str, pointer2: str, name: str, case_sens
|
||||
hdata = weechat.hdata_get("buffer")
|
||||
buffer1 = weechat.buffer_search("irc", "libera.#weechat")
|
||||
buffer2 = weechat.buffer_search("irc", "libera.#weechat-fr")
|
||||
weechat.prnt("", "number comparison = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparison of buffer number = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparison of number of lines = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "own_lines.lines_count", 0))
|
||||
weechat.prnt("", "comparison of local variable = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "local_variables.myvar", 0))
|
||||
----
|
||||
|
||||
==== hdata_set
|
||||
|
||||
@@ -18011,7 +18011,7 @@ for key in hash:
|
||||
|
||||
==== hdata_compare
|
||||
|
||||
_WeeChat ≥ 1.9._
|
||||
_WeeChat ≥ 1.9, ажурирано у верзији 4.1.0._
|
||||
|
||||
Пореди hdata променљиву два објекта.
|
||||
|
||||
@@ -18027,7 +18027,9 @@ int weechat_hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2
|
||||
* _hdata_: показивач на hdata
|
||||
* _pointer1_: показивач на први објекат програма WeeChat/додатка
|
||||
* _pointer2_: показивач на други објекат програма WeeChat/додатка
|
||||
* _name_: име променљиве; у случају низова, име може бити „N|име” где је N индекс низа (који почиње од 0), на пример: „2|име”
|
||||
// TRANSLATION MISSING
|
||||
* _name_: variable name or path to a variable name; у случају низова, име може
|
||||
бити „N|име” где је N индекс низа (који почиње од 0), на пример: „2|име”
|
||||
* _case_sensitive_: 1 за поређење стрингова које разликује величину слова, у супротном 0
|
||||
|
||||
Повратна вредност:
|
||||
@@ -18043,8 +18045,12 @@ C пример:
|
||||
struct t_hdata *hdata = weechat_hdata_get ("buffer");
|
||||
struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
|
||||
struct t_gui_buffer *buffer2 = weechat_buffer_search ("irc", "libera.#weechat-fr");
|
||||
weechat_printf (NULL, "number comparison = %d",
|
||||
weechat_printf (NULL, "comparison of buffer number = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "number", 0));
|
||||
weechat_printf (NULL, "comparison of number of lines = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "own_lines.lines_count", 0));
|
||||
weechat_printf (NULL, "comparison of local variable = %d",
|
||||
weechat_hdata_compare (hdata, buffer1, buffer2, "local_variables.myvar", 0));
|
||||
----
|
||||
|
||||
Скрипта (Python):
|
||||
@@ -18058,7 +18064,9 @@ def hdata_compare(hdata: str, pointer1: str, pointer2: str, name: str, case_sens
|
||||
hdata = weechat.hdata_get("buffer")
|
||||
buffer1 = weechat.buffer_search("irc", "libera.#weechat")
|
||||
buffer2 = weechat.buffer_search("irc", "libera.#weechat-fr")
|
||||
weechat.prnt("", "бројно поређење = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparison of buffer number = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparison of number of lines = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "own_lines.lines_count", 0))
|
||||
weechat.prnt("", "comparison of local variable = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "local_variables.myvar", 0))
|
||||
----
|
||||
|
||||
==== hdata_set
|
||||
|
||||
+139
-19
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "weechat.h"
|
||||
#include "wee-hdata.h"
|
||||
#include "wee-hook.h"
|
||||
#include "wee-eval.h"
|
||||
#include "wee-hashtable.h"
|
||||
#include "wee-log.h"
|
||||
@@ -955,12 +956,14 @@ int
|
||||
hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2,
|
||||
const char *name, int case_sensitive)
|
||||
{
|
||||
int rc, int_value1, int_value2;
|
||||
int rc, type, type1, type2, int_value1, int_value2;
|
||||
long long_value1, long_value2;
|
||||
char char_value1, char_value2;
|
||||
const char *ptr_name, *str_value1, *str_value2;
|
||||
char *var_name, *property, char_value1, char_value2;
|
||||
const char *ptr_var_name, *pos, *pos_open_paren, *hdata_name;
|
||||
const char *str_value1, *str_value2;
|
||||
void *ptr_value1, *ptr_value2;
|
||||
time_t time_value1, time_value2;
|
||||
struct t_hashtable *hashtable1, *hashtable2;
|
||||
|
||||
if (!hdata || !name)
|
||||
return 0;
|
||||
@@ -973,32 +976,47 @@ hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2,
|
||||
return 0;
|
||||
|
||||
rc = 0;
|
||||
ptr_value1 = NULL;
|
||||
ptr_value2 = NULL;
|
||||
|
||||
hdata_get_index_and_name (name, NULL, &ptr_name);
|
||||
switch (hdata_get_var_type (hdata, ptr_name))
|
||||
pos = strchr (name, '.');
|
||||
if (pos > name)
|
||||
var_name = string_strndup (name, pos - name);
|
||||
else
|
||||
var_name = strdup (name);
|
||||
|
||||
if (!var_name)
|
||||
goto end;
|
||||
|
||||
hdata_get_index_and_name (var_name, NULL, &ptr_var_name);
|
||||
type = hdata_get_var_type (hdata, ptr_var_name);
|
||||
if (type < 0)
|
||||
goto end;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case WEECHAT_HDATA_CHAR:
|
||||
char_value1 = hdata_char (hdata, pointer1, name);
|
||||
char_value2 = hdata_char (hdata, pointer2, name);
|
||||
char_value1 = hdata_char (hdata, pointer1, var_name);
|
||||
char_value2 = hdata_char (hdata, pointer2, var_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);
|
||||
int_value1 = hdata_integer (hdata, pointer1, var_name);
|
||||
int_value2 = hdata_integer (hdata, pointer2, var_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);
|
||||
long_value1 = hdata_long (hdata, pointer1, var_name);
|
||||
long_value2 = hdata_long (hdata, pointer2, var_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);
|
||||
str_value1 = hdata_string (hdata, pointer1, var_name);
|
||||
str_value2 = hdata_string (hdata, pointer2, var_name);
|
||||
if (!str_value1 && !str_value2)
|
||||
rc = 0;
|
||||
else if (str_value1 && !str_value2)
|
||||
@@ -1018,20 +1036,105 @@ hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2,
|
||||
}
|
||||
break;
|
||||
case WEECHAT_HDATA_POINTER:
|
||||
ptr_value1 = hdata_pointer (hdata, pointer1, name);
|
||||
ptr_value2 = hdata_pointer (hdata, pointer2, name);
|
||||
ptr_value1 = hdata_pointer (hdata, pointer1, var_name);
|
||||
ptr_value2 = hdata_pointer (hdata, pointer2, var_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);
|
||||
time_value1 = hdata_time (hdata, pointer1, var_name);
|
||||
time_value2 = hdata_time (hdata, pointer2, var_name);
|
||||
rc = (time_value1 < time_value2) ?
|
||||
-1 : ((time_value1 > time_value2) ? 1 : 0);
|
||||
break;
|
||||
case WEECHAT_HDATA_HASHTABLE:
|
||||
/* no comparison for hashtables */
|
||||
rc = 0;
|
||||
ptr_value1 = hdata_hashtable (hdata, pointer1, var_name);
|
||||
ptr_value2 = hdata_hashtable (hdata, pointer2, var_name);
|
||||
if (pos)
|
||||
{
|
||||
/*
|
||||
* for a hashtable, if there is a "." after name of hdata:
|
||||
* 1) If "()" is at the end, it is a function call to
|
||||
* hashtable_get_string().
|
||||
* 2) Otherwise, get the value for this key in hashtable.
|
||||
*/
|
||||
hashtable1 = ptr_value1;
|
||||
hashtable2 = ptr_value2;
|
||||
|
||||
pos_open_paren = strchr (pos, '(');
|
||||
if (pos_open_paren
|
||||
&& (pos_open_paren > pos + 1)
|
||||
&& (pos_open_paren[1] == ')'))
|
||||
{
|
||||
property = string_strndup (pos + 1,
|
||||
pos_open_paren - pos - 1);
|
||||
ptr_value1 = (void *)hashtable_get_string (hashtable1, property);
|
||||
ptr_value2 = (void *)hashtable_get_string (hashtable2, property);
|
||||
if (property)
|
||||
free (property);
|
||||
type1 = HASHTABLE_STRING;
|
||||
type2 = HASHTABLE_STRING;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr_value1 = hashtable_get (hashtable1, pos + 1);
|
||||
ptr_value2 = hashtable_get (hashtable2, pos + 1);
|
||||
type1 = hashtable1->type_values;
|
||||
type2 = hashtable2->type_values;
|
||||
}
|
||||
|
||||
if (!ptr_value1 && ptr_value2)
|
||||
rc = -1;
|
||||
else if (ptr_value1 && !ptr_value2)
|
||||
rc = 1;
|
||||
else if (!ptr_value1 && !ptr_value2)
|
||||
rc = 0;
|
||||
else if (type1 != type2)
|
||||
rc = 0;
|
||||
else
|
||||
{
|
||||
switch (type1)
|
||||
{
|
||||
case HASHTABLE_INTEGER:
|
||||
int_value1 = *((int *)ptr_value1);
|
||||
int_value2 = *((int *)ptr_value2);
|
||||
rc = (int_value1 < int_value2) ?
|
||||
-1 : ((int_value1 > int_value2) ? 1 : 0);
|
||||
break;
|
||||
case HASHTABLE_STRING:
|
||||
if (case_sensitive)
|
||||
rc = strcmp ((const char *)ptr_value1,
|
||||
(const char *)ptr_value2);
|
||||
else
|
||||
rc = string_strcasecmp ((const char *)ptr_value1,
|
||||
(const char *)ptr_value2);
|
||||
if (rc < 0)
|
||||
rc = -1;
|
||||
else if (rc > 0)
|
||||
rc = 1;
|
||||
break;
|
||||
case HASHTABLE_POINTER:
|
||||
case HASHTABLE_BUFFER:
|
||||
rc = (ptr_value1 < ptr_value2) ?
|
||||
-1 : ((ptr_value1 > ptr_value2) ? 1 : 0);
|
||||
break;
|
||||
case HASHTABLE_TIME:
|
||||
time_value1 = (long long)(*((time_t *)ptr_value1));
|
||||
time_value2 = (long long)(*((time_t *)ptr_value2));
|
||||
rc = (time_value1 < time_value2) ?
|
||||
-1 : ((time_value1 > time_value2) ? 1 : 0);
|
||||
break;
|
||||
case HASHTABLE_NUM_TYPES:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* compare hashtables by pointer */
|
||||
rc = (ptr_value1 < ptr_value2) ?
|
||||
-1 : ((ptr_value1 > ptr_value2) ? 1 : 0);
|
||||
}
|
||||
break;
|
||||
case WEECHAT_HDATA_OTHER:
|
||||
/* no comparison for other types */
|
||||
@@ -1039,6 +1142,23 @@ hdata_compare (struct t_hdata *hdata, void *pointer1, void *pointer2,
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* if we are on a pointer and that something else is in path (after "."),
|
||||
* go on with this pointer and remaining path
|
||||
*/
|
||||
if ((type == WEECHAT_HDATA_POINTER) && pos)
|
||||
{
|
||||
hdata_name = hdata_get_var_hdata (hdata, var_name);
|
||||
if (!hdata_name)
|
||||
goto end;
|
||||
hdata = hook_hdata_get (NULL, hdata_name);
|
||||
rc = hdata_compare (hdata, ptr_value1, ptr_value2, pos + 1,
|
||||
case_sensitive);
|
||||
}
|
||||
|
||||
end:
|
||||
if (var_name)
|
||||
free (var_name);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -2661,7 +2661,9 @@ def hdata_compare(hdata: str, pointer1: str, pointer2: str, name: str, case_sens
|
||||
hdata = weechat.hdata_get("buffer")
|
||||
buffer1 = weechat.buffer_search("irc", "libera.#weechat")
|
||||
buffer2 = weechat.buffer_search("irc", "libera.#weechat-fr")
|
||||
weechat.prnt("", "number comparison = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparison of buffer number = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "number", 0))
|
||||
weechat.prnt("", "comparison of number of lines = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "own_lines.lines_count", 0))
|
||||
weechat.prnt("", "comparison of local variable = %d" % weechat.hdata_compare(hdata, buffer1, buffer2, "local_variables.myvar", 0))
|
||||
"""
|
||||
...
|
||||
|
||||
|
||||
@@ -2048,6 +2048,9 @@ TEST(CoreHdataWithList, Hashtable)
|
||||
|
||||
TEST(CoreHdataWithList, Compare)
|
||||
{
|
||||
struct t_gui_buffer *test_buffer;
|
||||
struct t_hdata *ptr_hdata_buffer;
|
||||
|
||||
LONGS_EQUAL(0, hdata_compare (NULL, NULL, NULL, NULL, 0));
|
||||
LONGS_EQUAL(0, hdata_compare (ptr_hdata, NULL, NULL, NULL, 0));
|
||||
|
||||
@@ -2114,13 +2117,32 @@ TEST(CoreHdataWithList, Compare)
|
||||
LONGS_EQUAL(1, hdata_compare (ptr_hdata, ptr_item2, ptr_item1,
|
||||
"test_time", 0));
|
||||
|
||||
/* compare hashtables: not possible */
|
||||
LONGS_EQUAL(0, hdata_compare (ptr_hdata, ptr_item1, ptr_item2,
|
||||
"test_hashtable", 0));
|
||||
/* compare hashtables: pointer comparison */
|
||||
CHECK(hdata_compare (ptr_hdata, ptr_item1, ptr_item2,
|
||||
"test_hashtable", 0) != 0);
|
||||
|
||||
/* compare "other" type: not possible */
|
||||
LONGS_EQUAL(0, hdata_compare (ptr_hdata, ptr_item1, ptr_item2,
|
||||
"test_other", 0));
|
||||
|
||||
/* create a test buffer */
|
||||
test_buffer = gui_buffer_new (NULL, "test",
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
CHECK(test_buffer);
|
||||
ptr_hdata_buffer = hook_hdata_get (NULL, "buffer");
|
||||
|
||||
/* compare two sub-fields of buffers: test recursive path traversal */
|
||||
LONGS_EQUAL(1, hdata_compare (ptr_hdata_buffer, gui_buffers, test_buffer,
|
||||
"own_lines.lines_count", 0));
|
||||
gui_buffer_set (gui_buffers, "localvar_set_myvar", "def");
|
||||
gui_buffer_set (test_buffer, "localvar_set_myvar", "abc");
|
||||
CHECK(ptr_hdata_buffer);
|
||||
LONGS_EQUAL(1, hdata_compare (ptr_hdata_buffer, gui_buffers, test_buffer,
|
||||
"local_variables.myvar", 0));
|
||||
gui_buffer_set (gui_buffers, "localvar_del_myvar", "");
|
||||
|
||||
gui_buffer_close (test_buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user