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/mem.h>
14 #include <lib-lib/str.h>
19 list2_t* list_new (void) {
20 return p_new(list2_t, 1);
23 void list_del (list2_t** l, list_del_t* del) {
28 for (i = 0; i < (*l)->length; i++)
30 p_delete(&(*l)->data);
34 void list_push_back (list2_t** l, void* p) {
37 p_realloc(&(*l)->data, ++(*l)->length);
38 (*l)->data[(*l)->length-1] = p;
41 void list_push_front (list2_t** l, void* p) {
44 p_realloc(&(*l)->data, ++(*l)->length);
46 memmove (&(*l)->data[1], &(*l)->data[0], ((*l)->length-1)*sizeof(void*));
50 void* list_pop_back (list2_t* l) {
54 p = l->data[l->length-1];
55 p_realloc(&l->data, --(l->length));
59 void* list_pop_front (list2_t* l) {
64 memmove (&l->data[0], &l->data[1], (--(l->length))*sizeof(void*));
65 p_realloc(&l->data, l->length);
69 void* list_pop_idx (list2_t* l, int c) {
71 if (list_empty(l) || c < 0 || c >= l->length)
74 return (list_pop_back (l));
76 memmove (&l->data[c], &l->data[c+1], (l->length-c)*sizeof(void*));
77 p_realloc(&l->data, --(l->length));
81 list2_t *list_cpy(list2_t *l) {
86 ret->length = l->length;
87 ret->data = p_dup(l->data, l->length);
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 = p_new(void*, l->length);
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, m_strdup(p));