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"
30 struct mala_stringlistnode_struct
32 CIRCLEQ_ENTRY(mala_stringlistnode_struct
) node
;
37 #define MALA_STATIC_STRINGLIST_INIT(args...) \
38 (const char*[]){args, NULL}
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
);
56 mala_stringlist_new ();
59 mala_stringlist_new_cstrs (char **cstrs
,
61 MalaStringBucket bucket
);
64 mala_stringlist_erase (MalaStringList head
);
67 mala_stringlist_free (MalaStringList head
);
70 mala_stringlist_factory (MalaStringList_ref dest
, char** src
, MalaStringBucket bucket
);
73 mala_stringlist_head_new (MalaStringList head
, MalaString str
);
76 mala_stringlist_tail_new (MalaStringList head
, MalaString str
);
79 mala_stringlist_head_new_cstr (MalaStringList head
, const char * cstr
, MalaStringBucket bucket
);
82 mala_stringlist_tail_new_cstr (MalaStringList head
, const char * cstr
, MalaStringBucket bucket
);
85 mala_stringlist_tail_insert (MalaStringList head
, MalaStringListNode self
);
88 //mala_stringlist_tail_move (MalaStringList to, MalaStringList from, MalaStringListNode self);
91 mala_stringlist_after_new (MalaStringList head
,
92 MalaStringListNode pred
,
96 mala_stringlist_before_new (MalaStringList head
,
97 MalaStringListNode succ
,
102 mala_stringlist_elem_remove (MalaStringList head
,
103 MalaStringListNode elem
);
106 mala_stringlist_elem_delete (MalaStringList head
, MalaStringListNode elem
);
109 mala_stringlist_char_exists (MalaStringList head
, const char c
);
113 mala_stringlist_elem_delete_fwd (MalaStringList head
, MalaStringListNode_ref elem
);
116 mala_stringlist_is_tail (MalaStringList head
, MalaStringListNode elem
);
119 mala_stringlist_is_end (MalaStringList head
, MalaStringListNode elem
);
122 mala_stringlist_is_single (MalaStringList head
);
125 mala_stringlist_is_empty (MalaStringList head
);
127 static inline MalaStringListNode
128 mala_stringlist_node_remove (MalaStringList head
, MalaStringListNode self
);
132 mala_stringlistnode_fwd (MalaStringListNode_ref self
);
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
);
147 mala_stringlistnode_substitute_string (MalaStringListNode self
, MalaString subst
);
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,
167 static inline int mala_stringlist_new_before (MalaStringList head,
168 MalaStringListNode succ,
173 static inline MalaStringListNode mala_stringlist_head_new_cstr (MalaStringList head,
175 static inline MalaStringListNode mala_stringlist_tail_new_cstr (MalaStringList head,
185 mala_stringlist_insert_after (MalaStringList head
,
186 MalaStringListNode pred
,
190 CIRCLEQ_INSERT_AFTER(head
, TYPE
*listelm
, TYPE
*elm
, CIRCLEQ_ENTRY NAME
);
194 mala_stringlist_insert_before (MalaStringList head
,
195 MalaStringListNode succ
,
198 CIRCLEQ_INSERT_BEFORE(CIRCLEQ_HEAD
*head
, TYPE
*listelm
, TYPE
*elm
, CIRCLEQ_ENTRY NAME
);
201 mala_stringlist_insert_head (MalaStringList head
, MalaString str
)
202 CIRCLEQ_INSERT_HEAD(CIRCLEQ_HEAD
*head
, TYPE
*elm
, CIRCLEQ_ENTRY NAME
);
208 static inline MalaString
209 mala_stringlist_head_string_copy (MalaStringList self
)
211 return mala_string_copy (mala_stringlistnode_string (mala_stringlist_head (self
)));
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
);
223 mala_stringlist_elem_delete_fwd_n (MalaStringList head
,
224 MalaStringListNode_ref elem
,
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
);
239 mala_stringlist_tail_insert (MalaStringList head
, MalaStringListNode self
)
241 CIRCLEQ_INSERT_TAIL (head
, self
, node
);
246 mala_stringlist_is_empty (MalaStringList head
)
248 return head
->cqh_first
== (void *)head
;
252 mala_stringlist_init (MalaStringList 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
;
270 mala_stringlist_is_single (MalaStringList head
)
272 return head
->cqh_first
!= (void *)head
&& head
->cqh_first
->node
.cqe_next
== (void *)head
;
276 mala_stringlist_is_tail (MalaStringList head
, MalaStringListNode elem
)
278 return elem
->node
.cqe_next
== (void *)head
;
282 mala_stringlist_is_end (MalaStringList head
, MalaStringListNode elem
)
284 return elem
== (void *)head
;
288 mala_stringlistnode_fwd (MalaStringListNode_ref self
)
290 *self
= (*self
)->node
.cqe_next
;
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
;
318 mala_stringlistnode_substitute_string (MalaStringListNode self
, MalaString subst
)
320 mala_string_free (self
->string
);
321 self
->string
= mala_string_copy (subst
);
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 */
347 // c-file-style: "gnu"
349 // arch-tag: 44b2b6d9-80b8-43fa-938a-a492bd52cea2