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.
10 #include <lib-lib/lib-lib.h>
13 list2_t* list_new (void) {
14 return p_new(list2_t, 1);
17 void list_del (list2_t** l, list_del_t* del) {
22 for (i = 0; i < (*l)->length; i++)
24 p_delete(&(*l)->data);
28 void list_push_back (list2_t** l, void* p) {
31 p_realloc(&(*l)->data, ++(*l)->length);
32 (*l)->data[(*l)->length-1] = p;
35 void list_push_front (list2_t** l, void* p) {
38 p_realloc(&(*l)->data, ++(*l)->length);
40 memmove (&(*l)->data[1], &(*l)->data[0], ((*l)->length-1)*sizeof(void*));
44 void* list_pop_back (list2_t* l) {
48 p = l->data[l->length-1];
49 p_realloc(&l->data, --(l->length));
53 void* list_pop_front (list2_t* l) {
58 memmove (&l->data[0], &l->data[1], (--(l->length))*sizeof(void*));
59 p_realloc(&l->data, l->length);
63 void* list_pop_idx (list2_t* l, int c) {
65 if (list_empty(l) || c < 0 || c >= l->length)
68 return (list_pop_back (l));
70 memmove (&l->data[c], &l->data[c+1], (l->length-c)*sizeof(void*));
71 p_realloc(&l->data, --(l->length));
75 list2_t *list_cpy(list2_t *l) {
80 ret->length = l->length;
81 ret->data = p_dup(l->data, l->length);
85 list2_t* list_dup (list2_t* l, void* (*dup_f) (void*)) {
88 if (list_empty(l) || !*dup_f)
91 ret->length = l->length;
92 ret->data = p_new(void*, l->length);
93 for (i = 0; i < l->length; i++)
94 ret->data[i] = dup_f (l->data[i]);
98 int list_lookup (list2_t* l, int (*cmp) (const void*, const void*), const void* p) {
100 if (list_empty(l) || !*cmp)
102 for (i = 0; i < l->length; i++)
103 if (cmp (l->data[i], p) == 0)
108 list2_t* list_from_str (const char* str, const char* delim) {
110 char* tmp = NULL, *p = NULL;
112 if (!str || !*str || !delim || !*delim)
116 for (p = strtok (tmp, delim); p; p = strtok (NULL, delim)) {
117 list_push_back (&ret, m_strdup(p));