Go to the source code of this file.
Functions | |
int | ast_expr (char *expr, char *buf, int length, struct ast_channel *chan) |
Definition in file ast_expr.h.
int ast_expr | ( | char * | expr, | |
char * | buf, | |||
int | length, | |||
struct ast_channel * | chan | |||
) |
Definition at line 2382 of file ast_expr2f.c.
02383 { 02384 struct parse_io io; 02385 int return_value = 0; 02386 02387 memset(&io, 0, sizeof(io)); 02388 io.string = expr; /* to pass to the error routine */ 02389 io.chan = chan; 02390 02391 ast_yylex_init(&io.scanner); 02392 02393 ast_yy_scan_string(expr, io.scanner); 02394 02395 ast_yyparse ((void *) &io); 02396 02397 ast_yylex_destroy(io.scanner); 02398 02399 if (!io.val) { 02400 if (length > 1) { 02401 strcpy(buf, "0"); 02402 return_value = 1; 02403 } 02404 } else { 02405 if (io.val->type == AST_EXPR_number) { 02406 int res_length; 02407 02408 res_length = snprintf(buf, length, FP___PRINTF, io.val->u.i); 02409 return_value = (res_length <= length) ? res_length : length; 02410 } else { 02411 if (io.val->u.s) 02412 #if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE) 02413 strncpy(buf, io.val->u.s, length - 1); 02414 #else /* !STANDALONE && !LOW_MEMORY */ 02415 ast_copy_string(buf, io.val->u.s, length); 02416 #endif /* STANDALONE || LOW_MEMORY */ 02417 else 02418 buf[0] = 0; 02419 return_value = strlen(buf); 02420 free(io.val->u.s); 02421 } 02422 free(io.val); 02423 } 02424 return return_value; 02425 }