3 Part of the swftools package.
5 Copyright (c) 2001,2002,2003,2004 Matthias Kramm <kramm@quiss.org>
7 This program is rfx_free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the rfx_free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the rfx_free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
31 // ------------------------------- malloc, alloc routines ---------------------
34 char* strdup_n(const char*str, int size)
36 char*m = (char*)rfx_alloc(size+1);
42 char*qstrdup(const char*string)
44 return strdup(string);
46 char*qstrndup(const char*string, int len)
48 return strdup_n(string, len);
51 // ------------------------------- mem_t --------------------------------------
53 void mem_init(mem_t*mem)
55 memset(mem, 0, sizeof(mem_t));
57 void mem_clear(mem_t*mem)
59 rfx_free(mem->buffer);mem->buffer = 0;
61 void mem_destroy(mem_t*mem)
66 static int mem_put_(mem_t*m,const void*data, int length, int null)
69 m->pos += length + (null?1:0);
71 int v1 = (m->pos+63)&~63;
72 int v2 = m->len + m->len / 2;
74 m->buffer = m->buffer?(char*)rfx_realloc(m->buffer,m->len):(char*)rfx_alloc(m->len);
76 assert(n+length <= m->len);
77 memcpy(&m->buffer[n], data, length);
79 m->buffer[n + length] = 0;
82 int mem_put(mem_t*m,void*data, int length)
84 return mem_put_(m, data, length, 0);
86 int mem_putstring(mem_t*m,string_t str)
88 return mem_put_(m, str.str, str.len, 1);
90 int mem_get(mem_t*m, void*data, int length)
92 if(m->read_pos + length > m->pos) {
93 length = m->pos - m->read_pos;
95 memcpy(data, m->buffer+m->read_pos, length);
96 m->read_pos += length;
100 // ------------------------------- ringbuffer_t -------------------------------
102 typedef struct _ringbuffer_internal_t
104 unsigned char*buffer;
108 } ringbuffer_internal_t;
110 void ringbuffer_init(ringbuffer_t*r)
112 ringbuffer_internal_t*i = (ringbuffer_internal_t*)rfx_calloc(sizeof(ringbuffer_internal_t));
113 memset(r, 0, sizeof(ringbuffer_t));
115 i->buffer = (unsigned char*)rfx_alloc(1024);
116 i->buffersize = 1024;
118 int ringbuffer_read(ringbuffer_t*r, void*buf, int len)
120 unsigned char* data = (unsigned char*)buf;
121 ringbuffer_internal_t*i = (ringbuffer_internal_t*)r->internal;
122 if(r->available < len)
126 if(i->readpos + len > i->buffersize) {
127 int read1 = i->buffersize-i->readpos;
128 memcpy(data, &i->buffer[i->readpos], read1);
129 memcpy(&data[read1], &i->buffer[0], len - read1);
130 i->readpos = len - read1;
132 memcpy(data, &i->buffer[i->readpos], len);
134 i->readpos %= i->buffersize;
139 void ringbuffer_put(ringbuffer_t*r, void*buf, int len)
141 unsigned char* data = (unsigned char*)buf;
142 ringbuffer_internal_t*i = (ringbuffer_internal_t*)r->internal;
144 if(i->buffersize - r->available < len)
147 int newbuffersize = i->buffersize;
148 int oldavailable = r->available;
149 newbuffersize*=3;newbuffersize/=2; /*grow at least by 50% each time */
151 if(newbuffersize < r->available + len)
152 newbuffersize = r->available + len + 1024;
154 buf2 = (unsigned char*)rfx_alloc(newbuffersize);
155 ringbuffer_read(r, buf2, r->available);
158 i->buffersize = newbuffersize;
160 i->writepos = oldavailable;
161 r->available = oldavailable;
163 if(i->writepos + len > i->buffersize) {
164 int read1 = i->buffersize-i->writepos;
165 memcpy(&i->buffer[i->writepos], data, read1);
166 memcpy(&i->buffer[0], &data[read1], len - read1);
167 i->writepos = len - read1;
169 memcpy(&i->buffer[i->writepos], data, len);
171 i->writepos %= i->buffersize;
175 void ringbuffer_clear(ringbuffer_t*r)
177 ringbuffer_internal_t*i = (ringbuffer_internal_t*)r->internal;
178 rfx_free(i->buffer);i->buffer = 0;
182 // ------------------------------- heap_t -------------------------------
184 void heap_init(heap_t*h,int n,int elem_size, int(*compare)(const void *, const void *))
186 memset(h, 0, sizeof(heap_t));
189 h->elem_size = elem_size;
190 h->compare = compare;
191 h->elements = (void**)rfx_calloc(n*sizeof(void*));
192 h->data = (char*)rfx_calloc(h->max_size*h->elem_size);
194 void heap_clear(heap_t*h)
196 rfx_free(h->elements);
200 #define HEAP_NODE_SMALLER(h,node1,node2) ((h)->compare((node1),(node2))>0)
202 static void up(heap_t*h, int node)
204 void*node_p = h->elements[node];
210 h->elements[node] = h->elements[parent];
211 } while(HEAP_NODE_SMALLER(h,h->elements[parent], node_p));
213 h->elements[node] = node_p;
215 static void down(heap_t*h, int node)
217 void*node_p = h->elements[node];
222 /* determine new child's position */
226 if(child+1 < h->size && HEAP_NODE_SMALLER(h,h->elements[child],h->elements[child+1])) // search for bigger child
229 h->elements[node] = h->elements[child];
230 } while(HEAP_NODE_SMALLER(h,node_p, h->elements[child]));
232 h->elements[node] = node_p;
234 void heap_put(heap_t*h, void*e)
237 memcpy(&h->data[pos*h->elem_size],e,h->elem_size);
238 h->elements[pos] = &h->data[pos];
241 int heap_size(heap_t*h)
245 void* heap_max(heap_t*h)
247 return h->elements[0];
249 void* heap_chopmax(heap_t*h)
251 void*p = h->elements[0];
252 h->elements[0] = h->elements[--h->size];
256 void heap_dump(heap_t*h, FILE*fi)
259 for(t=0;t<h->size;t++) {
261 for(s=0;s<=t;s=(s+1)*2-1) {
262 if(s==t) fprintf(fi,"\n");
264 //fprintf(fi,"%d ", h->elements[t]->x); //?
267 void** heap_flatten(heap_t*h)
269 void**nodes = (void**)rfx_alloc(h->size*sizeof(void*));
273 /*printf("Heap Size: %d\n", h->size);
274 heap_print(stdout, h);
276 *p++ = heap_chopmax(h);
281 // ------------------------------- crc32 --------------------------------------
282 static unsigned int*crc32 = 0;
283 static void crc32_init(void)
288 crc32= (unsigned int*)rfx_alloc(sizeof(unsigned int)*256);
289 for(t=0; t<256; t++) {
292 for (s = 0; s < 8; s++) {
293 c = (0xedb88320L*(c&1)) ^ (c >> 1);
298 // ------------------------------- string_t -----------------------------------
300 void string_set2(string_t*str, const char*text, int len)
305 void string_set(string_t*str, const char*text)
308 str->len = strlen(text);
314 string_t string_new(const char*text, int len)
321 string_t string_new2(const char*text)
325 s.len = strlen(text);
332 string_t* string_new3(const char*text, int len)
335 string_t*s = malloc(sizeof(string_t));
340 string_t*s = malloc(sizeof(string_t)+len+1);
342 s->str = (const char*)(s+1);
343 memcpy((char*)s->str, text, len);
344 ((char*)s->str)[len]=0;
348 string_t* string_new4(const char*text)
350 int l = strlen(text);
351 return string_new3(text, l);
354 void string_free(string_t*s)
359 if((string_t*)(s->str) == s+1) {
363 rfx_free((char*)(s->str));
368 char* string_cstr(string_t*str)
370 return strdup_n(str->str, str->len);
372 char* string_escape(string_t*str)
376 for(t=0;t<str->len;t++) {
382 char*s = malloc(len+1);
384 for(t=0;t<str->len;t++) {
385 if(str->str[t]<0x20) {
387 unsigned char c = str->str[t];
388 *p++ = "0123456789abcdef"[c>>4];
389 *p++ = "0123456789abcdef"[c&0x0f];
395 assert(p == &s[len+1]);
399 unsigned int crc32_add_byte(unsigned int checksum, unsigned char b)
403 return checksum>>8 ^ crc32[(b^checksum)&0xff];
405 unsigned int crc32_add_string(unsigned int checksum, const char*s)
412 checksum = checksum>>8 ^ crc32[(*s^checksum)&0xff];
418 unsigned int string_hash(const string_t*str)
421 unsigned int checksum = 0;
424 for(t=0;t<str->len;t++) {
425 checksum = checksum>>8 ^ crc32[(str->str[t]^checksum)&0xff];
429 unsigned int string_hash2(const char*str)
431 unsigned int checksum = 0;
436 checksum = checksum>>8 ^ crc32[(*p^checksum)&0xff];
441 unsigned int string_hash3(const char*str, int len)
446 return string_hash(&s);
448 void string_dup2(string_t*str, const char*text, int len)
451 str->str = strdup_n(text, len);
453 void string_dup(string_t*str, const char*text)
455 str->len = strlen(text);
456 str->str = strdup(text);
458 int string_equals(string_t*str, const char*text)
460 int l = strlen(text);
461 if(str->len == l && !memcmp(str->str, text, l))
465 int string_equals2(string_t*str, string_t*str2)
467 if(str->len == str2->len && !memcmp(str->str, str2->str, str->len))
472 // ------------------------------- stringarray_t ------------------------------
474 typedef struct _stringlist {
476 struct _stringlist*next;
479 typedef struct _stringarray_internal_t
485 } stringarray_internal_t;
487 void stringarray_init(stringarray_t*sa, int hashsize)
489 stringarray_internal_t*s;
491 sa->internal = (stringarray_internal_t*)rfx_calloc(sizeof(stringarray_internal_t));
492 s = (stringarray_internal_t*)sa->internal;
494 s->hash = rfx_calloc(sizeof(stringlist_t*)*hashsize);
495 s->hashsize = hashsize;
497 void stringarray_put(stringarray_t*sa, string_t str)
499 stringarray_internal_t*s = (stringarray_internal_t*)sa->internal;
501 int hash = string_hash(&str) % s->hashsize;
503 char*ss = string_cstr(&str);
504 mem_put(&s->pos, &ss, sizeof(char*));
506 stringlist_t*l = rfx_alloc(sizeof(stringlist_t));
508 l->next = s->hash[hash];
513 char* stringarray_at(stringarray_t*sa, int pos)
515 stringarray_internal_t*s = (stringarray_internal_t*)sa->internal;
517 if(pos<0 || pos>=s->num)
519 p = *(char**)&s->pos.buffer[pos*sizeof(char*)];
524 string_t stringarray_at2(stringarray_t*sa, int pos)
527 s.str = stringarray_at(sa, pos);
528 s.len = s.str?strlen(s.str):0;
531 static stringlist_t* stringlist_del(stringarray_t*sa, stringlist_t*l, int index)
534 stringlist_t*old = l;
536 if(index==l->index) {
538 memset(l, 0, sizeof(stringlist_t));
548 fprintf(stderr, "Internal error: did not find string %d in hash\n", index);
552 void stringarray_del(stringarray_t*sa, int pos)
554 stringarray_internal_t*s = (stringarray_internal_t*)sa->internal;
555 string_t str = stringarray_at2(sa, pos);
556 int hash = string_hash(&str) % s->hashsize;
557 s->hash[hash] = stringlist_del(sa, s->hash[hash], pos);
558 *(char**)&s->pos.buffer[pos*sizeof(char*)] = 0;
560 int stringarray_find(stringarray_t*sa, string_t* str)
562 stringarray_internal_t*s = (stringarray_internal_t*)sa->internal;
563 int hash = string_hash(str) % s->hashsize;
565 stringlist_t*l = s->hash[hash];
568 string_t s = stringarray_at2(sa, l->index);
569 if(string_equals2(str, &s)) {
576 void stringarray_clear(stringarray_t*sa)
578 stringarray_internal_t*s = (stringarray_internal_t*)sa->internal;
581 for(t=0;t<s->hashsize;t++) {
582 stringlist_t*l = s->hash[t];
584 stringlist_t*next = l->next;
585 memset(l, 0, sizeof(stringlist_t));
590 rfx_free(s->hash);s->hash=0;
593 void stringarray_destroy(stringarray_t*sa)
595 stringarray_clear(sa);
599 // ------------------------------- type_t -------------------------------
601 char ptr_equals(const void*o1, const void*o2)
605 unsigned int ptr_hash(const void*o)
607 return string_hash3(&o, sizeof(o));
609 void* ptr_dup(const void*o)
613 void ptr_free(void*o)
618 char charptr_equals(const void*o1, const void*o2)
622 return !strcmp(o1,o2);
624 unsigned int charptr_hash(const void*o)
628 return string_hash2(o);
630 void* charptr_dup(const void*o)
636 void charptr_free(void*o)
643 char stringstruct_equals(const void*o1, const void*o2)
647 string_t*s1 = (string_t*)o1;
648 string_t*s2 = (string_t*)o2;
649 int l = s1->len<s2->len?s1->len:s2->len;
650 int r = memcmp(s1->str, s2->str, l);
654 return s1->len==s2->len;
656 unsigned int stringstruct_hash(const void*o)
659 return string_hash(o);
661 string_t*string_dup3(string_t*o)
665 string_t*s = malloc(sizeof(string_t));
670 string_t*s = rfx_alloc(sizeof(string_t)+o->len+1);
672 s->str = (const char*)(s+1);
673 memcpy((char*)s->str, o->str, s->len);
674 ((char*)s->str)[s->len]=0;
677 void stringstruct_free(void*o)
690 type_t charptr_type = {
691 equals: charptr_equals,
697 type_t stringstruct_type = {
698 equals: stringstruct_equals,
699 hash: stringstruct_hash,
700 dup: (dup_func)string_dup3,
701 free: stringstruct_free,
704 // ------------------------------- dictionary_t -------------------------------
706 #define INITIAL_SIZE 1
708 static int max(int x, int y) {
714 dict_t*d = rfx_alloc(sizeof(dict_t));
715 dict_init(d, INITIAL_SIZE);
718 dict_t*dict_new2(type_t*t)
720 dict_t*d = rfx_alloc(sizeof(dict_t));
721 dict_init(d, INITIAL_SIZE);
725 void dict_init(dict_t*h, int size)
727 memset(h, 0, sizeof(dict_t));
729 h->slots = h->hashsize?(dictentry_t**)rfx_calloc(sizeof(dictentry_t*)*h->hashsize):0;
731 h->key_type = &charptr_type;
734 dict_t*dict_clone(dict_t*o)
736 dict_t*h = rfx_alloc(sizeof(dict_t));
737 memcpy(h, o, sizeof(dict_t));
738 h->slots = h->hashsize?(dictentry_t**)rfx_calloc(sizeof(dictentry_t*)*h->hashsize):0;
740 for(t=0;t<o->hashsize;t++) {
741 dictentry_t*e = o->slots[t];
743 dictentry_t*n = (dictentry_t*)rfx_alloc(sizeof(dictentry_t));
744 memcpy(n, e, sizeof(dictentry_t));
745 n->key = h->key_type->dup(e->key);
747 n->next = h->slots[t];
755 static void dict_expand(dict_t*h, int newlen)
757 assert(h->hashsize < newlen);
758 dictentry_t**newslots = (dictentry_t**)rfx_calloc(sizeof(dictentry_t*)*newlen);
760 for(t=0;t<h->hashsize;t++) {
761 dictentry_t*e = h->slots[t];
763 dictentry_t*next = e->next;
764 unsigned int newhash = e->hash%newlen;
765 e->next = newslots[newhash];
766 newslots[newhash] = e;
773 h->hashsize = newlen;
776 dictentry_t* dict_put(dict_t*h, const void*key, void* data)
778 unsigned int hash = h->key_type->hash(key);
779 dictentry_t*e = (dictentry_t*)rfx_alloc(sizeof(dictentry_t));
780 unsigned int hash2 = hash % h->hashsize;
782 e->key = h->key_type->dup(key);
783 e->hash = hash; //for resizing
784 e->next = h->slots[hash2];
790 void dict_put2(dict_t*h, const char*s, void*data)
792 assert(h->key_type == &charptr_type);
793 dict_put(h, s, data);
795 void dict_dump(dict_t*h, FILE*fi, const char*prefix)
798 for(t=0;t<h->hashsize;t++) {
799 dictentry_t*e = h->slots[t];
801 if(h->key_type!=&charptr_type) {
802 fprintf(fi, "%s%08x=%08x\n", prefix, e->key, e->data);
804 fprintf(fi, "%s%s=%08x\n", prefix, e->key, e->data);
811 int dict_count(dict_t*h)
816 static inline dictentry_t* dict_do_lookup(dict_t*h, const void*key)
822 unsigned int ohash = h->key_type->hash(key);
823 unsigned int hash = ohash % h->hashsize;
825 /* check first entry for match */
826 dictentry_t*e = h->slots[hash];
827 if(e && h->key_type->equals(e->key, key)) {
833 /* if dict is 2/3 filled, double the size. Do
834 this the first time we have to actually iterate
835 through a slot to find our data */
836 if(e && h->num*3 >= h->hashsize*2) {
837 int newsize = h->hashsize;
838 while(h->num*3 >= newsize*2) {
839 newsize = newsize<15?15:(newsize+1)*2-1;
841 dict_expand(h, newsize);
842 hash = ohash % h->hashsize;
844 if(e && h->key_type->equals(e->key, key)) {
845 // omit move to front
852 /* check subsequent entries for a match */
853 dictentry_t*last = h->slots[hash];
855 if(h->key_type->equals(e->key, key)) {
856 /* move to front- makes a difference of about 10% in most applications */
857 last->next = e->next;
858 e->next = h->slots[hash];
867 void* dict_lookup(dict_t*h, const void*key)
869 dictentry_t*e = dict_do_lookup(h, key);
874 char dict_contains(dict_t*h, const void*key)
876 dictentry_t*e = dict_do_lookup(h, key);
880 char dict_del(dict_t*h, const void*key)
884 unsigned int hash = h->key_type->hash(key) % h->hashsize;
885 dictentry_t*head = h->slots[hash];
886 dictentry_t*e = head, *prev=0;
888 if(h->key_type->equals(e->key, key)) {
889 dictentry_t*next = e->next;
890 rfx_free((void*)e->key);
891 memset(e, 0, sizeof(dictentry_t));
908 dictentry_t* dict_get_slot(dict_t*h, const void*key)
912 unsigned int ohash = h->key_type->hash(key);
913 unsigned int hash = ohash % h->hashsize;
914 return h->slots[hash];
917 void dict_foreach_keyvalue(dict_t*h, void (*runFunction)(void*data, const void*key, void*val), void*data)
920 for(t=0;t<h->hashsize;t++) {
921 dictentry_t*e = h->slots[t];
923 dictentry_t*next = e->next;
925 runFunction(data, e->key, e->data);
931 void dict_foreach_value(dict_t*h, void (*runFunction)(void*))
934 for(t=0;t<h->hashsize;t++) {
935 dictentry_t*e = h->slots[t];
937 dictentry_t*next = e->next;
939 runFunction(e->data);
946 void dict_free_all(dict_t*h, char free_keys, void (*free_data_function)(void*))
949 for(t=0;t<h->hashsize;t++) {
950 dictentry_t*e = h->slots[t];
952 dictentry_t*next = e->next;
954 h->key_type->free(e->key);
956 if(free_data_function) {
957 free_data_function(e->data);
959 memset(e, 0, sizeof(dictentry_t));
966 memset(h, 0, sizeof(dict_t));
969 void dict_clear_shallow(dict_t*h)
971 dict_free_all(h, 0, 0);
974 void dict_clear(dict_t*h)
976 dict_free_all(h, 1, 0);
979 void dict_destroy_shallow(dict_t*dict)
981 dict_clear_shallow(dict);
985 void dict_destroy(dict_t*dict)
991 // ------------------------------- map_t --------------------------------------
993 typedef struct _map_internal_t
998 void map_init(map_t*map)
1001 map->internal = (map_internal_t*)rfx_calloc(sizeof(map_internal_t));
1002 m = (map_internal_t*)map->internal;
1003 dict_init(&m->d, INITIAL_SIZE);
1005 void map_put(map_t*map, string_t t1, string_t t2)
1007 map_internal_t*m = (map_internal_t*)map->internal;
1009 char* s1 = string_cstr(&t1);
1010 dict_put2(&m->d, s1, (void*)string_cstr(&t2));
1013 const char* map_lookup(map_t*map, const char*name)
1015 map_internal_t*m = (map_internal_t*)map->internal;
1016 const char*value = dict_lookup(&m->d, name);
1019 static void freestring(void*data)
1023 static void dumpmapentry(void*data, const void*key, void*value)
1025 FILE*fi = (FILE*)data;
1026 fprintf(fi, "%s=%s\n", key, (char*)value);
1028 void map_dump(map_t*map, FILE*fi, const char*prefix)
1031 map_internal_t*m = (map_internal_t*)map->internal;
1032 dict_foreach_keyvalue(&m->d, dumpmapentry, fi);
1034 void map_clear(map_t*map)
1036 map_internal_t*m = (map_internal_t*)map->internal;
1037 dict_free_all(&m->d, 1, freestring);
1040 void map_destroy(map_t*map)
1046 // ------------------------------- array_t --------------------------------------
1048 array_t* array_new() {
1049 array_t*d = malloc(sizeof(array_t));
1050 memset(d, 0, sizeof(array_t));
1051 d->entry2pos = dict_new();
1054 array_t* array_new2(type_t*type) {
1055 array_t*d = malloc(sizeof(array_t));
1056 memset(d, 0, sizeof(array_t));
1057 d->entry2pos = dict_new2(type);
1060 void*array_getkey(array_t*array, int nr) {
1061 if(nr > array->num || nr<0) {
1062 printf("error: reference to element %d in array[%d]\n", nr, array->num);
1066 return array->d[nr].name;
1068 void*array_getvalue(array_t*array, int nr) {
1069 if(nr > array->num || nr<0) {
1070 printf("error: reference to element %d in array[%d]\n", nr, array->num);
1074 return array->d[nr].data;
1076 int array_append(array_t*array, const void*name, void*data) {
1077 while(array->size <= array->num) {
1080 array->d = malloc(sizeof(array_entry_t)*array->size);
1082 array->d = realloc(array->d, sizeof(array_entry_t)*array->size);
1086 dictentry_t*e = dict_put(array->entry2pos, name, (void*)(ptroff_t)(array->num+1));
1089 array->d[array->num].name = e->key;
1091 array->d[array->num].name = 0;
1093 array->d[array->num].data = (void*)data;
1094 return array->num++;
1096 int array_find(array_t*array, const void*name)
1098 int pos = (int)(ptroff_t)dict_lookup(array->entry2pos, name);
1101 int array_find2(array_t*array, const void*name, void*data)
1103 dict_t*h= array->entry2pos;
1104 dictentry_t*e = dict_get_slot(array->entry2pos, name);
1107 int index = ((int)(ptroff_t)e->data) - 1;
1108 if(h->key_type->equals(e->key, name) && array->d[index].data == data) {
1115 int array_update(array_t*array, const void*name, void*data) {
1116 int pos = array_find(array, name);
1118 array->d[pos].data = data;
1121 return array_append(array, name, data);
1123 int array_append_if_new(array_t*array, const void*name, void*data) {
1124 int pos = array_find(array, name);
1127 return array_append(array, name, data);
1129 void array_free(array_t*array) {
1130 dict_destroy(array->entry2pos);
1132 free(array->d);array->d = 0;
1137 // ------------------------------- list_t --------------------------------------
1140 typedef struct _listinfo {
1142 struct _commonlist*last;
1145 typedef struct _commonlist {
1147 struct _commonlist*next;
1151 int list_length_(void*_list)
1153 commonlist_t*l = (commonlist_t*)_list;
1156 return l->info[0].size;
1158 void list_concat_(void*_l1, void*_l2)
1160 commonlist_t**l1 = (commonlist_t**)_l1;
1161 commonlist_t**l2 = (commonlist_t**)_l2;
1166 (*l1)->info[0].last->next = *l2;
1167 (*l1)->info[0].last = (*l2)->info[0].last;
1168 (*l1)->info[0].size += (*l2)->info[0].size;
1172 void list_append_(void*_list, void*entry)
1174 commonlist_t**list = (commonlist_t**)_list;
1175 commonlist_t* n = 0;
1177 n = (commonlist_t*)malloc(sizeof(commonlist_t)+sizeof(listinfo_t));
1179 (*list)->info[0].size = 0;
1181 n = malloc(sizeof(commonlist_t));
1182 (*list)->info[0].last->next = n;
1186 (*list)->info[0].last = n;
1187 (*list)->info[0].size++;
1189 /* notice: prepending uses slighly more space than appending */
1190 void list_prepend_(void*_list, void*entry)
1192 commonlist_t**list = (commonlist_t**)_list;
1193 commonlist_t* n = (commonlist_t*)malloc(sizeof(commonlist_t)+sizeof(listinfo_t));
1195 commonlist_t* last = 0;
1197 last = (*list)->info[0].last;
1198 size = (*list)->info[0].size;
1203 (*list)->info[0].last = last;
1204 (*list)->info[0].size = size+1;
1206 void list_free_(void*_list)
1208 commonlist_t**list = (commonlist_t**)_list;
1209 commonlist_t*l = *list;
1211 commonlist_t*next = l->next;
1217 void*list_clone_(void*_list)
1219 commonlist_t*l = *(commonlist_t**)_list;
1223 commonlist_t*next = l->next;
1224 list_append_(&dest, l->entry);