diff options
author | ihm | 1998-03-05 17:31:32 +0000 |
---|---|---|
committer | ihm | 1998-03-05 17:31:32 +0000 |
commit | dc706ef662bda4a843aa088696132078472400d5 (patch) | |
tree | 0d877ea0200e0603f48c65fa2cf9cb6a4854edb0 /list.h | |
parent | 23abb4b87c7e40ed259dd02f653516f60e55ade4 (diff) | |
download | ivy-c-dc706ef662bda4a843aa088696132078472400d5.zip ivy-c-dc706ef662bda4a843aa088696132078472400d5.tar.gz ivy-c-dc706ef662bda4a843aa088696132078472400d5.tar.bz2 ivy-c-dc706ef662bda4a843aa088696132078472400d5.tar.xz |
Initial revision
Diffstat (limited to 'list.h')
-rw-r--r-- | list.h | 55 |
1 files changed, 55 insertions, 0 deletions
@@ -0,0 +1,55 @@ +#define LIST_ITER( list, p, cond ) \ + p = list; \ + while ( p && (cond) ) p = p->next + +#define LIST_REMOVE( list, p ) \ + { \ + void *toRemove; \ + if ( list == p ) \ + { \ + list = p->next; \ + free(p);\ + } \ + else \ + {\ + toRemove = p;\ + LIST_ITER( list, p, ( p->next != toRemove ));\ + if ( p )\ + {\ + /* somme tricky swapping to use a untyped variable */\ + void *suiv; \ + void *prec = p;\ + p = toRemove;\ + suiv = p->next;\ + p = prec;\ + p->next = suiv;\ + free(toRemove);\ + }\ + } \ + } + +#define LIST_ADD(list, p ) \ + if ((p = malloc( sizeof( *p ))))\ + { \ + memset( p, 0 , sizeof( *p ));\ + p->next = list; \ + list = p; \ + } + +#define LIST_EACH( list, p ) \ + for ( p = list ; p ; p = p -> next ) + +#define LIST_EACH_SAFE( list, p, next )\ +for ( p = list ; (next = p ? p->next: p ),p ; p = next ) + + +#define LIST_EMPTY( list ) \ + { \ + void *p; \ + while( list ) \ + { \ + p = list;\ + list = list->next; \ + free(p);\ + } \ + } |