else_parser
[mala.git] / engine / stringlist.h
blobad29f0b9e8ceee63cc812b88b49a7c23b1d015d7
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 MalaString
52 mala_stringlist_head_string_copy (MalaStringList self);
55 MalaStringList
56 mala_stringlist_new ();
58 MalaStringList
59 mala_stringlist_new_cstrs (char **cstrs,
60 int nelem,
61 MalaStringBucket bucket);
63 void
64 mala_stringlist_erase (MalaStringList head);
66 void
67 mala_stringlist_free (MalaStringList head);
69 void *
70 mala_stringlist_factory (MalaStringList_ref dest, char** src, MalaStringBucket bucket);
72 MalaStringListNode
73 mala_stringlist_head_new (MalaStringList head, MalaString str);
75 MalaStringListNode
76 mala_stringlist_tail_new (MalaStringList head, MalaString str);
78 MalaStringListNode
79 mala_stringlist_head_new_cstr (MalaStringList head, const char * cstr, MalaStringBucket bucket);
81 MalaStringListNode
82 mala_stringlist_tail_new_cstr (MalaStringList head, const char * cstr, MalaStringBucket bucket);
84 static inline void
85 mala_stringlist_tail_insert (MalaStringList head, MalaStringListNode self);
87 //static inline void
88 //mala_stringlist_tail_move (MalaStringList to, MalaStringList from, MalaStringListNode self);
90 MalaStringListNode
91 mala_stringlist_after_new (MalaStringList head,
92 MalaStringListNode pred,
93 MalaString str);
95 MalaStringListNode
96 mala_stringlist_before_new (MalaStringList head,
97 MalaStringListNode succ,
98 MalaString str);
101 MalaStringListNode
102 mala_stringlist_elem_remove (MalaStringList head,
103 MalaStringListNode elem);
105 void
106 mala_stringlist_elem_delete (MalaStringList head, MalaStringListNode elem);
109 mala_stringlist_char_exists (MalaStringList head, const char c);
112 static inline void
113 mala_stringlist_elem_delete_fwd (MalaStringList head, MalaStringListNode_ref elem);
115 static inline int
116 mala_stringlist_is_tail (MalaStringList head, MalaStringListNode elem);
118 static inline int
119 mala_stringlist_is_end (MalaStringList head, MalaStringListNode elem);
121 static inline int
122 mala_stringlist_is_single (MalaStringList head);
124 static inline int
125 mala_stringlist_is_empty (MalaStringList head);
127 static inline MalaStringListNode
128 mala_stringlist_node_remove (MalaStringList head, MalaStringListNode self);
130 /*stringlistnode*/
131 static inline void
132 mala_stringlistnode_fwd (MalaStringListNode_ref self);
134 static inline void
135 mala_stringlistnode_rev (MalaStringListNode_ref self);
137 static inline MalaStringListNode
138 mala_stringlistnode_next (MalaStringListNode self);
140 static inline MalaStringListNode
141 mala_stringlistnode_prev (MalaStringListNode self);
143 static inline MalaString
144 mala_stringlistnode_string (MalaStringListNode self);
146 static inline void
147 mala_stringlistnode_substitute_string (MalaStringListNode self, MalaString subst);
149 static inline void*
150 mala_stringlistnode_user_get (MalaStringListNode self);
152 static inline const char*
153 mala_stringlistnode_cstr (MalaStringListNode self);
157 static inline int mala_stringlist_insert_before (MalaStringList head,
158 MalaStringListNode succ,
159 MalaStringListNode elem);
160 static inline int mala_stringlist_insert_head (MalaStringList head, MalaStringListNode elem);
161 static inline int mala_stringlist_insert_tail (MalaStringList head, MalaStringListNode elem);
164 static inline int mala_stringlist_new_after (MalaStringList head,
165 MalaStringListNode pred,
166 MalaString str);
167 static inline int mala_stringlist_new_before (MalaStringList head,
168 MalaStringListNode succ,
169 MalaString str);
173 static inline MalaStringListNode mala_stringlist_head_new_cstr (MalaStringList head,
174 const char * cstr);
175 static inline MalaStringListNode mala_stringlist_tail_new_cstr (MalaStringList head,
176 const char * cstr);
181 * Inlines
183 #if 0
184 static inline void
185 mala_stringlist_insert_after (MalaStringList head,
186 MalaStringListNode pred,
187 MalaString str)
190 CIRCLEQ_INSERT_AFTER(head, TYPE *listelm, TYPE *elm, CIRCLEQ_ENTRY NAME);
193 static inline void
194 mala_stringlist_insert_before (MalaStringList head,
195 MalaStringListNode succ,
196 MalaString str)
198 CIRCLEQ_INSERT_BEFORE(CIRCLEQ_HEAD *head, TYPE *listelm, TYPE *elm, CIRCLEQ_ENTRY NAME);
200 static inline void
201 mala_stringlist_insert_head (MalaStringList head, MalaString str)
202 CIRCLEQ_INSERT_HEAD(CIRCLEQ_HEAD *head, TYPE *elm, CIRCLEQ_ENTRY NAME);
204 #endif
206 /* statics */
208 static inline MalaString
209 mala_stringlist_head_string_copy (MalaStringList self)
211 return mala_string_copy (mala_stringlistnode_string (mala_stringlist_head (self)));
214 static inline void
215 mala_stringlist_elem_delete_fwd (MalaStringList head, MalaStringListNode_ref elem)
217 MalaStringListNode tmp = *elem;
218 *elem = (*elem)->node.cqe_next;
219 mala_stringlist_elem_delete (head, tmp);
222 static inline void
223 mala_stringlist_elem_delete_fwd_n (MalaStringList head,
224 MalaStringListNode_ref elem,
225 unsigned n)
227 while (n--)
228 mala_stringlist_elem_delete_fwd (head, elem);
231 static inline MalaStringListNode
232 mala_stringlist_node_remove (MalaStringList head, MalaStringListNode self)
234 CIRCLEQ_REMOVE (head, self, node);
235 return self;
238 static inline void
239 mala_stringlist_tail_insert (MalaStringList head, MalaStringListNode self)
241 CIRCLEQ_INSERT_TAIL (head, self, node);
245 static inline int
246 mala_stringlist_is_empty (MalaStringList head)
248 return head->cqh_first == (void *)head;
251 static inline void
252 mala_stringlist_init (MalaStringList self)
254 CIRCLEQ_INIT(self);
257 static inline MalaStringListNode
258 mala_stringlist_head (MalaStringList self)
260 return self->cqh_first;
263 static inline MalaStringListNode
264 mala_stringlist_tail (MalaStringList self)
266 return self->cqh_last;
269 static inline int
270 mala_stringlist_is_single (MalaStringList head)
272 return head->cqh_first != (void *)head && head->cqh_first->node.cqe_next == (void *)head;
275 static inline int
276 mala_stringlist_is_tail (MalaStringList head, MalaStringListNode elem)
278 return elem->node.cqe_next == (void *)head;
281 static inline int
282 mala_stringlist_is_end (MalaStringList head, MalaStringListNode elem)
284 return elem == (void *)head;
287 static inline void
288 mala_stringlistnode_fwd (MalaStringListNode_ref self)
290 *self = (*self)->node.cqe_next;
293 static inline void
294 mala_stringlistnode_rev (MalaStringListNode_ref self)
296 *self = (*self)->node.cqe_prev;
299 static inline MalaStringListNode
300 mala_stringlistnode_next (MalaStringListNode self)
302 return self->node.cqe_next;
305 static inline MalaStringListNode
306 mala_stringlistnode_prev (MalaStringListNode self)
308 return self->node.cqe_prev;
311 static inline MalaString
312 mala_stringlistnode_string (MalaStringListNode self)
314 return self ? self->string : NULL;
317 static inline void
318 mala_stringlistnode_substitute_string (MalaStringListNode self, MalaString subst)
320 mala_string_free (self->string);
321 self->string = mala_string_copy (subst);
324 static inline void*
325 mala_stringlistnode_user_get (MalaStringListNode self)
327 return self ? mala_string_user_get (self->string) : NULL;
330 static inline const char*
331 mala_stringlistnode_cstr (MalaStringListNode self)
333 return self ? mala_string_cstr (self->string) : NULL;
336 static inline MalaString
337 mala_stringlistnode_string_copy (MalaStringListNode self)
339 return mala_string_copy (mala_stringlistnode_string (self));
342 #endif /* MALA_STRINGLIST_H */
345 // Local Variables:
346 // mode: C
347 // c-file-style: "gnu"
348 // End:
349 // arch-tag: 44b2b6d9-80b8-43fa-938a-a492bd52cea2
350 // end_of_file