diff options
| author | Rocky Bernstein <rockyb@users.sourceforge.net> | 2005-01-01 02:43:56 +0000 |
|---|---|---|
| committer | Rocky Bernstein <rockyb@users.sourceforge.net> | 2005-01-01 02:43:56 +0000 |
| commit | 01d976496634a07467382bfb7c621f95792946b7 (patch) | |
| tree | 39bf1a66b7f7517e27f2da388ed99a20d5b1f450 /src/input/vcd/libvcd/data_structures.c | |
| parent | 5c8aac6caa78d6ea1a635ba6a0162d2c41b20a74 (diff) | |
| download | xine-lib-01d976496634a07467382bfb7c621f95792946b7.tar.gz xine-lib-01d976496634a07467382bfb7c621f95792946b7.tar.bz2 | |
Update internal (and messy) copies to libcdio 0.71 and
vcdimager 0.7.21.
CVS patchset: 7313
CVS date: 2005/01/01 02:43:56
Diffstat (limited to 'src/input/vcd/libvcd/data_structures.c')
| -rw-r--r-- | src/input/vcd/libvcd/data_structures.c | 262 |
1 files changed, 39 insertions, 223 deletions
diff --git a/src/input/vcd/libvcd/data_structures.c b/src/input/vcd/libvcd/data_structures.c index a269cc8f8..1fdca95c9 100644 --- a/src/input/vcd/libvcd/data_structures.c +++ b/src/input/vcd/libvcd/data_structures.c @@ -1,7 +1,8 @@ /* - $Id: data_structures.c,v 1.2 2004/04/11 12:20:32 miguelfreitas Exp $ + $Id: data_structures.c,v 1.3 2005/01/01 02:43:59 rockyb Exp $ Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org> + Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,63 +36,38 @@ #include "data_structures.h" #include "util.h" -static const char _rcsid[] = "$Id: data_structures.c,v 1.2 2004/04/11 12:20:32 miguelfreitas Exp $"; +static const char _rcsid[] = "$Id: data_structures.c,v 1.3 2005/01/01 02:43:59 rockyb Exp $"; -struct _VcdList +struct _CdioList { unsigned length; - VcdListNode *begin; - VcdListNode *end; + CdioListNode *begin; + CdioListNode *end; }; -struct _VcdListNode +struct _CdioListNode { - VcdList *list; + CdioList *list; - VcdListNode *next; + CdioListNode *next; void *data; }; /* impl */ -VcdList * -_vcd_list_new (void) -{ - VcdList *new_obj = _vcd_malloc (sizeof (VcdList)); - - return new_obj; -} - -void -_vcd_list_free (VcdList *list, int free_data) -{ - while (_vcd_list_length (list)) - _vcd_list_node_free (_vcd_list_begin (list), free_data); - - free (list); -} - -unsigned -_vcd_list_length (const VcdList *list) -{ - vcd_assert (list != NULL); - - return list->length; -} - static bool -_bubble_sort_iteration (VcdList *list, _vcd_list_cmp_func cmp_func) +_bubble_sort_iteration (CdioList *list, _cdio_list_cmp_func cmp_func) { - VcdListNode **pnode; + CdioListNode **pnode; bool changed = false; for (pnode = &(list->begin); (*pnode) != NULL && (*pnode)->next != NULL; pnode = &((*pnode)->next)) { - VcdListNode *node = *pnode; + CdioListNode *node = *pnode; if (cmp_func (node->data, node->next->data) <= 0) continue; /* n <= n->next */ @@ -110,7 +86,7 @@ _bubble_sort_iteration (VcdList *list, _vcd_list_cmp_func cmp_func) return changed; } -void _vcd_list_sort (VcdList *list, _vcd_list_cmp_func cmp_func) +void _vcd_list_sort (CdioList *list, _cdio_list_cmp_func cmp_func) { /* fixme -- this is bubble sort -- worst sorting algo... */ @@ -120,187 +96,27 @@ void _vcd_list_sort (VcdList *list, _vcd_list_cmp_func cmp_func) while (_bubble_sort_iteration (list, cmp_func)); } -void -_vcd_list_prepend (VcdList *list, void *data) -{ - VcdListNode *new_node; - - vcd_assert (list != NULL); - - new_node = _vcd_malloc (sizeof (VcdListNode)); - - new_node->list = list; - new_node->next = list->begin; - new_node->data = data; - - list->begin = new_node; - if (list->length == 0) - list->end = new_node; - - list->length++; -} - -void -_vcd_list_append (VcdList *list, void *data) -{ - vcd_assert (list != NULL); - - if (list->length == 0) - { - _vcd_list_prepend (list, data); - } - else - { - VcdListNode *new_node = _vcd_malloc (sizeof (VcdListNode)); - - new_node->list = list; - new_node->next = NULL; - new_node->data = data; - - list->end->next = new_node; - list->end = new_node; - - list->length++; - } -} - -void -_vcd_list_foreach (VcdList *list, _vcd_list_iterfunc func, void *user_data) -{ - VcdListNode *node; - - vcd_assert (list != NULL); - vcd_assert (func != 0); - - for (node = _vcd_list_begin (list); - node != NULL; - node = _vcd_list_node_next (node)) - func (_vcd_list_node_data (node), user_data); -} - -VcdListNode * -_vcd_list_find (VcdList *list, _vcd_list_iterfunc cmp_func, void *user_data) -{ - VcdListNode *node; - - vcd_assert (list != NULL); - vcd_assert (cmp_func != 0); - - for (node = _vcd_list_begin (list); - node != NULL; - node = _vcd_list_node_next (node)) - if (cmp_func (_vcd_list_node_data (node), user_data)) - break; - - return node; -} - /* node ops */ -VcdListNode * -_vcd_list_at (VcdList *list, int idx) +CdioListNode * +_vcd_list_at (CdioList *list, int idx) { - VcdListNode *node = _vcd_list_begin (list); + CdioListNode *node = _cdio_list_begin (list); if (idx < 0) - return _vcd_list_at (list, _vcd_list_length (list) + idx); + return _vcd_list_at (list, _cdio_list_length (list) + idx); vcd_assert (idx >= 0); while (node && idx) { - node = _vcd_list_node_next (node); + node = _cdio_list_node_next (node); idx--; } return node; } -VcdListNode * -_vcd_list_begin (const VcdList *list) -{ - vcd_assert (list != NULL); - - return list->begin; -} - -VcdListNode * -_vcd_list_end (VcdList *list) -{ - vcd_assert (list != NULL); - - return list->end; -} - -VcdListNode * -_vcd_list_node_next (VcdListNode *node) -{ - if (node) - return node->next; - - return NULL; -} - -void -_vcd_list_node_free (VcdListNode *node, int free_data) -{ - VcdList *list; - VcdListNode *prev_node; - - vcd_assert (node != NULL); - - list = node->list; - - vcd_assert (_vcd_list_length (list) > 0); - - if (free_data) - free (_vcd_list_node_data (node)); - - if (_vcd_list_length (list) == 1) - { - vcd_assert (list->begin == list->end); - - list->end = list->begin = NULL; - list->length = 0; - free (node); - return; - } - - vcd_assert (list->begin != list->end); - - if (list->begin == node) - { - list->begin = node->next; - free (node); - list->length--; - return; - } - - for (prev_node = list->begin; prev_node->next; prev_node = prev_node->next) - if (prev_node->next == node) - break; - - vcd_assert (prev_node->next != NULL); - - if (list->end == node) - list->end = prev_node; - - prev_node->next = node->next; - - list->length--; - - free (node); -} - -void * -_vcd_list_node_data (VcdListNode *node) -{ - if (node) - return node->data; - - return NULL; -} - /* * n-way tree based on list -- somewhat inefficent */ @@ -314,10 +130,10 @@ struct _VcdTreeNode { void *data; - VcdListNode *listnode; + CdioListNode *listnode; VcdTree *tree; VcdTreeNode *parent; - VcdList *children; + CdioList *children; }; VcdTree * @@ -363,8 +179,8 @@ _vcd_tree_node_destroy (VcdTreeNode *node, bool free_data) if (node->children) { - vcd_assert (_vcd_list_length (node->children) == 0); - _vcd_list_free (node->children, true); + vcd_assert (_cdio_list_length (node->children) == 0); + _cdio_list_free (node->children, true); node->children = NULL; } @@ -372,7 +188,7 @@ _vcd_tree_node_destroy (VcdTreeNode *node, bool free_data) free (_vcd_tree_node_set_data (node, NULL)); if (node->parent) - _vcd_list_node_free (node->listnode, true); + _cdio_list_node_free (node->listnode, true); else _vcd_tree_node_set_data (node, NULL); } @@ -407,16 +223,16 @@ _vcd_tree_node_append_child (VcdTreeNode *pnode, void *cdata) vcd_assert (pnode != NULL); if (!pnode->children) - pnode->children = _vcd_list_new (); + pnode->children = _cdio_list_new (); nnode = _vcd_malloc (sizeof (VcdTreeNode)); - _vcd_list_append (pnode->children, nnode); + _cdio_list_append (pnode->children, nnode); nnode->data = cdata; nnode->parent = pnode; nnode->tree = pnode->tree; - nnode->listnode = _vcd_list_end (pnode->children); + nnode->listnode = _cdio_list_end (pnode->children); return nnode; } @@ -429,7 +245,7 @@ _vcd_tree_node_first_child (VcdTreeNode *node) if (!node->children) return NULL; - return _vcd_list_node_data (_vcd_list_begin (node->children)); + return _cdio_list_node_data (_cdio_list_begin (node->children)); } VcdTreeNode * @@ -437,7 +253,7 @@ _vcd_tree_node_next_sibling (VcdTreeNode *node) { vcd_assert (node != NULL); - return _vcd_list_node_data (_vcd_list_node_next (node->listnode)); + return _cdio_list_node_data (_cdio_list_node_next (node->listnode)); } void @@ -446,7 +262,7 @@ _vcd_tree_node_sort_children (VcdTreeNode *node, _vcd_tree_node_cmp_func cmp_fun vcd_assert (node != NULL); if (node->children) - _vcd_list_sort (node->children, (_vcd_list_cmp_func) cmp_func); + _vcd_list_sort (node->children, (_cdio_list_cmp_func) cmp_func); } void @@ -471,31 +287,31 @@ _vcd_tree_node_traverse_bf (VcdTreeNode *node, _vcd_tree_node_traversal_func trav_func, void *user_data) /* breath-first */ { - VcdList *queue; + CdioList *queue; vcd_assert (node != NULL); - queue = _vcd_list_new (); + queue = _cdio_list_new (); - _vcd_list_prepend (queue, node); + _cdio_list_prepend (queue, node); - while (_vcd_list_length (queue)) + while (_cdio_list_length (queue)) { - VcdListNode *lastnode = _vcd_list_end (queue); - VcdTreeNode *treenode = _vcd_list_node_data (lastnode); - VcdTreeNode *childnode; + CdioListNode *lastnode = _cdio_list_end (queue); + VcdTreeNode *treenode = _cdio_list_node_data (lastnode); + VcdTreeNode *childnode; - _vcd_list_node_free (lastnode, false); + _cdio_list_node_free (lastnode, false); trav_func (treenode, user_data); _VCD_CHILD_FOREACH (childnode, treenode) { - _vcd_list_prepend (queue, childnode); + _cdio_list_prepend (queue, childnode); } } - _vcd_list_free (queue, false); + _cdio_list_free (queue, false); } VcdTreeNode *_vcd_tree_node_parent (VcdTreeNode *node) |
