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"
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");
38 mala_stringlist_acogc_initize (void * o
)
41 MalaStringList self
= (MalaStringList
) o
;
42 llist_init (&self
->node
);
47 mala_stringlist_acogc_finalize (void * o
)
50 MalaStringList self
= (MalaStringList
) o
;
51 llist_unlink (&self
->node
);
55 mala_stringlist_new (MalaEngine engine
)
57 return acogc_factory_alloc (&engine
->gcfactory_stringlists
);
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
);
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
);
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
);
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
);
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
);
142 mala_stringlist_node_new (MalaString str
, MalaEngine engine
)
144 TRACE (mala_stringlist
);
146 MalaStringList node
= acogc_factory_alloc (&engine
->gcfactory_stringlists
);
152 mala_stringlist_dump (MalaStringList self
,
164 LLIST_FOREACH (&self
->node
, n
)
167 fprintf (f
, after
, lineno
);
168 fprintf (f
, before
, lineno
);
169 fprintf (f
, fmt
, mala_stringlist_cstr_from_llist (n
));
175 nobug_mala_stringlist_dump (const_MalaStringList self
,
182 LLIST_FOREACH (&self
->node
, n
)
184 DUMP_LOG ("%s", mala_stringlist_cstr_from_llist (n
));
192 // c-file-style: "gnu"
194 // arch-tag: 75b1fbb2-0328-450d-8708-daf943e7bbf6