removed old test sources
[mala.git] / engine / stringlist.c
blob60898a35d344d8862433b6df78ac1039c353dbc2
1 /*
2 stringlist.c - 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.
21 #include "stringlist.h"
23 acogc_mark_result
24 mala_stringlist_acogc_mark (void* o)
26 TRACE (mala_acogc,"start");
27 MalaStringList self = (MalaStringList) o;
29 acogc_object_mark (self->string);
30 acogc_object_lastmark (LLIST_TO_STRUCTP (llist_get_next (&self->node), mala_stringlist, node));
31 //acogc_object_mark (LLIST_TO_STRUCTP (llist_get_next (&self->node), mala_stringlist, node));
33 TRACE (mala_acogc, "finished");
34 return ACOGC_KEEP;
37 void
38 mala_stringlist_acogc_initize (void * o)
40 TRACE (mala_acogc);
41 MalaStringList self = (MalaStringList) o;
42 llist_init (&self->node);
43 self->string = NULL;
46 void
47 mala_stringlist_acogc_finalize (void * o)
49 TRACE (mala_acogc);
50 MalaStringList self = (MalaStringList) o;
51 llist_unlink (&self->node);
54 MalaStringList
55 mala_stringlist_new (MalaEngine engine)
57 return acogc_factory_alloc (&engine->gcfactory_stringlists);
60 void
61 mala_stringlist_append_cstrs (MalaStringList self, int nelem, char** cstrs, MalaEngine engine)
63 TRACE (mala_stringlist);
65 ACOGC_STACK_ENTER (&engine->gcroot);
66 ACOGC_STACK_PTR (MalaStringList, node);
68 for (; nelem != 0 && *cstrs; --nelem , ++cstrs)
70 node.ptr = mala_stringlist_node_new_cstr (*cstrs, engine);
71 mala_stringlist_insert_tail (self, node.ptr);
74 ACOGC_STACK_LEAVE;
77 void
78 mala_stringlist_append_literal_cstrs (MalaStringList self, int nelem, char** cstrs, MalaEngine engine)
80 TRACE (mala_stringlist);
82 ACOGC_STACK_ENTER (&engine->gcroot);
83 ACOGC_STACK_PTR (MalaStringList, node);
85 for (; nelem != 0 && *cstrs; --nelem , ++cstrs)
87 node.ptr = mala_stringlist_node_new_literal_cstr (*cstrs, engine);
88 mala_stringlist_insert_tail (self, node.ptr);
91 ACOGC_STACK_LEAVE;
94 MalaStringList
95 mala_stringlist_copy (MalaStringList source, MalaEngine engine)
97 TRACE (mala_stringlist);
99 ACOGC_STACK_ENTER (&engine->gcroot);
100 ACOGC_STACK_PTR (MalaStringList, ret);
101 ACOGC_STACK_PTR (MalaStringList, elem);
103 ret.ptr = mala_stringlist_new (engine);
105 LLIST_FOREACH (&source->node, node)
107 elem.ptr = mala_stringlist_node_new (mala_stringlist_string_from_llist(node), engine);
108 mala_stringlist_insert_tail (ret.ptr, elem.ptr);
111 ACOGC_STACK_LEAVE;
112 return ret.ptr;
115 MalaStringList
116 mala_stringlist_node_new_literal_cstr (const char * cstr, MalaEngine engine)
118 TRACE (mala_stringlist);
120 ACOGC_STACK_ENTER (&engine->gcroot);
121 ACOGC_STACK_PTR (MalaStringList, node);
122 node.ptr = mala_stringlist_new (engine);
123 node.ptr->string = mala_string_new_literal_cstr (cstr, engine->words);
124 ACOGC_STACK_LEAVE;
125 return node.ptr;
128 MalaStringList
129 mala_stringlist_node_new_cstr (const char * cstr, MalaEngine engine)
131 TRACE (mala_stringlist);
133 ACOGC_STACK_ENTER (&engine->gcroot);
134 ACOGC_STACK_PTR (MalaStringList, node);
135 node.ptr = mala_stringlist_new (engine);
136 node.ptr->string = mala_string_new_cstr (cstr, engine->words);
137 ACOGC_STACK_LEAVE;
138 return node.ptr;
141 MalaStringList
142 mala_stringlist_node_new (MalaString str, MalaEngine engine)
144 TRACE (mala_stringlist);
146 MalaStringList node = acogc_factory_alloc (&engine->gcfactory_stringlists);
147 node->string = str;
148 return node;
151 void
152 mala_stringlist_dump (MalaStringList self,
153 FILE * f,
154 const char* head,
155 const char* before,
156 const char* fmt,
157 const char* after,
158 const char* foot)
160 unsigned lineno = 0;
162 fprintf (f, head);
164 LLIST_FOREACH (&self->node, n)
166 if (lineno++)
167 fprintf (f, after, lineno);
168 fprintf (f, before, lineno);
169 fprintf (f, fmt, mala_stringlist_cstr_from_llist (n));
171 fprintf (f, foot);
174 void
175 nobug_mala_stringlist_dump (const_MalaStringList self,
176 const int depth,
177 const char* file,
178 const int line)
180 if (self && depth)
182 LLIST_FOREACH (&self->node, n)
184 DUMP_LOG ("%s", mala_stringlist_cstr_from_llist (n));
190 // Local Variables:
191 // mode: C
192 // c-file-style: "gnu"
193 // End:
194 // arch-tag: 75b1fbb2-0328-450d-8708-daf943e7bbf6
195 // end_of_file