macrodelete_parser fix
[mala.git] / engine / stringlist.h
blobcfbd83909c5ddad81aca3f6073ad88b1b696e399
1 /*
2 stringlist.h - MaLa stringlists
4 Copyright (C) 2004, 2005, Christian Thaeter <chth@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, contact me.
20 #ifndef MALA_STRINGLIST_H
21 #define MALA_STRINGLIST_H
23 #include "mala_types.h"
24 #include "strings.h"
27 * StringList
30 struct mala_stringlistnode_struct
32 CIRCLEQ_ENTRY(mala_stringlistnode_struct) node;
33 MalaString string;
37 #define MALA_STATIC_STRINGLIST_INIT(args...) \
38 (const char*[]){args, NULL}
41 static inline void
42 mala_stringlist_init (MalaStringList self);
45 static inline MalaStringListNode
46 mala_stringlist_head (MalaStringList self);
48 static inline MalaStringListNode
49 mala_stringlist_tail (MalaStringList self);
51 static inline void
52 mala_stringlist_fwd (MalaStringListNode_ref self);
55 static inline void
56 mala_stringlist_rev (MalaStringListNode_ref self);
58 static inline MalaStringListNode
59 mala_stringlist_next (MalaStringListNode self);
61 static inline MalaStringListNode
62 mala_stringlist_prev (MalaStringListNode self);
64 MalaStringList
65 mala_stringlist_new ();
67 MalaStringList
68 mala_stringlist_new_cstrs (char **cstrs,
69 int nelem,
70 MalaStringBucket bucket);
72 void
73 mala_stringlist_erase (MalaStringList head);
75 void
76 mala_stringlist_free (MalaStringList head);
78 void *
79 mala_stringlist_factory (MalaStringList_ref dest, char** src, MalaStringBucket bucket);
81 MalaStringListNode
82 mala_stringlist_head_new (MalaStringList head, MalaString str);
84 MalaStringListNode
85 mala_stringlist_tail_new (MalaStringList head, MalaString str);
87 MalaStringListNode
88 mala_stringlist_head_new_cstr (MalaStringList head, const char * cstr, MalaStringBucket bucket);
90 MalaStringListNode
91 mala_stringlist_tail_new_cstr (MalaStringList head, const char * cstr, MalaStringBucket bucket);
93 static inline void
94 mala_stringlist_tail_insert (MalaStringList head, MalaStringListNode self);
96 //static inline void
97 //mala_stringlist_tail_move (MalaStringList to, MalaStringList from, MalaStringListNode self);
99 MalaStringListNode
100 mala_stringlist_after_new (MalaStringList head,
101 MalaStringListNode pred,
102 MalaString str);
104 MalaStringListNode
105 mala_stringlist_before_new (MalaStringList head,
106 MalaStringListNode succ,
107 MalaString str);
110 MalaStringListNode
111 mala_stringlist_elem_remove (MalaStringList head,
112 MalaStringListNode elem);
114 void
115 mala_stringlist_elem_delete (MalaStringList head, MalaStringListNode elem);
117 static inline void
118 mala_stringlist_elem_delete_fwd (MalaStringList head, MalaStringListNode_ref elem);
120 static inline int
121 mala_stringlist_is_tail (MalaStringList head, MalaStringListNode elem);
123 static inline int
124 mala_stringlist_is_end (MalaStringList head, MalaStringListNode elem);
126 static inline int
127 mala_stringlist_is_empty (MalaStringList head);
129 static inline MalaStringListNode
130 mala_stringlist_node_remove (MalaStringList head, MalaStringListNode self);
134 static inline int mala_stringlist_insert_before (MalaStringList head,
135 MalaStringListNode succ,
136 MalaStringListNode elem);
137 static inline int mala_stringlist_insert_head (MalaStringList head, MalaStringListNode elem);
138 static inline int mala_stringlist_insert_tail (MalaStringList head, MalaStringListNode elem);
141 static inline int mala_stringlist_new_after (MalaStringList head,
142 MalaStringListNode pred,
143 MalaString str);
144 static inline int mala_stringlist_new_before (MalaStringList head,
145 MalaStringListNode succ,
146 MalaString str);
150 static inline MalaStringListNode mala_stringlist_head_new_cstr (MalaStringList head,
151 const char * cstr);
152 static inline MalaStringListNode mala_stringlist_tail_new_cstr (MalaStringList head,
153 const char * cstr);
158 * Inlines
160 #if 0
161 static inline void
162 mala_stringlist_insert_after (MalaStringList head,
163 MalaStringListNode pred,
164 MalaString str)
167 CIRCLEQ_INSERT_AFTER(head, TYPE *listelm, TYPE *elm, CIRCLEQ_ENTRY NAME);
170 static inline void
171 mala_stringlist_insert_before (MalaStringList head,
172 MalaStringListNode succ,
173 MalaString str)
175 CIRCLEQ_INSERT_BEFORE(CIRCLEQ_HEAD *head, TYPE *listelm, TYPE *elm, CIRCLEQ_ENTRY NAME);
177 static inline void
178 mala_stringlist_insert_head (MalaStringList head, MalaString str)
179 CIRCLEQ_INSERT_HEAD(CIRCLEQ_HEAD *head, TYPE *elm, CIRCLEQ_ENTRY NAME);
181 #endif
183 /* statics */
185 static inline void
186 mala_stringlist_elem_delete_fwd (MalaStringList head, MalaStringListNode_ref elem)
188 MalaStringListNode tmp = *elem;
189 *elem = (*elem)->node.cqe_next;
190 mala_stringlist_elem_delete (head, tmp);
193 static inline MalaStringListNode
194 mala_stringlist_node_remove (MalaStringList head, MalaStringListNode self)
196 CIRCLEQ_REMOVE (head, self, node);
197 return self;
200 static inline void
201 mala_stringlist_tail_insert (MalaStringList head, MalaStringListNode self)
203 CIRCLEQ_INSERT_TAIL (head, self, node);
207 static inline int
208 mala_stringlist_is_empty (MalaStringList head)
210 return head->cqh_first == (void *)head;
213 static inline void
214 mala_stringlist_fwd (MalaStringListNode_ref self)
216 *self = (*self)->node.cqe_next;
219 static inline void
220 mala_stringlist_rev (MalaStringListNode_ref self)
222 *self = (*self)->node.cqe_prev;
225 static inline MalaStringListNode
226 mala_stringlist_next (MalaStringListNode self)
228 return self->node.cqe_next;
231 static inline MalaStringListNode
232 mala_stringlist_prev (MalaStringListNode self)
234 return self->node.cqe_prev;
237 static inline void
238 mala_stringlist_init (MalaStringList self)
240 CIRCLEQ_INIT(self);
243 static inline MalaStringListNode
244 mala_stringlist_head (MalaStringList self)
246 return self->cqh_first;
249 static inline MalaStringListNode
250 mala_stringlist_tail (MalaStringList self)
252 return self->cqh_last;
255 static inline int
256 mala_stringlist_is_tail (MalaStringList head, MalaStringListNode elem)
258 return elem->node.cqe_next == (void *)head;
261 static inline int
262 mala_stringlist_is_end (MalaStringList head, MalaStringListNode elem)
264 return elem == (void *)head;
268 #endif /* MALA_STRINGLIST_H */
271 // Local Variables:
272 // mode: C
273 // c-file-style: "gnu"
274 // End:
275 // arch-tag: 44b2b6d9-80b8-43fa-938a-a492bd52cea2
276 // end_of_file