summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-hdata.c85
-rw-r--r--src/core/wee-hdata.h3
-rw-r--r--src/plugins/guile/weechat-guile-api.c20
-rw-r--r--src/plugins/lua/weechat-lua-api.c25
-rw-r--r--src/plugins/perl/weechat-perl-api.c24
-rw-r--r--src/plugins/plugin.c1
-rw-r--r--src/plugins/python/weechat-python-api.c24
-rw-r--r--src/plugins/ruby/weechat-ruby-api.c31
-rw-r--r--src/plugins/tcl/weechat-tcl-api.c28
-rw-r--r--src/plugins/weechat-plugin.h6
10 files changed, 245 insertions, 2 deletions
diff --git a/src/core/wee-hdata.c b/src/core/wee-hdata.c
index 02dda08ca..2e8fc1dfd 100644
--- a/src/core/wee-hdata.c
+++ b/src/core/wee-hdata.c
@@ -28,6 +28,7 @@
#include "weechat.h"
#include "wee-hdata.h"
+#include "wee-eval.h"
#include "wee-hashtable.h"
#include "wee-log.h"
#include "wee-string.h"
@@ -36,6 +37,10 @@
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;
+
char *hdata_type_string[8] =
{ "other", "char", "integer", "long", "string", "pointer", "time",
"hashtable" };
@@ -90,6 +95,7 @@ hdata_new (struct t_weechat_plugin *plugin, const char *hdata_name,
new_hdata = malloc (sizeof (*new_hdata));
if (new_hdata)
{
+ new_hdata->name = strdup (hdata_name);
new_hdata->plugin = plugin;
new_hdata->var_prev = (var_prev) ? strdup (var_prev) : NULL;
new_hdata->var_next = (var_next) ? strdup (var_next) : NULL;
@@ -460,6 +466,69 @@ hdata_move (struct t_hdata *hdata, void *pointer, int count)
}
/*
+ * Searches for an element in list using expression.
+ *
+ * Returns pointer to element found, NULL if not found.
+ */
+
+void *
+hdata_search (struct t_hdata *hdata, void *pointer, const char *search, int move)
+{
+ char *result;
+ int rc;
+
+ if (!hdata || !pointer || !search || !search[0] || (move == 0))
+ return NULL;
+
+ /* clear or create hashtable with pointer for search */
+ if (hdata_search_pointers)
+ {
+ hashtable_remove_all (hdata_search_pointers);
+ }
+ else
+ {
+ hdata_search_pointers = 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)
+ {
+ hdata_search_extra_vars = hashtable_new (32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
+ }
+
+ while (pointer)
+ {
+ /* set pointer in hashtable (used for evaluating expression) */
+ hashtable_set (hdata_search_pointers, hdata->name, pointer);
+
+ /* evaluate expression */
+ result = eval_expression (search, hdata_search_pointers,
+ hdata_search_extra_vars);
+ rc = eval_is_true (result);
+ if (result)
+ free (result);
+ if (rc)
+ return pointer;
+
+ pointer = hdata_move (hdata, pointer, move);
+ }
+
+ return NULL;
+}
+
+/*
* Extracts index from name of a variable.
*
* A name can contain index with this format: "NNN|name" (where NNN is an
@@ -1000,11 +1069,13 @@ hdata_print_log_map_cb (void *data, struct t_hashtable *hashtable,
/* make C compiler happy */
(void) data;
(void) hashtable;
+ (void) key;
ptr_hdata = (struct t_hdata *)value;
log_printf ("");
- log_printf ("[hdata (addr:0x%lx, name:'%s')]", ptr_hdata, (const char *)key);
+ log_printf ("[hdata (addr:0x%lx)]", ptr_hdata);
+ log_printf (" name . . . . . . . . . : '%s'", ptr_hdata->name);
log_printf (" plugin . . . . . . . . : 0x%lx", ptr_hdata->plugin);
log_printf (" var_prev . . . . . . . : '%s'", ptr_hdata->var_prev);
log_printf (" var_next . . . . . . . : '%s'", ptr_hdata->var_next);
@@ -1055,4 +1126,16 @@ 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;
+ }
}
diff --git a/src/core/wee-hdata.h b/src/core/wee-hdata.h
index 43f43c971..cda479cab 100644
--- a/src/core/wee-hdata.h
+++ b/src/core/wee-hdata.h
@@ -38,6 +38,7 @@ struct t_hdata_var
struct t_hdata
{
+ char *name; /* name of hdata */
struct t_weechat_plugin *plugin; /* plugin which created this hdata */
/* (NULL if created by WeeChat) */
char *var_prev; /* name of var with pointer to */
@@ -98,6 +99,8 @@ extern void *hdata_get_list (struct t_hdata *hdata, const char *name);
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);
extern char hdata_char (struct t_hdata *hdata, void *pointer,
const char *name);
extern int hdata_integer (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 b01b31e50..8f6e99873 100644
--- a/src/plugins/guile/weechat-guile-api.c
+++ b/src/plugins/guile/weechat-guile-api.c
@@ -4264,6 +4264,25 @@ 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)
+{
+ char *result;
+ SCM return_value;
+
+ API_FUNC(1, "hdata_search", API_RETURN_EMPTY);
+ if (!scm_is_string (hdata) || !scm_is_string (pointer)
+ || !scm_is_string (search) || !scm_is_integer (move))
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ 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),
+ scm_to_int (move)));
+
+ API_RETURN_STRING_FREE(result);
+}
+
+SCM
weechat_guile_api_hdata_char (SCM hdata, SCM pointer, SCM name)
{
int value;
@@ -4732,6 +4751,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_char, 3);
API_DEF_FUNC(hdata_integer, 3);
API_DEF_FUNC(hdata_long, 3);
diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c
index e7554abe9..fb0069d34 100644
--- a/src/plugins/lua/weechat-lua-api.c
+++ b/src/plugins/lua/weechat-lua-api.c
@@ -4712,6 +4712,30 @@ weechat_lua_api_hdata_move (lua_State *L)
}
static int
+weechat_lua_api_hdata_search (lua_State *L)
+{
+ const char *hdata, *pointer, *search;
+ char *result;
+ int move;
+
+ API_FUNC(1, "hdata_search", API_RETURN_EMPTY);
+ if (lua_gettop (lua_current_interpreter) < 4)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ hdata = lua_tostring (lua_current_interpreter, -4);
+ pointer = lua_tostring (lua_current_interpreter, -3);
+ search = lua_tostring (lua_current_interpreter, -2);
+ move = lua_tonumber (lua_current_interpreter, -1);
+
+ result = API_PTR2STR(weechat_hdata_search (API_STR2PTR(hdata),
+ API_STR2PTR(pointer),
+ search,
+ move));
+
+ API_RETURN_STRING_FREE(result);
+}
+
+static int
weechat_lua_api_hdata_char (lua_State *L)
{
const char *hdata, *pointer, *name;
@@ -5208,6 +5232,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(hdata_get_list),
API_DEF_FUNC(hdata_check_pointer),
API_DEF_FUNC(hdata_move),
+ API_DEF_FUNC(hdata_search),
API_DEF_FUNC(hdata_char),
API_DEF_FUNC(hdata_integer),
API_DEF_FUNC(hdata_long),
diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c
index 3578e9f3f..11d3f1c8c 100644
--- a/src/plugins/perl/weechat-perl-api.c
+++ b/src/plugins/perl/weechat-perl-api.c
@@ -4462,6 +4462,29 @@ XS (XS_weechat_api_hdata_move)
API_RETURN_STRING_FREE(result);
}
+XS (XS_weechat_api_hdata_search)
+{
+ char *result, *hdata, *pointer, *search;
+ int move;
+ dXSARGS;
+
+ API_FUNC(1, "hdata_search", API_RETURN_EMPTY);
+ if (items < 4)
+ 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));
+
+ result = API_PTR2STR(weechat_hdata_search (API_STR2PTR(hdata),
+ API_STR2PTR(pointer),
+ search,
+ move));
+
+ API_RETURN_STRING_FREE(result);
+}
+
XS (XS_weechat_api_hdata_char)
{
char *hdata, *pointer, *name;
@@ -4965,6 +4988,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(hdata_get_list);
API_DEF_FUNC(hdata_check_pointer);
API_DEF_FUNC(hdata_move);
+ API_DEF_FUNC(hdata_search);
API_DEF_FUNC(hdata_char);
API_DEF_FUNC(hdata_integer);
API_DEF_FUNC(hdata_long);
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 207b89129..3ad99bd68 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -760,6 +760,7 @@ plugin_load (const char *filename, int argc, char **argv)
new_plugin->hdata_get_list = &hdata_get_list;
new_plugin->hdata_check_pointer = &hdata_check_pointer;
new_plugin->hdata_move = &hdata_move;
+ new_plugin->hdata_search = &hdata_search;
new_plugin->hdata_char = &hdata_char;
new_plugin->hdata_integer = &hdata_integer;
new_plugin->hdata_long = &hdata_long;
diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c
index 6eef2ac4f..e2d776d69 100644
--- a/src/plugins/python/weechat-python-api.c
+++ b/src/plugins/python/weechat-python-api.c
@@ -4632,6 +4632,29 @@ weechat_python_api_hdata_move (PyObject *self, PyObject *args)
}
static PyObject *
+weechat_python_api_hdata_search (PyObject *self, PyObject *args)
+{
+ char *result, *hdata, *pointer, *search;
+ int move;
+ PyObject *return_value;
+
+ API_FUNC(1, "hdata_search", API_RETURN_EMPTY);
+ hdata = NULL;
+ pointer = NULL;
+ search = NULL;
+ move = 0;
+ if (!PyArg_ParseTuple (args, "sssi", &hdata, &pointer, &search, &move))
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ result = API_PTR2STR(weechat_hdata_search (API_STR2PTR(hdata),
+ API_STR2PTR(pointer),
+ search,
+ move));
+
+ API_RETURN_STRING_FREE(result);
+}
+
+static PyObject *
weechat_python_api_hdata_char (PyObject *self, PyObject *args)
{
char *hdata, *pointer, *name;
@@ -5117,6 +5140,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(hdata_get_list),
API_DEF_FUNC(hdata_check_pointer),
API_DEF_FUNC(hdata_move),
+ API_DEF_FUNC(hdata_search),
API_DEF_FUNC(hdata_char),
API_DEF_FUNC(hdata_integer),
API_DEF_FUNC(hdata_long),
diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c
index aaefeaaf1..9888e5a93 100644
--- a/src/plugins/ruby/weechat-ruby-api.c
+++ b/src/plugins/ruby/weechat-ruby-api.c
@@ -5445,6 +5445,36 @@ 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)
+{
+ char *c_hdata, *c_pointer, *c_search, *result;
+ int c_move;
+ VALUE return_value;
+
+ API_FUNC(1, "hdata_search", API_RETURN_EMPTY);
+ if (NIL_P (hdata) || NIL_P (pointer) || NIL_P (search) || 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 (move, T_FIXNUM);
+
+ c_hdata = StringValuePtr (hdata);
+ c_pointer = StringValuePtr (pointer);
+ c_search = StringValuePtr (search);
+ c_move = FIX2INT (move);
+
+ result = API_PTR2STR(weechat_hdata_search (API_STR2PTR(c_hdata),
+ API_STR2PTR(c_pointer),
+ c_search,
+ c_move));
+
+ API_RETURN_STRING_FREE(result);
+}
+
+static VALUE
weechat_ruby_api_hdata_char (VALUE class, VALUE hdata, VALUE pointer,
VALUE name)
{
@@ -6053,6 +6083,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_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 ab6613fd6..451d9d5e9 100644
--- a/src/plugins/tcl/weechat-tcl-api.c
+++ b/src/plugins/tcl/weechat-tcl-api.c
@@ -5166,6 +5166,33 @@ weechat_tcl_api_hdata_move (ClientData clientData, Tcl_Interp *interp,
}
static int
+weechat_tcl_api_hdata_search (ClientData clientData, Tcl_Interp *interp,
+ int objc, Tcl_Obj *CONST objv[])
+{
+ Tcl_Obj *objp;
+ char *hdata, *pointer, *search, *result;
+ int i, move;
+
+ API_FUNC(1, "hdata_search", API_RETURN_EMPTY);
+ if (objc < 5)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ hdata = Tcl_GetStringFromObj (objv[1], &i);
+ pointer = Tcl_GetStringFromObj (objv[2], &i);
+ search = Tcl_GetStringFromObj (objv[3], &i);
+
+ if (Tcl_GetIntFromObj (interp, objv[4], &move) != TCL_OK)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ result = API_PTR2STR(weechat_hdata_search (API_STR2PTR(hdata),
+ API_STR2PTR(pointer),
+ search,
+ move));
+
+ API_RETURN_STRING_FREE(result);
+}
+
+static int
weechat_tcl_api_hdata_char (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
@@ -5802,6 +5829,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(hdata_get_list);
API_DEF_FUNC(hdata_check_pointer);
API_DEF_FUNC(hdata_move);
+ API_DEF_FUNC(hdata_search);
API_DEF_FUNC(hdata_char);
API_DEF_FUNC(hdata_integer);
API_DEF_FUNC(hdata_long);
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 429eeecc6..fb78fb40a 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -52,7 +52,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 "20121208-01"
+#define WEECHAT_PLUGIN_API_VERSION "20130421-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -877,6 +877,8 @@ struct t_weechat_plugin
int (*hdata_check_pointer) (struct t_hdata *hdata, void *list,
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);
char (*hdata_char) (struct t_hdata *hdata, void *pointer,
const char *name);
int (*hdata_integer) (struct t_hdata *hdata, void *pointer,
@@ -1674,6 +1676,8 @@ 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) \
+ weechat_plugin->hdata_search(__hdata, __pointer, __search, __move)
#define weechat_hdata_char(__hdata, __pointer, __name) \
weechat_plugin->hdata_char(__hdata, __pointer, __name)
#define weechat_hdata_integer(__hdata, __pointer, __name) \