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