1998-04-22 20:58:34 +08:00
|
|
|
/*
|
|
|
|
* BIRD Library -- Linked Lists
|
|
|
|
*
|
|
|
|
* (c) 1998 Martin Mares <mj@ucw.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BIRD_LISTS_H_
|
|
|
|
#define _BIRD_LISTS_H_
|
|
|
|
|
|
|
|
typedef struct node {
|
|
|
|
struct node *next, *prev;
|
|
|
|
} node;
|
|
|
|
|
|
|
|
typedef struct list { /* In fact two overlayed nodes */
|
|
|
|
struct node *head, *null, *tail;
|
|
|
|
} list;
|
|
|
|
|
|
|
|
#define NODE (node *)
|
|
|
|
#define HEAD(list) ((void *)((list).head))
|
|
|
|
#define TAIL(list) ((void *)((list).tail))
|
1998-07-10 03:35:23 +08:00
|
|
|
#define WALK_LIST(n,list) for((NODE (n))=HEAD(list);(NODE (n))->next; \
|
1998-04-22 20:58:34 +08:00
|
|
|
n=(void *)((NODE (n))->next))
|
1998-07-10 03:35:23 +08:00
|
|
|
#define WALK_LIST_DELSAFE(n,ne,list) \
|
|
|
|
if ( ((NODE n) = HEAD(list)) ) \
|
|
|
|
for( (NODE ne) = (NODE n)->next; \
|
|
|
|
ne; \
|
|
|
|
(NODE ne) = (NODE (n=ne))->next )
|
|
|
|
|
1998-04-22 20:58:34 +08:00
|
|
|
#define EMPTY_LIST(list) (!(list).head->next)
|
|
|
|
|
|
|
|
void add_tail(list *, node *);
|
|
|
|
void add_head(list *, node *);
|
|
|
|
void rem_node(node *);
|
|
|
|
void add_tail_list(list *, list *);
|
|
|
|
void init_list(list *);
|
|
|
|
void insert_node(node *, node *);
|
|
|
|
|
|
|
|
#ifndef _BIRD_LISTS_C_
|
|
|
|
#define LIST_INLINE extern inline
|
1998-05-04 00:43:39 +08:00
|
|
|
#include "lib/lists.c"
|
1998-04-22 20:58:34 +08:00
|
|
|
#undef LIST_INLINE
|
|
|
|
#else
|
|
|
|
#define LIST_INLINE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|