1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 2000-2021 ircd-hybrid development team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file list.h |
23 |
* \brief A header for the list manipulation routines. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#ifndef INCLUDED_list_h |
28 |
#define INCLUDED_list_h |
29 |
|
30 |
/* These macros are basically swiped from the linux kernel |
31 |
* they are simple yet effective |
32 |
*/ |
33 |
|
34 |
/* |
35 |
* Walks forward of a list. |
36 |
* pos is your node |
37 |
* head is your list head |
38 |
*/ |
39 |
#define DLINK_FOREACH(pos, head) for (pos = (head); pos != NULL; pos = pos->next) |
40 |
|
41 |
/* |
42 |
* Walks forward of a list safely while removing nodes |
43 |
* pos is your node |
44 |
* n is another list head for temporary storage |
45 |
* head is your list head |
46 |
*/ |
47 |
#define DLINK_FOREACH_SAFE(pos, n, head) for (pos = (head), n = pos ? pos->next : NULL; pos != NULL; pos = n, n = pos ? pos->next : NULL) |
48 |
#define DLINK_FOREACH_PREV(pos, head) for (pos = (head); pos != NULL; pos = pos->prev) |
49 |
|
50 |
/* Returns the list length */ |
51 |
#define dlink_list_length(list) (list)->length |
52 |
|
53 |
/* |
54 |
* double-linked-list stuff |
55 |
*/ |
56 |
typedef struct _dlink_node dlink_node; |
57 |
typedef struct _dlink_list dlink_list; |
58 |
|
59 |
struct _dlink_node |
60 |
{ |
61 |
void *data; |
62 |
dlink_node *prev; |
63 |
dlink_node *next; |
64 |
}; |
65 |
|
66 |
struct _dlink_list |
67 |
{ |
68 |
dlink_node *head; |
69 |
dlink_node *tail; |
70 |
unsigned int length; |
71 |
}; |
72 |
|
73 |
extern void free_dlink_node(dlink_node *); |
74 |
extern void dlinkAdd(void *, dlink_node *, dlink_list *); |
75 |
extern void dlinkAddBefore(dlink_node *, void *, dlink_node *, dlink_list *); |
76 |
extern void dlinkAddTail(void *, dlink_node *, dlink_list *); |
77 |
extern void dlinkDelete(dlink_node *, dlink_list *); |
78 |
extern void dlinkMoveList(dlink_list *, dlink_list *); |
79 |
extern void dlink_move_node(dlink_node *, dlink_list *, dlink_list *); |
80 |
extern dlink_node *dlinkFind(dlink_list *, const void *); |
81 |
extern dlink_node *dlinkFindDelete(dlink_list *, void *); |
82 |
extern dlink_node *make_dlink_node(void); |
83 |
#endif |