summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-string.c42
-rw-r--r--src/core/wee-string.h2
-rw-r--r--src/plugins/guile/weechat-guile-api.c19
-rw-r--r--src/plugins/javascript/weechat-js-api.cpp19
-rw-r--r--src/plugins/lua/weechat-lua-api.c22
-rw-r--r--src/plugins/perl/weechat-perl-api.c19
-rw-r--r--src/plugins/php/weechat-php-api.c23
-rw-r--r--src/plugins/php/weechat-php-api.h1
-rw-r--r--src/plugins/php/weechat-php.c1
-rw-r--r--src/plugins/plugin-script-api.c29
-rw-r--r--src/plugins/plugin-script-api.h4
-rw-r--r--src/plugins/plugin.c1
-rw-r--r--src/plugins/python/weechat-python-api.c21
-rw-r--r--src/plugins/ruby/weechat-ruby-api.c28
-rw-r--r--src/plugins/tcl/weechat-tcl-api.c25
-rw-r--r--src/plugins/weechat-plugin.h7
16 files changed, 262 insertions, 1 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 5380ec8d4..04308a451 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -628,6 +628,48 @@ string_match (const char *string, const char *mask, int case_sensitive)
}
/*
+ * Checks if a string matches a list of masks. Negative masks are allowed
+ * with "!mask" to exclude this mask and have higher priority than standard
+ * masks.
+ *
+ * Each mask is compared with the function string_match.
+ *
+ * Example of masks to allow anything by default, but "toto" and "abc" are
+ * forbidden:
+ * "*", "!toto", "!abc"
+ *
+ * Returns:
+ * 1: string matches list of masks
+ * 0: string does not match list of masks
+ */
+
+int
+string_match_list (const char *string, const char **masks, int case_sensitive)
+{
+ int match, i;
+ const char *ptr_mask;
+
+ if (!string || !masks)
+ return 0;
+
+ match = 0;
+
+ for (i = 0; masks[i]; i++)
+ {
+ ptr_mask = (masks[i][0] == '!') ? masks[i] + 1 : masks[i];
+ if (string_match (string, ptr_mask, case_sensitive))
+ {
+ if (masks[i][0] == '!')
+ return 0;
+ else
+ match = 1;
+ }
+ }
+
+ return match;
+}
+
+/*
* Expands home in a path.
*
* Example: "~/file.txt" => "/home/xxx/file.txt"
diff --git a/src/core/wee-string.h b/src/core/wee-string.h
index dc84c6dc4..eddbf26ad 100644
--- a/src/core/wee-string.h
+++ b/src/core/wee-string.h
@@ -57,6 +57,8 @@ extern int string_strcmp_ignore_chars (const char *string1,
extern const char *string_strcasestr (const char *string, const char *search);
extern int string_match (const char *string, const char *mask,
int case_sensitive);
+extern int string_match_list (const char *string, const char **masks,
+ int case_sensitive);
extern char *string_replace (const char *string, const char *search,
const char *replace);
extern char *string_expand_home (const char *path);
diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c
index c49832bb1..29f8fbf78 100644
--- a/src/plugins/guile/weechat-guile-api.c
+++ b/src/plugins/guile/weechat-guile-api.c
@@ -351,6 +351,24 @@ weechat_guile_api_string_match (SCM string, SCM mask, SCM case_sensitive)
}
SCM
+weechat_guile_api_string_match_list (SCM string, SCM masks, SCM case_sensitive)
+{
+ int value;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (!scm_is_string (string) || !scm_is_string (masks)
+ || !scm_is_integer (case_sensitive))
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ value = plugin_script_api_string_match_list (weechat_guile_plugin,
+ API_SCM_TO_STRING(string),
+ API_SCM_TO_STRING(masks),
+ scm_to_int (case_sensitive));
+
+ API_RETURN_INT(value);
+}
+
+SCM
weechat_guile_api_string_has_highlight (SCM string, SCM highlight_words)
{
int value;
@@ -4855,6 +4873,7 @@ weechat_guile_api_module_init (void *data)
API_DEF_FUNC(ngettext, 3);
API_DEF_FUNC(strlen_screen, 1);
API_DEF_FUNC(string_match, 3);
+ API_DEF_FUNC(string_match_list, 3);
API_DEF_FUNC(string_has_highlight, 2);
API_DEF_FUNC(string_has_highlight_regex, 2);
API_DEF_FUNC(string_mask_to_regex, 1);
diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp
index a40f61d57..8f0032bac 100644
--- a/src/plugins/javascript/weechat-js-api.cpp
+++ b/src/plugins/javascript/weechat-js-api.cpp
@@ -305,6 +305,24 @@ API_FUNC(string_match)
API_RETURN_INT(value);
}
+API_FUNC(string_match_list)
+{
+ int value;
+
+ API_INIT_FUNC(1, "string_match_list", "ssi", API_RETURN_INT(0));
+
+ v8::String::Utf8Value string(args[0]);
+ v8::String::Utf8Value masks(args[1]);
+ int case_sensitive = args[2]->IntegerValue();
+
+ value = plugin_script_api_string_match_list (weechat_js_plugin,
+ *string,
+ *masks,
+ case_sensitive);
+
+ API_RETURN_INT(value);
+}
+
API_FUNC(string_has_highlight)
{
int value;
@@ -4806,6 +4824,7 @@ WeechatJsV8::loadLibs()
API_DEF_FUNC(ngettext);
API_DEF_FUNC(strlen_screen);
API_DEF_FUNC(string_match);
+ API_DEF_FUNC(string_match_list);
API_DEF_FUNC(string_has_highlight);
API_DEF_FUNC(string_has_highlight_regex);
API_DEF_FUNC(string_mask_to_regex);
diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c
index 4a943a9c0..a07709fa1 100644
--- a/src/plugins/lua/weechat-lua-api.c
+++ b/src/plugins/lua/weechat-lua-api.c
@@ -338,6 +338,27 @@ API_FUNC(string_match)
API_RETURN_INT(value);
}
+API_FUNC(string_match_list)
+{
+ const char *string, *masks;
+ int case_sensitive, value;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (lua_gettop (L) < 3)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ string = lua_tostring (L, -3);
+ masks = lua_tostring (L, -2);
+ case_sensitive = lua_tonumber (L, -1);
+
+ value = plugin_script_api_string_match_list (weechat_lua_plugin,
+ string,
+ masks,
+ case_sensitive);
+
+ API_RETURN_INT(value);
+}
+
API_FUNC(string_has_highlight)
{
const char *string, *highlight_words;
@@ -5154,6 +5175,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(ngettext),
API_DEF_FUNC(strlen_screen),
API_DEF_FUNC(string_match),
+ API_DEF_FUNC(string_match_list),
API_DEF_FUNC(string_has_highlight),
API_DEF_FUNC(string_has_highlight_regex),
API_DEF_FUNC(string_mask_to_regex),
diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c
index c026f5709..9192bbe97 100644
--- a/src/plugins/perl/weechat-perl-api.c
+++ b/src/plugins/perl/weechat-perl-api.c
@@ -309,6 +309,24 @@ API_FUNC(string_match)
API_RETURN_INT(value);
}
+API_FUNC(string_match_list)
+{
+ int value;
+ dXSARGS;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (items < 3)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ value = plugin_script_api_string_match_list (
+ weechat_perl_plugin,
+ SvPV_nolen (ST (0)), /* string */
+ SvPV_nolen (ST (1)), /* masks */
+ SvIV (ST (2))); /* case_sensitive */
+
+ API_RETURN_INT(value);
+}
+
API_FUNC(string_has_highlight)
{
int value;
@@ -5116,6 +5134,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(ngettext);
API_DEF_FUNC(strlen_screen);
API_DEF_FUNC(string_match);
+ API_DEF_FUNC(string_match_list);
API_DEF_FUNC(string_has_highlight);
API_DEF_FUNC(string_has_highlight_regex);
API_DEF_FUNC(string_mask_to_regex);
diff --git a/src/plugins/php/weechat-php-api.c b/src/plugins/php/weechat-php-api.c
index adad1123c..0f9e1a554 100644
--- a/src/plugins/php/weechat-php-api.c
+++ b/src/plugins/php/weechat-php-api.c
@@ -396,6 +396,29 @@ API_FUNC(string_match)
API_RETURN_INT(result);
}
+API_FUNC(string_match_list)
+{
+ zend_string *z_string, *z_masks;
+ zend_long z_case_sensitive;
+ int case_sensitive, result;
+ char *string, *masks;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSl", &z_string, &z_masks,
+ &z_case_sensitive) == FAILURE)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ string = ZSTR_VAL(z_string);
+ masks = ZSTR_VAL(z_masks);
+ case_sensitive = (int)z_case_sensitive;
+ result = plugin_script_api_string_match_list (weechat_php_plugin,
+ (const char *)string,
+ (const char *)masks,
+ case_sensitive);
+
+ API_RETURN_INT(result);
+}
+
API_FUNC(string_has_highlight)
{
zend_string *z_string, *z_highlight_words;
diff --git a/src/plugins/php/weechat-php-api.h b/src/plugins/php/weechat-php-api.h
index 81772e7b0..ca01f3f02 100644
--- a/src/plugins/php/weechat-php-api.h
+++ b/src/plugins/php/weechat-php-api.h
@@ -54,6 +54,7 @@ PHP_FUNCTION(weechat_gettext);
PHP_FUNCTION(weechat_ngettext);
PHP_FUNCTION(weechat_strlen_screen);
PHP_FUNCTION(weechat_string_match);
+PHP_FUNCTION(weechat_string_match_list);
PHP_FUNCTION(weechat_string_has_highlight);
PHP_FUNCTION(weechat_string_has_highlight_regex);
PHP_FUNCTION(weechat_string_mask_to_regex);
diff --git a/src/plugins/php/weechat-php.c b/src/plugins/php/weechat-php.c
index 0d37a9f29..f84e49f4f 100644
--- a/src/plugins/php/weechat-php.c
+++ b/src/plugins/php/weechat-php.c
@@ -108,6 +108,7 @@ const zend_function_entry weechat_functions[] = {
PHP_FE(weechat_ngettext, NULL)
PHP_FE(weechat_strlen_screen, NULL)
PHP_FE(weechat_string_match, NULL)
+ PHP_FE(weechat_string_match_list, NULL)
PHP_FE(weechat_string_has_highlight, NULL)
PHP_FE(weechat_string_has_highlight_regex, NULL)
PHP_FE(weechat_string_mask_to_regex, NULL)
diff --git a/src/plugins/plugin-script-api.c b/src/plugins/plugin-script-api.c
index 3caecdddc..bb797ced1 100644
--- a/src/plugins/plugin-script-api.c
+++ b/src/plugins/plugin-script-api.c
@@ -48,6 +48,35 @@ plugin_script_api_charset_set (struct t_plugin_script *script,
}
/*
+ * Checks if a string matches a list of masks.
+ *
+ * Returns:
+ * 1: string matches list of masks
+ * 0: string does not match list of masks
+ */
+
+int
+plugin_script_api_string_match_list (struct t_weechat_plugin *weechat_plugin,
+ const char *string, const char *masks,
+ int case_sensitive)
+{
+ char **list_masks;
+ int match;
+
+ list_masks = (masks && masks[0]) ?
+ weechat_string_split (masks, ",", 0, 0, NULL) : NULL;
+
+ match = weechat_string_match_list (string,
+ (const char **)list_masks,
+ case_sensitive);
+
+ if (list_masks)
+ weechat_string_free_split (list_masks);
+
+ return match;
+}
+
+/*
* Creates a new configuration file.
*
* Returns pointer to new configuration file, NULL if error.
diff --git a/src/plugins/plugin-script-api.h b/src/plugins/plugin-script-api.h
index b103961fc..ce7bd285a 100644
--- a/src/plugins/plugin-script-api.h
+++ b/src/plugins/plugin-script-api.h
@@ -25,6 +25,10 @@
extern void plugin_script_api_charset_set (struct t_plugin_script *script,
const char *charset);
+extern int plugin_script_api_string_match_list (struct t_weechat_plugin *weechat_plugin,
+ const char *string,
+ const char *masks,
+ int case_sensitive);
extern struct t_config_file *plugin_script_api_config_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *name,
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index fd76c45ed..d8e82ef25 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -616,6 +616,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->strcasestr = &string_strcasestr;
new_plugin->strlen_screen = &gui_chat_strlen_screen;
new_plugin->string_match = &string_match;
+ new_plugin->string_match_list = &string_match_list;
new_plugin->string_replace = &string_replace;
new_plugin->string_expand_home = &string_expand_home;
new_plugin->string_eval_path_home = &string_eval_path_home;
diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c
index ab829fa02..f27d1e169 100644
--- a/src/plugins/python/weechat-python-api.c
+++ b/src/plugins/python/weechat-python-api.c
@@ -288,6 +288,26 @@ API_FUNC(string_match)
API_RETURN_INT(value);
}
+API_FUNC(string_match_list)
+{
+ char *string, *masks;
+ int case_sensitive, value;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ string = NULL;
+ masks = NULL;
+ case_sensitive = 0;
+ if (!PyArg_ParseTuple (args, "ssi", &string, &masks, &case_sensitive))
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ value = plugin_script_api_string_match_list (weechat_python_plugin,
+ string,
+ masks,
+ case_sensitive);
+
+ API_RETURN_INT(value);
+}
+
API_FUNC(string_has_highlight)
{
char *string, *highlight_words;
@@ -5064,6 +5084,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(ngettext),
API_DEF_FUNC(strlen_screen),
API_DEF_FUNC(string_match),
+ API_DEF_FUNC(string_match_list),
API_DEF_FUNC(string_has_highlight),
API_DEF_FUNC(string_has_highlight_regex),
API_DEF_FUNC(string_mask_to_regex),
diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c
index 21b22b659..dbd7ce278 100644
--- a/src/plugins/ruby/weechat-ruby-api.c
+++ b/src/plugins/ruby/weechat-ruby-api.c
@@ -340,6 +340,33 @@ weechat_ruby_api_string_match (VALUE class, VALUE string, VALUE mask,
}
static VALUE
+weechat_ruby_api_string_match_list (VALUE class, VALUE string, VALUE masks,
+ VALUE case_sensitive)
+{
+ char *c_string, *c_masks;
+ int c_case_sensitive, value;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (NIL_P (string) || NIL_P (masks) || NIL_P (case_sensitive))
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ Check_Type (string, T_STRING);
+ Check_Type (masks, T_STRING);
+ Check_Type (case_sensitive, T_FIXNUM);
+
+ c_string = StringValuePtr (string);
+ c_masks = StringValuePtr (masks);
+ c_case_sensitive = FIX2INT (case_sensitive);
+
+ value = plugin_script_api_string_match_list (weechat_ruby_plugin,
+ c_string,
+ c_masks,
+ c_case_sensitive);
+
+ API_RETURN_INT(value);
+}
+
+static VALUE
weechat_ruby_api_string_has_highlight (VALUE class, VALUE string,
VALUE highlight_words)
{
@@ -6218,6 +6245,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
API_DEF_FUNC(ngettext, 3);
API_DEF_FUNC(strlen_screen, 1);
API_DEF_FUNC(string_match, 3);
+ API_DEF_FUNC(string_match_list, 3);
API_DEF_FUNC(string_has_highlight, 2);
API_DEF_FUNC(string_has_highlight_regex, 2);
API_DEF_FUNC(string_mask_to_regex, 1);
diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c
index ed63f3494..527380e48 100644
--- a/src/plugins/tcl/weechat-tcl-api.c
+++ b/src/plugins/tcl/weechat-tcl-api.c
@@ -437,6 +437,30 @@ API_FUNC(string_match)
API_RETURN_INT(result);
}
+API_FUNC(string_match_list)
+{
+ Tcl_Obj *objp;
+ char *string, *masks;
+ int case_sensitive, result, i;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (objc < 4)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ string = Tcl_GetStringFromObj (objv[1], &i);
+ masks = Tcl_GetStringFromObj (objv[2], &i);
+
+ if (Tcl_GetIntFromObj (interp, objv[3], &case_sensitive) != TCL_OK)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ result = plugin_script_api_string_match_list (weechat_tcl_plugin,
+ string,
+ masks,
+ case_sensitive);
+
+ API_RETURN_INT(result);
+}
+
API_FUNC(string_has_highlight)
{
Tcl_Obj *objp;
@@ -5586,6 +5610,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(ngettext);
API_DEF_FUNC(strlen_screen);
API_DEF_FUNC(string_match);
+ API_DEF_FUNC(string_match_list);
API_DEF_FUNC(string_has_highlight);
API_DEF_FUNC(string_has_highlight_regex);
API_DEF_FUNC(string_mask_to_regex);
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index e93c665c9..da4eda6ba 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -67,7 +67,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 "20190219-01"
+#define WEECHAT_PLUGIN_API_VERSION "20190226-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -289,6 +289,8 @@ struct t_weechat_plugin
int (*strlen_screen) (const char *string);
int (*string_match) (const char *string, const char *mask,
int case_sensitive);
+ int (*string_match_list) (const char *string, const char **masks,
+ int case_sensitive);
char *(*string_replace) (const char *string, const char *search,
const char *replace);
char *(*string_expand_home) (const char *path);
@@ -1172,6 +1174,9 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
(weechat_plugin->strlen_screen)(__string)
#define weechat_string_match(__string, __mask, __case_sensitive) \
(weechat_plugin->string_match)(__string, __mask, __case_sensitive)
+#define weechat_string_match_list(__string, __masks, __case_sensitive) \
+ (weechat_plugin->string_match_list)(__string, __masks, \
+ __case_sensitive)
#define weechat_string_replace(__string, __search, __replace) \
(weechat_plugin->string_replace)(__string, __search, __replace)
#define weechat_string_expand_home(__path) \