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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* Ivy, C interface
*
* Copyright (C) 1997-2000
* Centre d'Études de la Navigation Aérienne
*
* Simple lists in C
*
* Authors: François-Régis Colin <fcolin@cena.fr>
*
* $Id$
*
* Please refer to file version.h for the
* copyright notice regarding this software
*/
#ifdef WIN32
#define TYPEOF(p) void*
#else
#if (__GNUC__ >= 2)
#define TYPEOF(p) typeof (p)
#else
#define TYPEOF(p) void *
#endif
#endif
#define IVY_LIST_ITER( list, p, cond ) \
p = list; \
while ( p && (cond) ) p = p->next
#define IVY_LIST_REMOVE( list, p ) \
{ \
TYPEOF(p) toRemove; \
if ( list == p ) \
{ \
list = p->next; \
free(p);\
} \
else \
{\
toRemove = p;\
IVY_LIST_ITER( list, p, ( p->next != toRemove ));\
if ( p )\
{\
/* somme tricky swapping to use a untyped variable */\
TYPEOF(p) suiv; \
TYPEOF(p) prec = p;\
p = toRemove;\
suiv = p->next;\
p = prec;\
p->next = suiv;\
free(toRemove);\
}\
} \
}
#define IVY_LIST_ADD(list, p ) \
if ((p = (TYPEOF(p)) (malloc( sizeof( *p ))))) \
{ \
memset( p, 0 , sizeof( *p ));\
p->next = list; \
list = p; \
}
#define IVY_LIST_ADD_END(list, p ) \
if ((p = (TYPEOF(p)) (malloc( sizeof( *p ))))) \
{ \
TYPEOF(p) list_end; \
memset( p, 0 , sizeof( *p ));\
p->next = 0; \
if ( list ) \
{\
list_end = list; \
while ( list_end && list_end->next ) \
list_end = list_end->next;\
list_end->next = p; \
} \
else list = p; \
}
#define IVY_LIST_EACH( list, p ) \
for ( p = list ; p ; p = p -> next )
#define IVY_LIST_EACH_SAFE( list, p, p_next )\
for ( p = list ; (p_next = p ? p->next: p ),p ; p = p_next )
#define IVY_LIST_EMPTY( list ) \
{ \
TYPEOF(list) p; \
while( list ) \
{ \
p = list;\
list = list->next; \
free(p);\
} \
}
|