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_elem_delete_fwd (MalaStringList head
, MalaStringListNode_ref elem
);
121 mala_stringlist_is_tail (MalaStringList head
, MalaStringListNode elem
);
124 mala_stringlist_is_end (MalaStringList head
, MalaStringListNode elem
);
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,
144 static inline int mala_stringlist_new_before (MalaStringList head,
145 MalaStringListNode succ,
150 static inline MalaStringListNode mala_stringlist_head_new_cstr (MalaStringList head,
152 static inline MalaStringListNode mala_stringlist_tail_new_cstr (MalaStringList head,
162 mala_stringlist_insert_after (MalaStringList head
,
163 MalaStringListNode pred
,
167 CIRCLEQ_INSERT_AFTER(head
, TYPE
*listelm
, TYPE
*elm
, CIRCLEQ_ENTRY NAME
);
171 mala_stringlist_insert_before (MalaStringList head
,
172 MalaStringListNode succ
,
175 CIRCLEQ_INSERT_BEFORE(CIRCLEQ_HEAD
*head
, TYPE
*listelm
, TYPE
*elm
, CIRCLEQ_ENTRY NAME
);
178 mala_stringlist_insert_head (MalaStringList head
, MalaString str
)
179 CIRCLEQ_INSERT_HEAD(CIRCLEQ_HEAD
*head
, TYPE
*elm
, CIRCLEQ_ENTRY NAME
);
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
);
201 mala_stringlist_tail_insert (MalaStringList head
, MalaStringListNode self
)
203 CIRCLEQ_INSERT_TAIL (head
, self
, node
);
208 mala_stringlist_is_empty (MalaStringList head
)
210 return head
->cqh_first
== (void *)head
;
214 mala_stringlist_fwd (MalaStringListNode_ref self
)
216 *self
= (*self
)->node
.cqe_next
;
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
;
238 mala_stringlist_init (MalaStringList 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
;
256 mala_stringlist_is_tail (MalaStringList head
, MalaStringListNode elem
)
258 return elem
->node
.cqe_next
== (void *)head
;
262 mala_stringlist_is_end (MalaStringList head
, MalaStringListNode elem
)
264 return elem
== (void *)head
;
268 #endif /* MALA_STRINGLIST_H */
273 // c-file-style: "gnu"
275 // arch-tag: 44b2b6d9-80b8-43fa-938a-a492bd52cea2