comparison eval.c @ 3778:67a63fa775a7 libavcodec

Make AVOption parsign code use ff_eval2()
author takis
date Wed, 27 Sep 2006 20:01:39 +0000
parents 699bceae338c
children 3f7aa9fa5c98
comparison
equal deleted inserted replaced
3777:20545fbb6f7c 3778:67a63fa775a7
53 char **func2_name; // NULL terminated 53 char **func2_name; // NULL terminated
54 void *opaque; 54 void *opaque;
55 char **error; 55 char **error;
56 } Parser; 56 } Parser;
57 57
58 extern double av_strtod(const char *name, char **tail);
59
60 static double evalExpression(Parser *p); 58 static double evalExpression(Parser *p);
59
60 static int8_t si_prefixes['z' - 'E' + 1]={
61 ['y'-'E']= -24,
62 ['z'-'E']= -21,
63 ['a'-'E']= -18,
64 ['f'-'E']= -15,
65 ['p'-'E']= -12,
66 ['n'-'E']= - 9,
67 ['u'-'E']= - 6,
68 ['m'-'E']= - 3,
69 ['c'-'E']= - 2,
70 ['d'-'E']= - 1,
71 ['h'-'E']= 2,
72 ['k'-'E']= 3,
73 ['K'-'E']= 3,
74 ['M'-'E']= 6,
75 ['G'-'E']= 9,
76 ['T'-'E']= 12,
77 ['P'-'E']= 15,
78 ['E'-'E']= 18,
79 ['Z'-'E']= 21,
80 ['Y'-'E']= 24,
81 };
82
83 /** strtod() function extended with 'k', 'M', 'G', 'ki', 'Mi', 'Gi' and 'B'
84 * postfixes. This allows using f.e. kB, MiB, G and B as a postfix. This
85 * function assumes that the unit of numbers is bits not bytes.
86 */
87 static double av_strtod(const char *name, char **tail) {
88 double d;
89 int p = 0;
90 char *next;
91 d = strtod(name, &next);
92 /* if parsing succeeded, check for and interpret postfixes */
93 if (next!=name) {
94
95 if(*next >= 'E' && *next <= 'z'){
96 int e= si_prefixes[*next - 'E'];
97 if(e){
98 if(next[1] == 'i'){
99 d*= pow( 2, e/0.3);
100 next+=2;
101 }else{
102 d*= pow(10, e);
103 next++;
104 }
105 }
106 }
107
108 if(*next=='B') {
109 d*=8;
110 *next++;
111 }
112 }
113 /* if requested, fill in tail with the position after the last parsed
114 character */
115 if (tail)
116 *tail = next;
117 return d;
118 }
61 119
62 static int strmatch(const char *s, const char *prefix){ 120 static int strmatch(const char *s, const char *prefix){
63 int i; 121 int i;
64 for(i=0; prefix[i]; i++){ 122 for(i=0; prefix[i]; i++){
65 if(prefix[i] != s[i]) return 0; 123 if(prefix[i] != s[i]) return 0;