diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-08-29 22:03:37 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-08-29 22:03:37 +0000 |
commit | 558f8be1b81fd211756afb3f3814490bfc0763d7 (patch) | |
tree | e6aa0fcc15c7915e5b37a2267d1c36c2c86f0b19 /ast_expr2.fl | |
parent | 02052f2d90c56c341514e1b0ed5f62c65f9ea142 (diff) |
don't make expression evaluator allocate a memory buffer for each result
to
be returned; use the buffers already present in the PBX for this purpose
update testexpr2/check_expr to allocate buffers for expression
evaluation
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6440 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'ast_expr2.fl')
-rwxr-xr-x | ast_expr2.fl | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/ast_expr2.fl b/ast_expr2.fl index a2282cdbe..39df6013b 100755 --- a/ast_expr2.fl +++ b/ast_expr2.fl @@ -15,6 +15,7 @@ #include <limits.h> #include <asterisk/ast_expr.h> #include <asterisk/logger.h> +#include <asterisk/strings.h> enum valtype { AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string @@ -41,6 +42,8 @@ struct parse_io yyscan_t scanner; }; +void ast_yyset_column(int column_no, yyscan_t yyscanner); +int ast_yyget_column(yyscan_t yyscanner); %} @@ -90,42 +93,47 @@ struct parse_io ast_yy_scan_string in the .y file, because then, I'd have to define YY_BUFFER_STATE there... UGH! that would be inappropriate. */ -int ast_yyparse( void *); /* need to/should define this prototype for the call to yyparse */ -char *ast_expr(char *arg); /* and this prototype for the following func */ -int ast_yyerror(const char *,YYLTYPE *, struct parse_io *); /* likewise */ +int ast_yyparse(void *); /* need to/should define this prototype for the call to yyparse */ +int ast_yyerror(const char *, YYLTYPE *, struct parse_io *); /* likewise */ -char *ast_expr (char *arg) +int ast_expr(char *expr, char *buf, int length) { struct parse_io *io; - char *pirouni; - io = (struct parse_io *)calloc(sizeof(struct parse_io),1); - io->string = arg; /* to pass to the error routine */ + io = calloc(sizeof(struct parse_io),1); + io->string = expr; /* to pass to the error routine */ ast_yylex_init(&io->scanner); - ast_yy_scan_string(arg,io->scanner); + ast_yy_scan_string(expr, io->scanner); - ast_yyparse ((void *)io); + ast_yyparse ((void *) io); ast_yylex_destroy(io->scanner); - - if (io->val==NULL) { - pirouni=strdup("0"); - return(pirouni); + if (io->val == NULL) { + if (length > 1) { + strcpy(buf, "0"); + return 1; + } } else { if (io->val->type == AST_EXPR_integer) { - pirouni = malloc(24); - sprintf(pirouni, "%ld", io->val->u.i); - } - else { - pirouni=strdup(io->val->u.s); + int res_length; + + res_length = snprintf(buf, length, "%ld", (long int) io->val->u.i); + return res_length <= length ? res_length : length; + } else { +#ifdef STANDALONE + strncpy(buf, io->val->u.s, length - 1); +#else /* !STANDALONE */ + ast_copy_string(buf, io->val->u.s, length); +#endif /* STANDALONE */ + return strlen(buf); } free(io->val); } free(io); - return(pirouni); + return 0; } int ast_yyerror (const char *s, yyltype *loc, struct parse_io *parseio ) |