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 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
));
35 mala_stringlist_acogc_initize (void * o
)
37 MalaStringList self
= (MalaStringList
) o
;
38 llist_init (&self
->node
);
43 mala_stringlist_acogc_finalize (void * o
)
45 MalaStringList self
= (MalaStringList
) o
;
46 llist_unlink (&self
->node
);
50 mala_stringlist_new (MalaEngine engine
)
52 return acogc_factory_alloc (&engine
->gcfactory_stringlists
);
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
);
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
);
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
);
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
);
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
);
127 mala_stringlist_node_new (MalaString str
, MalaEngine engine
)
129 MalaStringList node
= acogc_factory_alloc (&engine
->gcfactory_stringlists
);
135 mala_stringlist_dump (MalaStringList self
,
147 LLIST_FOREACH (&self
->node
, n
)
150 fprintf (f
, after
, lineno
);
151 fprintf (f
, before
, lineno
);
152 fprintf (f
, fmt
, mala_stringlist_cstr_from_llist (n
));
160 // c-file-style: "gnu"
162 // arch-tag: 75b1fbb2-0328-450d-8708-daf943e7bbf6