X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lib%2Flist.h;h=2dac0f855d1791efbe156b438f96f2934d98b698;hp=245a8660780c66c0840c5c5d5bcca0e4cd339df7;hb=23e6291cb5d5b4cd2008403d8b628007fd75ff23;hpb=b68ee108ca7aed9fd3fdfe5eefc1cf284a32fb17 diff --git a/lib-lib/list.h b/lib-lib/list.h index 245a866..2dac0f8 100644 --- a/lib-lib/list.h +++ b/lib-lib/list.h @@ -25,26 +25,10 @@ #ifndef MUTT_LIB_LIB_LIST_H #define MUTT_LIB_LIB_LIST_H +#include "mem.h" #include "str.h" -typedef struct list_t { - char *data; - struct list_t *next; -} LIST; - -#define mutt_new_list() p_new(LIST, 1) -void mutt_free_list(LIST **); - -LIST *mutt_copy_list(LIST *); - -/* add an element to a list */ -LIST *mutt_add_list_n(LIST*, const void*, size_t len); -static inline LIST *mutt_add_list(LIST *head, const char *data) { - size_t len = m_strlen(data); - return mutt_add_list_n(head, data, len ? len + 1 : 0); -} - -#define DO_SLIST(type, prefix) \ +#define DO_SLIST(type, prefix, dtor) \ static inline type *prefix##_list_pop(type **list) { \ if (*list) { \ type *res = *list; \ @@ -76,19 +60,35 @@ static inline LIST *mutt_add_list(LIST *head, const char *data) { *list = NULL; \ return list; \ } \ - static inline void prefix##_list_wipe(type **list, int del) { \ - if (del) { \ - while (*list) { \ - type *item = prefix##_list_pop(list); \ - prefix##_delete(&item); \ - } \ - } else { \ - *list = NULL; \ + static inline void prefix##_list_wipe(type **list) { \ + while (*list) { \ + type *item = prefix##_list_pop(list); \ + dtor(&item); \ } \ } \ +typedef struct string_list_t { + struct string_list_t *next; + char *data; +} string_list_t; + +DO_INIT(string_list_t, string_item); +static inline void string_item_wipe(string_list_t *it) { + p_delete(&it->data); +} +DO_NEW(string_list_t, string_item); +DO_DELETE(string_list_t, string_item); +DO_SLIST(string_list_t, string, string_item_delete); +string_list_t *string_list_dup(const string_list_t *); +/* FIXME: b0rken API's, replace that at any cost */ +/* add an element to a list */ +string_list_t *mutt_add_list_n(string_list_t*, const void*, size_t len); +static inline string_list_t *mutt_add_list(string_list_t *head, const char *data) { + size_t len = m_strlen(data); + return mutt_add_list_n(head, data, len ? len + 1 : 0); +} #endif /* MUTT_LIB_LIB_LIST_H */