summaryrefslogtreecommitdiff
path: root/libavcodec/eval.c
diff options
context:
space:
mode:
authorPanagiotis Issaris <takis.issaris@uhasselt.be>2006-09-27 20:01:39 +0000
committerPanagiotis Issaris <takis.issaris@uhasselt.be>2006-09-27 20:01:39 +0000
commit95c99430819c60d3365350875d2283e324d5af3a (patch)
treec2db462b064309ea593183f819a8d080672c4e3b /libavcodec/eval.c
parent62bb489b13c1f7967946bf538492dce0af1150fe (diff)
Make AVOption parsign code use ff_eval2()
Originally committed as revision 6357 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/eval.c')
-rw-r--r--libavcodec/eval.c62
1 files changed, 60 insertions, 2 deletions
diff --git a/libavcodec/eval.c b/libavcodec/eval.c
index 72822ee318..11ca2be2e9 100644
--- a/libavcodec/eval.c
+++ b/libavcodec/eval.c
@@ -55,10 +55,68 @@ typedef struct Parser{
char **error;
} Parser;
-extern double av_strtod(const char *name, char **tail);
-
static double evalExpression(Parser *p);
+static int8_t si_prefixes['z' - 'E' + 1]={
+ ['y'-'E']= -24,
+ ['z'-'E']= -21,
+ ['a'-'E']= -18,
+ ['f'-'E']= -15,
+ ['p'-'E']= -12,
+ ['n'-'E']= - 9,
+ ['u'-'E']= - 6,
+ ['m'-'E']= - 3,
+ ['c'-'E']= - 2,
+ ['d'-'E']= - 1,
+ ['h'-'E']= 2,
+ ['k'-'E']= 3,
+ ['K'-'E']= 3,
+ ['M'-'E']= 6,
+ ['G'-'E']= 9,
+ ['T'-'E']= 12,
+ ['P'-'E']= 15,
+ ['E'-'E']= 18,
+ ['Z'-'E']= 21,
+ ['Y'-'E']= 24,
+};
+
+/** strtod() function extended with 'k', 'M', 'G', 'ki', 'Mi', 'Gi' and 'B'
+ * postfixes. This allows using f.e. kB, MiB, G and B as a postfix. This
+ * function assumes that the unit of numbers is bits not bytes.
+ */
+static double av_strtod(const char *name, char **tail) {
+ double d;
+ int p = 0;
+ char *next;
+ d = strtod(name, &next);
+ /* if parsing succeeded, check for and interpret postfixes */
+ if (next!=name) {
+
+ if(*next >= 'E' && *next <= 'z'){
+ int e= si_prefixes[*next - 'E'];
+ if(e){
+ if(next[1] == 'i'){
+ d*= pow( 2, e/0.3);
+ next+=2;
+ }else{
+ d*= pow(10, e);
+ next++;
+ }
+ }
+ }
+
+ if(*next=='B') {
+ d*=8;
+ *next++;
+ }
+ }
+ /* if requested, fill in tail with the position after the last parsed
+ character */
+ if (tail)
+ *tail = next;
+ return d;
+}
+
static int strmatch(const char *s, const char *prefix){
int i;
for(i=0; prefix[i]; i++){