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.
13 #include <lib-lib/lib-lib.h>
18 list2_t* list_new (void) {
19 return p_new(list2_t, 1);
22 void list_del (list2_t** l, list_del_t* del) {
27 for (i = 0; i < (*l)->length; i++)
29 p_delete(&(*l)->data);
33 void list_push_back (list2_t** l, void* p) {
36 p_realloc(&(*l)->data, ++(*l)->length);
37 (*l)->data[(*l)->length-1] = p;
40 void list_push_front (list2_t** l, void* p) {
43 p_realloc(&(*l)->data, ++(*l)->length);
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 p_realloc(&l->data, --(l->length));
58 void* list_pop_front (list2_t* l) {
63 memmove (&l->data[0], &l->data[1], (--(l->length))*sizeof(void*));
64 p_realloc(&l->data, l->length);
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 p_realloc(&l->data, --(l->length));
80 list2_t *list_cpy(list2_t *l) {
85 ret->length = l->length;
86 ret->data = p_dup(l->data, l->length);
90 list2_t* list_dup (list2_t* l, void* (*dup_f) (void*)) {
93 if (list_empty(l) || !*dup_f)
96 ret->length = l->length;
97 ret->data = p_new(void*, l->length);
98 for (i = 0; i < l->length; i++)
99 ret->data[i] = dup_f (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)
113 list2_t* list_from_str (const char* str, const char* delim) {
115 char* tmp = NULL, *p = NULL;
117 if (!str || !*str || !delim || !*delim)
121 for (p = strtok (tmp, delim); p; p = strtok (NULL, delim)) {
122 list_push_back (&ret, m_strdup(p));