[asterisk-commits] dhubbard: trunk r72524 - /trunk/funcs/func_math.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 28 15:52:23 CDT 2007


Author: dhubbard
Date: Thu Jun 28 15:52:22 2007
New Revision: 72524

URL: http://svn.digium.com/view/asterisk?view=rev&rev=72524
Log:
Added AND, OR, and XOR bitwise operations to MATH for issue 9891, thanks jcmoore

Modified:
    trunk/funcs/func_math.c

Modified: trunk/funcs/func_math.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_math.c?view=diff&rev=72524&r1=72523&r2=72524
==============================================================================
--- trunk/funcs/func_math.c (original)
+++ trunk/funcs/func_math.c Thu Jun 28 15:52:22 2007
@@ -53,6 +53,9 @@
 	POWFUNCTION,
 	SHLEFTFUNCTION,
 	SHRIGHTFUNCTION,
+	BITWISEANDFUNCTION,
+	BITWISEXORFUNCTION,
+	BITWISEORFUNCTION,
 	GTFUNCTION,
 	LTFUNCTION,
 	GTEFUNCTION,
@@ -113,6 +116,18 @@
 		*op = '\0';
 	} else if ((op = strchr(mvalue1, '^'))) {
 		iaction = POWFUNCTION;
+		*op = '\0';
+	} else if ((op = strstr(mvalue1, "AND"))) {
+		iaction = BITWISEANDFUNCTION;
+		op += 3;
+		*op = '\0';
+	} else if ((op = strstr(mvalue1, "XOR"))) {
+		iaction = BITWISEXORFUNCTION;
+		op += 3;
+		*op = '\0';
+	} else if ((op = strstr(mvalue1, "OR"))) {
+		iaction = BITWISEORFUNCTION;
+		op += 2;
 		*op = '\0';
 	} else if ((op = strchr(mvalue1, '>'))) {
 		iaction = GTFUNCTION;
@@ -237,6 +252,27 @@
 			ftmp = (inum1 >> inum2);
 			break;
 		}
+	case BITWISEANDFUNCTION:
+		{
+			int inum1 = fnum1;
+			int inum2 = fnum2;
+			ftmp = (inum1 & inum2);
+			break;
+		}
+	case BITWISEXORFUNCTION:
+		{
+			int inum1 = fnum1;
+			int inum2 = fnum2;
+			ftmp = (inum1 ^ inum2);
+			break;
+		}
+	case BITWISEORFUNCTION:
+		{
+			int inum1 = fnum1;
+			int inum2 = fnum2;
+			ftmp = (inum1 | inum2);
+			break;
+		}
 	case GTFUNCTION:
 		ast_copy_string(buf, (fnum1 > fnum2) ? "TRUE" : "FALSE", len);
 		break;
@@ -278,7 +314,7 @@
 	.synopsis = "Performs Mathematical Functions",
 	.syntax = "MATH(<number1><op><number2>[,<type_of_result>])",
 	.desc = "Perform calculation on number1 to number2. Valid ops are: \n"
-		"    +,-,/,*,%,<<,>>,^,<,>,>=,<=,==\n"
+		"    +,-,/,*,%,<<,>>,^,AND,OR,XOR,<,>,>=,<=,==\n"
 		"and behave as their C equivalents.\n"
 		"<type_of_result> - wanted type of result:\n"
 		"	f, float - float(default)\n"




More information about the asterisk-commits mailing list