annotate eval.c @ 612:c0005de2be59 libavcodec

new ratecontrol code
author michaelni
date Sun, 25 Aug 2002 21:19:50 +0000
parents
children b786f15df503
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
1 /*
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
2 * simple arithmetic expression evaluator
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
3 *
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
4 * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
5 *
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
10 *
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
14 * Lesser General Public License for more details.
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
15 *
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
19 *
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
20 */
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
21
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
22 /*
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
23 * see http://joe.hotchkiss.com/programming/eval/eval.html
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
24 */
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
25
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
26 #include <stdio.h>
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
27 #include <stdlib.h>
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
28 #include <string.h>
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
29 #include <math.h>
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
30
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
31 #define STACK_SIZE 100
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
32
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
33 typedef struct Parser{
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
34 double stack[STACK_SIZE];
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
35 int stack_index;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
36 char *s;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
37 double *const_value;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
38 char **const_name; // NULL terminated
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
39 double (**func1)(void *, double a); // NULL terminated
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
40 char **func1_name; // NULL terminated
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
41 double (**func2)(void *, double a, double b); // NULL terminated
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
42 char **func2_name; // NULL terminated
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
43 void *opaque;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
44 } Parser;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
45
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
46 static void evalExpression(Parser *p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
47
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
48 static void push(Parser *p, double d){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
49 if(p->stack_index+1>= STACK_SIZE){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
50 fprintf(stderr, "stack overflow in the parser\n");
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
51 return;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
52 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
53 p->stack[ p->stack_index++ ]= d;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
54 //printf("push %f\n", d); fflush(stdout);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
55 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
56
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
57 static double pop(Parser *p){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
58 if(p->stack_index<=0){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
59 fprintf(stderr, "stack underflow in the parser\n");
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
60 return NAN;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
61 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
62 //printf("pop\n"); fflush(stdout);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
63 return p->stack[ --p->stack_index ];
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
64 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
65
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
66 static int strmatch(char *s, char *prefix){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
67 int i;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
68 for(i=0; prefix[i]; i++){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
69 if(prefix[i] != s[i]) return 0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
70 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
71 return 1;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
72 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
73
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
74 static void evalPrimary(Parser *p){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
75 double d, d2=NAN;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
76 char *next= p->s;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
77 int i;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
78
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
79 /* number */
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
80 d= strtod(p->s, &next);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
81 if(next != p->s){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
82 push(p, d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
83 p->s= next;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
84 return;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
85 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
86
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
87 /* named constants */
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
88 for(i=0; p->const_name[i]; i++){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
89 if(strmatch(p->s, p->const_name[i])){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
90 push(p, p->const_value[i]);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
91 p->s+= strlen(p->const_name[i]);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
92 return;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
93 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
94 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
95
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
96 p->s= strchr(p->s, '(');
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
97 if(p->s==NULL){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
98 fprintf(stderr, "Parser: missing ( in \"%s\"\n", next);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
99 return;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
100 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
101 p->s++; // "("
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
102 evalExpression(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
103 d= pop(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
104 p->s++; // ")" or ","
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
105 if(p->s[-1]== ','){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
106 evalExpression(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
107 d2= pop(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
108 p->s++; // ")"
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
109 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
110
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
111 if( strmatch(next, "sinh" ) ) d= sinh(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
112 else if( strmatch(next, "cosh" ) ) d= cosh(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
113 else if( strmatch(next, "tanh" ) ) d= tanh(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
114 else if( strmatch(next, "sin" ) ) d= sin(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
115 else if( strmatch(next, "cos" ) ) d= cos(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
116 else if( strmatch(next, "tan" ) ) d= tan(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
117 else if( strmatch(next, "exp" ) ) d= exp(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
118 else if( strmatch(next, "log" ) ) d= log(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
119 else if( strmatch(next, "squish") ) d= 1/(1+exp(4*d));
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
120 else if( strmatch(next, "gauss" ) ) d= exp(-d*d/2)/sqrt(2*M_PI);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
121 else if( strmatch(next, "abs" ) ) d= abs(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
122 else if( strmatch(next, "max" ) ) d= d > d2 ? d : d2;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
123 else if( strmatch(next, "min" ) ) d= d < d2 ? d : d2;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
124 else if( strmatch(next, "gt" ) ) d= d > d2 ? 1.0 : 0.0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
125 else if( strmatch(next, "lt" ) ) d= d > d2 ? 0.0 : 1.0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
126 else if( strmatch(next, "eq" ) ) d= d == d2 ? 1.0 : 0.0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
127 // else if( strmatch(next, "l1" ) ) d= 1 + d2*(d - 1);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
128 // else if( strmatch(next, "sq01" ) ) d= (d >= 0.0 && d <=1.0) ? 1.0 : 0.0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
129 else{
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
130 int error=1;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
131 for(i=0; p->func1_name && p->func1_name[i]; i++){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
132 if(strmatch(next, p->func1_name[i])){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
133 d= p->func1[i](p->opaque, d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
134 error=0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
135 break;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
136 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
137 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
138
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
139 for(i=0; p->func2_name && p->func2_name[i]; i++){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
140 if(strmatch(next, p->func2_name[i])){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
141 d= p->func2[i](p->opaque, d, d2);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
142 error=0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
143 break;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
144 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
145 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
146
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
147 if(error){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
148 fprintf(stderr, "Parser: unknown function in \"%s\"\n", next);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
149 return;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
150 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
151 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
152
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
153 if(p->s[-1]!= ')'){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
154 fprintf(stderr, "Parser: missing ) in \"%s\"\n", next);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
155 return;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
156 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
157 push(p, d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
158 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
159
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
160 static void evalPow(Parser *p){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
161 int neg= 0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
162 if(p->s[0]=='+') p->s++;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
163
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
164 if(p->s[0]=='-'){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
165 neg= 1;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
166 p->s++;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
167 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
168
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
169 if(p->s[0]=='('){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
170 p->s++;;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
171 evalExpression(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
172
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
173 if(p->s[0]!=')')
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
174 fprintf(stderr, "Parser: missing )\n");
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
175 p->s++;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
176 }else{
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
177 evalPrimary(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
178 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
179
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
180 if(neg) push(p, -pop(p));
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
181 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
182
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
183 static void evalFactor(Parser *p){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
184 evalPow(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
185 while(p->s[0]=='^'){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
186 double d;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
187
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
188 p->s++;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
189 evalPow(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
190 d= pop(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
191 push(p, pow(pop(p), d));
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
192 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
193 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
194
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
195 static void evalTerm(Parser *p){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
196 evalFactor(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
197 while(p->s[0]=='*' || p->s[0]=='/'){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
198 int inv= p->s[0]=='/';
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
199 double d;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
200
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
201 p->s++;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
202 evalFactor(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
203 d= pop(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
204 if(inv) d= 1.0/d;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
205 push(p, d * pop(p));
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
206 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
207 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
208
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
209 static void evalExpression(Parser *p){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
210 evalTerm(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
211 while(p->s[0]=='+' || p->s[0]=='-'){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
212 int sign= p->s[0]=='-';
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
213 double d;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
214
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
215 p->s++;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
216 evalTerm(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
217 d= pop(p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
218 if(sign) d= -d;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
219 push(p, d + pop(p));
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
220 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
221 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
222
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
223 double ff_eval(char *s, double *const_value, char **const_name,
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
224 double (**func1)(void *, double), char **func1_name,
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
225 double (**func2)(void *, double, double), char **func2_name,
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
226 void *opaque){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
227 Parser p;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
228
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
229 p.stack_index=0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
230 p.s= s;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
231 p.const_value= const_value;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
232 p.const_name = const_name;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
233 p.func1 = func1;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
234 p.func1_name = func1_name;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
235 p.func2 = func2;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
236 p.func2_name = func2_name;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
237 p.opaque = opaque;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
238
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
239 evalExpression(&p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
240 return pop(&p);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
241 }