| 1 |
michael |
5351 |
/* |
| 2 |
|
|
* Copyright (c) 2002-2003 Erik Fears |
| 3 |
michael |
8750 |
* Copyright (c) 2014-2019 ircd-hybrid development team |
| 4 |
michael |
5052 |
* |
| 5 |
michael |
5351 |
* 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 |
michael |
5052 |
* |
| 10 |
michael |
5351 |
* 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 |
michael |
5052 |
* |
| 15 |
michael |
5351 |
* 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 |
michael |
5052 |
*/ |
| 20 |
|
|
|
| 21 |
michael |
8192 |
/*! \file list.h |
| 22 |
|
|
* \brief A header for the list manipulation routines. |
| 23 |
|
|
* \version $Id$ |
| 24 |
|
|
*/ |
| 25 |
|
|
|
| 26 |
michael |
5351 |
#ifndef LIST_H |
| 27 |
|
|
#define LIST_H |
| 28 |
|
|
|
| 29 |
michael |
5052 |
#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 |
michael |
6175 |
#define LIST_SIZE(list) (list)->elements |
| 33 |
michael |
5052 |
|
| 34 |
|
|
typedef struct _node node_t; |
| 35 |
|
|
typedef struct _list list_t; |
| 36 |
|
|
|
| 37 |
|
|
struct _list |
| 38 |
|
|
{ |
| 39 |
michael |
5704 |
struct _node *head; |
| 40 |
|
|
struct _node *tail; |
| 41 |
michael |
7020 |
unsigned int elements; |
| 42 |
michael |
5052 |
}; |
| 43 |
|
|
|
| 44 |
|
|
struct _node |
| 45 |
|
|
{ |
| 46 |
michael |
5704 |
struct _node *next; |
| 47 |
|
|
struct _node *prev; |
| 48 |
|
|
void *data; |
| 49 |
michael |
5052 |
}; |
| 50 |
|
|
|
| 51 |
michael |
8582 |
extern node_t *node_create(void); |
| 52 |
|
|
extern void node_free(node_t *); |
| 53 |
michael |
5052 |
|
| 54 |
michael |
8582 |
extern node_t *list_add(void *, node_t *, list_t *); |
| 55 |
|
|
extern node_t *list_remove(node_t *, list_t *); |
| 56 |
michael |
5052 |
#endif /* LIST_H */ |