/* The routines in this file are copyright (c) 1987 by Helene (Lee) Taran.
 * Permission is granted for use and free distribution as long as the
 * original author's name is included with the code.
 */

/*
 *   This file defines a general purpose doubly-linked circluar list.
 */
#ifndef DLIST_H
#define DLIST_H

#include <stdio.h>

typedef struct dlist {
   void *contents;
   struct dlist *next;
   struct dlist *prev;
} DLIST_ELEMENT, *DLISTPTR;

/* The first element in the list is a dummy record that
 * contains the current length of the list
 */

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

#define FIRST(list) ((list)->next)
#define LAST(list) ((list)->prev)
#define NEXT(element) ((element)->next)
#define PREVIOUS(element) ((element)->prev)
#define LENGTH(list) (*(int *)((list)->contents))
#define ISEMPTY(list) (LENGTH(list) == 0)
#define INSERT_FIRST(element,list) Insert_Before(FIRST(list),element,list)
#define INSERT_LAST(element,list)  Insert_After(LAST(list),element,list)
#define MOVE_FIRST(x,y)  INSERT_FIRST( Remove_Element( FIRST((x)),(x)), (y))
#define MOVE_LAST(x,y)   INSERT_LAST( Remove_Element(  LAST((x)),(x)), (y))
#endif
