]> git.sesse.net Git - mlt/blob - src/framework/mlt_properties.c
+ Adds a utility function for listing files in a directory (aids with cross platform...
[mlt] / src / framework / mlt_properties.c
1 /*
2  * mlt_properties.c -- base properties class
3  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4  * Author: Charles Yates <charles.yates@pandora.be>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #include "config.h"
22 #include "mlt_properties.h"
23 #include "mlt_property.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <ctype.h>
29
30 #include <sys/types.h>
31 #include <dirent.h>
32
33 /* ---------------- // Private Implementation // ---------------- */
34
35 /** Private implementation of the property list.
36 */
37
38 typedef struct
39 {
40         int hash[ 199 ];
41         char **name;
42         mlt_property *value;
43         int count;
44         int size;
45         mlt_properties mirror;
46         int ref_count;
47 }
48 property_list;
49
50 /** Memory leak checks.
51 */
52
53 //#define _MLT_PROPERTY_CHECKS_ 2
54
55 #ifdef _MLT_PROPERTY_CHECKS_
56 static int properties_created = 0;
57 static int properties_destroyed = 0;
58 #endif
59
60 /** Basic implementation.
61 */
62
63 int mlt_properties_init( mlt_properties this, void *child )
64 {
65         if ( this != NULL )
66         {
67 #ifdef _MLT_PROPERTY_CHECKS_
68                 // Increment number of properties created
69                 properties_created ++;
70 #endif
71
72                 // NULL all methods
73                 memset( this, 0, sizeof( struct mlt_properties_s ) );
74
75                 // Assign the child of the object
76                 this->child = child;
77
78                 // Allocate the local structure
79                 this->local = calloc( sizeof( property_list ), 1 );
80
81                 // Increment the ref count
82                 ( ( property_list * )this->local )->ref_count = 1;
83         }
84
85         // Check that initialisation was successful
86         return this != NULL && this->local == NULL;
87 }
88
89 /** Constructor for stand alone object.
90 */
91
92 mlt_properties mlt_properties_new( )
93 {
94         // Construct a standalone properties object
95         mlt_properties this = calloc( sizeof( struct mlt_properties_s ), 1 );
96
97         // Initialise this
98         mlt_properties_init( this, NULL );
99
100         // Return the pointer
101         return this;
102 }
103
104 /** Load properties from a file.
105 */
106
107 mlt_properties mlt_properties_load( const char *filename )
108 {
109         // Construct a standalone properties object
110         mlt_properties this = mlt_properties_new( );
111
112         if ( this != NULL )
113         {
114                 // Open the file
115                 FILE *file = fopen( filename, "r" );
116
117                 // Load contents of file
118                 if ( file != NULL )
119                 {
120                         // Temp string
121                         char temp[ 1024 ];
122                         char last[ 1024 ] = "";
123
124                         // Read each string from the file
125                         while( fgets( temp, 1024, file ) )
126                         {
127                                 // Chomp the string
128                                 temp[ strlen( temp ) - 1 ] = '\0';
129
130                                 // Check if the line starts with a .
131                                 if ( temp[ 0 ] == '.' )
132                                 {
133                                         char temp2[ 1024 ];
134                                         sprintf( temp2, "%s%s", last, temp );
135                                         strcpy( temp, temp2 );
136                                 }
137                                 else if ( strchr( temp, '=' ) )
138                                 {
139                                         strcpy( last, temp );
140                                         *( strchr( last, '=' ) ) = '\0';
141                                 }
142
143                                 // Parse and set the property
144                                 if ( strcmp( temp, "" ) && temp[ 0 ] != '#' )
145                                         mlt_properties_parse( this, temp );
146                         }
147
148                         // Close the file
149                         fclose( file );
150                 }
151         }
152
153         // Return the pointer
154         return this;
155 }
156
157 static inline int generate_hash( const char *name )
158 {
159         int hash = 0;
160         int i = 1;
161         while ( *name )
162                 hash = ( hash + ( i ++ * ( *name ++ & 31 ) ) ) % 199;
163         return hash;
164 }
165
166 /** Special case - when a container (such as fezzik) is protecting another 
167         producer, we need to ensure that properties are passed through to the
168         real producer.
169 */
170
171 static inline void mlt_properties_do_mirror( mlt_properties this, const char *name )
172 {
173         property_list *list = this->local;
174         if ( list->mirror != NULL ) 
175         {
176                 char *value = mlt_properties_get( this, name );
177                 if ( value != NULL )
178                         mlt_properties_set( list->mirror, name, value );
179         }
180 }
181
182 /** Maintain ref count to allow multiple uses of an mlt object.
183 */
184
185 int mlt_properties_inc_ref( mlt_properties this )
186 {
187         if ( this != NULL )
188         {
189                 property_list *list = this->local;
190                 return ++ list->ref_count;
191         }
192         return 0;
193 }
194
195 /** Maintain ref count to allow multiple uses of an mlt object.
196 */
197
198 int mlt_properties_dec_ref( mlt_properties this )
199 {
200         if ( this != NULL )
201         {
202                 property_list *list = this->local;
203                 return -- list->ref_count;
204         }
205         return 0;
206 }
207
208 /** Return the ref count of this object.
209 */
210
211 int mlt_properties_ref_count( mlt_properties this )
212 {
213         if ( this != NULL )
214         {
215                 property_list *list = this->local;
216                 return list->ref_count;
217         }
218         return 0;
219 }
220
221 /** Mirror properties set on 'this' to 'that'.
222 */
223
224 void mlt_properties_mirror( mlt_properties this, mlt_properties that )
225 {
226         property_list *list = this->local;
227         list->mirror = that;
228 }
229
230 /** Inherit all serialisable properties from that into this.
231 */
232
233 int mlt_properties_inherit( mlt_properties this, mlt_properties that )
234 {
235         int count = mlt_properties_count( that );
236         int i = 0;
237         for ( i = 0; i < count; i ++ )
238         {
239                 char *value = mlt_properties_get_value( that, i );
240                 if ( value != NULL )
241                 {
242                         char *name = mlt_properties_get_name( that, i );
243                         mlt_properties_set( this, name, value );
244                 }
245         }
246         return 0;
247 }
248
249 /** Pass all properties from 'that' that match the prefix to 'this' (excluding the prefix).
250 */
251
252 int mlt_properties_pass( mlt_properties this, mlt_properties that, const char *prefix )
253 {
254         int count = mlt_properties_count( that );
255         int length = strlen( prefix );
256         int i = 0;
257         for ( i = 0; i < count; i ++ )
258         {
259                 char *name = mlt_properties_get_name( that, i );
260                 if ( !strncmp( name, prefix, length ) )
261                 {
262                         char *value = mlt_properties_get_value( that, i );
263                         if ( value != NULL )
264                                 mlt_properties_set( this, name + length, value );
265                 }
266         }
267         return 0;
268 }
269
270 /** Locate a property by name
271 */
272
273 static inline mlt_property mlt_properties_find( mlt_properties this, const char *name )
274 {
275         property_list *list = this->local;
276         mlt_property value = NULL;
277         int key = generate_hash( name );
278         int i = list->hash[ key ] - 1;
279
280         if ( i >= 0 )
281         {
282                 // Check if we're hashed
283                 if ( list->count > 0 &&
284                         name[ 0 ] == list->name[ i ][ 0 ] && 
285                         !strcmp( list->name[ i ], name ) )
286                         value = list->value[ i ];
287
288                 // Locate the item 
289                 for ( i = list->count - 1; value == NULL && i >= 0; i -- )
290                         if ( name[ 0 ] == list->name[ i ][ 0 ] && !strcmp( list->name[ i ], name ) )
291                                 value = list->value[ i ];
292         }
293
294         return value;
295 }
296
297 /** Add a new property.
298 */
299
300 static mlt_property mlt_properties_add( mlt_properties this, const char *name )
301 {
302         property_list *list = this->local;
303         int key = generate_hash( name );
304
305         // Check that we have space and resize if necessary
306         if ( list->count == list->size )
307         {
308                 list->size += 50;
309                 list->name = realloc( list->name, list->size * sizeof( const char * ) );
310                 list->value = realloc( list->value, list->size * sizeof( mlt_property ) );
311         }
312
313         // Assign name/value pair
314         list->name[ list->count ] = strdup( name );
315         list->value[ list->count ] = mlt_property_init( );
316
317         // Assign to hash table
318         if ( list->hash[ key ] == 0 )
319                 list->hash[ key ] = list->count + 1;
320
321         // Return and increment count accordingly
322         return list->value[ list->count ++ ];
323 }
324
325 /** Fetch a property by name - this includes add if not found.
326 */
327
328 static mlt_property mlt_properties_fetch( mlt_properties this, const char *name )
329 {
330         // Try to find an existing property first
331         mlt_property property = mlt_properties_find( this, name );
332
333         // If it wasn't found, create one
334         if ( property == NULL )
335                 property = mlt_properties_add( this, name );
336
337         // Return the property
338         return property;
339 }
340
341 /** Pass property 'name' from 'that' to 'this' 
342 * Who to blame: Zach <zachary.drew@gmail.com>
343 */
344
345 void mlt_properties_pass_property( mlt_properties this, mlt_properties that, const char *name )
346 {
347         // Make sure the source property isn't null.
348         mlt_property that_prop = mlt_properties_find( that, name );
349         if( that_prop == NULL )
350                 return;
351
352         mlt_property_pass( mlt_properties_fetch( this, name ), that_prop );
353 }
354
355 /** Pass all properties from 'that' to 'this' as found in comma seperated 'list'.
356 * Who to blame: Zach <zachary.drew@gmail.com>
357 */
358
359 int mlt_properties_pass_list( mlt_properties this, mlt_properties that, const char *list )
360 {
361         char *props = strdup( list );
362         char *ptr = props;
363         char *delim = " ,\t\n"; // Any combination of spaces, commas, tabs, and newlines
364         int count, done = 0;
365
366         while( !done )
367         {
368                 count = strcspn( ptr, delim );
369
370                 if( ptr[count] == '\0' )
371                         done = 1;
372                 else
373                         ptr[count] = '\0';      // Make it a real string
374
375                 mlt_properties_pass_property( this, that, ptr );
376
377                 ptr += count + 1;
378                 ptr += strspn( ptr, delim );
379         }
380
381         free( props );
382
383         return 0;
384 }
385
386
387 /** Set the property.
388 */
389
390 int mlt_properties_set( mlt_properties this, const char *name, const char *value )
391 {
392         int error = 1;
393
394         // Fetch the property to work with
395         mlt_property property = mlt_properties_fetch( this, name );
396
397         // Set it if not NULL
398         if ( property == NULL )
399         {
400                 fprintf( stderr, "Whoops - %s not found (should never occur)\n", name );
401         }
402         else if ( value == NULL )
403         {
404                 error = mlt_property_set_string( property, value );
405                 mlt_properties_do_mirror( this, name );
406         }
407         else if ( *value != '@' )
408         {
409                 error = mlt_property_set_string( property, value );
410                 mlt_properties_do_mirror( this, name );
411         }
412         else if ( value[ 0 ] == '@' )
413         {
414                 int total = 0;
415                 int current = 0;
416                 char id[ 255 ];
417                 char op = '+';
418
419                 value ++;
420
421                 while ( *value != '\0' )
422                 {
423                         int length = strcspn( value, "+-*/" );
424
425                         // Get the identifier
426                         strncpy( id, value, length );
427                         id[ length ] = '\0';
428                         value += length;
429
430                         // Determine the value
431                         if ( isdigit( id[ 0 ] ) )
432                                 current = atof( id );
433                         else
434                                 current = mlt_properties_get_int( this, id );
435
436                         // Apply the operation
437                         switch( op )
438                         {
439                                 case '+':
440                                         total += current;
441                                         break;
442                                 case '-':
443                                         total -= current;
444                                         break;
445                                 case '*':
446                                         total *= current;
447                                         break;
448                                 case '/':
449                                         total /= current;
450                                         break;
451                         }
452
453                         // Get the next op
454                         op = *value != '\0' ? *value ++ : ' ';
455                 }
456
457                 error = mlt_property_set_int( property, total );
458                 mlt_properties_do_mirror( this, name );
459         }
460
461         mlt_events_fire( this, "property-changed", name, NULL );
462
463         return error;
464 }
465
466 /** Set or default the property.
467 */
468
469 int mlt_properties_set_or_default( mlt_properties this, const char *name, const char *value, const char *def )
470 {
471         return mlt_properties_set( this, name, value == NULL ? def : value );
472 }
473
474 /** Get a string value by name.
475 */
476
477 char *mlt_properties_get( mlt_properties this, const char *name )
478 {
479         mlt_property value = mlt_properties_find( this, name );
480         return value == NULL ? NULL : mlt_property_get_string( value );
481 }
482
483 /** Get a name by index.
484 */
485
486 char *mlt_properties_get_name( mlt_properties this, int index )
487 {
488         property_list *list = this->local;
489         if ( index >= 0 && index < list->count )
490                 return list->name[ index ];
491         return NULL;
492 }
493
494 /** Get a string value by index.
495 */
496
497 char *mlt_properties_get_value( mlt_properties this, int index )
498 {
499         property_list *list = this->local;
500         if ( index >= 0 && index < list->count )
501                 return mlt_property_get_string( list->value[ index ] );
502         return NULL;
503 }
504
505 /** Get a data value by index.
506 */
507
508 void *mlt_properties_get_data_at( mlt_properties this, int index, int *size )
509 {
510         property_list *list = this->local;
511         if ( index >= 0 && index < list->count )
512                 return mlt_property_get_data( list->value[ index ], size );
513         return NULL;
514 }
515
516 /** Return the number of items in the list.
517 */
518
519 int mlt_properties_count( mlt_properties this )
520 {
521         property_list *list = this->local;
522         return list->count;
523 }
524
525 /** Set a value by parsing a name=value string
526 */
527
528 int mlt_properties_parse( mlt_properties this, const char *namevalue )
529 {
530         char *name = strdup( namevalue );
531         char *value = NULL;
532         int error = 0;
533         char *ptr = strchr( name, '=' );
534
535         if ( ptr )
536         {
537                 *( ptr ++ ) = '\0';
538
539                 if ( *ptr != '\"' )
540                 {
541                         value = strdup( ptr );
542                 }
543                 else
544                 {
545                         ptr ++;
546                         value = strdup( ptr );
547                         if ( value != NULL && value[ strlen( value ) - 1 ] == '\"' )
548                                 value[ strlen( value ) - 1 ] = '\0';
549                 }
550         }
551         else
552         {
553                 value = strdup( "" );
554         }
555
556         error = mlt_properties_set( this, name, value );
557
558         free( name );
559         free( value );
560
561         return error;
562 }
563
564 /** Get a value associated to the name.
565 */
566
567 int mlt_properties_get_int( mlt_properties this, const char *name )
568 {
569         mlt_property value = mlt_properties_find( this, name );
570         return value == NULL ? 0 : mlt_property_get_int( value );
571 }
572
573 /** Set a value associated to the name.
574 */
575
576 int mlt_properties_set_int( mlt_properties this, const char *name, int value )
577 {
578         int error = 1;
579
580         // Fetch the property to work with
581         mlt_property property = mlt_properties_fetch( this, name );
582
583         // Set it if not NULL
584         if ( property != NULL )
585         {
586                 error = mlt_property_set_int( property, value );
587                 mlt_properties_do_mirror( this, name );
588         }
589
590         mlt_events_fire( this, "property-changed", name, NULL );
591
592         return error;
593 }
594
595 /** Get a value associated to the name.
596 */
597
598 int64_t mlt_properties_get_int64( mlt_properties this, const char *name )
599 {
600         mlt_property value = mlt_properties_find( this, name );
601         return value == NULL ? 0 : mlt_property_get_int64( value );
602 }
603
604 /** Set a value associated to the name.
605 */
606
607 int mlt_properties_set_int64( mlt_properties this, const char *name, int64_t value )
608 {
609         int error = 1;
610
611         // Fetch the property to work with
612         mlt_property property = mlt_properties_fetch( this, name );
613
614         // Set it if not NULL
615         if ( property != NULL )
616         {
617                 error = mlt_property_set_int64( property, value );
618                 mlt_properties_do_mirror( this, name );
619         }
620
621         mlt_events_fire( this, "property-changed", name, NULL );
622
623         return error;
624 }
625
626 /** Get a value associated to the name.
627 */
628
629 double mlt_properties_get_double( mlt_properties this, const char *name )
630 {
631         mlt_property value = mlt_properties_find( this, name );
632         return value == NULL ? 0 : mlt_property_get_double( value );
633 }
634
635 /** Set a value associated to the name.
636 */
637
638 int mlt_properties_set_double( mlt_properties this, const char *name, double value )
639 {
640         int error = 1;
641
642         // Fetch the property to work with
643         mlt_property property = mlt_properties_fetch( this, name );
644
645         // Set it if not NULL
646         if ( property != NULL )
647         {
648                 error = mlt_property_set_double( property, value );
649                 mlt_properties_do_mirror( this, name );
650         }
651
652         mlt_events_fire( this, "property-changed", name, NULL );
653
654         return error;
655 }
656
657 /** Get a value associated to the name.
658 */
659
660 mlt_position mlt_properties_get_position( mlt_properties this, const char *name )
661 {
662         mlt_property value = mlt_properties_find( this, name );
663         return value == NULL ? 0 : mlt_property_get_position( value );
664 }
665
666 /** Set a value associated to the name.
667 */
668
669 int mlt_properties_set_position( mlt_properties this, const char *name, mlt_position value )
670 {
671         int error = 1;
672
673         // Fetch the property to work with
674         mlt_property property = mlt_properties_fetch( this, name );
675
676         // Set it if not NULL
677         if ( property != NULL )
678         {
679                 error = mlt_property_set_position( property, value );
680                 mlt_properties_do_mirror( this, name );
681         }
682
683         mlt_events_fire( this, "property-changed", name, NULL );
684
685         return error;
686 }
687
688 /** Get a value associated to the name.
689 */
690
691 void *mlt_properties_get_data( mlt_properties this, const char *name, int *length )
692 {
693         mlt_property value = mlt_properties_find( this, name );
694         return value == NULL ? NULL : mlt_property_get_data( value, length );
695 }
696
697 /** Set a value associated to the name.
698 */
699
700 int mlt_properties_set_data( mlt_properties this, const char *name, void *value, int length, mlt_destructor destroy, mlt_serialiser serialise )
701 {
702         int error = 1;
703
704         // Fetch the property to work with
705         mlt_property property = mlt_properties_fetch( this, name );
706
707         // Set it if not NULL
708         if ( property != NULL )
709                 error = mlt_property_set_data( property, value, length, destroy, serialise );
710
711         mlt_events_fire( this, "property-changed", name, NULL );
712
713         return error;
714 }
715
716 /** Rename a property.
717 */
718
719 int mlt_properties_rename( mlt_properties this, const char *source, const char *dest )
720 {
721         mlt_property value = mlt_properties_find( this, dest );
722
723         if ( value == NULL )
724         {
725                 property_list *list = this->local;
726                 int i = 0;
727
728                 // Locate the item 
729                 for ( i = 0; i < list->count; i ++ )
730                 {
731                         if ( !strcmp( list->name[ i ], source ) )
732                         {
733                                 free( list->name[ i ] );
734                                 list->name[ i ] = strdup( dest );
735                                 list->hash[ generate_hash( dest ) ] = i + 1;
736                                 break;
737                         }
738                 }
739         }
740
741         return value != NULL;
742 }
743
744 /** Dump the properties.
745 */
746
747 void mlt_properties_dump( mlt_properties this, FILE *output )
748 {
749         property_list *list = this->local;
750         int i = 0;
751         for ( i = 0; i < list->count; i ++ )
752                 if ( mlt_properties_get( this, list->name[ i ] ) != NULL )
753                         fprintf( output, "%s=%s\n", list->name[ i ], mlt_properties_get( this, list->name[ i ] ) );
754 }
755
756 void mlt_properties_debug( mlt_properties this, const char *title, FILE *output )
757 {
758         if ( output == NULL ) output = stderr;
759         fprintf( output, "%s: ", title );
760         if ( this != NULL )
761         {
762                 property_list *list = this->local;
763                 int i = 0;
764                 fprintf( output, "[ ref=%d", list->ref_count );
765                 for ( i = 0; i < list->count; i ++ )
766                         if ( mlt_properties_get( this, list->name[ i ] ) != NULL )
767                                 fprintf( output, ", %s=%s", list->name[ i ], mlt_properties_get( this, list->name[ i ] ) );
768                         else
769                                 fprintf( output, ", %s=%p", list->name[ i ], mlt_properties_get_data( this, list->name[ i ], NULL ) );
770                 fprintf( output, " ]" );
771         }
772         fprintf( output, "\n" );
773 }
774
775 int mlt_properties_save( mlt_properties this, const char *filename )
776 {
777         int error = 1;
778         FILE *f = fopen( filename, "w" );
779         if ( f != NULL )
780         {
781                 mlt_properties_dump( this, f );
782                 fclose( f );
783                 error = 0;
784         }
785         return error;
786 }
787
788 /* This is a very basic cross platform fnmatch replacement - it will fail in
789 ** many cases, but for the basic *.XXX and YYY*.XXX, it will work ok.
790 */
791
792 static int mlt_fnmatch( const char *wild, const char *file )
793 {
794         int f = 0;
795         int w = 0;
796
797         while( f < strlen( file ) && w < strlen( wild ) )
798         {
799                 if ( wild[ w ] == '*' )
800                 {
801                         w ++;
802                         if ( w == strlen( wild ) )
803                                 f = strlen( file );
804                         while ( f != strlen( file ) && tolower( file[ f ] ) != tolower( wild[ w ] ) )
805                                 f ++;
806                 }
807                 else if ( wild[ w ] == '?' || tolower( file[ f ] ) == tolower( wild[ w ] ) )
808                 {
809                         f ++;
810                         w ++;
811                 }
812                 else if ( wild[ 0 ] == '*' )
813                 {
814                         w = 0;
815                 }
816                 else
817                 {
818                         return 0;
819                 }
820         }
821
822         return strlen( file ) == f &&  strlen( wild ) == w;
823 }
824
825 static int mlt_compare( const void *this, const void *that )
826 {
827         return strcmp( mlt_property_get_string( *( mlt_property * )this ), mlt_property_get_string( *( mlt_property * )that ) );
828 }
829
830 /* Obtains an optionally sorted list of the files found in a directory with a specific wild card.
831  * Entries in the list have a numeric name (running from 0 to count - 1). Only values change
832  * position if sort is enabled. Designed to be posix compatible (linux, os/x, mingw etc).
833  */
834
835 int mlt_properties_dir_list( mlt_properties this, const char *dirname, const char *pattern, int sort )
836 {
837         DIR *dir = opendir( dirname );
838
839         if ( dir )
840         {
841                 char key[ 20 ];
842                 struct dirent *de = readdir( dir );
843                 char fullname[ 1024 ];
844                 while( de != NULL )
845                 {
846                         sprintf( key, "%d", mlt_properties_count( this ) );
847                         snprintf( fullname, 1024, "%s/%s", dirname, de->d_name );
848                         if ( de->d_name[ 0 ] != '.' && mlt_fnmatch( pattern, de->d_name ) )
849                                 mlt_properties_set( this, key, fullname );
850                         de = readdir( dir );
851                 }
852
853                 closedir( dir );
854         }
855
856         if ( sort && mlt_properties_count( this ) )
857         {
858                 property_list *list = this->local;
859                 qsort( list->value, mlt_properties_count( this ), sizeof( mlt_property ), mlt_compare );
860         }
861
862         return mlt_properties_count( this );
863 }
864
865 /** Close the list.
866 */
867
868 void mlt_properties_close( mlt_properties this )
869 {
870         if ( this != NULL && mlt_properties_dec_ref( this ) <= 0 )
871         {
872                 if ( this->close != NULL )
873                 {
874                         this->close( this->close_object );
875                 }
876                 else
877                 {
878                         property_list *list = this->local;
879                         int index = 0;
880
881 #if _MLT_PROPERTY_CHECKS_ == 1
882                         // Show debug info
883                         mlt_properties_debug( this, "Closing", stderr );
884 #endif
885
886 #ifdef _MLT_PROPERTY_CHECKS_
887                         // Increment destroyed count
888                         properties_destroyed ++;
889
890                         // Show current stats - these should match when the app is closed
891                         fprintf( stderr, "Created %d, destroyed %d\n", properties_created, properties_destroyed );
892 #endif
893
894                         // Clean up names and values
895                         for ( index = list->count - 1; index >= 0; index -- )
896                         {
897                                 free( list->name[ index ] );
898                                 mlt_property_close( list->value[ index ] );
899                         }
900         
901                         // Clear up the list
902                         free( list->name );
903                         free( list->value );
904                         free( list );
905         
906                         // Free this now if this has no child
907                         if ( this->child == NULL )
908                                 free( this );
909                 }
910         }
911 }
912