updated test.sh for nobug compatibility, has still problems with joined stderr and...
[mala.git] / engine / stringlist.h
blob2789340f63b69715ed24e95e46403590db435f74
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 <stdio.h>
24 #include "mala_types.h"
25 #include "engine.h"
26 #include "strings.h"
27 #include "llist.h"
30 #define MALA_STATIC_STRINGLIST_INIT(args...) \
31 (const char*[]){args, NULL}
35 * StringList
38 struct mala_stringlist_struct
40 llist node;
41 MalaString string;
44 /*gc support*/
45 acogc_mark_result
46 mala_stringlist_acogc_mark (void* o);
48 void
49 mala_stringlist_acogc_initize (void * o);
51 void
52 mala_stringlist_acogc_finalize (void * o);
55 /* constructors */
56 MalaStringList
57 mala_stringlist_new (MalaEngine engine);
59 MalaStringList
60 mala_stringlist_copy (MalaStringList source, MalaEngine engine);
62 void
63 mala_stringlist_append_cstrs (MalaStringList self, int nelem, char** cstrs, MalaEngine engine);
65 void
66 mala_stringlist_append_literal_cstrs (MalaStringList self, int nelem, char** cstrs, MalaEngine engine);
68 MalaStringList
69 mala_stringlist_node_new_literal_cstr (const char * cstr, MalaEngine engine);
71 MalaStringList
72 mala_stringlist_node_new_cstr (const char * cstr, MalaEngine engine);
74 MalaStringList
75 mala_stringlist_node_new (MalaString str, MalaEngine engine);
77 /* declarations */
78 static inline void
79 mala_stringlist_insert_after_stringlist (MalaStringList self, MalaStringList src);
81 static inline MalaString
82 mala_stringlist_string_from_llist (const_LList self);
84 static inline const char *
85 mala_stringlist_cstr_from_llist (const_LList self);
87 void
88 mala_stringlist_dump (MalaStringList self, FILE * f,
89 const char* head,
90 const char* before,
91 const char* fmt,
92 const char* after,
93 const char* foot);
95 void
96 nobug_mala_stringlist_dump (const_MalaStringList self,
97 const int depth,
98 const char* file,
99 const int line,
100 const char* func);
102 static inline MalaString
103 mala_stringlist_string (MalaStringList self);
105 static inline void
106 mala_stringlist_string_set (MalaStringList self, MalaString str);
108 static inline MalaStringList
109 mala_stringlist_next (MalaStringList self);
111 static inline MalaStringList
112 mala_stringlist_prev (MalaStringList self);
114 static inline void
115 mala_stringlist_fwd (MalaStringList_ref self);
117 static inline void
118 mala_stringlist_rev (MalaStringList_ref self);
120 static inline void
121 mala_stringlist_advance (MalaStringList self);
123 static inline void
124 mala_stringlist_remove (MalaStringList self);
126 static inline void
127 mala_stringlist_insert_tail (MalaStringList self, MalaStringList node);
129 static inline void
130 mala_stringlist_insert_head (MalaStringList self, MalaStringList node);
132 #define mala_stringlist_insert_before mala_stringlist_insert_tail
133 #define mala_stringlist_insert_after mala_stringlist_insert_head
135 /* inlines */
136 static inline void
137 mala_stringlist_insert_after_stringlist (MalaStringList self, MalaStringList src)
139 llist_insert_list_after (&src->node, &self->node);
142 static inline MalaString
143 mala_stringlist_string (MalaStringList self)
145 return self->string;
148 static inline void
149 mala_stringlist_string_set (MalaStringList self, MalaString str)
151 self->string = str;
154 static inline const char*
155 mala_stringlist_cstr (MalaStringList self)
157 return mala_string_cstr (self->string);
160 static inline MalaStringList
161 mala_stringlist_head_get (MalaStringList self)
163 return LLIST_TO_STRUCTP (llist_get_next (&self->node), mala_stringlist, node);
166 static inline MalaString
167 mala_stringlist_string_from_llist (const_LList self)
169 return LLIST_TO_STRUCTP (self, mala_stringlist, node)->string;
172 static inline const char *
173 mala_stringlist_cstr_from_llist (const_LList self)
175 return mala_string_cstr (mala_stringlist_string_from_llist (self));
178 static inline void
179 mala_stringlist_fwd (MalaStringList_ref self)
181 *self = LLIST_TO_STRUCTP (llist_get_next (&(*self)->node), mala_stringlist, node);
184 static inline void
185 mala_stringlist_rev (MalaStringList_ref self)
187 *self = LLIST_TO_STRUCTP (llist_get_prev (&(*self)->node), mala_stringlist, node);
190 static inline void
191 mala_stringlist_advance (MalaStringList self)
193 llist_advance (&self->node);
196 static inline void
197 mala_stringlist_remove (MalaStringList self)
199 llist_unlink (&self->node);
202 static inline MalaStringList
203 mala_stringlist_next (MalaStringList self)
205 return LLIST_TO_STRUCTP (llist_get_next(&self->node), mala_stringlist, node);
208 static inline MalaStringList
209 mala_stringlist_prev (MalaStringList self)
211 return LLIST_TO_STRUCTP (llist_get_prev(&self->node), mala_stringlist, node);
214 static inline void
215 mala_stringlist_insert_tail (MalaStringList self, MalaStringList node)
217 llist_insert_tail (&self->node, &node->node);
220 static inline void
221 mala_stringlist_insert_head (MalaStringList self, MalaStringList node)
223 llist_insert_head (&self->node, &node->node);
226 static inline MalaStringList
227 mala_stringlist_tail_get (MalaStringList self)
229 return LLIST_TO_STRUCTP(llist_get_tail (&self->node), mala_stringlist, node);
232 static inline int
233 mala_stringlist_is_end (MalaStringList self, MalaStringList other)
235 return self == other;
238 #endif /* MALA_STRINGLIST_H */
241 // Local Variables:
242 // mode: C
243 // c-file-style: "gnu"
244 // End:
245 // arch-tag: 44b2b6d9-80b8-43fa-938a-a492bd52cea2
246 // end_of_file