1 |
/* |
2 |
* Copyright (c) 2002-2003 Erik Fears |
3 |
* Copyright (c) 2014-2019 ircd-hybrid development team |
4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
7 |
* the Free Software Foundation; either version 2 of the License, or |
8 |
* (at your option) any later version. |
9 |
* |
10 |
* This program is distributed in the hope that it will be useful, |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
* GNU General Public License for more details. |
14 |
* |
15 |
* You should have received a copy of the GNU General Public License |
16 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
18 |
* USA |
19 |
*/ |
20 |
|
21 |
/*! \file list.h |
22 |
* \brief A header for the list manipulation routines. |
23 |
* \version $Id$ |
24 |
*/ |
25 |
|
26 |
#ifndef LIST_H |
27 |
#define LIST_H |
28 |
|
29 |
#define LIST_FOREACH(pos, head) for (pos = (head); pos != NULL; pos = pos->next) |
30 |
#define LIST_FOREACH_SAFE(pos, n, head) for (pos = (head), n = pos ? pos->next : NULL; pos != NULL; pos = n, n = pos ? pos->next : NULL) |
31 |
#define LIST_FOREACH_PREV(pos, head) for (pos = (head); pos != NULL; pos = pos->prev) |
32 |
#define LIST_SIZE(list) (list)->elements |
33 |
|
34 |
typedef struct _node node_t; |
35 |
typedef struct _list list_t; |
36 |
|
37 |
struct _list |
38 |
{ |
39 |
struct _node *head; |
40 |
struct _node *tail; |
41 |
unsigned int elements; |
42 |
}; |
43 |
|
44 |
struct _node |
45 |
{ |
46 |
struct _node *next; |
47 |
struct _node *prev; |
48 |
void *data; |
49 |
}; |
50 |
|
51 |
extern node_t *node_create(void); |
52 |
extern void node_free(node_t *); |
53 |
|
54 |
extern node_t *list_add(void *, node_t *, list_t *); |
55 |
extern node_t *list_remove(node_t *, list_t *); |
56 |
#endif /* LIST_H */ |