more include simplifications
[apps/madmutt.git] / lib / list.h
1 /*
2  * written for mutt-ng by:
3  * Rocco Rutte <pdmef@cs.tu-berlin.de>
4  *
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.
8  */
9
10 /*
11  * this aims to provide a generic list 
12  * implementation using arrays only
13  * mostly untested
14  */
15
16 #ifndef _LIB_LIST_H
17 #define _LIB_LIST_H
18
19 typedef struct list2_t {
20   void** data;
21   ssize_t length;
22 } list2_t;
23
24 /*
25  * basics
26  */
27
28 list2_t* list_new (void);
29
30 typedef void list_del_t (void**);
31
32 /* free() all memory used by list and optionally
33  * use del function to free() items as well */
34 void list_del (list2_t**, list_del_t* del);
35
36 #define list_empty(l) (!l || l->length == 0 || !l->data)
37
38 /*
39  * insertion, removal
40  * the list_push_* functions create a list if empty so far
41  * for convenience
42  */
43 void list_push_back (list2_t**, void*);
44 void list_push_front (list2_t**, void*);
45 void* list_pop_back (list2_t*);
46 void* list_pop_front (list2_t*);
47 void* list_pop_idx (list2_t*, int);
48
49 /*
50  * copying
51  */
52
53 /* plain copy */
54 list2_t* list_cpy (list2_t*);
55 /* "hard copy" using callback to copy items */
56 list2_t* list_dup (list2_t*, void* (*dup) (void*));
57
58 /*
59  * misc
60  */
61
62 /* looks up item in list using callback function and comparison item
63  * return:
64  *      -1 if not found
65  *      index in data array otherwise
66  * the callback must return 0 on equality
67  */
68 typedef int list_lookup_t (const void*, const void*);
69 int list_lookup (list2_t*, list_lookup_t* cmp, const void*);
70
71 /*
72  * dumb-splits string at boundary characters into list
73  */
74 list2_t* list_from_str (const char* str, const char* delim);
75
76 #endif /* !_LIB_LIST_H */