diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2014-02-13 18:20:00 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2014-02-13 18:20:00 +0100 |
commit | a7dbaf8162e8cc028537262de8418a1d06f2c319 (patch) | |
tree | c2de0e66606994a413058b2a165cdbe9de5393c2 /src | |
parent | d74259303f3dbb0985514fe6ad4cb7e154c738cb (diff) | |
download | weechat-a7dbaf8162e8cc028537262de8418a1d06f2c319.zip |
trigger: evaluate regex replacement on execution of trigger (and not when creating the trigger)
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/trigger/trigger-callback.c | 62 | ||||
-rw-r--r-- | src/plugins/trigger/trigger.c | 10 | ||||
-rw-r--r-- | src/plugins/trigger/trigger.h | 1 |
3 files changed, 35 insertions, 38 deletions
diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c index 6dc197030..2910f3a6e 100644 --- a/src/plugins/trigger/trigger-callback.c +++ b/src/plugins/trigger/trigger-callback.c @@ -157,9 +157,10 @@ trigger_callback_check_conditions (struct t_trigger *trigger, void trigger_callback_replace_regex (struct t_trigger *trigger, + struct t_hashtable *pointers, struct t_hashtable *extra_vars) { - char *value; + char *value, *replace_eval; const char *ptr_key, *ptr_value; int i; @@ -198,33 +199,40 @@ trigger_callback_replace_regex (struct t_trigger *trigger, continue; } - value = weechat_string_replace_regex (ptr_value, - trigger->regex[i].regex, - trigger->regex[i].replace_eval, - '$'); - if (!value) - continue; - - /* display debug info on trigger buffer */ - if (trigger_buffer) + replace_eval = weechat_string_eval_expression (trigger->regex[i].replace, + pointers, + extra_vars, + NULL); + if (replace_eval) { - weechat_printf_tags (trigger_buffer, "no_trigger", - "\t regex %d %s(%s%s%s)%s: %s\"%s%s%s\"", - i + 1, - weechat_color ("chat_delimiters"), - weechat_color ("reset"), - ptr_key, - weechat_color ("chat_delimiters"), - weechat_color ("reset"), - weechat_color ("chat_delimiters"), - weechat_color ("reset"), - value, - weechat_color ("chat_delimiters")); + value = weechat_string_replace_regex (ptr_value, + trigger->regex[i].regex, + replace_eval, + '$'); + if (value) + { + /* display debug info on trigger buffer */ + if (trigger_buffer) + { + weechat_printf_tags (trigger_buffer, "no_trigger", + "\t regex %d %s(%s%s%s)%s: " + "%s\"%s%s%s\"", + i + 1, + weechat_color ("chat_delimiters"), + weechat_color ("reset"), + ptr_key, + weechat_color ("chat_delimiters"), + weechat_color ("reset"), + weechat_color ("chat_delimiters"), + weechat_color ("reset"), + value, + weechat_color ("chat_delimiters")); + } + weechat_hashtable_set (extra_vars, ptr_key, value); + free (value); + } + free (replace_eval); } - - weechat_hashtable_set (extra_vars, ptr_key, value); - - free (value); } } @@ -307,7 +315,7 @@ trigger_callback_execute (struct t_trigger *trigger, if (trigger_callback_check_conditions (trigger, pointers, extra_vars)) { /* replace text with regex */ - trigger_callback_replace_regex (trigger, extra_vars); + trigger_callback_replace_regex (trigger, pointers, extra_vars); /* execute command(s) */ trigger_callback_run_command (trigger, buffer, pointers, extra_vars); diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c index a6c4fc97b..b9bc1bbef 100644 --- a/src/plugins/trigger/trigger.c +++ b/src/plugins/trigger/trigger.c @@ -466,8 +466,6 @@ trigger_free_regex (int *regex_count, struct t_trigger_regex **regex) } if ((*regex)[i].replace) free ((*regex)[i].replace); - if ((*regex)[i].replace_eval) - free ((*regex)[i].replace_eval); } free (*regex); *regex = NULL; @@ -556,7 +554,6 @@ trigger_split_regex (const char *trigger_name, const char *str_regex, (*regex)[index].str_regex = NULL; (*regex)[index].regex = NULL; (*regex)[index].replace = NULL; - (*regex)[index].replace_eval = NULL; /* set string with regex */ (*regex)[index].str_regex = weechat_strndup (ptr_regex, @@ -588,11 +585,6 @@ trigger_split_regex (const char *trigger_name, const char *str_regex, strdup (pos_replace + length_delimiter); if (!(*regex)[index].replace) goto memory_error; - (*regex)[index].replace_eval = - weechat_string_eval_expression ((*regex)[index].replace, - NULL, NULL, NULL); - if (!(*regex)[index].replace_eval) - goto memory_error; if (!pos_replace_end) break; @@ -1077,8 +1069,6 @@ trigger_print_log () i, ptr_trigger->regex[i].regex); weechat_log_printf (" regex[%03d].replace. . . : '%s'", i, ptr_trigger->regex[i].replace); - weechat_log_printf (" regex[%03d].replace_eval : '%s'", - i, ptr_trigger->regex[i].replace_eval); } weechat_log_printf (" commands_count. . . . . : %d", ptr_trigger->commands_count); weechat_log_printf (" commands. . . . . . . . : 0x%lx", ptr_trigger->commands); diff --git a/src/plugins/trigger/trigger.h b/src/plugins/trigger/trigger.h index bd546cb2d..978947d04 100644 --- a/src/plugins/trigger/trigger.h +++ b/src/plugins/trigger/trigger.h @@ -72,7 +72,6 @@ struct t_trigger_regex char *str_regex; /* regex to search for replacement */ regex_t *regex; /* compiled regex */ char *replace; /* replacement text */ - char *replace_eval; /* evaluatued replacement text */ }; struct t_trigger |