# if	!defined(_LLIST_H)
# include	"../foxlib/chkalloc.h"
# define	_LLIST_H
# define	DEBUG

/**********************************************************************/
/*   Following  macro  used  to  allow  compilation  with ANSI C and  */
/*   non-ANSI C compilers automatically.			      */
/**********************************************************************/
# if !defined(PROTO)
# 	if	defined(__STDC__)
#		define	PROTO(x)	x
#	else
#		define	PROTO(x)	()
#	endif
# endif

typedef	struct llist	{
	struct	llist	*ll_next;
	struct	llist	*ll_prev;
	char		*ll_elem;
	short		ll_magic;
	} 
		List, 
		Head;

typedef	List	*List_p;
typedef	Head	*Head_p;

# define	LL_HEAD		0x4c48
# define	LL_LIST		0x4c4c

# define LL_MAGIC(lp)	{if (lp == 0 || lp->ll_magic != LL_LIST) ll_magic(lp);}
# define LL_HMAGIC(hp)	{if (hp == 0 || hp->ll_magic != LL_HEAD) ll_hmagic(hp);}
#ifndef	NULL
# define	NULL	0
#endif

/**********************************************************************/
/*   Following  macro  used  to  allow  compilation  with ANSI C and  */
/*   non-ANSI C compilers automatically.			      */
/**********************************************************************/
# if !defined(PROTO)
#	if	defined(__STDC__)
#		define	PROTO(x)	x
#	else
#		define	PROTO(x)	()
#	endif
# endif

# define	LIST_INCR(x)	__list_stats.x++
# define	LIST_DECR(x)	__list_stats.x--
extern struct list_stats {
	unsigned long	hd_alloced;	/* Head_p structures currently allocated. */
	unsigned long	lp_alloced;	/* List_p structures currently allocated. */
	unsigned long	ll_alloc;	/* Number of calls to ll_alloc.		*/
	unsigned long	ll_append;
	unsigned long	ll_clear;
	unsigned long	ll_delete;
	unsigned long	ll_elem;
	unsigned long	ll_first;
	unsigned long	ll_free;
	unsigned long	ll_hook;
	unsigned long	ll_init;
	unsigned long	ll_insert;
	unsigned long	ll_lookup;
	unsigned long	ll_next;
	unsigned long	ll_pop;
	unsigned long	ll_prev;
	unsigned long	ll_push;
	unsigned long	ll_remove;
	unsigned long	ll_unhook;
	} __list_stats;

struct llist	*ll_alloc PROTO((void));
struct llist	*ll_append PROTO((Head_p, char *));
void 		ll_clear PROTO((Head_p));
void 		ll_delete PROTO((List_p));
char  		*ll_elem PROTO((List_p));
struct llist	*ll_first PROTO((Head_p));
void 		ll_free PROTO((Head_p));
struct llist	*ll_hook PROTO((Head_p, List_p));
struct llist	*ll_init PROTO((void));
struct llist	*ll_insert PROTO((Head_p, char *, int));
struct llist	*ll_lookup PROTO((Head_p, char *, int (*)()));
void		ll_hmagic PROTO((Head_p));
void		ll_magic PROTO((List_p));
struct llist	*ll_next PROTO((List_p));
struct llist	*ll_prev PROTO((List_p));
char		*ll_push PROTO((Head_p, char *));
struct llist	*ll_pop PROTO((Head_p));
void		ll_remove PROTO((List_p));
struct llist	*ll_unhook PROTO((List_p));
# endif
