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_new ()
27 self
= malloc (sizeof(mala_stringlist
));
36 mala_stringlist_new_cstrs (char **cstrs
,
38 MalaStringBucket bucket
)
41 MalaStringListNode node
;
43 self
= mala_stringlist_new ();
47 for (; nelem
!= 0 && *cstrs
; --nelem
, ++cstrs
)
49 node
= malloc (sizeof(mala_stringlistnode
));
53 node
->string
= mala_string_new (*cstrs
, bucket
);
57 CIRCLEQ_INSERT_TAIL(self
, node
, node
);
65 mala_stringlist_free (self
);
71 mala_stringlist_head_new (MalaStringList head
, MalaString str
)
78 n
= malloc(sizeof(mala_stringlistnode
));
82 n
->string
= mala_string_copy (str
);
84 CIRCLEQ_INSERT_HEAD (head
, n
, node
);
89 mala_stringlist_tail_new (MalaStringList head
, MalaString str
)
96 n
= malloc(sizeof(mala_stringlistnode
));
100 n
->string
= mala_string_copy (str
);
102 CIRCLEQ_INSERT_TAIL (head
, n
, node
);
107 mala_stringlist_head_new_cstr (MalaStringList head
, const char * cstr
, MalaStringBucket bucket
)
110 MalaStringListNode n
;
112 str
= mala_string_new (cstr
, bucket
);
116 n
= mala_stringlist_head_new (head
, str
);
118 mala_string_free (str
);
123 mala_stringlist_tail_new_cstr (MalaStringList head
, const char * cstr
, MalaStringBucket bucket
)
126 MalaStringListNode n
;
128 str
= mala_string_new (cstr
, bucket
);
132 n
= mala_stringlist_tail_new (head
, str
);
134 mala_string_free (str
);
140 mala_stringlist_after_new (MalaStringList head
, MalaStringListNode pred
, MalaString str
)
142 MalaStringListNode n
= malloc(sizeof(mala_stringlistnode
));
146 n
->string
= mala_string_copy (str
);
148 CIRCLEQ_INSERT_AFTER (head
, pred
, n
, node
);
154 mala_stringlist_before_new (MalaStringList head
, MalaStringListNode succ
, MalaString str
)
156 MalaStringListNode n
= malloc(sizeof(mala_stringlistnode
));
160 n
->string
= mala_string_copy (str
);
162 CIRCLEQ_INSERT_BEFORE (head
, succ
, n
, node
);
168 mala_stringlist_elem_remove (MalaStringList head
, MalaStringListNode elem
)
170 CIRCLEQ_REMOVE (head
, elem
, node
);
175 mala_stringlist_elem_delete (MalaStringList head
, MalaStringListNode_ref elem
)
177 mala_stringlist_elem_remove (head
, *elem
);
178 mala_string_free ((*elem
)->string
);
184 mala_stringlist_erase (MalaStringList head
)
186 while (head
->cqh_first
!= (void *) head
)
188 MalaStringListNode n
= head
->cqh_first
;
189 CIRCLEQ_REMOVE(head
, n
, node
);
190 mala_string_free (n
->string
);
196 mala_stringlist_free (MalaStringList head
)
201 mala_stringlist_erase (head
);
206 mala_stringlist_factory (MalaStringList_ref dest
, char** src
, MalaStringBucket bucket
)
210 return *dest
= mala_stringlist_new_cstrs (src
, -1, bucket
);
214 mala_stringlist_free (*dest
);
222 // c-file-style: "gnu"
224 // arch-tag: 75b1fbb2-0328-450d-8708-daf943e7bbf6