2
$Id: ds.c,v 1.3 2005/02/03 07:35:15 rocky Exp $
4
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
5
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
#include <cdio/util.h>
31
#include <cdio/types.h>
32
#include "cdio_assert.h"
34
static const char _rcsid[] = "$Id: ds.c,v 1.3 2005/02/03 07:35:15 rocky Exp $";
40
CdioListNode_t *begin;
58
CdioList_t *p_new_obj = calloc (1, sizeof (CdioList_t));
64
_cdio_list_free (CdioList_t *p_list, int free_data)
66
while (_cdio_list_length (p_list))
67
_cdio_list_node_free (_cdio_list_begin (p_list), free_data);
73
_cdio_list_length (const CdioList_t *p_list)
75
cdio_assert (p_list != NULL);
77
return p_list->length;
81
_cdio_list_prepend (CdioList_t *p_list, void *p_data)
83
CdioListNode_t *p_new_node;
85
cdio_assert (p_list != NULL);
87
p_new_node = calloc (1, sizeof (CdioListNode_t));
89
p_new_node->list = p_list;
90
p_new_node->next = p_list->begin;
91
p_new_node->data = p_data;
93
p_list->begin = p_new_node;
94
if (p_list->length == 0)
95
p_list->end = p_new_node;
101
_cdio_list_append (CdioList_t *p_list, void *p_data)
103
cdio_assert (p_list != NULL);
105
if (p_list->length == 0)
107
_cdio_list_prepend (p_list, p_data);
111
CdioListNode_t *p_new_node = calloc (1, sizeof (CdioListNode_t));
113
p_new_node->list = p_list;
114
p_new_node->next = NULL;
115
p_new_node->data = p_data;
117
p_list->end->next = p_new_node;
118
p_list->end = p_new_node;
125
_cdio_list_foreach (CdioList_t *p_list, _cdio_list_iterfunc_t func,
128
CdioListNode_t *node;
130
cdio_assert (p_list != NULL);
131
cdio_assert (func != 0);
133
for (node = _cdio_list_begin (p_list);
135
node = _cdio_list_node_next (node))
136
func (_cdio_list_node_data (node), p_user_data);
140
_cdio_list_find (CdioList_t *p_list, _cdio_list_iterfunc_t cmp_func,
143
CdioListNode_t *p_node;
145
cdio_assert (p_list != NULL);
146
cdio_assert (cmp_func != 0);
148
for (p_node = _cdio_list_begin (p_list);
150
p_node = _cdio_list_node_next (p_node))
151
if (cmp_func (_cdio_list_node_data (p_node), p_user_data))
158
_cdio_list_begin (const CdioList_t *p_list)
160
cdio_assert (p_list != NULL);
162
return p_list->begin;
166
_cdio_list_end (CdioList_t *p_list)
168
cdio_assert (p_list != NULL);
174
_cdio_list_node_next (CdioListNode_t *p_node)
183
_cdio_list_node_free (CdioListNode_t *p_node, int free_data)
186
CdioListNode_t *prev_node;
188
cdio_assert (p_node != NULL);
190
p_list = p_node->list;
192
cdio_assert (_cdio_list_length (p_list) > 0);
195
free (_cdio_list_node_data (p_node));
197
if (_cdio_list_length (p_list) == 1)
199
cdio_assert (p_list->begin == p_list->end);
201
p_list->end = p_list->begin = NULL;
207
cdio_assert (p_list->begin != p_list->end);
209
if (p_list->begin == p_node)
211
p_list->begin = p_node->next;
217
for (prev_node = p_list->begin; prev_node->next; prev_node = prev_node->next)
218
if (prev_node->next == p_node)
221
cdio_assert (prev_node->next != NULL);
223
if (p_list->end == p_node)
224
p_list->end = prev_node;
226
prev_node->next = p_node->next;
234
_cdio_list_node_data (CdioListNode_t *p_node)
247
* c-file-style: "gnu"
249
* indent-tabs-mode: nil