/* This file is part of the Project Athena Zephyr Notification System.
 * It is one of the source files comprising zwgc, the Zephyr WindowGram
 * client.
 *
 *      Created by:     Marc Horowitz <marc@athena.mit.edu>
 *
 *      $Source: /afs/athena.mit.edu/astaff/project/zephyr/src/zwgc/RCS/stack.h,v $
 *      $Author: jtkohl $
 *	$Id: stack.h,v 1.3 89/11/08 14:36:21 jtkohl Exp $
 *
 *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
 *      For copying and distribution information, see the file
 *      "mit-copyright.h".
 */


#include <zephyr/mit-copyright.h>

/****************************************************************************/
/*                                                                          */
/*               A generic stack type based on linked lists:                */
/*                                                                          */
/****************************************************************************/

#ifndef xmode_stack_TYPE
#define xmode_stack_TYPE

#ifndef  NULL
#define  NULL 0
#endif

typedef struct _xmode_stack {
    struct _xmode_stack *next;
    xmode data;
} *xmode_stack;

#define  xmode_stack_create()           ((struct _xmode_stack *) NULL)

#define  xmode_stack_empty(stack)       (!(stack))

#ifdef DEBUG
#define  xmode_stack_top(stack)         ((stack) ? (stack)->data :\
					  (abort(),(stack)->data))
#else
#define  xmode_stack_top(stack)         ((stack)->data)
#endif

#ifdef DEBUG
#define  xmode_stack_pop(stack)  { xmode_stack old = (stack);\
				    if (!old)\
				      abort(); /*<<<>>>*/\
				    (stack) = old->next;\
				    free(old); }
#else
#define  xmode_stack_pop(stack)  { xmode_stack old = (stack);\
				    (stack) = old->next;\
				    free(old); }
#endif

#define  xmode_stack_push(stack,object) \
           { xmode_stack new = (struct _xmode_stack *)\
	       malloc(sizeof (struct _xmode_stack));\
	     new->next = (stack);\
	     new->data = object;\
	     (stack) = new; }

#endif
