calisto-20000323/
calisto-20000323/lib/
calisto-20000323/lib/etc/
calisto-20000323/lib/players/
calisto-20000323/lib/text/
calisto-20000323/log/
/*
 Calisto (c) 1998-1999 Peter Howkins, Matthew Howkins, Simon Howkins

 $Id: dllist.h,v 1.1 1999/12/21 20:29:26 peter Exp $

 $Log: dllist.h,v $
 Revision 1.1  1999/12/21 20:29:26  peter
 Initial revision


 */
#ifndef dllist_h
#define dllist_h

#ifndef OFFSETOF
#define OFFSETOF(pstructcast, linkfield) \
  ((char *) &(((pstructcast) 0)->linkfield))
#endif

typedef struct listnode listnode;

struct listnode {
  listnode *prev;
  listnode *next;
};

typedef struct listhead listhead;

struct listhead {
  listnode head;
  listnode tail;
};

#define LIST_INIT(listhead) (                          \
  (listhead).head.next = &(listhead).tail,             \
  (listhead).tail.prev = &(listhead).head,             \
  (listhead).head.prev = (listhead).tail.next = NULL )

/* listnode is a pointer to a listnode */
#define LIST_UNLINK_NODE(listnode) (          \
  (listnode)->next->prev = (listnode)->prev,  \
  (listnode)->prev->next = (listnode)->next )

#define LIST_IS_EMPTY(listhead) ((listhead).head.next = &(listhead).tail)

#define LIST_LINK_NODE_AT_END(listhead,listnode) \
  ((listnode)->next = &(listhead).tail,          \
  (listnode)->prev = (listhead).tail.prev,       \
  (listhead).tail.prev->next = (listnode),       \
  (listhead).tail.prev = (listnode))

#define LIST_NODE_IS_REAL(listnode) ((listnode)->prev && (listnode)->next)

#define LIST_GET_DATA(listnode,pstructcast,linkfield) \
  ((pstructcast) ((char *) listnode - OFFSETOF(pstructcast, linkfield)))


#endif /* dllist_h */