2 * written for mutt-ng by:
3 * Rocco Rutte <pdmef@cs.tu-berlin.de>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
17 list2_t* list_new (void) {
18 return (safe_calloc (1, sizeof (list2_t)));
21 void list_del (list2_t** l, void (*edel) (void**)) {
26 for (i = 0; i < (*l)->length; i++)
27 edel (&(*l)->data[i]);
32 void list_push_back (list2_t** l, void* p) {
35 safe_realloc (&(*l)->data, (++(*l)->length)*sizeof(void*));
36 (*l)->data[(*l)->length-1] = p;
39 void list_push_front (list2_t** l, void* p) {
42 safe_realloc (&(*l)->data, (++(*l)->length)*sizeof(void*));
44 memmove (&(*l)->data[1], &(*l)->data[0], ((*l)->length-1)*sizeof(void*));
48 void* list_pop_back (list2_t* l) {
52 p = l->data[l->length-1];
53 safe_realloc (&l->data, --(l->length)*sizeof(void*));
57 void* list_pop_front (list2_t* l) {
62 memmove (&l->data[0], &l->data[1], (--(l->length))*sizeof(void*));
63 safe_realloc (&l->data, l->length*sizeof(void*));
67 void* list_pop_idx (list2_t* l, int c) {
69 if (list_empty(l) || c < 0 || c >= l->length)
72 return (list_pop_back (l));
74 memmove (&l->data[c], &l->data[c+1], (l->length-c)*sizeof(void*));
75 safe_realloc (&l->data, (--(l->length))*sizeof(void*));
79 list2_t* list_cpy (list2_t* l) {
84 ret->length = l->length;
85 ret->data = safe_malloc (l->length*sizeof(void*));
86 memcpy (ret->data, l->data, l->length*sizeof(void*));
90 list2_t* list_dup (list2_t* l, void* (*dup) (void*)) {
93 if (list_empty(l) || !*dup)
96 ret->length = l->length;
97 ret->data = safe_malloc (l->length*sizeof(void*));
98 for (i = 0; i < l->length; i++)
99 ret->data[i] = dup (l->data[i]);
103 int _list_lookup (list2_t* l, int (*cmp) (const void*, const void*), const void* p) {
105 if (list_empty(l) || !*cmp)
107 for (i = 0; i < l->length; i++)
108 if (cmp (l->data[i], p) == 0)