189 char *mvalue1, *mvalue2 =
NULL, *mtype_of_result;
197 ast_log(
LOG_WARNING,
"Syntax: MATH(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
204 ast_log(
LOG_WARNING,
"Syntax: MATH(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
208 mvalue1 =
args.argv0;
210 if (mvalue1[0] ==
'-') {
215 if ((op = strchr(mvalue1,
'*'))) {
218 }
else if ((op = strchr(mvalue1,
'/'))) {
221 }
else if ((op = strchr(mvalue1,
'%'))) {
224 }
else if ((op = strchr(mvalue1,
'^'))) {
227 }
else if ((op = strstr(mvalue1,
"AND"))) {
231 }
else if ((op = strstr(mvalue1,
"XOR"))) {
235 }
else if ((op = strstr(mvalue1,
"OR"))) {
239 }
else if ((op = strchr(mvalue1,
'>'))) {
242 if (*(op + 1) ==
'=') {
245 }
else if (*(op + 1) ==
'>') {
249 }
else if ((op = strchr(mvalue1,
'<'))) {
252 if (*(op + 1) ==
'=') {
255 }
else if (*(op + 1) ==
'<') {
259 }
else if ((op = strchr(mvalue1,
'='))) {
261 if (*(op + 1) ==
'=') {
266 }
else if ((op = strchr(mvalue1,
'+'))) {
269 }
else if ((op = strchr(mvalue1,
'-'))) {
278 mtype_of_result =
args.argv1;
279 if (mtype_of_result) {
280 if (!strcasecmp(mtype_of_result,
"float")
281 || !strcasecmp(mtype_of_result,
"f"))
283 else if (!strcasecmp(mtype_of_result,
"int")
284 || !strcasecmp(mtype_of_result,
"i"))
286 else if (!strcasecmp(mtype_of_result,
"hex")
287 || !strcasecmp(mtype_of_result,
"h"))
289 else if (!strcasecmp(mtype_of_result,
"char")
290 || !strcasecmp(mtype_of_result,
"c"))
301 "Supply all the parameters - just this once, please\n");
305 if (sscanf(mvalue1,
"%30lf", &fnum1) != 1) {
310 if (sscanf(mvalue2,
"%30lf", &fnum2) != 1) {
320 ftmp = fnum1 + fnum2;
326 ftmp = (fnum1 / fnum2);
329 ftmp = (fnum1 * fnum2);
332 ftmp = (fnum1 - fnum2);
342 ftmp = (inum1 % inum2);
348 ftmp = pow(fnum1, fnum2);
355 ftmp = (inum1 << inum2);
363 ftmp = (inum1 >> inum2);
370 ftmp = (inum1 & inum2);
377 ftmp = (inum1 ^ inum2);
384 ftmp = (inum1 | inum2);
404 "Something happened that neither of us should be proud of %d\n",
409 if (iaction < GTFUNCTION || iaction >
EQFUNCTION) {
411 snprintf(
buf,
len,
"%f", ftmp);
413 snprintf(
buf,
len,
"%i", (
int) ftmp);
415 snprintf(
buf,
len,
"%x", (
unsigned int) ftmp);
417 snprintf(
buf,
len,
"%c", (
unsigned char) ftmp);
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define ast_strlen_zero(foo)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void parse(struct mgcp_request *req)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_APP_ARG(name)
Define an application argument.