-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdlist.h
60 lines (52 loc) · 2.01 KB
/
dlist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* IOMPLX
* Copyright © 2012 Felipe Astroza
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DLIST_H
#define DLIST_H
typedef struct _dlist_node {
struct _dlist_node *next, *prev;
} dlist_node;
typedef struct {
dlist_node *head, *tail;
} dlist;
static inline int __copy_dlist_node(dlist_node *dst, dlist_node *src)
{
*dst = *src;
return 1;
}
#ifndef NULL
#define NULL ((void *)0)
#endif
#define DLIST_INIT(list) ((dlist *)list)->head = NULL; ((dlist *)list)->tail = NULL
#define DLIST_APPEND(list, node) dlist_append((dlist *)(list), (dlist_node *)(node))
#define DLIST_DEL(list, node) dlist_del((dlist *)(list), (dlist_node *)(node))
#define DLIST_TAIL(list) ((void *)((dlist *)list)->tail)
#define DLIST_ISEMPTY(list) (((dlist *)list)->head == NULL)
#define DLIST_NODE_INIT(a)
#define DLIST(name) dlist name##_list
#define DLIST_NODE(name) dlist_node name##_node
#define AS ,
#define RCOPY_ID(line) node_copy_ ## line
#define COPY_ID(line) RCOPY_ID(line)
#define _FOREACH(node_copy, list, node) for(node = (void *)((dlist *)list)->head; \
node != NULL && __copy_dlist_node(&node_copy, (dlist_node *)node); \
node = (void *)node_copy.next)
#define DLIST_FOREACH(exp) dlist_node COPY_ID(__LINE__); _FOREACH(COPY_ID(__LINE__), exp)
void dlist_append(dlist *, dlist_node *);
void dlist_del(dlist *, dlist_node *);
#endif