[asterisk-commits] tilghman: trunk r351079 - in /trunk: CHANGES main/ast_expr2.c main/ast_expr2.y

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 16 13:49:54 CST 2012


Author: tilghman
Date: Mon Jan 16 13:49:50 2012
New Revision: 351079

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=351079
Log:
Add ABS() absolute value function to the expression parser.

Modified:
    trunk/CHANGES
    trunk/main/ast_expr2.c
    trunk/main/ast_expr2.y

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=351079&r1=351078&r2=351079
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Mon Jan 16 13:49:50 2012
@@ -11,6 +11,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
 -------------------

Modified: trunk/main/ast_expr2.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/ast_expr2.c?view=diff&rev=351079&r1=351078&r2=351079
==============================================================================
--- trunk/main/ast_expr2.c (original)
+++ trunk/main/ast_expr2.c Mon Jan 16 13:49:50 2012
@@ -3036,6 +3036,15 @@
 				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)

Modified: trunk/main/ast_expr2.y
URL: http://svnview.digium.com/svn/asterisk/trunk/main/ast_expr2.y?view=diff&rev=351079&r1=351078&r2=351079
==============================================================================
--- trunk/main/ast_expr2.y (original)
+++ trunk/main/ast_expr2.y Mon Jan 16 13:49:50 2012
@@ -1029,6 +1029,15 @@
 				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)




More information about the asterisk-commits mailing list