From c60d15222c8c414b8f4a09a287d52916d70e27dd Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Mon, 16 Jan 2012 19:49:50 +0000 Subject: [PATCH] Add ABS() absolute value function to the expression parser. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@351079 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- CHANGES | 5 +++++ main/ast_expr2.c | 9 +++++++++ main/ast_expr2.y | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGES b/CHANGES index 034320ac9f..a03f5b7eae 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,11 @@ --- Functionality changes from Asterisk 10 to Asterisk 11 -------------------- ------------------------------------------------------------------------------ +Core +---- + * The expression parser now recognizes the ABS() absolute value function, + which will convert negative floating point values to positive values. + ConfBridge ------------------- * Added menu action admin_toggle_mute_participants. This will mute / unmute diff --git a/main/ast_expr2.c b/main/ast_expr2.c index fe93c35774..83caad4e81 100644 --- a/main/ast_expr2.c +++ b/main/ast_expr2.c @@ -3036,6 +3036,15 @@ static struct val *op_func(struct val *funcname, struct expr_node *arglist, stru return make_number(0.0); } #endif + } else if (strcmp(funcname->u.s, "ABS") == 0) { + if (arglist && !arglist->right && arglist->val) { + to_number(arglist->val); + result = make_number(arglist->val->u.i < 0 ? arglist->val->u.i * -1 : arglist->val->u.i); + return result; + } else { + ast_log(LOG_WARNING, "Wrong args to %s() function\n", funcname->u.s); + return make_number(0.0); + } } else { /* is this a custom function we should execute and collect the results of? */ #if !defined(STANDALONE) && !defined(STANDALONE2) diff --git a/main/ast_expr2.y b/main/ast_expr2.y index aabca8a463..bf1237a532 100644 --- a/main/ast_expr2.y +++ b/main/ast_expr2.y @@ -1029,6 +1029,15 @@ static struct val *op_func(struct val *funcname, struct expr_node *arglist, stru return make_number(0.0); } #endif + } else if (strcmp(funcname->u.s, "ABS") == 0) { + if (arglist && !arglist->right && arglist->val) { + to_number(arglist->val); + result = make_number(arglist->val->u.i < 0 ? arglist->val->u.i * -1 : arglist->val->u.i); + return result; + } else { + ast_log(LOG_WARNING, "Wrong args to %s() function\n", funcname->u.s); + return make_number(0.0); + } } else { /* is this a custom function we should execute and collect the results of? */ #if !defined(STANDALONE) && !defined(STANDALONE2)