Newer
Older
Kevin P. Fleming
committed
YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
case 2:
/* Line 1455 of yacc.c */
{ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
Kevin P. Fleming
committed
((struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type;
if( (yyvsp[(1) - (1)].val)->type == AST_EXPR_number )
Kevin P. Fleming
committed
((struct parse_io *)parseio)->val->u.i = (yyvsp[(1) - (1)].val)->u.i;
Kevin P. Fleming
committed
((struct parse_io *)parseio)->val->u.s = (yyvsp[(1) - (1)].val)->u.s;
free((yyvsp[(1) - (1)].val));
;}
break;
case 3:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{/* 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("");
;}
break;
case 4:
/* Line 1455 of yacc.c */
{ (yyval.arglist) = alloc_expr_node(AST_EXPR_NODE_VAL); (yyval.arglist)->val = (yyvsp[(1) - (1)].val);;}
break;
case 5:
/* Line 1455 of yacc.c */
{struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL);
struct expr_node *t;
DESTROY((yyvsp[(2) - (3)].val));
for (t=(yyvsp[(1) - (3)].arglist);t->right;t=t->right)
;
(yyval.arglist) = (yyvsp[(1) - (3)].arglist); t->right = x; x->val = (yyvsp[(3) - (3)].val);;}
break;
case 6:
/* Line 1455 of yacc.c */
Steve Murphy
committed
{struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL);
struct expr_node *t; /* NULL args should OK */
DESTROY((yyvsp[(2) - (2)].val));
for (t=(yyvsp[(1) - (2)].arglist);t->right;t=t->right)
;
(yyval.arglist) = (yyvsp[(1) - (2)].arglist); t->right = x; x->val = make_str("");;}
Steve Murphy
committed
break;
case 7:
/* Line 1455 of yacc.c */
{ (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));
DESTROY((yyvsp[(1) - (4)].val));
destroy_arglist((yyvsp[(3) - (4)].arglist));
;}
break;
Steve Murphy
committed
case 8:
/* Line 1455 of yacc.c */
{(yyval.val) = (yyvsp[(1) - (1)].val);;}
break;
Steve Murphy
committed
case 9:
/* Line 1455 of yacc.c */
{ (yyval.val) = (yyvsp[(2) - (3)].val);
Kevin P. Fleming
committed
(yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;
DESTROY((yyvsp[(1) - (3)].val)); DESTROY((yyvsp[(3) - (3)].val)); ;}
break;
Steve Murphy
committed
case 10:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 11:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 12:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 13:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 14:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 15:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 16:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 17:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 18:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 19:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 20:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 21:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 22:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 23:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 24:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 25:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 26:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
Kevin P. Fleming
committed
break;
Steve Murphy
committed
case 27:
/* Line 1455 of yacc.c */
Kevin P. Fleming
committed
{ (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));
(yyloc).first_column = (yylsp[(1) - (5)]).first_column; (yyloc).last_column = (yylsp[(3) - (5)]).last_column;
(yyloc).first_line=0; (yyloc).last_line=0;;}
break;
Steve Murphy
committed
case 28:
/* Line 1455 of yacc.c */
{ (yyval.val) = op_tildetilde ((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;
(yyloc).first_line=0; (yyloc).last_line=0;;}
/* Line 1455 of yacc.c */
#line 2283 "ast_expr2.c"
Kevin P. Fleming
committed
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
Kevin P. Fleming
committed
YYPOPSTACK (yylen);
yylen = 0;
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
YY_STACK_PRINT (yyss, yyssp);
*++yyvsp = yyval;
*++yylsp = yyloc;
/* Now `shift' the result of the reduction. Determine what state
that goes to, based on the state we popped back to and the rule
number reduced by. */
yyn = yyr1[yyn];
yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
yystate = yytable[yystate];
else
yystate = yydefgoto[yyn - YYNTOKENS];
goto yynewstate;
/*------------------------------------.
| yyerrlab -- here on detecting error |
`------------------------------------*/
yyerrlab:
/* If not already recovering from an error, report this error. */
if (!yyerrstatus)
{
++yynerrs;
Kevin P. Fleming
committed
#if ! YYERROR_VERBOSE
yyerror (YY_("syntax error"));
#else
{
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
{
YYSIZE_T yyalloc = 2 * yysize;
if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
yyalloc = YYSTACK_ALLOC_MAXIMUM;
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
yymsg = (char *) YYSTACK_ALLOC (yyalloc);
if (yymsg)
yymsg_alloc = yyalloc;
else
{
yymsg = yymsgbuf;
yymsg_alloc = sizeof yymsgbuf;
}
}
if (0 < yysize && yysize <= yymsg_alloc)
{
(void) yysyntax_error (yymsg, yystate, yychar);
yyerror (yymsg);
}
else
{
yyerror (YY_("syntax error"));
if (yysize != 0)
goto yyexhaustedlab;
}
Kevin P. Fleming
committed
}
#endif
}
yyerror_range[0] = yylloc;
if (yyerrstatus == 3)
{
/* If just tried and failed to reuse lookahead token after an
error, discard it. */
if (yychar <= YYEOF)
Kevin P. Fleming
committed
{
/* Return failure if at end of input. */
if (yychar == YYEOF)
Kevin P. Fleming
committed
}
else
{
Kevin P. Fleming
committed
yydestruct ("Error: discarding",
yytoken, &yylval, &yylloc);
yychar = YYEMPTY;
}
}
/* Else will try to reuse lookahead token after shifting the error
token. */
goto yyerrlab1;
/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR. |
`---------------------------------------------------*/
yyerrorlab:
/* Pacify compilers like GCC when the user code never invokes
YYERROR and the label yyerrorlab therefore never appears in user
code. */
Kevin P. Fleming
committed
if (/*CONSTCOND*/ 0)
goto yyerrorlab;
yyerror_range[0] = yylsp[1-yylen];
Kevin P. Fleming
committed
/* Do not reclaim the symbols of the rule which action triggered
this YYERROR. */
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
yystate = *yyssp;
goto yyerrlab1;
/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR. |
`-------------------------------------------------------------*/
yyerrlab1:
yyerrstatus = 3; /* Each real token shifted decrements this. */
for (;;)
{
yyn = yypact[yystate];
if (yyn != YYPACT_NINF)
{
yyn += YYTERROR;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
{
yyn = yytable[yyn];
if (0 < yyn)
break;
}
}
/* Pop the current state because it cannot handle the error token. */
if (yyssp == yyss)
YYABORT;
yyerror_range[0] = *yylsp;
Kevin P. Fleming
committed
yydestruct ("Error: popping",
yystos[yystate], yyvsp, yylsp);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
}
*++yyvsp = yylval;
yyerror_range[1] = yylloc;
the lookahead. YYLOC is available though. */
YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
*++yylsp = yyloc;
Kevin P. Fleming
committed
/* Shift the error token. */
yystate = yyn;
goto yynewstate;
/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here. |
`-------------------------------------*/
yyacceptlab:
yyresult = 0;
goto yyreturn;
/*-----------------------------------.
| yyabortlab -- YYABORT comes here. |
`-----------------------------------*/
yyabortlab:
yyresult = 1;
goto yyreturn;
#if !defined(yyoverflow) || YYERROR_VERBOSE
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
yyexhaustedlab:
yyerror (YY_("memory exhausted"));
yyresult = 2;
/* Fall through. */
#endif
yyreturn:
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval, &yylloc);
Kevin P. Fleming
committed
/* Do not reclaim the symbols of the rule which action triggered
this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
YY_STACK_PRINT (yyss, yyssp);
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
yystos[*yyssp], yyvsp, yylsp);
Kevin P. Fleming
committed
YYPOPSTACK (1);
#ifndef yyoverflow
if (yyss != yyssa)
YYSTACK_FREE (yyss);
Kevin P. Fleming
committed
#endif
#if YYERROR_VERBOSE
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
#endif
/* Make sure YYID is used. */
return YYID (yyresult);
}
/* Line 1675 of yacc.c */
static struct expr_node *alloc_expr_node(enum node_type nt)
{
struct expr_node *x = calloc(1,sizeof(struct expr_node));
if (!x) {
ast_log(LOG_ERROR, "Allocation for expr_node FAILED!!\n");
return 0;
}
x->type = nt;
return x;
}
static struct val *
{
struct val *vp;
vp = (struct val *) malloc (sizeof (*vp));
if (vp == NULL) {
ast_log(LOG_WARNING, "malloc() failed\n");
return(NULL);
}
vp->u.i = i;
return vp;
}
static struct val *
make_str (const char *s)
{
struct val *vp;
size_t i;
int isint; /* this started out being a test for an integer, but then ended up being a test for a float */
vp = (struct val *) malloc (sizeof (*vp));
if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
ast_log(LOG_WARNING,"malloc() failed\n");
return(NULL);
}
for (i = 0, isint = (isdigit(s[0]) || s[0] == '-' || s[0]=='.'); isint && i < strlen(s); i++)
if (!isdigit(s[i]) && s[i] != '.') {
isint = 0;
break;
}
}
if (isint)
vp->type = AST_EXPR_numeric_string;
else
vp->type = AST_EXPR_string;
return vp;
}
static void
free_value (struct val *vp)
{
if (vp==NULL) {
return;
}
if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
free (vp->u.s);
}
static int
to_number (struct val *vp)
if (vp == NULL) {
ast_log(LOG_WARNING,"vp==NULL in to_number()\n");
return(0);
}
if (vp->type == AST_EXPR_number)
return 1;
if (vp->type == AST_EXPR_string)
return 0;
/* vp->type == AST_EXPR_numeric_string, make it numeric */
errno = 0;
i = FUNC_STRTOD(vp->u.s, (char**)0); /* either strtod, or strtold on a good day */
if (errno != 0) {
ast_log(LOG_WARNING,"Conversion of %s to number under/overflowed!\n", vp->u.s);
free(vp->u.s);
vp->u.s = 0;
return(0);
}
free (vp->u.s);
vp->u.i = i;
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
return 1;
}
static void
strip_quotes(struct val *vp)
{
if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
return;
if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
{
char *f, *t;
f = vp->u.s;
t = vp->u.s;
while( *f )
{
if( *f && *f != '"' )
*t++ = *f++;
else
f++;
}
*t = *f;
}
}
static void
to_string (struct val *vp)
{
char *tmp;
if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
return;
if (asprintf(&tmp, FP___PRINTF, vp->u.i) == -1) {
ast_log(LOG_WARNING, "asprintf() failed\n");
return;
}
vp->type = AST_EXPR_string;
vp->u.s = tmp;
}
static int
isstring (struct val *vp)
{
/* only TRUE if this string is not a valid number */
return (vp->type == AST_EXPR_string);
}
static int
is_zero_or_null (struct val *vp)
{
if (vp->type == AST_EXPR_number) {
return (vp->u.i == 0);
} else {
return (*vp->u.s == 0 || (to_number(vp) && vp->u.i == 0));
}
/* NOTREACHED */
}
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
#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)
/* I put the ast_yyerror func in the flex input file,
because it refers to the buffer state. Best to
let it access the BUFFER stuff there and not trying
define all the structs, macros etc. in this file! */
static void destroy_arglist(struct expr_node *arglist)
{
struct expr_node *arglist_next;
while (arglist)
{
arglist_next = arglist->right;
if (arglist->val)
free_value(arglist->val);
arglist->val = 0;
arglist->right = 0;
free(arglist);
arglist = arglist_next;
}
}
#if !defined(STANDALONE) && !defined(STANDALONE2)
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
static char *compose_func_args(struct expr_node *arglist)
{
struct expr_node *t = arglist;
char *argbuf;
int total_len = 0;
while (t) {
if (t != arglist)
total_len += 1; /* for the sep */
if (t->val) {
if (t->val->type == AST_EXPR_number)
total_len += 25; /* worst case */
else
total_len += strlen(t->val->u.s);
}
t = t->right;
}
total_len++; /* for the null */
ast_log(LOG_NOTICE,"argbuf allocated %d bytes;\n", total_len);
argbuf = malloc(total_len);
argbuf[0] = 0;
t = arglist;
while (t) {
char numbuf[30];
if (t != arglist)
Steve Murphy
committed
strcat(argbuf,",");
if (t->val) {
if (t->val->type == AST_EXPR_number) {
sprintf(numbuf,FP___PRINTF,t->val->u.i);
strcat(argbuf,numbuf);
} else
strcat(argbuf,t->val->u.s);
}
t = t->right;
}
ast_log(LOG_NOTICE,"argbuf uses %d bytes;\n", (int) strlen(argbuf));
return argbuf;
}
static int is_really_num(char *str)
{
if ( strspn(str,"-0123456789. ") == strlen(str))
return 1;
else
return 0;
}
static struct val *op_func(struct val *funcname, struct expr_node *arglist, struct ast_channel *chan)
{
if (strspn(funcname->u.s,"ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789") == strlen(funcname->u.s))
{
struct val *result;
if (0) {
#ifdef FUNC_COS
} else if (strcmp(funcname->u.s,"COS") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_COS(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_SIN
} else if (strcmp(funcname->u.s,"SIN") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_SIN(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_TAN
} else if (strcmp(funcname->u.s,"TAN") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_TAN(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_ACOS
} else if (strcmp(funcname->u.s,"ACOS") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_ACOS(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_ASIN
} else if (strcmp(funcname->u.s,"ASIN") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_ASIN(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_ATAN
} else if (strcmp(funcname->u.s,"ATAN") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_ATAN(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_ATAN2
} else if (strcmp(funcname->u.s,"ATAN2") == 0) {
if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
to_number(arglist->val);
to_number(arglist->right->val);
result = make_number(FUNC_ATAN2(arglist->val->u.i, arglist->right->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_POW
} else if (strcmp(funcname->u.s,"POW") == 0) {
if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
to_number(arglist->val);
to_number(arglist->right->val);
result = make_number(FUNC_POW(arglist->val->u.i, arglist->right->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_SQRT
} else if (strcmp(funcname->u.s,"SQRT") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_SQRT(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_FLOOR
} else if (strcmp(funcname->u.s,"FLOOR") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_FLOOR(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_CEIL
} else if (strcmp(funcname->u.s,"CEIL") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_CEIL(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
Tilghman Lesher
committed
#ifdef FUNC_ROUND
} else if (strcmp(funcname->u.s,"ROUND") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_ROUND(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
Tilghman Lesher
committed
#endif /* defined(FUNC_ROUND) */
#ifdef FUNC_RINT
} else if (strcmp(funcname->u.s,"RINT") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_RINT(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
Tilghman Lesher
committed
#ifdef FUNC_TRUNC
} else if (strcmp(funcname->u.s,"TRUNC") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_TRUNC(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
Tilghman Lesher
committed
#endif /* defined(FUNC_TRUNC) */
#ifdef FUNC_EXP
} else if (strcmp(funcname->u.s,"EXP") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_EXP(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_EXP2
} else if (strcmp(funcname->u.s,"EXP2") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_EXP2(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_EXP10
Tilghman Lesher
committed
} else if (strcmp(funcname->u.s,"EXP10") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_EXP10(arglist->val->u.i));
return result;
} else {
ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
return make_number(0.0);
}
#endif
#ifdef FUNC_LOG
} else if (strcmp(funcname->u.s,"LOG") == 0) {
if (arglist && !arglist->right && arglist->val){
to_number(arglist->val);
result = make_number(FUNC_LOG(arglist->val->u.i));