reformated common-strings macro
[mala.git] / engine / stringlist.c
blob49b67201a27c0d65e749b89bd6d106393975500f
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 MalaStringList self = (MalaStringList) o;
28 acogc_object_mark (self->string);
29 acogc_object_lastmark (LLIST_TO_STRUCTP (llist_get_next (&self->node), mala_stringlist, node));
31 return ACOGC_KEEP;
34 void
35 mala_stringlist_acogc_initize (void * o)
37 MalaStringList self = (MalaStringList) o;
38 llist_init (&self->node);
39 self->string = NULL;
42 void
43 mala_stringlist_acogc_finalize (void * o)
45 MalaStringList self = (MalaStringList) o;
46 llist_unlink (&self->node);
49 MalaStringList
50 mala_stringlist_new (MalaEngine engine)
52 return acogc_factory_alloc (&engine->gcfactory_stringlists);
55 void
56 mala_stringlist_append_cstrs (MalaStringList self, int nelem, char** cstrs, MalaEngine engine)
58 ACOGC_STACK_ENTER (&engine->gcroot);
59 ACOGC_STACK_PTR (MalaStringList, node);
61 for (; nelem != 0 && *cstrs; --nelem , ++cstrs)
63 node.ptr = mala_stringlist_node_new_cstr (*cstrs, engine);
64 mala_stringlist_insert_tail (self, node.ptr);
67 ACOGC_STACK_LEAVE;
70 void
71 mala_stringlist_append_literal_cstrs (MalaStringList self, int nelem, char** cstrs, MalaEngine engine)
73 ACOGC_STACK_ENTER (&engine->gcroot);
74 ACOGC_STACK_PTR (MalaStringList, node);
76 for (; nelem != 0 && *cstrs; --nelem , ++cstrs)
78 node.ptr = mala_stringlist_node_new_literal_cstr (*cstrs, engine);
79 mala_stringlist_insert_tail (self, node.ptr);
82 ACOGC_STACK_LEAVE;
85 MalaStringList
86 mala_stringlist_copy (MalaStringList source, MalaEngine engine)
88 ACOGC_STACK_ENTER (&engine->gcroot);
89 ACOGC_STACK_PTR (MalaStringList, ret);
90 ACOGC_STACK_PTR (MalaStringList, elem);
92 ret.ptr = mala_stringlist_new (engine);
94 LLIST_FOREACH (&source->node, node)
96 elem.ptr = mala_stringlist_node_new (mala_stringlist_string_from_llist(node), engine);
97 mala_stringlist_insert_tail (ret.ptr, elem.ptr);
100 ACOGC_STACK_LEAVE;
101 return ret.ptr;
104 MalaStringList
105 mala_stringlist_node_new_literal_cstr (const char * cstr, MalaEngine engine)
107 ACOGC_STACK_ENTER (&engine->gcroot);
108 ACOGC_STACK_PTR (MalaStringList, node);
109 node.ptr = mala_stringlist_new (engine);
110 node.ptr->string = mala_string_new_literal_cstr (cstr, engine->words);
111 ACOGC_STACK_LEAVE;
112 return node.ptr;
115 MalaStringList
116 mala_stringlist_node_new_cstr (const char * cstr, MalaEngine engine)
118 ACOGC_STACK_ENTER (&engine->gcroot);
119 ACOGC_STACK_PTR (MalaStringList, node);
120 node.ptr = mala_stringlist_new (engine);
121 node.ptr->string = mala_string_new_cstr (cstr, engine->words);
122 ACOGC_STACK_LEAVE;
123 return node.ptr;
126 MalaStringList
127 mala_stringlist_node_new (MalaString str, MalaEngine engine)
129 MalaStringList node = acogc_factory_alloc (&engine->gcfactory_stringlists);
130 node->string = str;
131 return node;
134 void
135 mala_stringlist_dump (MalaStringList self,
136 FILE * f,
137 const char* head,
138 const char* before,
139 const char* fmt,
140 const char* after,
141 const char* foot)
143 unsigned lineno = 0;
145 fprintf (f, head);
147 LLIST_FOREACH (&self->node, n)
149 if (lineno++)
150 fprintf (f, after, lineno);
151 fprintf (f, before, lineno);
152 fprintf (f, fmt, mala_stringlist_cstr_from_llist (n));
154 fprintf (f, foot);
158 // Local Variables:
159 // mode: C
160 // c-file-style: "gnu"
161 // End:
162 // arch-tag: 75b1fbb2-0328-450d-8708-daf943e7bbf6
163 // end_of_file