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
);
52 mala_stringlist_fwd (MalaStringListNode_ref self
);
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
);
65 mala_stringlist_new ();
68 mala_stringlist_new_cstrs (char **cstrs
,
70 MalaStringBucket bucket
);
73 mala_stringlist_erase (MalaStringList head
);
76 mala_stringlist_free (MalaStringList head
);
79 mala_stringlist_factory (MalaStringList_ref dest
, char** src
, MalaStringBucket bucket
);
82 mala_stringlist_head_new (MalaStringList head
, MalaString str
);
85 mala_stringlist_tail_new (MalaStringList head
, MalaString str
);
88 mala_stringlist_head_new_cstr (MalaStringList head
, const char * cstr
, MalaStringBucket bucket
);
91 mala_stringlist_tail_new_cstr (MalaStringList head
, const char * cstr
, MalaStringBucket bucket
);
94 mala_stringlist_tail_insert (MalaStringList head
, MalaStringListNode self
);
97 //mala_stringlist_tail_move (MalaStringList to, MalaStringList from, MalaStringListNode self);
100 mala_stringlist_after_new (MalaStringList head
,
101 MalaStringListNode pred
,
105 mala_stringlist_before_new (MalaStringList head
,
106 MalaStringListNode succ
,
111 mala_stringlist_elem_remove (MalaStringList head
,
112 MalaStringListNode elem
);
115 mala_stringlist_elem_delete (MalaStringList head
, MalaStringListNode elem
);
118 mala_stringlist_char_exists (MalaStringList head
, const char c
);
122 mala_stringlist_elem_delete_fwd (MalaStringList head
, MalaStringListNode_ref elem
);
125 mala_stringlist_is_tail (MalaStringList head
, MalaStringListNode elem
);
128 mala_stringlist_is_end (MalaStringList head
, MalaStringListNode elem
);
131 mala_stringlist_is_single (MalaStringList head
);
134 mala_stringlist_is_empty (MalaStringList head
);
136 static inline MalaStringListNode
137 mala_stringlist_node_remove (MalaStringList head
, MalaStringListNode self
);
141 static inline int mala_stringlist_insert_before (MalaStringList head,
142 MalaStringListNode succ,
143 MalaStringListNode elem);
144 static inline int mala_stringlist_insert_head (MalaStringList head, MalaStringListNode elem);
145 static inline int mala_stringlist_insert_tail (MalaStringList head, MalaStringListNode elem);
148 static inline int mala_stringlist_new_after (MalaStringList head,
149 MalaStringListNode pred,
151 static inline int mala_stringlist_new_before (MalaStringList head,
152 MalaStringListNode succ,
157 static inline MalaStringListNode mala_stringlist_head_new_cstr (MalaStringList head,
159 static inline MalaStringListNode mala_stringlist_tail_new_cstr (MalaStringList head,
169 mala_stringlist_insert_after (MalaStringList head
,
170 MalaStringListNode pred
,
174 CIRCLEQ_INSERT_AFTER(head
, TYPE
*listelm
, TYPE
*elm
, CIRCLEQ_ENTRY NAME
);
178 mala_stringlist_insert_before (MalaStringList head
,
179 MalaStringListNode succ
,
182 CIRCLEQ_INSERT_BEFORE(CIRCLEQ_HEAD
*head
, TYPE
*listelm
, TYPE
*elm
, CIRCLEQ_ENTRY NAME
);
185 mala_stringlist_insert_head (MalaStringList head
, MalaString str
)
186 CIRCLEQ_INSERT_HEAD(CIRCLEQ_HEAD
*head
, TYPE
*elm
, CIRCLEQ_ENTRY NAME
);
193 mala_stringlist_elem_delete_fwd (MalaStringList head
, MalaStringListNode_ref elem
)
195 MalaStringListNode tmp
= *elem
;
196 *elem
= (*elem
)->node
.cqe_next
;
197 mala_stringlist_elem_delete (head
, tmp
);
200 static inline MalaStringListNode
201 mala_stringlist_node_remove (MalaStringList head
, MalaStringListNode self
)
203 CIRCLEQ_REMOVE (head
, self
, node
);
208 mala_stringlist_tail_insert (MalaStringList head
, MalaStringListNode self
)
210 CIRCLEQ_INSERT_TAIL (head
, self
, node
);
215 mala_stringlist_is_empty (MalaStringList head
)
217 return head
->cqh_first
== (void *)head
;
221 mala_stringlist_fwd (MalaStringListNode_ref self
)
223 *self
= (*self
)->node
.cqe_next
;
227 mala_stringlist_rev (MalaStringListNode_ref self
)
229 *self
= (*self
)->node
.cqe_prev
;
232 static inline MalaStringListNode
233 mala_stringlist_next (MalaStringListNode self
)
235 return self
->node
.cqe_next
;
238 static inline MalaStringListNode
239 mala_stringlist_prev (MalaStringListNode self
)
241 return self
->node
.cqe_prev
;
245 mala_stringlist_init (MalaStringList self
)
250 static inline MalaStringListNode
251 mala_stringlist_head (MalaStringList self
)
253 return self
->cqh_first
;
256 static inline MalaStringListNode
257 mala_stringlist_tail (MalaStringList self
)
259 return self
->cqh_last
;
263 mala_stringlist_is_single (MalaStringList head
)
265 return head
->cqh_first
!= (void *)head
&& head
->cqh_first
->node
.cqe_next
== (void *)head
;
269 mala_stringlist_is_tail (MalaStringList head
, MalaStringListNode elem
)
271 return elem
->node
.cqe_next
== (void *)head
;
275 mala_stringlist_is_end (MalaStringList head
, MalaStringListNode elem
)
277 return elem
== (void *)head
;
281 #endif /* MALA_STRINGLIST_H */
286 // c-file-style: "gnu"
288 // arch-tag: 44b2b6d9-80b8-43fa-938a-a492bd52cea2