mirror of
https://github.com/irssi/irssi.git
synced 2026-08-22 10:02:22 +02:00
Add -expando flag, allow case-sensitive regexp matching
This commit is contained in:
parent
b97ebe46bf
commit
f6c589b88b
2 changed files with 28 additions and 19 deletions
|
|
@ -37,6 +37,7 @@
|
|||
#include "printtext.h"
|
||||
#include "formats.h"
|
||||
#include "special-vars.h"
|
||||
#include "window-items.h"
|
||||
|
||||
static NICKMATCH_REC *nickmatch;
|
||||
static int never_hilight_level, default_hilight_level;
|
||||
|
|
@ -80,6 +81,7 @@ static void hilight_add_config(HILIGHT_REC *rec)
|
|||
if (rec->nickmask) iconfig_node_set_bool(node, "mask", TRUE);
|
||||
if (rec->fullword) iconfig_node_set_bool(node, "fullword", TRUE);
|
||||
if (rec->regexp) iconfig_node_set_bool(node, "regexp", TRUE);
|
||||
if (rec->expando) iconfig_node_set_bool(node, "expando", TRUE);
|
||||
if (rec->case_sensitive) iconfig_node_set_bool(node, "matchcase", TRUE);
|
||||
if (rec->servertag) iconfig_node_set_str(node, "servertag", rec->servertag);
|
||||
|
||||
|
|
@ -191,40 +193,43 @@ static HILIGHT_REC *hilight_find(const char *text, char **channels)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean hilight_match_text(HILIGHT_REC *rec, SERVER_REC *server, const char *text,
|
||||
static gboolean hilight_match_text(HILIGHT_REC *rec, SERVER_REC *server, const char *channel, const char *text,
|
||||
int *match_beg, int *match_end)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
WI_ITEM_REC *witem = window_item_find(server, channel);
|
||||
char *pattern = rec->expando ? (parse_special_string(rec->regexp ? g_regex_get_pattern(rec->preg) : rec->text, server, witem, "", NULL, 0)) :
|
||||
rec->text;
|
||||
|
||||
if (pattern == NULL || strlen(pattern) == 0)
|
||||
return FALSE;
|
||||
|
||||
if (rec->regexp) {
|
||||
if (rec->preg != NULL) {
|
||||
MatchInfo *match;
|
||||
i_regex_match(rec->preg, text, 0, &match);
|
||||
GRegex *regex = i_regex_new(pattern, G_REGEX_OPTIMIZE | (rec->case_sensitive ? 0 : G_REGEX_CASELESS), 0, NULL);
|
||||
i_regex_match(regex, text, 0, &match);
|
||||
|
||||
if (i_match_info_matches(match))
|
||||
ret = i_match_info_fetch_pos(match, 0, match_beg, match_end);
|
||||
|
||||
i_match_info_free(match);
|
||||
}
|
||||
i_regex_unref(regex);
|
||||
} else {
|
||||
char *match;
|
||||
char *str = parse_special_string(rec->text, server, NULL, "", NULL, 0);
|
||||
|
||||
if (g_strcmp0(str, "") == 0) return FALSE;
|
||||
|
||||
if (rec->case_sensitive) {
|
||||
match = rec->fullword ?
|
||||
strstr_full(text, str) :
|
||||
strstr(text, str);
|
||||
strstr_full(text, pattern) :
|
||||
strstr(text, pattern);
|
||||
} else {
|
||||
match = rec->fullword ?
|
||||
stristr_full(text, str) :
|
||||
stristr(text, str);
|
||||
stristr_full(text, pattern) :
|
||||
stristr(text, pattern);
|
||||
}
|
||||
if (match != NULL) {
|
||||
if (match_beg != NULL && match_end != NULL) {
|
||||
*match_beg = (int) (match-text);
|
||||
*match_end = *match_beg + strlen(str);
|
||||
*match_end = *match_beg + strlen(pattern);
|
||||
}
|
||||
ret = TRUE;
|
||||
}
|
||||
|
|
@ -278,7 +283,7 @@ HILIGHT_REC *hilight_match(SERVER_REC *server, const char *channel,
|
|||
hilight_match_channel(rec, channel) &&
|
||||
(rec->servertag == NULL ||
|
||||
(server != NULL && g_ascii_strcasecmp(rec->servertag, server->tag) == 0)) &&
|
||||
hilight_match_text(rec, server, str, match_beg, match_end))
|
||||
hilight_match_text(rec, server, channel, str, match_beg, match_end))
|
||||
return rec;
|
||||
}
|
||||
|
||||
|
|
@ -472,6 +477,7 @@ static void read_hilight_config(void)
|
|||
rec->nickmask = config_node_get_bool(node, "mask", FALSE);
|
||||
rec->fullword = config_node_get_bool(node, "fullword", FALSE);
|
||||
rec->regexp = config_node_get_bool(node, "regexp", FALSE);
|
||||
rec->expando = config_node_get_bool(node, "expando", FALSE);
|
||||
servertag = config_node_get_str(node, "servertag", NULL);
|
||||
rec->servertag = servertag == NULL || *servertag == '\0' ? NULL :
|
||||
g_strdup(servertag);
|
||||
|
|
@ -502,6 +508,7 @@ static void hilight_print(int index, HILIGHT_REC *rec)
|
|||
if (rec->nickmask) g_string_append(options, "-mask ");
|
||||
if (rec->fullword) g_string_append(options, "-full ");
|
||||
if (rec->case_sensitive) g_string_append(options, "-matchcase ");
|
||||
if (rec->expando) g_string_append(options, "-expando ");
|
||||
if (rec->regexp) {
|
||||
g_string_append(options, "-regexp ");
|
||||
if (rec->preg == NULL)
|
||||
|
|
@ -549,7 +556,7 @@ static void cmd_hilight_show(void)
|
|||
}
|
||||
|
||||
/* SYNTAX: HILIGHT [-nick | -word | -line] [-mask | -full | -matchcase | -regexp]
|
||||
[-color <color>] [-actcolor <color>] [-level <level>]
|
||||
[-expando] [-color <color>] [-actcolor <color>] [-level <level>]
|
||||
[-network <network>] [-channels <channels>] <text> */
|
||||
static void cmd_hilight(const char *data)
|
||||
{
|
||||
|
|
@ -616,6 +623,7 @@ static void cmd_hilight(const char *data)
|
|||
rec->nickmask = g_hash_table_lookup(optlist, "mask") != NULL;
|
||||
rec->fullword = g_hash_table_lookup(optlist, "full") != NULL;
|
||||
rec->regexp = g_hash_table_lookup(optlist, "regexp") != NULL;
|
||||
rec->expando = g_hash_table_lookup(optlist, "expando") != NULL;
|
||||
rec->case_sensitive = g_hash_table_lookup(optlist, "matchcase") != NULL;
|
||||
|
||||
if (colorarg != NULL) {
|
||||
|
|
@ -723,7 +731,7 @@ void hilight_text_init(void)
|
|||
|
||||
command_bind("hilight", NULL, (SIGNAL_FUNC) cmd_hilight);
|
||||
command_bind("dehilight", NULL, (SIGNAL_FUNC) cmd_dehilight);
|
||||
command_set_options("hilight", "-color -actcolor -level -priority -network -channels nick word line mask full regexp matchcase");
|
||||
command_set_options("hilight", "-color -actcolor -level -priority -network -channels nick word line mask full regexp matchcase expando");
|
||||
}
|
||||
|
||||
void hilight_text_deinit(void)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ struct _HILIGHT_REC {
|
|||
unsigned int nick:1; /* hilight only nick if possible */
|
||||
unsigned int word:1; /* hilight only word, not full line */
|
||||
|
||||
unsigned int expando:1; /* `text' contains expandos */
|
||||
unsigned int nickmask:1; /* `text' is a nick mask */
|
||||
unsigned int fullword:1; /* match `text' only for full words */
|
||||
unsigned int regexp:1; /* `text' is a regular expression */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue