1 |
michael |
5052 |
#ifndef LIST_H |
2 |
|
|
#define LIST_H |
3 |
|
|
|
4 |
|
|
|
5 |
|
|
/* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
|
|
* The following macros are adapted from Hybrid7 DLINK macros |
7 |
|
|
* |
8 |
|
|
* This program is free software; you can redistribute it and/or |
9 |
|
|
* modify it under the terms of the GNU General Public License |
10 |
|
|
* as published by the Free Software Foundation; either version 2 |
11 |
|
|
* of the License, or (at your option) any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU General Public License |
19 |
|
|
* along with this program; if not, write to |
20 |
|
|
* |
21 |
|
|
* The Free Software Foundation, Inc. |
22 |
|
|
* 59 Temple Place - Suite 330 |
23 |
|
|
* Boston, MA 02111-1307, USA. |
24 |
|
|
* |
25 |
|
|
*/ |
26 |
|
|
|
27 |
|
|
#define LIST_FOREACH(pos, head) for (pos = (head); pos != NULL; pos = pos->next) |
28 |
|
|
#define LIST_FOREACH_SAFE(pos, n, head) for (pos = (head), n = pos ? pos->next : NULL; pos != NULL; pos = n, n = pos ? pos->next : NULL) |
29 |
|
|
#define LIST_FOREACH_PREV(pos, head) for (pos = (head); pos != NULL; pos = pos->prev) |
30 |
|
|
#define LIST_SIZE(list) list->elements |
31 |
|
|
/* End Copyright/Hybrid Macros */ |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
typedef struct _node node_t; |
35 |
|
|
typedef struct _list list_t; |
36 |
|
|
|
37 |
|
|
struct _list |
38 |
|
|
{ |
39 |
|
|
|
40 |
|
|
struct _node *head; |
41 |
|
|
struct _node *tail; |
42 |
|
|
|
43 |
|
|
int elements; |
44 |
|
|
}; |
45 |
|
|
|
46 |
|
|
struct _node |
47 |
|
|
{ |
48 |
|
|
|
49 |
|
|
struct _node *next; |
50 |
|
|
struct _node *prev; |
51 |
|
|
|
52 |
|
|
void *data; |
53 |
|
|
}; |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
node_t *node_create(void *); |
58 |
|
|
list_t *list_create(void); |
59 |
|
|
|
60 |
|
|
node_t *list_add(list_t *, node_t *); |
61 |
|
|
node_t *list_remove(list_t *, node_t *); |
62 |
|
|
|
63 |
|
|
void list_free(list_t *); |
64 |
|
|
void node_free(node_t *); |
65 |
|
|
|
66 |
|
|
#endif /* LIST_H */ |