summaryrefslogtreecommitdiff
path: root/zwgc/stack.h
blob: ec722c81658117f69caae25e594d2effe68b86d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* 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>
 *
 *      $Id$
 *
 *      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 TYPE_T_stack_TYPE
#define TYPE_T_stack_TYPE

#ifndef  NULL
#define  NULL 0
#endif

typedef struct _TYPE_T_stack {
    struct _TYPE_T_stack *next;
    TYPE_T data;
} *TYPE_T_stack;

#define  TYPE_T_stack_create()           ((struct _TYPE_T_stack *) NULL)

#define  TYPE_T_stack_empty(stack)       (!(stack))

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

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

#define  TYPE_T_stack_push(stack,object) \
           { TYPE_T_stack new = (struct _TYPE_T_stack *)\
	       malloc(sizeof (struct _TYPE_T_stack));\
	     new->next = (stack);\
	     new->data = object;\
	     (stack) = new; }

#endif