ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/libopm/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: 2342 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 "setup.h"
25
26 #include "opm_common.h"
27 #include "list.h"
28 #include "malloc.h"
29 #include "opm.h"
30
31
32 OPM_NODE_T *libopm_node_create(void *data)
33 {
34 OPM_NODE_T *node = MyMalloc(sizeof *node);
35 node->next = NULL;
36 node->prev = NULL;
37 node->data = (void *) data;
38
39 return node;
40 }
41
42 OPM_LIST_T *libopm_list_create()
43 {
44 OPM_LIST_T *list = MyMalloc(sizeof *list);
45
46 list->head = NULL;
47 list->tail = NULL;
48
49 list->elements = 0;
50
51 return list;
52 }
53
54 OPM_NODE_T *libopm_list_add(OPM_LIST_T *list, OPM_NODE_T *node)
55 {
56
57 if(list == NULL || node == NULL)
58 return NULL;
59
60 if(list->tail == NULL)
61 {
62 list->head = node;
63 list->tail = node;
64
65 node->next = NULL;
66 node->prev = NULL;
67 }
68 else
69 {
70 node->prev = list->tail;
71 list->tail->next = node;
72 list->tail = node;
73 node->next = NULL;
74 }
75
76 list->elements++;
77 return node;
78 }
79
80 OPM_NODE_T *libopm_list_remove(OPM_LIST_T *list, OPM_NODE_T *node)
81 {
82
83 if(list == NULL || node == NULL)
84 return NULL;
85
86 if(node == list->head)
87 {
88 list->head = node->next;
89
90 if(node->next)
91 node->next->prev = NULL;
92 else
93 list->tail = NULL;
94 }
95 else if(node == list->tail)
96 {
97 list->tail = list->tail->prev;
98 list->tail->next = NULL;
99 }
100 else
101 {
102 node->prev->next = node->next;
103 node->next->prev = node->prev;
104 }
105
106 list->elements--;
107 return node;
108 }
109
110 void libopm_list_free(OPM_LIST_T *list)
111 {
112 MyFree(list);
113 }
114
115 void libopm_node_free(OPM_NODE_T *node)
116 {
117 MyFree(node);
118 }