2
* dlist.h - macros for handling doubly linked lists
4
* Copyright © 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
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, or (at your option)
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.
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 Foundation,
18
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#ifndef ADNS_DLIST_H_INCLUDED
22
#define ADNS_DLIST_H_INCLUDED
24
#define LIST_INIT(list) ((list).head = (list).tail = NULL)
25
#define LINK_INIT(link) ((link).next = (link).back = NULL)
27
#define LIST_UNLINK_PART(list, node, part) \
29
if ((node)->part back) \
30
(node)->part back->part next = (node)->part next; \
32
(list).head = (node)->part next; \
33
if ((node)->part next) \
34
(node)->part next->part back = (node)->part back; \
36
(list).tail = (node)->part back; \
39
#define LIST_LINK_TAIL_PART(list, node, part) \
41
(node)->part next = NULL; \
42
(node)->part back = (list).tail; \
44
(list).tail->part next = (node); \
45
else (list).head = (node); \
46
(list).tail = (node); \
50
#define LIST_CHECKNODE_PART(list, node, part) \
53
assert((node)->part next->part back == (node)); \
55
assert((node) == (list).tail); \
57
assert((node)->part back->part next == (node)); \
59
assert((node) == (list).head); \
62
#define LIST_UNLINK(list, node) LIST_UNLINK_PART(list, node,)
63
#define LIST_LINK_TAIL(list, node) LIST_LINK_TAIL_PART(list, node,)
64
#define LIST_CHECKNODE(list, node) LIST_CHECKNODE_PART(list, node,)