diff options
Diffstat (limited to 'main/ast_expr2.c')
-rw-r--r-- | main/ast_expr2.c | 225 |
1 files changed, 141 insertions, 84 deletions
diff --git a/main/ast_expr2.c b/main/ast_expr2.c index ebe7fe742..b7b533e7a 100644 --- a/main/ast_expr2.c +++ b/main/ast_expr2.c @@ -146,7 +146,8 @@ #include <sys/types.h> #include <stdio.h> -#if !defined(STANDALONE) +#if !defined(STANDALONE) && !defined(STANDALONE2) \ + ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #else #ifndef __USE_ISOC99 @@ -341,7 +342,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/ast_expr.h" #include "asterisk/logger.h" -#ifndef STANDALONE +#if !defined(STANDALONE) && !defined(STANDALONE2) #include "asterisk/pbx.h" #endif @@ -369,7 +370,7 @@ enum valtype { AST_EXPR_number, AST_EXPR_numeric_string, AST_EXPR_string } ; -#ifdef STANDALONE +#if defined(STANDALONE) || defined(STANDALONE2) void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6))); #endif @@ -482,13 +483,13 @@ int ast_yyerror(const char *,YYLTYPE *, struct parse_io *); #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE -#line 343 "ast_expr2.y" +#line 344 "ast_expr2.y" { struct val *val; struct expr_node *arglist; } /* Line 187 of yacc.c. */ -#line 492 "ast_expr2.c" +#line 493 "ast_expr2.c" YYSTYPE; # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 @@ -510,13 +511,13 @@ typedef struct YYLTYPE /* Copy the second part of user declarations. */ -#line 348 "ast_expr2.y" +#line 349 "ast_expr2.y" extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t)); /* Line 216 of yacc.c. */ -#line 520 "ast_expr2.c" +#line 521 "ast_expr2.c" #ifdef short # undef short @@ -812,9 +813,9 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 374, 374, 382, 389, 390, 396, 405, 411, 412, - 416, 420, 424, 428, 432, 436, 440, 444, 448, 452, - 456, 460, 464, 468, 472, 476, 480, 484 + 0, 375, 375, 383, 390, 391, 397, 406, 412, 413, + 417, 421, 425, 429, 433, 437, 441, 445, 449, 453, + 457, 461, 465, 469, 473, 477, 481, 485 }; #endif @@ -1467,114 +1468,114 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp) switch (yytype) { case 4: /* "TOK_COLONCOLON" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1473 "ast_expr2.c" +#line 1474 "ast_expr2.c" break; case 5: /* "TOK_COND" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1478 "ast_expr2.c" +#line 1479 "ast_expr2.c" break; case 6: /* "TOK_OR" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1483 "ast_expr2.c" +#line 1484 "ast_expr2.c" break; case 7: /* "TOK_AND" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1488 "ast_expr2.c" +#line 1489 "ast_expr2.c" break; case 8: /* "TOK_NE" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1493 "ast_expr2.c" +#line 1494 "ast_expr2.c" break; case 9: /* "TOK_LE" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1498 "ast_expr2.c" +#line 1499 "ast_expr2.c" break; case 10: /* "TOK_GE" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1503 "ast_expr2.c" +#line 1504 "ast_expr2.c" break; case 11: /* "TOK_LT" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1508 "ast_expr2.c" +#line 1509 "ast_expr2.c" break; case 12: /* "TOK_GT" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1513 "ast_expr2.c" +#line 1514 "ast_expr2.c" break; case 13: /* "TOK_EQ" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1518 "ast_expr2.c" +#line 1519 "ast_expr2.c" break; case 14: /* "TOK_MINUS" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1523 "ast_expr2.c" +#line 1524 "ast_expr2.c" break; case 15: /* "TOK_PLUS" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1528 "ast_expr2.c" +#line 1529 "ast_expr2.c" break; case 16: /* "TOK_MOD" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1533 "ast_expr2.c" +#line 1534 "ast_expr2.c" break; case 17: /* "TOK_DIV" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1538 "ast_expr2.c" +#line 1539 "ast_expr2.c" break; case 18: /* "TOK_MULT" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1543 "ast_expr2.c" +#line 1544 "ast_expr2.c" break; case 19: /* "TOK_COMPL" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1548 "ast_expr2.c" +#line 1549 "ast_expr2.c" break; case 20: /* "TOK_EQTILDE" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1553 "ast_expr2.c" +#line 1554 "ast_expr2.c" break; case 21: /* "TOK_COLON" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1558 "ast_expr2.c" +#line 1559 "ast_expr2.c" break; case 22: /* "TOK_LP" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1563 "ast_expr2.c" +#line 1564 "ast_expr2.c" break; case 23: /* "TOK_RP" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1568 "ast_expr2.c" +#line 1569 "ast_expr2.c" break; case 24: /* "TOKEN" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1573 "ast_expr2.c" +#line 1574 "ast_expr2.c" break; case 28: /* "expr" */ -#line 368 "ast_expr2.y" +#line 369 "ast_expr2.y" { free_value((yyvaluep->val)); }; -#line 1578 "ast_expr2.c" +#line 1579 "ast_expr2.c" break; default: @@ -1897,7 +1898,7 @@ yyreduce: switch (yyn) { case 2: -#line 374 "ast_expr2.y" +#line 375 "ast_expr2.y" { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1); ((struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type; if( (yyvsp[(1) - (1)].val)->type == AST_EXPR_number ) @@ -1909,7 +1910,7 @@ yyreduce: break; case 3: -#line 382 "ast_expr2.y" +#line 383 "ast_expr2.y" {/* nothing */ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1); ((struct parse_io *)parseio)->val->type = AST_EXPR_string; ((struct parse_io *)parseio)->val->u.s = strdup(""); @@ -1917,12 +1918,12 @@ yyreduce: break; case 4: -#line 389 "ast_expr2.y" +#line 390 "ast_expr2.y" { (yyval.arglist) = alloc_expr_node(AST_EXPR_NODE_VAL); (yyval.arglist)->val = (yyvsp[(1) - (1)].val);;} break; case 5: -#line 390 "ast_expr2.y" +#line 391 "ast_expr2.y" {struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL); struct expr_node *t; DESTROY((yyvsp[(2) - (3)].val)); @@ -1932,7 +1933,7 @@ yyreduce: break; case 6: -#line 396 "ast_expr2.y" +#line 397 "ast_expr2.y" {struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL); struct expr_node *t; /* NULL args should OK */ DESTROY((yyvsp[(2) - (2)].val)); @@ -1942,7 +1943,7 @@ yyreduce: break; case 7: -#line 405 "ast_expr2.y" +#line 406 "ast_expr2.y" { (yyval.val) = op_func((yyvsp[(1) - (4)].val),(yyvsp[(3) - (4)].arglist), ((struct parse_io *)parseio)->chan); DESTROY((yyvsp[(2) - (4)].val)); DESTROY((yyvsp[(4) - (4)].val)); @@ -1952,12 +1953,12 @@ yyreduce: break; case 8: -#line 411 "ast_expr2.y" +#line 412 "ast_expr2.y" {(yyval.val) = (yyvsp[(1) - (1)].val);;} break; case 9: -#line 412 "ast_expr2.y" +#line 413 "ast_expr2.y" { (yyval.val) = (yyvsp[(2) - (3)].val); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; (yyloc).first_line=0; (yyloc).last_line=0; @@ -1965,7 +1966,7 @@ yyreduce: break; case 10: -#line 416 "ast_expr2.y" +#line 417 "ast_expr2.y" { (yyval.val) = op_or ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -1973,7 +1974,7 @@ yyreduce: break; case 11: -#line 420 "ast_expr2.y" +#line 421 "ast_expr2.y" { (yyval.val) = op_and ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -1981,7 +1982,7 @@ yyreduce: break; case 12: -#line 424 "ast_expr2.y" +#line 425 "ast_expr2.y" { (yyval.val) = op_eq ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -1989,7 +1990,7 @@ yyreduce: break; case 13: -#line 428 "ast_expr2.y" +#line 429 "ast_expr2.y" { (yyval.val) = op_gt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -1997,7 +1998,7 @@ yyreduce: break; case 14: -#line 432 "ast_expr2.y" +#line 433 "ast_expr2.y" { (yyval.val) = op_lt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -2005,7 +2006,7 @@ yyreduce: break; case 15: -#line 436 "ast_expr2.y" +#line 437 "ast_expr2.y" { (yyval.val) = op_ge ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -2013,7 +2014,7 @@ yyreduce: break; case 16: -#line 440 "ast_expr2.y" +#line 441 "ast_expr2.y" { (yyval.val) = op_le ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -2021,7 +2022,7 @@ yyreduce: break; case 17: -#line 444 "ast_expr2.y" +#line 445 "ast_expr2.y" { (yyval.val) = op_ne ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -2029,7 +2030,7 @@ yyreduce: break; case 18: -#line 448 "ast_expr2.y" +#line 449 "ast_expr2.y" { (yyval.val) = op_plus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -2037,7 +2038,7 @@ yyreduce: break; case 19: -#line 452 "ast_expr2.y" +#line 453 "ast_expr2.y" { (yyval.val) = op_minus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -2045,7 +2046,7 @@ yyreduce: break; case 20: -#line 456 "ast_expr2.y" +#line 457 "ast_expr2.y" { (yyval.val) = op_negate ((yyvsp[(2) - (2)].val)); DESTROY((yyvsp[(1) - (2)].val)); (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column; @@ -2053,7 +2054,7 @@ yyreduce: break; case 21: -#line 460 "ast_expr2.y" +#line 461 "ast_expr2.y" { (yyval.val) = op_compl ((yyvsp[(2) - (2)].val)); DESTROY((yyvsp[(1) - (2)].val)); (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column; @@ -2061,7 +2062,7 @@ yyreduce: break; case 22: -#line 464 "ast_expr2.y" +#line 465 "ast_expr2.y" { (yyval.val) = op_times ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -2069,7 +2070,7 @@ yyreduce: break; case 23: -#line 468 "ast_expr2.y" +#line 469 "ast_expr2.y" { (yyval.val) = op_div ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -2077,7 +2078,7 @@ yyreduce: break; case 24: -#line 472 "ast_expr2.y" +#line 473 "ast_expr2.y" { (yyval.val) = op_rem ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -2085,7 +2086,7 @@ yyreduce: break; case 25: -#line 476 "ast_expr2.y" +#line 477 "ast_expr2.y" { (yyval.val) = op_colon ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -2093,7 +2094,7 @@ yyreduce: break; case 26: -#line 480 "ast_expr2.y" +#line 481 "ast_expr2.y" { (yyval.val) = op_eqtilde ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val)); DESTROY((yyvsp[(2) - (3)].val)); (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column; @@ -2101,7 +2102,7 @@ yyreduce: break; case 27: -#line 484 "ast_expr2.y" +#line 485 "ast_expr2.y" { (yyval.val) = op_cond ((yyvsp[(1) - (5)].val), (yyvsp[(3) - (5)].val), (yyvsp[(5) - (5)].val)); DESTROY((yyvsp[(2) - (5)].val)); DESTROY((yyvsp[(4) - (5)].val)); @@ -2111,7 +2112,7 @@ yyreduce: /* Line 1267 of yacc.c. */ -#line 2115 "ast_expr2.c" +#line 2116 "ast_expr2.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -2331,7 +2332,7 @@ yyreturn: } -#line 491 "ast_expr2.y" +#line 492 "ast_expr2.y" static struct expr_node *alloc_expr_node(enum node_type nt) @@ -2497,6 +2498,62 @@ is_zero_or_null (struct val *vp) /* NOTREACHED */ } +#ifdef STANDALONE2 + +void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) +{ + va_list vars; + va_start(vars,fmt); + + printf("LOG: lev:%d file:%s line:%d func: %s ", + level, file, line, function); + vprintf(fmt, vars); + fflush(stdout); + va_end(vars); +} + + +int main(int argc,char **argv) { + char s[4096]; + char out[4096]; + FILE *infile; + + if( !argv[1] ) + exit(20); + + if( access(argv[1],F_OK)== 0 ) + { + int ret; + + infile = fopen(argv[1],"r"); + if( !infile ) + { + printf("Sorry, couldn't open %s for reading!\n", argv[1]); + exit(10); + } + while( fgets(s,sizeof(s),infile) ) + { + if( s[strlen(s)-1] == '\n' ) + s[strlen(s)-1] = 0; + + ret = ast_expr(s, out, sizeof(out), NULL); + printf("Expression: %s Result: [%d] '%s'\n", + s, ret, out); + } + fclose(infile); + } + else + { + if (ast_expr(argv[1], s, sizeof(s), NULL)) + printf("=====%s======\n",s); + else + printf("No result\n"); + } + return 0; +} + +#endif + #undef ast_yyerror #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio) @@ -2521,7 +2578,7 @@ static void destroy_arglist(struct expr_node *arglist) } } -#if !defined(STANDALONE) +#if !defined(STANDALONE) && !defined(STANDALONE2) static char *compose_func_args(struct expr_node *arglist) { struct expr_node *t = arglist; @@ -2815,7 +2872,7 @@ static struct val *op_func(struct val *funcname, struct expr_node *arglist, stru #endif } else { /* is this a custom function we should execute and collect the results of? */ -#ifndef STANDALONE +#if !defined(STANDALONE) && !defined(STANDALONE2) struct ast_custom_function *f = ast_custom_function_find(funcname->u.s); if (!chan) ast_log(LOG_WARNING,"Hey! chan is NULL.\n"); |