summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-11-25 21:28:14 +0100
committerSebastien Helleu <flashcode@flashtux.org>2010-11-25 21:28:14 +0100
commite92079cfe9c2ad89cf4c9f7d2ce146f4393cb9f4 (patch)
tree09343bd04a8c939351237d3babdcf0b05f0a0eb4 /src/plugins
parent8b9abab711ccdccceafcbea351b8bef0d23b8ecd (diff)
downloadweechat-e92079cfe9c2ad89cf4c9f7d2ce146f4393cb9f4.zip
Add new option weechat.look.highlight_regex and function string_has_highlight_regex in plugin API (task #10321)
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/irc/CMakeLists.txt3
-rw-r--r--src/plugins/plugin.c1
-rw-r--r--src/plugins/scripts/lua/weechat-lua-api.c40
-rw-r--r--src/plugins/scripts/perl/weechat-perl-api.c34
-rw-r--r--src/plugins/scripts/python/weechat-python-api.c38
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby-api.c42
-rw-r--r--src/plugins/scripts/tcl/weechat-tcl-api.c42
-rw-r--r--src/plugins/weechat-plugin.h5
8 files changed, 201 insertions, 4 deletions
diff --git a/src/plugins/irc/CMakeLists.txt b/src/plugins/irc/CMakeLists.txt
index 58774f4b5..9488b319a 100644
--- a/src/plugins/irc/CMakeLists.txt
+++ b/src/plugins/irc/CMakeLists.txt
@@ -45,9 +45,6 @@ irc-server.c irc-server.h
irc-upgrade.c irc-upgrade.h)
SET_TARGET_PROPERTIES(irc PROPERTIES PREFIX "")
-CHECK_INCLUDE_FILES("regex.h" HAVE_REGEX_H)
-CHECK_FUNCTION_EXISTS(regexec HAVE_REGEXEC)
-
SET (LINK_LIBS)
IF(GNUTLS_FOUND)
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 3c8070366..3fbda4721 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -465,6 +465,7 @@ plugin_load (const char *filename)
new_plugin->string_remove_quotes = &string_remove_quotes;
new_plugin->string_strip = &string_strip;
new_plugin->string_has_highlight = &string_has_highlight;
+ new_plugin->string_has_highlight_regex = &string_has_highlight_regex;
new_plugin->string_mask_to_regex = &string_mask_to_regex;
new_plugin->string_split = &string_split;
new_plugin->string_free_split = &string_free_split;
diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c
index 5bf9f15d5..226eb86ba 100644
--- a/src/plugins/scripts/lua/weechat-lua-api.c
+++ b/src/plugins/scripts/lua/weechat-lua-api.c
@@ -423,6 +423,45 @@ weechat_lua_api_string_has_highlight (lua_State *L)
}
/*
+ * weechat_lua_api_string_has_highlight_regex: return 1 if string contains a
+ * highlight (using regular
+ * expression)
+ * return 0 if no highlight is
+ * found in string
+ */
+
+static int
+weechat_lua_api_string_has_highlight_regex (lua_State *L)
+{
+ const char *string, *regex;
+ int n, value;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script || !lua_current_script->name)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "string_has_highlight_regex");
+ LUA_RETURN_INT(0);
+ }
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "string_has_highlight_regex");
+ LUA_RETURN_INT(0);
+ }
+
+ string = lua_tostring (lua_current_interpreter, -2);
+ regex = lua_tostring (lua_current_interpreter, -1);
+
+ value = weechat_string_has_highlight_regex (string, regex);
+
+ LUA_RETURN_INT(value);
+}
+
+/*
* weechat_lua_api_string_mask_to_regex: convert a mask (string with only
* "*" as wildcard) to a regex, paying
* attention to special chars in a
@@ -7562,6 +7601,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "ngettext", &weechat_lua_api_ngettext },
{ "string_match", &weechat_lua_api_string_match },
{ "string_has_highlight", &weechat_lua_api_string_has_highlight },
+ { "string_has_highlight_regex", &weechat_lua_api_string_has_highlight_regex },
{ "string_mask_to_regex", &weechat_lua_api_string_mask_to_regex },
{ "string_remove_color", &weechat_lua_api_string_remove_color },
{ "string_is_command_char", &weechat_lua_api_string_is_command_char },
diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c
index 8db134118..273661e9c 100644
--- a/src/plugins/scripts/perl/weechat-perl-api.c
+++ b/src/plugins/scripts/perl/weechat-perl-api.c
@@ -388,6 +388,39 @@ XS (XS_weechat_api_string_has_highlight)
}
/*
+ * weechat::string_has_highlight_regex: return 1 if string contains a highlight
+ * (using regular expression)
+ * return 0 if no highlight is found in
+ * string
+ */
+
+XS (XS_weechat_api_string_has_highlight_regex)
+{
+ int value;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script || !perl_current_script->name)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "string_has_highlight_regex");
+ PERL_RETURN_INT(0);
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "string_has_highlight_regex");
+ PERL_RETURN_INT(0);
+ }
+
+ value = weechat_string_has_highlight_regex (SvPV (ST (0), PL_na), /* string */
+ SvPV (ST (1), PL_na)); /* regex */
+
+ PERL_RETURN_INT(value);
+}
+
+/*
* weechat::string_mask_to_regex: convert a mask (string with only "*" as
* wildcard) to a regex, paying attention to
* special chars in a regex
@@ -6509,6 +6542,7 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::ngettext", XS_weechat_api_ngettext, "weechat");
newXS ("weechat::string_match", XS_weechat_api_string_match, "weechat");
newXS ("weechat::string_has_highlight", XS_weechat_api_string_has_highlight, "weechat");
+ newXS ("weechat::string_has_highlight_regex", XS_weechat_api_string_has_highlight_regex, "weechat");
newXS ("weechat::string_mask_to_regex", XS_weechat_api_string_mask_to_regex, "weechat");
newXS ("weechat::string_remove_color", XS_weechat_api_string_remove_color, "weechat");
newXS ("weechat::string_is_command_char", XS_weechat_api_string_is_command_char, "weechat");
diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c
index 16ff35db0..6429ad383 100644
--- a/src/plugins/scripts/python/weechat-python-api.c
+++ b/src/plugins/scripts/python/weechat-python-api.c
@@ -396,6 +396,43 @@ weechat_python_api_string_has_highlight (PyObject *self, PyObject *args)
}
/*
+ * weechat_python_api_string_has_highlight_regex: return 1 if string contains a
+ * highlight (using regular
+ * expression)
+ * return 0 if no highlight is
+ * found in string
+ */
+
+static PyObject *
+weechat_python_api_string_has_highlight_regex (PyObject *self, PyObject *args)
+{
+ char *string, *regex;
+ int value;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script || !python_current_script->name)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "string_has_highlight_regex");
+ PYTHON_RETURN_INT(0);
+ }
+
+ string = NULL;
+ regex = NULL;
+
+ if (!PyArg_ParseTuple (args, "ss", &string, &regex))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "string_has_highlight_regex");
+ PYTHON_RETURN_INT(0);
+ }
+
+ value = weechat_string_has_highlight_regex (string, regex);
+
+ PYTHON_RETURN_INT(value);
+}
+
+/*
* weechat_python_api_string_mask_to_regex: convert a mask (string with only
* "*" as wildcard) to a regex, paying
* attention to special chars in a
@@ -6838,6 +6875,7 @@ PyMethodDef weechat_python_funcs[] =
{ "ngettext", &weechat_python_api_ngettext, METH_VARARGS, "" },
{ "string_match", &weechat_python_api_string_match, METH_VARARGS, "" },
{ "string_has_highlight", &weechat_python_api_string_has_highlight, METH_VARARGS, "" },
+ { "string_has_highlight_regex", &weechat_python_api_string_has_highlight_regex, METH_VARARGS, "" },
{ "string_mask_to_regex", &weechat_python_api_string_mask_to_regex, METH_VARARGS, "" },
{ "string_remove_color", &weechat_python_api_string_remove_color, METH_VARARGS, "" },
{ "string_is_command_char", &weechat_python_api_string_is_command_char, METH_VARARGS, "" },
diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c
index 78fdad487..33516526a 100644
--- a/src/plugins/scripts/ruby/weechat-ruby-api.c
+++ b/src/plugins/scripts/ruby/weechat-ruby-api.c
@@ -431,6 +431,47 @@ weechat_ruby_api_string_has_highlight (VALUE class, VALUE string,
}
/*
+ * weechat_ruby_api_string_has_highlight_regex: return 1 if string contains a
+ * highlight (using regular
+ * expression)
+ * return 0 if no highlight is
+ * found in string
+ */
+
+static VALUE
+weechat_ruby_api_string_has_highlight_regex (VALUE class, VALUE string,
+ VALUE regex)
+{
+ char *c_string, *c_regex;
+ int value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script || !ruby_current_script->name)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "string_has_highlight_regex");
+ RUBY_RETURN_INT(0);
+ }
+
+ if (NIL_P (string) || NIL_P (regex))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "string_has_highlight_regex");
+ RUBY_RETURN_INT(0);
+ }
+
+ Check_Type (string, T_STRING);
+ Check_Type (regex, T_STRING);
+
+ c_string = StringValuePtr (string);
+ c_regex = StringValuePtr (regex);
+
+ value = weechat_string_has_highlight_regex (c_string, c_regex);
+
+ RUBY_RETURN_INT(value);
+}
+
+/*
* weechat_ruby_api_string_mask_to_regex: convert a mask (string with only
* "*" as wildcard) to a regex, paying
* attention to special chars in a
@@ -7494,6 +7535,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "ngettext", &weechat_ruby_api_ngettext, 3);
rb_define_module_function (ruby_mWeechat, "string_match", &weechat_ruby_api_string_match, 3);
rb_define_module_function (ruby_mWeechat, "string_has_highlight", &weechat_ruby_api_string_has_highlight, 2);
+ rb_define_module_function (ruby_mWeechat, "string_has_highlight_regex", &weechat_ruby_api_string_has_highlight_regex, 2);
rb_define_module_function (ruby_mWeechat, "string_mask_to_regex", &weechat_ruby_api_string_mask_to_regex, 1);
rb_define_module_function (ruby_mWeechat, "string_remove_color", &weechat_ruby_api_string_remove_color, 2);
rb_define_module_function (ruby_mWeechat, "string_is_command_char", &weechat_ruby_api_string_is_command_char, 1);
diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c
index 196850a0c..581b5499b 100644
--- a/src/plugins/scripts/tcl/weechat-tcl-api.c
+++ b/src/plugins/scripts/tcl/weechat-tcl-api.c
@@ -531,6 +531,46 @@ weechat_tcl_api_string_has_highlight (ClientData clientData,
}
/*
+ * weechat_tcl_api_string_has_highlight_regex: return 1 if string contains a
+ * highlight (using a regular
+ * expression)
+ * return 0 if no highlight is
+ * found in string
+ */
+
+static int
+weechat_tcl_api_string_has_highlight_regex (ClientData clientData,
+ Tcl_Interp *interp,
+ int objc, Tcl_Obj *CONST objv[])
+{
+ Tcl_Obj* objp;
+ char *string, *regex;
+ int result, i;
+
+ /* make C compiler happy */
+ (void) clientData;
+
+ if (!tcl_current_script || !tcl_current_script->name)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "string_has_highlight_regex");
+ TCL_RETURN_INT(0);
+ }
+
+ if (objc < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "string_has_highlight_regex");
+ TCL_RETURN_INT(0);
+ }
+
+ string = Tcl_GetStringFromObj (objv[1], &i);
+ regex = Tcl_GetStringFromObj (objv[2], &i);
+
+ result = weechat_string_has_highlight_regex (string, regex);
+
+ TCL_RETURN_INT(result);
+}
+
+/*
* weechat_tcl_api_string_mask_to_regex: convert a mask (string with only
* "*" as wildcard) to a regex, paying
* attention to special chars in a
@@ -7343,6 +7383,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
weechat_tcl_api_string_match, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::string_has_highlight",
weechat_tcl_api_string_has_highlight, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
+ Tcl_CreateObjCommand (interp, "weechat::string_has_highlight_regex",
+ weechat_tcl_api_string_has_highlight_regex, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::string_mask_to_regex",
weechat_tcl_api_string_mask_to_regex, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::string_remove_color",
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 3e41167f1..4f846694a 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -45,7 +45,7 @@ struct timeval;
*/
/* API version (used to check that plugin has same API and can be loaded) */
-#define WEECHAT_PLUGIN_API_VERSION "20101110-01"
+#define WEECHAT_PLUGIN_API_VERSION "20101125-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -180,6 +180,7 @@ struct t_weechat_plugin
const char *chars);
int (*string_has_highlight) (const char *string,
const char *highlight_words);
+ int (*string_has_highlight_regex) (const char *string, const char *regex);
char *(*string_mask_to_regex) (const char *mask);
char **(*string_split) (const char *string, const char *separators,
int keep_eol, int num_items_max, int *num_items);
@@ -800,6 +801,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->string_strip(__string, __left, __right, __chars)
#define weechat_string_has_highlight(__string, __highlight_words) \
weechat_plugin->string_has_highlight(__string, __highlight_words)
+#define weechat_string_has_highlight_regex(__string, __regex) \
+ weechat_plugin->string_has_highlight_regex(__string, __regex)
#define weechat_string_mask_to_regex(__mask) \
weechat_plugin->string_mask_to_regex(__mask)
#define weechat_string_split(__string, __separator, __eol, __max, \