Mercurial > libavcodec.hg
comparison eval.c @ 3770:ea345e1e440f libavcodec
Introduce ff_eval2 which is equivalent to ff_eval but does not log anything.
Instead, error messages are passed upward by means of a struct member variable.
| author | takis |
|---|---|
| date | Tue, 26 Sep 2006 22:01:33 +0000 |
| parents | 9813c594dac5 |
| children | 699bceae338c |
comparison
equal
deleted
inserted
replaced
| 3769:cf04e15a72ac | 3770:ea345e1e440f |
|---|---|
| 50 double (**func1)(void *, double a); // NULL terminated | 50 double (**func1)(void *, double a); // NULL terminated |
| 51 const char **func1_name; // NULL terminated | 51 const char **func1_name; // NULL terminated |
| 52 double (**func2)(void *, double a, double b); // NULL terminated | 52 double (**func2)(void *, double a, double b); // NULL terminated |
| 53 char **func2_name; // NULL terminated | 53 char **func2_name; // NULL terminated |
| 54 void *opaque; | 54 void *opaque; |
| 55 char **error; | |
| 55 } Parser; | 56 } Parser; |
| 56 | 57 |
| 57 extern double av_strtod(const char *name, char **tail); | 58 extern double av_strtod(const char *name, char **tail); |
| 58 | 59 |
| 59 static double evalExpression(Parser *p); | 60 static double evalExpression(Parser *p); |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 | 89 |
| 89 p->s= strchr(p->s, '('); | 90 p->s= strchr(p->s, '('); |
| 90 if(p->s==NULL){ | 91 if(p->s==NULL){ |
| 91 av_log(NULL, AV_LOG_ERROR, "Parser: missing ( in \"%s\"\n", next); | 92 *p->error = "missing ("; |
| 92 p->s= next; | 93 p->s= next; |
| 93 return NAN; | 94 return NAN; |
| 94 } | 95 } |
| 95 p->s++; // "(" | 96 p->s++; // "(" |
| 96 d= evalExpression(p); | 97 d= evalExpression(p); |
| 97 if(p->s[0]== ','){ | 98 if(p->s[0]== ','){ |
| 98 p->s++; // "," | 99 p->s++; // "," |
| 99 d2= evalExpression(p); | 100 d2= evalExpression(p); |
| 100 } | 101 } |
| 101 if(p->s[0] != ')'){ | 102 if(p->s[0] != ')'){ |
| 102 av_log(NULL, AV_LOG_ERROR, "Parser: missing ) in \"%s\"\n", next); | 103 *p->error = "missing )"; |
| 103 return NAN; | 104 return NAN; |
| 104 } | 105 } |
| 105 p->s++; // ")" | 106 p->s++; // ")" |
| 106 | 107 |
| 107 if( strmatch(next, "sinh" ) ) d= sinh(d); | 108 if( strmatch(next, "sinh" ) ) d= sinh(d); |
| 136 if(strmatch(next, p->func2_name[i])){ | 137 if(strmatch(next, p->func2_name[i])){ |
| 137 return p->func2[i](p->opaque, d, d2); | 138 return p->func2[i](p->opaque, d, d2); |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 | 141 |
| 141 av_log(NULL, AV_LOG_ERROR, "Parser: unknown function in \"%s\"\n", next); | 142 *p->error = "unknown function"; |
| 142 return NAN; | 143 return NAN; |
| 143 } | 144 } |
| 144 | 145 |
| 145 return d; | 146 return d; |
| 146 } | 147 } |
| 183 p->stack_index++; | 184 p->stack_index++; |
| 184 | 185 |
| 185 return ret; | 186 return ret; |
| 186 } | 187 } |
| 187 | 188 |
| 188 double ff_eval(char *s, double *const_value, const char **const_name, | 189 double ff_eval2(char *s, double *const_value, const char **const_name, |
| 189 double (**func1)(void *, double), const char **func1_name, | 190 double (**func1)(void *, double), const char **func1_name, |
| 190 double (**func2)(void *, double, double), char **func2_name, | 191 double (**func2)(void *, double, double), char **func2_name, |
| 191 void *opaque){ | 192 void *opaque, char **error){ |
| 192 Parser p; | 193 Parser p; |
| 193 | 194 |
| 194 p.stack_index=100; | 195 p.stack_index=100; |
| 195 p.s= s; | 196 p.s= s; |
| 196 p.const_value= const_value; | 197 p.const_value= const_value; |
| 198 p.func1 = func1; | 199 p.func1 = func1; |
| 199 p.func1_name = func1_name; | 200 p.func1_name = func1_name; |
| 200 p.func2 = func2; | 201 p.func2 = func2; |
| 201 p.func2_name = func2_name; | 202 p.func2_name = func2_name; |
| 202 p.opaque = opaque; | 203 p.opaque = opaque; |
| 204 p.error= error; | |
| 203 | 205 |
| 204 return evalExpression(&p); | 206 return evalExpression(&p); |
| 205 } | 207 } |
| 208 | |
| 209 #if LIBAVCODEC_VERSION_INT < ((51<<16)+(16<<8)+0) | |
| 210 attribute_deprecated double ff_eval(char *s, double *const_value, const char **const_name, | |
| 211 double (**func1)(void *, double), const char **func1_name, | |
| 212 double (**func2)(void *, double, double), char **func2_name, | |
| 213 void *opaque){ | |
| 214 char *error=NULL; | |
| 215 double ret; | |
| 216 ret = ff_eval2(s, const_value, const_name, func1, func1_name, func2, func2_name, opaque, &error); | |
| 217 if (error) | |
| 218 av_log(NULL, AV_LOG_ERROR, "Error evaluating \"%s\": %s\n", s, error); | |
| 219 return ret; | |
| 220 } | |
| 221 #endif | |
| 206 | 222 |
| 207 #ifdef TEST | 223 #ifdef TEST |
| 208 #undef printf | 224 #undef printf |
| 209 static double const_values[]={ | 225 static double const_values[]={ |
| 210 M_PI, | 226 M_PI, |
