From: lilo_booter Date: Wed, 9 Jun 2004 09:22:13 +0000 (+0000) Subject: Rudimentary arithmetic property assignment X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=4a27595beb7047b430cc2df49865e269c0a0eef4;p=melted Rudimentary arithmetic property assignment git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@322 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/src/framework/mlt_properties.c b/src/framework/mlt_properties.c index cf6c792..895be28 100644 --- a/src/framework/mlt_properties.c +++ b/src/framework/mlt_properties.c @@ -25,6 +25,7 @@ #include #include #include +#include /* ---------------- // Private Implementation // ---------------- */ @@ -286,11 +287,59 @@ int mlt_properties_set( mlt_properties this, char *name, char *value ) mlt_property property = mlt_properties_fetch( this, name ); // Set it if not NULL - if ( property != NULL ) + if ( property != NULL && ( value == NULL || value[ 0 ] != '@' ) ) { error = mlt_property_set_string( property, value ); mlt_properties_do_mirror( this, name ); } + else if ( property != NULL && value[ 0 ] == '@' ) + { + int total = 0; + int current = 0; + char id[ 255 ]; + char op = '+'; + + value ++; + + while ( *value != '\0' ) + { + int length = strcspn( value, "+-*/" ); + + // Get the identifier + strncpy( id, value, length ); + id[ length ] = '\0'; + value += length; + + // Determine the value + if ( isdigit( id[ 0 ] ) ) + current = atof( id ); + else + current = mlt_properties_get_int( this, id ); + + // Apply the operation + switch( op ) + { + case '+': + total += current; + break; + case '-': + total -= current; + break; + case '*': + total *= current; + break; + case '/': + total /= current; + break; + } + + // Get the next op + op = *value != '\0' ? *value ++ : ' '; + } + + error = mlt_property_set_int( property, total ); + mlt_properties_do_mirror( this, name ); + } return error; }