ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/list.c
Revision: 5081
Committed: Mon Dec 22 19:16:10 2014 UTC (9 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 2203 byte(s)
Log Message:
- Removed rcs tags

File Contents

# Content
1 /*
2 * Copyright (C) 2002-2003 Erik Fears
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to
16 *
17 * The Free Software Foundation, Inc.
18 * 59 Temple Place - Suite 330
19 * Boston, MA 02111-1307, USA.
20 *
21 *
22 */
23
24 #include "malloc.h"
25 #include "list.h"
26 #include "defs.h"
27
28
29 node_t *node_create(void *data)
30 {
31 node_t *node = MyMalloc(sizeof *node);
32 node->next = NULL;
33 node->prev = NULL;
34 node->data = (void *) data;
35
36 return node;
37 }
38
39 list_t *list_create()
40 {
41 list_t *list = MyMalloc(sizeof *list);
42
43 list->head = NULL;
44 list->tail = NULL;
45
46 list->elements = 0;
47
48 return list;
49 }
50
51 node_t *list_add(list_t *list, node_t *node)
52 {
53
54 if(list == NULL || node == NULL)
55 return NULL;
56
57 if(list->tail == NULL)
58 {
59 list->head = node;
60 list->tail = node;
61
62 node->next = NULL;
63 node->prev = NULL;
64 }
65 else
66 {
67 node->prev = list->tail;
68 list->tail->next = node;
69 list->tail = node;
70 node->next = NULL;
71 }
72
73 list->elements++;
74 return node;
75 }
76
77 node_t *list_remove(list_t *list, node_t *node)
78 {
79 if(list == NULL || node == NULL)
80 return NULL;
81
82 if(node == list->head)
83 {
84 list->head = node->next;
85
86 if(node->next)
87 node->next->prev = NULL;
88 else
89 list->tail = NULL;
90 }
91 else if(node == list->tail)
92 {
93 list->tail = list->tail->prev;
94 list->tail->next = NULL;
95 }
96 else
97 {
98 node->prev->next = node->next;
99 node->next->prev = node->prev;
100 }
101
102 list->elements--;
103 return node;
104 }
105
106 void list_free(list_t *list)
107 {
108 MyFree(list);
109 }
110
111 void node_free(node_t *node)
112 {
113 MyFree(node);
114 }