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.
18 list2_t* list_new (void) {
19 return (mem_calloc (1, sizeof (list2_t)));
22 void list_del (list2_t** l, list_del_t* del) {
27 for (i = 0; i < (*l)->length; i++)
29 mem_free(&(*l)->data);
33 void list_push_back (list2_t** l, void* p) {
36 mem_realloc (&(*l)->data, (++(*l)->length)*sizeof(void*));
37 (*l)->data[(*l)->length-1] = p;
40 void list_push_front (list2_t** l, void* p) {
43 mem_realloc (&(*l)->data, (++(*l)->length)*sizeof(void*));
45 memmove (&(*l)->data[1], &(*l)->data[0], ((*l)->length-1)*sizeof(void*));
49 void* list_pop_back (list2_t* l) {
53 p = l->data[l->length-1];
54 mem_realloc (&l->data, --(l->length)*sizeof(void*));
58 void* list_pop_front (list2_t* l) {
63 memmove (&l->data[0], &l->data[1], (--(l->length))*sizeof(void*));
64 mem_realloc (&l->data, l->length*sizeof(void*));
68 void* list_pop_idx (list2_t* l, int c) {
70 if (list_empty(l) || c < 0 || c >= l->length)
73 return (list_pop_back (l));
75 memmove (&l->data[c], &l->data[c+1], (l->length-c)*sizeof(void*));
76 mem_realloc (&l->data, (--(l->length))*sizeof(void*));
80 list2_t* list_cpy (list2_t* l) {
85 ret->length = l->length;
86 ret->data = mem_malloc (l->length*sizeof(void*));
87 memcpy (ret->data, l->data, l->length*sizeof(void*));
91 list2_t* list_dup (list2_t* l, void* (*dup) (void*)) {
94 if (list_empty(l) || !*dup)
97 ret->length = l->length;
98 ret->data = mem_malloc (l->length*sizeof(void*));
99 for (i = 0; i < l->length; i++)
100 ret->data[i] = dup (l->data[i]);
104 int list_lookup (list2_t* l, int (*cmp) (const void*, const void*), const void* p) {
106 if (list_empty(l) || !*cmp)
108 for (i = 0; i < l->length; i++)
109 if (cmp (l->data[i], p) == 0)
114 list2_t* list_from_str (const char* str, const char* delim) {
116 char* tmp = NULL, *p = NULL;
118 if (!str || !*str || !delim || !*delim)
122 for (p = strtok (tmp, delim); p; p = strtok (NULL, delim)) {
123 list_push_back (&ret, str_dup (p));