X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fq.c;h=0083dcd56056cc3482d0d7e418e4499c12bf4cde;hb=3ef17c4cee41231e1eed731c08381d3ddf0c8d1a;hp=400c92d933e42ae0da08a5044ece1252ea8aa0a7;hpb=9788caae660683c6c8f98f53b3fc1a4274b73e47;p=swftools.git diff --git a/lib/q.c b/lib/q.c index 400c92d..0083dcd 100644 --- 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 *))