From e92079cfe9c2ad89cf4c9f7d2ce146f4393cb9f4 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Thu, 25 Nov 2010 21:28:14 +0100 Subject: Add new option weechat.look.highlight_regex and function string_has_highlight_regex in plugin API (task #10321) --- src/plugins/scripts/tcl/weechat-tcl-api.c | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/plugins/scripts/tcl/weechat-tcl-api.c') 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 @@ -530,6 +530,46 @@ weechat_tcl_api_string_has_highlight (ClientData clientData, TCL_RETURN_INT(result); } +/* + * 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 @@ -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", -- cgit v1.2.3