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
|
/*
* Ivy, C interface
*
* Copyright (C) 1997-2008
* Centre d'Études de la Navigation Aérienne
*
* Simple lists in C
*
* Authors: François-Régis Colin <fcolin@cena.dgac.fr>
*
* $Id$
*
* Please refer to file version.h for the
* copyright notice regarding this software
*/
#if (__GNUC__ >= 3)
#define TYPEOF(p) typeof (p)
#else
#define TYPEOF(p) void *
#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);\
}\
} \
}
/*
on place le code d'initialisation de l'objet entre START et END
pour eviter de chainer un objet non initialise
*/
/* printf ("sizeof (*"#p") = %d\n", sizeof( *p )); \ */ \
#define IVY_LIST_ADD_START(list, p ) \
if ((p = (TYPEOF(p)) (malloc( sizeof( *p ))))) \
{ \
memset( p, 0 , sizeof( *p ));
#define IVY_LIST_ADD_END(list, p ) \
p->next = list; \
list = p; \
} \
else \
{ \
perror( "IVY LIST ADD malloc" ); \
exit(0); \
}
#define IVY_LIST_EACH( list, p ) \
for ( p = list ; p ; p = p -> next )
/* le pointeur next est sauvegarder dans nxt avant l'iteration */
#define IVY_LIST_EACH_SAFE( list, p, nxt )\
for ( p = list ; (nxt = p ? p->next: p ),p ; p = nxt )
#define IVY_LIST_IS_EMPTY( list ) \
list == NULL
#define IVY_LIST_EMPTY( list ) \
{ \
TYPEOF(list) p; \
while( list ) \
{ \
p = list;\
list = list->next; \
free(p);\
} \
}
|