diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2021-11-06 15:59:18 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2021-11-06 15:59:18 +0100 |
commit | 2da21725937cfa6ea5bee911175a0cc82f478cdf (patch) | |
tree | e610418233289b61bfffd7ebb7f88acdfad2cee7 /src/core | |
parent | 018a4bda53cd7abca7c13dc07422c40511626a4f (diff) | |
download | weechat-2da21725937cfa6ea5bee911175a0cc82f478cdf.zip |
api: add parameters pointers, extra_vars and options in function hdata_search
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-hdata.c | 97 | ||||
-rw-r--r-- | src/core/wee-hdata.h | 4 |
2 files changed, 44 insertions, 57 deletions
diff --git a/src/core/wee-hdata.c b/src/core/wee-hdata.c index d1b800473..8b8636196 100644 --- a/src/core/wee-hdata.c +++ b/src/core/wee-hdata.c @@ -37,11 +37,6 @@ struct t_hashtable *weechat_hdata = NULL; -/* hashtables used in hdata_search() for evaluating expression */ -struct t_hashtable *hdata_search_pointers = NULL; -struct t_hashtable *hdata_search_extra_vars = NULL; -struct t_hashtable *hdata_search_options = NULL; - char *hdata_type_string[9] = { "other", "char", "integer", "long", "string", "pointer", "time", "hashtable", "shared_string" }; @@ -587,72 +582,78 @@ hdata_move (struct t_hdata *hdata, void *pointer, int count) */ void * -hdata_search (struct t_hdata *hdata, void *pointer, const char *search, int move) +hdata_search (struct t_hdata *hdata, + void *pointer, + const char *search, + struct t_hashtable *pointers, + struct t_hashtable *extra_vars, + struct t_hashtable *options, + int move) { + struct t_hashtable *pointers2, *options2; char *result; + void *ret_pointer; int rc; if (!hdata || !pointer || !search || !search[0] || (move == 0)) return NULL; - /* clear or create hashtable with pointer for search */ - if (hdata_search_pointers) + ret_pointer = NULL; + + /* duplicate or create hashtable with pointers */ + if (pointers) { - hashtable_remove_all (hdata_search_pointers); + pointers2 = hashtable_dup (pointers); } else { - hdata_search_pointers = hashtable_new (32, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_POINTER, - NULL, - NULL); + pointers2 = hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER, + NULL, + NULL); } - /* - * create hashtable with extra vars (empty hashtable) - * (hashtable would be created in eval_expression(), but it's created here - * so it will not be created for each call to eval_expression()) - */ - if (!hdata_search_extra_vars) + /* duplicate or create hashtable with options */ + if (options) { - hdata_search_extra_vars = hashtable_new (32, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); + options2 = hashtable_dup (options); } - - if (!hdata_search_options) + else { - hdata_search_options = hashtable_new (32, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); - if (hdata_search_options) - hashtable_set (hdata_search_options, "type", "condition"); + options2 = hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER, + NULL, + NULL); } + if (options2) + hashtable_set (options2, "type", "condition"); while (pointer) { /* set pointer in hashtable (used for evaluating expression) */ - hashtable_set (hdata_search_pointers, hdata->name, pointer); + if (pointers2) + hashtable_set (pointers2, hdata->name, pointer); /* evaluate expression */ - result = eval_expression (search, hdata_search_pointers, - hdata_search_extra_vars, - hdata_search_options); + result = eval_expression (search, pointers2, extra_vars, options2); rc = eval_is_true (result); if (result) free (result); if (rc) - return pointer; + { + ret_pointer = pointer; + goto end; + } pointer = hdata_move (hdata, pointer, move); } - return NULL; +end: + hashtable_free (pointers2); + hashtable_free (options2); + return ret_pointer; } /* @@ -1399,20 +1400,4 @@ hdata_end () hdata_free_all (); hashtable_free (weechat_hdata); weechat_hdata = NULL; - - if (hdata_search_pointers) - { - hashtable_free (hdata_search_pointers); - hdata_search_pointers = NULL; - } - if (hdata_search_extra_vars) - { - hashtable_free (hdata_search_extra_vars); - hdata_search_extra_vars = NULL; - } - if (hdata_search_options) - { - hashtable_free (hdata_search_options); - hdata_search_options = NULL; - } } diff --git a/src/core/wee-hdata.h b/src/core/wee-hdata.h index 24eb6eb8a..c84e00562 100644 --- a/src/core/wee-hdata.h +++ b/src/core/wee-hdata.h @@ -111,7 +111,9 @@ extern int hdata_check_pointer (struct t_hdata *hdata, void *list, void *pointer); extern void *hdata_move (struct t_hdata *hdata, void *pointer, int count); extern void *hdata_search (struct t_hdata *hdata, void *pointer, - const char *search, int move); + const char *search, struct t_hashtable *pointers, + struct t_hashtable *extra_vars, + struct t_hashtable *options, int move); extern void hdata_get_index_and_name (const char *name, int *index, const char **ptr_name); extern char hdata_char (struct t_hdata *hdata, void *pointer, |