add some list functions.
[apps/madmutt.git] / lib-lib / list.h
index 1a915b3..2e13fca 100644 (file)
@@ -22,8 +22,8 @@
  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
  */
 
-#ifndef _MUTT_LIST_H
-#define _MUTT_LIST_H
+#ifndef MUTT_LIB_LIB_LIST_H
+#define MUTT_LIB_LIB_LIST_H
 
 typedef struct list_t {
     char *data;
@@ -42,4 +42,38 @@ static inline LIST *mutt_add_list(LIST *head, const char *data) {
     return mutt_add_list_n(head, data, len ? len + 1 : 0);
 }
 
-#endif /* !_MUTT_LIST_H */
+#define DO_SLIST(type, prefix)                                               \
+    static inline type *prefix##_list_pop(type **list) {                     \
+        if (*list) {                                                         \
+            type *res = *list;                                               \
+            *list = res->next;                                               \
+            res->next = NULL;                                                \
+            return res;                                                      \
+        }                                                                    \
+        return NULL;                                                         \
+    }                                                                        \
+    static inline void prefix##_list_push(type **list, type *item) {         \
+        item->next = *list;                                                  \
+        *list = item;                                                        \
+    }                                                                        \
+                                                                             \
+    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;                                                    \
+        }                                                                    \
+    }                                                                        \
+
+
+
+
+
+#endif /* MUTT_LIB_LIB_LIST_H */