diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2016-08-18 21:24:10 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2016-08-18 21:24:10 +0200 |
commit | 61bc6b6550cfb5073edbe320bc4565e83de77883 (patch) | |
tree | 166fc3877ace29746a7588d775e966a8d760cc96 /src | |
parent | c8d9be036bebccc0fc7bac68f0a9c8927e0a3751 (diff) | |
parent | ed337d929162a32a947a3c812f1d4516072a6737 (diff) | |
download | weechat-61bc6b6550cfb5073edbe320bc4565e83de77883.zip |
Merge remote-tracking branch 'origin/pr/534'
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-eval.c | 67 |
1 files changed, 48 insertions, 19 deletions
diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index fb3ca8ec4..2531107dc 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -52,6 +52,7 @@ char *comparisons[EVAL_NUM_COMPARISONS] = char *eval_replace_vars (const char *expr, struct t_hashtable *pointers, struct t_hashtable *extra_vars, const char *prefix, const char *suffix, + int extra_vars_eval, struct t_eval_regex *eval_regex); @@ -255,7 +256,7 @@ eval_replace_vars_cb (void *data, const char *text) const char *prefix, *suffix, *ptr_value, *ptr_arguments, *ptr_string; struct t_hdata *hdata; void *pointer; - int i, length_hide_char, length, index, rc; + int extra_vars_eval, i, length_hide_char, length, index, rc; long number; long unsigned int ptr; time_t date; @@ -265,14 +266,24 @@ eval_replace_vars_cb (void *data, const char *text) extra_vars = (struct t_hashtable *)(((void **)data)[1]); prefix = (const char *)(((void **)data)[2]); suffix = (const char *)(((void **)data)[3]); - eval_regex = (struct t_eval_regex *)(((void **)data)[4]); + extra_vars_eval = *(int *)(((void **)data)[4]); + eval_regex = (struct t_eval_regex *)(((void **)data)[5]); /* 1. variable in hashtable "extra_vars" */ if (extra_vars) { ptr_value = hashtable_get (extra_vars, text); if (ptr_value) - return strdup (ptr_value); + { + if (extra_vars_eval) + { + return eval_replace_vars (ptr_value, pointers, extra_vars, + prefix, suffix, extra_vars_eval, + eval_regex); + } + else + return strdup (ptr_value); + } } /* @@ -282,7 +293,8 @@ eval_replace_vars_cb (void *data, const char *text) if (strncmp (text, "eval:", 5) == 0) { return eval_replace_vars (text + 5, pointers, extra_vars, - prefix, suffix, eval_regex); + prefix, suffix, extra_vars_eval, + eval_regex); } /* 3. convert escaped chars */ @@ -518,15 +530,17 @@ char * eval_replace_vars (const char *expr, struct t_hashtable *pointers, struct t_hashtable *extra_vars, const char *prefix, const char *suffix, + int extra_vars_eval, struct t_eval_regex *eval_regex) { - const void *ptr[5]; + const void *ptr[6]; ptr[0] = pointers; ptr[1] = extra_vars; ptr[2] = prefix; ptr[3] = suffix; - ptr[4] = eval_regex; + ptr[4] = &extra_vars_eval; + ptr[5] = eval_regex; return string_replace_with_callback (expr, prefix, suffix, &eval_replace_vars_cb, ptr, NULL); @@ -692,7 +706,8 @@ eval_expression_condition (const char *expr, struct t_hashtable *pointers, struct t_hashtable *extra_vars, const char *prefix, - const char *suffix) + const char *suffix, + int extra_vars_eval) { int logic, comp, length, level, rc; const char *pos, *pos_end; @@ -747,7 +762,8 @@ eval_expression_condition (const char *expr, goto end; tmp_value = eval_expression_condition (sub_expr, pointers, extra_vars, - prefix, suffix); + prefix, suffix, + extra_vars_eval); free (sub_expr); rc = eval_is_true (tmp_value); if (tmp_value) @@ -768,7 +784,8 @@ eval_expression_condition (const char *expr, pos++; } tmp_value = eval_expression_condition (pos, pointers, extra_vars, - prefix, suffix); + prefix, suffix, + extra_vars_eval); rc = eval_is_true (tmp_value); if (tmp_value) free (tmp_value); @@ -809,10 +826,12 @@ eval_expression_condition (const char *expr, tmp_value = eval_replace_vars (sub_expr, pointers, extra_vars, prefix, suffix, + extra_vars_eval, NULL); tmp_value2 = eval_replace_vars (pos, pointers, extra_vars, prefix, suffix, + extra_vars_eval, NULL); } else @@ -820,10 +839,12 @@ eval_expression_condition (const char *expr, /* other comparison: fully evaluate both expressions */ tmp_value = eval_expression_condition (sub_expr, pointers, extra_vars, - prefix, suffix); + prefix, suffix, + extra_vars_eval); tmp_value2 = eval_expression_condition (pos, pointers, extra_vars, - prefix, suffix); + prefix, suffix, + extra_vars_eval); } free (sub_expr); value = eval_compare (tmp_value, comp, tmp_value2); @@ -862,7 +883,7 @@ eval_expression_condition (const char *expr, if (!sub_expr) goto end; tmp_value = eval_expression_condition (sub_expr, pointers, extra_vars, - prefix, suffix); + prefix, suffix, extra_vars_eval); free (sub_expr); if (!pos[1]) { @@ -898,7 +919,7 @@ eval_expression_condition (const char *expr, * so we just replace variables in string and return the result */ value = eval_replace_vars (expr2, pointers, extra_vars, prefix, suffix, - NULL); + extra_vars_eval, NULL); end: if (expr2) @@ -935,7 +956,8 @@ char * eval_replace_regex (const char *string, regex_t *regex, const char *replace, struct t_hashtable *pointers, struct t_hashtable *extra_vars, - const char *prefix, const char *suffix) + const char *prefix, const char *suffix, + int extra_vars_eval) { char *result, *result2, *str_replace; int length, length_replace, start_offset, i, rc, end; @@ -989,7 +1011,8 @@ eval_replace_regex (const char *string, regex_t *regex, const char *replace, eval_regex.result = result; str_replace = eval_replace_vars (replace, pointers, extra_vars, - prefix, suffix, &eval_regex); + prefix, suffix, extra_vars_eval, + &eval_regex); length_replace = (str_replace) ? strlen (str_replace) : 0; @@ -1071,7 +1094,7 @@ char * eval_expression (const char *expr, struct t_hashtable *pointers, struct t_hashtable *extra_vars, struct t_hashtable *options) { - int condition, rc, pointers_allocated, regex_allocated; + int condition, extra_vars_eval, rc, pointers_allocated, regex_allocated; char *value; const char *prefix, *suffix; const char *default_prefix = EVAL_DEFAULT_PREFIX; @@ -1084,6 +1107,7 @@ eval_expression (const char *expr, struct t_hashtable *pointers, return NULL; condition = 0; + extra_vars_eval = 0; pointers_allocated = 0; regex_allocated = 0; prefix = default_prefix; @@ -1132,6 +1156,11 @@ eval_expression (const char *expr, struct t_hashtable *pointers, if (ptr_value && (strcmp (ptr_value, "condition") == 0)) condition = 1; + /* */ + ptr_value = hashtable_get (options, "extra"); + if (ptr_value && (strcmp (ptr_value, "eval") == 0)) + extra_vars_eval = 1; + /* check for custom prefix */ ptr_value = hashtable_get (options, "prefix"); if (ptr_value && ptr_value[0]) @@ -1172,7 +1201,7 @@ eval_expression (const char *expr, struct t_hashtable *pointers, { /* evaluate as condition (return a boolean: "0" or "1") */ value = eval_expression_condition (expr, pointers, extra_vars, - prefix, suffix); + prefix, suffix, extra_vars_eval); rc = eval_is_true (value); if (value) free (value); @@ -1185,13 +1214,13 @@ eval_expression (const char *expr, struct t_hashtable *pointers, /* replace with regex */ value = eval_replace_regex (expr, regex, regex_replace, pointers, extra_vars, - prefix, suffix); + prefix, suffix, extra_vars_eval); } else { /* only replace variables in expression */ value = eval_replace_vars (expr, pointers, extra_vars, - prefix, suffix, NULL); + prefix, suffix, extra_vars_eval, NULL); } } |