applied patches from Huub Schaeks
[swftools.git] / lib / q.c
diff --git a/lib/q.c b/lib/q.c
index 400c92d..0083dcd 100644 (file)
--- a/lib/q.c
+++ b/lib/q.c
@@ -36,30 +36,6 @@ char* strdup_n(const char*str, int size)
     return m;
 }
 #endif
-void* qmalloc_internal(int len)
-{
-    void*val = malloc(len);
-    if(!val) {
-       printf("memory error! Couldn't reserve %d bytes\n", len);
-       fprintf(stderr, "memory error! Couldn't reserve %d bytes\n", len);
-       exit(1);
-    }
-    return val;
-}
-void* qrealloc_internal(void*old, int len)
-{
-    void*val = realloc(old, len);
-    if(!val) {
-       printf("memory error! Couldn't reserve %d bytes\n", len);
-       fprintf(stderr, "memory error! Couldn't reserve %d bytes\n", len);
-       exit(1);
-    }
-    return val;
-}
-void qfree_internal(void*old)
-{
-    free(old);
-}
 char*qstrdup(const char*string)
 {
     return strdup(string);
@@ -408,6 +384,12 @@ void dictionary_put2(dictionary_t*dict, const char*t1, void* t2)
     string_set(&s, (char*)t1);
     dictionary_put(dict, s, t2);
 }
+stringarray_t* dictionary_index(dictionary_t*dict)
+{
+    dictionary_internal_t*d = (dictionary_internal_t*)dict->internal;
+    return &d->keys;
+}
+
 void* dictionary_lookup(dictionary_t*dict, const char*name)
 {
     int s;
@@ -454,6 +436,20 @@ void dictionary_destroy(dictionary_t*dict)
     free(dict);
 }
 
+void dictionary_free_all(dictionary_t* dict, void (*freeFunction)(void*))
+{
+    dictionary_internal_t*d = (dictionary_internal_t*)dict->internal;
+    int num = 0;
+    char* name = stringarray_at(&d->keys, num)    ;
+    while (name)
+    {
+        freeFunction(dictionary_lookup(dict, name));
+        num++;
+        name = stringarray_at(&d->keys, num);
+    }
+    dictionary_clear(dict);
+}
+
 // ------------------------------- heap_t -------------------------------
 
 void heap_init(heap_t*h,int n,int elem_size, int(*compare)(const void *, const void *))