const_name -> const_names const_value -> const_values func[12]_name -> func[12]_names func[12] -> funcs[12] All these parameters contain a list of values, using plural names for them help understanding a little. Originally committed as revision 23403 to svn://svn.ffmpeg.org/ffmpeg/trunktags/n0.8
| @@ -33,12 +33,12 @@ typedef struct Parser{ | |||
| const AVClass *class; | |||
| int stack_index; | |||
| char *s; | |||
| const double *const_value; | |||
| const char * const *const_name; // NULL terminated | |||
| double (* const *func1)(void *, double a); // NULL terminated | |||
| const char * const *func1_name; // NULL terminated | |||
| double (* const *func2)(void *, double a, double b); // NULL terminated | |||
| const char * const *func2_name; // NULL terminated | |||
| const double *const_values; | |||
| const char * const *const_names; // NULL terminated | |||
| double (* const *funcs1)(void *, double a); // NULL terminated | |||
| const char * const *func1_names; // NULL terminated | |||
| double (* const *funcs2)(void *, double a, double b); // NULL terminated | |||
| const char * const *func2_names; // NULL terminated | |||
| void *opaque; | |||
| int log_offset; | |||
| void *log_ctx; | |||
| @@ -132,7 +132,7 @@ struct AVExpr { | |||
| 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_value[e->a.const_index]; | |||
| case e_const: return e->value * p->const_values[e->a.const_index]; | |||
| case e_func0: return e->value * e->a.func0(eval_expr(p, e->param[0])); | |||
| case e_func1: return e->value * e->a.func1(p->opaque, eval_expr(p, e->param[0])); | |||
| case e_func2: return e->value * e->a.func2(p->opaque, eval_expr(p, e->param[0]), eval_expr(p, e->param[1])); | |||
| @@ -196,9 +196,9 @@ static int parse_primary(AVExpr **e, Parser *p) | |||
| d->value = 1; | |||
| /* named constants */ | |||
| for(i=0; p->const_name && p->const_name[i]; i++){ | |||
| if(strmatch(p->s, p->const_name[i])){ | |||
| p->s+= strlen(p->const_name[i]); | |||
| for(i=0; p->const_names && p->const_names[i]; i++){ | |||
| if(strmatch(p->s, p->const_names[i])){ | |||
| p->s+= strlen(p->const_names[i]); | |||
| d->type = e_const; | |||
| d->a.const_index = i; | |||
| *e = d; | |||
| @@ -269,18 +269,18 @@ static int parse_primary(AVExpr **e, Parser *p) | |||
| else if( strmatch(next, "st" ) ) d->type = e_st; | |||
| else if( strmatch(next, "while" ) ) d->type = e_while; | |||
| else { | |||
| for(i=0; p->func1_name && p->func1_name[i]; i++){ | |||
| if(strmatch(next, p->func1_name[i])){ | |||
| d->a.func1 = p->func1[i]; | |||
| for(i=0; p->func1_names && p->func1_names[i]; i++){ | |||
| if(strmatch(next, p->func1_names[i])){ | |||
| d->a.func1 = p->funcs1[i]; | |||
| d->type = e_func1; | |||
| *e = d; | |||
| return 0; | |||
| } | |||
| } | |||
| for(i=0; p->func2_name && p->func2_name[i]; i++){ | |||
| if(strmatch(next, p->func2_name[i])){ | |||
| d->a.func2 = p->func2[i]; | |||
| for(i=0; p->func2_names && p->func2_names[i]; i++){ | |||
| if(strmatch(next, p->func2_names[i])){ | |||
| d->a.func2 = p->funcs2[i]; | |||
| d->type = e_func2; | |||
| *e = d; | |||
| return 0; | |||
| @@ -434,9 +434,9 @@ static int verify_expr(AVExpr * e) { | |||
| } | |||
| int ff_parse_expr(AVExpr **expr, const char *s, | |||
| const char * const *const_name, | |||
| const char * const *func1_name, double (* const *func1)(void *, double), | |||
| const char * const *func2_name, double (* const *func2)(void *, double, double), | |||
| const char * const *const_names, | |||
| const char * const *func1_names, double (* const *funcs1)(void *, double), | |||
| const char * const *func2_names, double (* const *funcs2)(void *, double, double), | |||
| int log_offset, void *log_ctx) | |||
| { | |||
| Parser p; | |||
| @@ -455,11 +455,11 @@ int ff_parse_expr(AVExpr **expr, const char *s, | |||
| p.class = &class; | |||
| p.stack_index=100; | |||
| p.s= w; | |||
| p.const_name = const_name; | |||
| p.func1 = func1; | |||
| p.func1_name = func1_name; | |||
| p.func2 = func2; | |||
| p.func2_name = func2_name; | |||
| p.const_names = const_names; | |||
| p.funcs1 = funcs1; | |||
| p.func1_names = func1_names; | |||
| p.funcs2 = funcs2; | |||
| p.func2_names = func2_names; | |||
| p.log_offset = log_offset; | |||
| p.log_ctx = log_ctx; | |||
| @@ -476,28 +476,28 @@ end: | |||
| return ret; | |||
| } | |||
| double ff_eval_expr(AVExpr * e, const double *const_value, void *opaque) { | |||
| double ff_eval_expr(AVExpr *e, const double *const_values, void *opaque) { | |||
| Parser p; | |||
| p.const_value= const_value; | |||
| p.const_values = const_values; | |||
| p.opaque = opaque; | |||
| return eval_expr(&p, e); | |||
| } | |||
| int ff_parse_and_eval_expr(double *d, const char *s, | |||
| const char * const *const_name, const double *const_value, | |||
| const char * const *func1_name, double (* const *func1)(void *, double), | |||
| const char * const *func2_name, double (* const *func2)(void *, double, double), | |||
| const char * const *const_names, const double *const_values, | |||
| const char * const *func1_names, double (* const *funcs1)(void *, double), | |||
| const char * const *func2_names, double (* const *funcs2)(void *, double, double), | |||
| void *opaque, int log_offset, void *log_ctx) | |||
| { | |||
| AVExpr *e = NULL; | |||
| int ret = ff_parse_expr(&e, s, const_name, func1_name, func1, func2_name, func2, log_offset, log_ctx); | |||
| int ret = ff_parse_expr(&e, s, const_names, func1_names, funcs1, func2_names, funcs2, log_offset, log_ctx); | |||
| if (ret < 0) { | |||
| *d = NAN; | |||
| return ret; | |||
| } | |||
| *d = ff_eval_expr(e, const_value, opaque); | |||
| *d = ff_eval_expr(e, const_values, opaque); | |||
| ff_free_expr(e); | |||
| return isnan(*d) ? AVERROR(EINVAL) : 0; | |||
| } | |||
| @@ -35,21 +35,21 @@ typedef struct AVExpr AVExpr; | |||
| * @param res a pointer to a double where is put the result value of | |||
| * the expression, or NAN in case of error | |||
| * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)" | |||
| * @param const_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0} | |||
| * @param const_value a zero terminated array of values for the identifers from const_name | |||
| * @param func1_name NULL terminated array of zero terminated strings of func1 identifers | |||
| * @param func1 NULL terminated array of function pointers for functions which take 1 argument | |||
| * @param func2_name NULL terminated array of zero terminated strings of func2 identifers | |||
| * @param func2 NULL terminated array of function pointers for functions which take 2 arguments | |||
| * @param opaque a pointer which will be passed to all functions from func1 and func2 | |||
| * @param const_names NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0} | |||
| * @param const_values a zero terminated array of values for the identifers from const_names | |||
| * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifers | |||
| * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument | |||
| * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifers | |||
| * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments | |||
| * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2 | |||
| * @param log_ctx parent logging context | |||
| * @return 0 in case of success, a negative value corresponding to an | |||
| * AVERROR code otherwise | |||
| */ | |||
| int ff_parse_and_eval_expr(double *res, const char *s, | |||
| const char * const *const_name, const double *const_value, | |||
| const char * const *func1_name, double (* const *func1)(void *, double), | |||
| const char * const *func2_name, double (* const *func2)(void *, double, double), | |||
| const char * const *const_names, const double *const_values, | |||
| const char * const *func1_names, double (* const *funcs1)(void *, double), | |||
| const char * const *func2_names, double (* const *funcs2)(void *, double, double), | |||
| void *opaque, int log_offset, void *log_ctx); | |||
| /** | |||
| @@ -60,29 +60,29 @@ int ff_parse_and_eval_expr(double *res, const char *s, | |||
| * The pointed to AVExpr must be freed with ff_free_expr() by the user | |||
| * when it is not needed anymore. | |||
| * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)" | |||
| * @param const_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0} | |||
| * @param func1_name NULL terminated array of zero terminated strings of func1 identifers | |||
| * @param func1 NULL terminated array of function pointers for functions which take 1 argument | |||
| * @param func2_name NULL terminated array of zero terminated strings of func2 identifers | |||
| * @param func2 NULL terminated array of function pointers for functions which take 2 arguments | |||
| * @param const_names NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0} | |||
| * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifers | |||
| * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument | |||
| * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifers | |||
| * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments | |||
| * @param log_ctx parent logging context | |||
| * @return 0 in case of success, a negative value corresponding to an | |||
| * AVERROR code otherwise | |||
| */ | |||
| int ff_parse_expr(AVExpr **expr, const char *s, | |||
| const char * const *const_name, | |||
| const char * const *func1_name, double (* const *func1)(void *, double), | |||
| const char * const *func2_name, double (* const *func2)(void *, double, double), | |||
| const char * const *const_names, | |||
| const char * const *func1_names, double (* const *funcs1)(void *, double), | |||
| const char * const *func2_names, double (* const *funcs2)(void *, double, double), | |||
| int log_offset, void *log_ctx); | |||
| /** | |||
| * Evaluates a previously parsed expression. | |||
| * | |||
| * @param const_value a zero terminated array of values for the identifers from ff_parse const_name | |||
| * @param opaque a pointer which will be passed to all functions from func1 and func2 | |||
| * @param const_values a zero terminated array of values for the identifers from ff_parse() const_names | |||
| * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2 | |||
| * @return the value of the expression | |||
| */ | |||
| double ff_eval_expr(AVExpr * e, const double *const_value, void *opaque); | |||
| double ff_eval_expr(AVExpr *e, const double *const_values, void *opaque); | |||
| /** | |||
| * Frees a parsed expression previously created with ff_parse_expr(). | |||