X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lib%2Flist.h;h=b1b612eb994650d3732f395ab0f8df3ddef89b1b;hp=2d6e2283c7707312a06cd2d7f99afa1340bd44f8;hb=38dacbf03fe1a0daa9ce426caaef5582b90006b2;hpb=871a94fc21c9d349bb0fe8851e0f2e3a07527ed5 diff --git a/lib-lib/list.h b/lib-lib/list.h index 2d6e228..b1b612e 100644 --- a/lib-lib/list.h +++ b/lib-lib/list.h @@ -25,26 +25,7 @@ #ifndef MUTT_LIB_LIB_LIST_H #define MUTT_LIB_LIB_LIST_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; \ @@ -59,23 +40,52 @@ static inline LIST *mutt_add_list(LIST *head, const char *data) { *list = item; \ } \ \ + static inline type **prefix##_list_last(type **list) { \ + while (*list) { \ + list = &(*list)->next; \ + } \ + return list; \ + } \ + \ + static inline type **prefix##_list_append(type **list, type *item) { \ + list = prefix##_list_last(list); \ + *list = item; \ + return list; \ + } \ + \ static inline type **prefix##_list_init(type **list) { \ *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 */