|
|
|
@ -71,13 +71,13 @@ static const int8_t si_prefixes['z' - 'E' + 1]={ |
|
|
|
|
['Y'-'E']= 24, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
double av_strtod(const char *numstr, char **tail) { |
|
|
|
|
double av_strtod(const char *numstr, char **tail) |
|
|
|
|
{ |
|
|
|
|
double d; |
|
|
|
|
char *next; |
|
|
|
|
d = strtod(numstr, &next); |
|
|
|
|
/* if parsing succeeded, check for and interpret postfixes */ |
|
|
|
|
if (next!=numstr) { |
|
|
|
|
|
|
|
|
|
if (*next >= 'E' && *next <= 'z') { |
|
|
|
|
int e= si_prefixes[*next - 'E']; |
|
|
|
|
if (e) { |
|
|
|
@ -103,7 +103,8 @@ double av_strtod(const char *numstr, char **tail) { |
|
|
|
|
return d; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int strmatch(const char *s, const char *prefix){ |
|
|
|
|
static int strmatch(const char *s, const char *prefix) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
|
for (i=0; prefix[i]; i++) { |
|
|
|
|
if (prefix[i] != s[i]) return 0; |
|
|
|
@ -129,7 +130,8 @@ struct AVExpr { |
|
|
|
|
struct AVExpr *param[2]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static double eval_expr(Parser * p, AVExpr * e) { |
|
|
|
|
static double eval_expr(Parser *p, AVExpr *e) |
|
|
|
|
{ |
|
|
|
|
switch (e->type) { |
|
|
|
|
case e_value: return e->value; |
|
|
|
|
case e_const: return e->value * p->const_values[e->a.const_index]; |
|
|
|
@ -169,7 +171,8 @@ static double eval_expr(Parser * p, AVExpr * e) { |
|
|
|
|
|
|
|
|
|
static int parse_expr(AVExpr **e, Parser *p); |
|
|
|
|
|
|
|
|
|
void ff_free_expr(AVExpr * e) { |
|
|
|
|
void ff_free_expr(AVExpr *e) |
|
|
|
|
{ |
|
|
|
|
if (!e) return; |
|
|
|
|
ff_free_expr(e->param[0]); |
|
|
|
|
ff_free_expr(e->param[1]); |
|
|
|
@ -296,7 +299,8 @@ static int parse_primary(AVExpr **e, Parser *p) |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static AVExpr * new_eval_expr(int type, int value, AVExpr *p0, AVExpr *p1){ |
|
|
|
|
static AVExpr *new_eval_expr(int type, int value, AVExpr *p0, AVExpr *p1) |
|
|
|
|
{ |
|
|
|
|
AVExpr *e = av_mallocz(sizeof(AVExpr)); |
|
|
|
|
if (!e) |
|
|
|
|
return NULL; |
|
|
|
@ -419,7 +423,8 @@ static int parse_expr(AVExpr **e, Parser *p) |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int verify_expr(AVExpr * e) { |
|
|
|
|
static int verify_expr(AVExpr *e) |
|
|
|
|
{ |
|
|
|
|
if (!e) return 0; |
|
|
|
|
switch (e->type) { |
|
|
|
|
case e_value: |
|
|
|
@ -476,7 +481,8 @@ end: |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double ff_eval_expr(AVExpr *e, const double *const_values, void *opaque) { |
|
|
|
|
double ff_eval_expr(AVExpr *e, const double *const_values, void *opaque) |
|
|
|
|
{ |
|
|
|
|
Parser p; |
|
|
|
|
|
|
|
|
|
p.const_values = const_values; |
|
|
|
@ -514,7 +520,8 @@ static const char *const_names[]={ |
|
|
|
|
"E", |
|
|
|
|
0 |
|
|
|
|
}; |
|
|
|
|
int main(void){ |
|
|
|
|
int main(void) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
|
double d; |
|
|
|
|
ff_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, NULL); |
|
|
|
|