Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:20 2009

## Asterisk developer's documentation

# ast_expr.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions

int | ast_expr (char *expr, char *buf, int length)

## Function Documentation

int ast_expr | ( | char * | expr,
|  | char * | buf,
|  | int | length |
| ) |  |  |

Definition at line 2912 of file ast_expr2f.c.

References AST_EXPR_integer, ast_yy_scan_string(), ast_yylex_destroy(), ast_yylex_init(), ast_yyparse(), free, parse_io::scanner, and parse_io::string.

Referenced by pbx_substitute_variables_helper_full().

    02913 {
    02914    struct parse_io io;
    02915    int return_value = 0;
    02916
    02917    memset(&io, 0, sizeof(io));
    02918    io.string = expr;  /* to pass to the error routine */
    02919
    02920    ast_yylex_init(&io.scanner);
    02921
    02922    ast_yy_scan_string(expr, io.scanner);
    02923
    02924    ast_yyparse ((void *) &io);
    02925
    02926    ast_yylex_destroy(io.scanner);
    02927
    02928    if (!io.val) {
    02929       if (length > 1) {
    02930          strcpy(buf, "0");
    02931          return_value = 1;
    02932       }
    02933    } else {
    02934       if (io.val->type == AST_EXPR_integer) {
    02935          int res_length;
    02936
    02937          res_length = snprintf(buf, length, "%ld", (long int) io.val->u.i);
    02938          return_value = (res_length <= length) ? res_length : length;
    02939       } else {
    02940 #ifdef STANDALONE
    02941          strncpy(buf, io.val->u.s, length - 1);
    02942 #else /* !STANDALONE */
    02943          ast_copy_string(buf, io.val->u.s, length);
    02944 #endif /* STANDALONE */
    02945          return_value = strlen(buf);
    02946          free(io.val->u.s);
    02947       }
    02948       free(io.val);
    02949    }
    02950    return return_value;
    02951 }