00001
00002 static char const cvsid[] = "$Id: dltree_8c-source.html,v 1.10 2001/10/10 20:40:59 sandro Exp $";
00003
00004 #include <stdlib.h>
00005 #include "dltree.h"
00006
00007 void *dltree_alloc(size_t bytes) {
00008 return calloc(bytes, 4);
00009 }
00010
00011 void dltree_free(void *node) {
00012 free(node);
00013 }
00014
00015
00016
00017
00018
00019
00020
00021 #define child ((DLTreeNode *) v_child)
00022 #define parent ((DLTreeNode *) v_parent)
00023 void *dltree_append_child(void *v_parent, void *v_child) {
00024 child->next = 0;
00025 child->prev = parent->last;
00026 parent->last = child;
00027 if (parent->first) {
00028 child->prev->next = child;
00029 } else {
00030 parent->first = child;
00031 }
00032 return v_parent;
00033 }
00034
00035 void *dltree_unlink_last_child(void *v_parent) {
00036 void *v_child = parent->last;
00037 if (child) {
00038 if (parent->last == parent->first) {
00039 parent->last = 0;
00040 parent->first = 0;
00041 } else {
00042 parent->last = child->prev;
00043 parent->last->next = 0;
00044 }
00045 child->prev = 0;
00046 child->next = 0;
00047 }
00048 return v_child;
00049 }
00050
00051 #undef child
00052 #undef parent