]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/zwgc/stack.h
ec722c81658117f69caae25e594d2effe68b86d3
[1ts-debian.git] / zephyr / zwgc / stack.h
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It is one of the source files comprising zwgc, the Zephyr WindowGram
3  * client.
4  *
5  *      Created by:     Marc Horowitz <marc@athena.mit.edu>
6  *
7  *      $Id$
8  *
9  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
10  *      For copying and distribution information, see the file
11  *      "mit-copyright.h".
12  */
13
14
15 #include <zephyr/mit-copyright.h>
16
17 /****************************************************************************/
18 /*                                                                          */
19 /*               A generic stack type based on linked lists:                */
20 /*                                                                          */
21 /****************************************************************************/
22
23 #ifndef TYPE_T_stack_TYPE
24 #define TYPE_T_stack_TYPE
25
26 #ifndef  NULL
27 #define  NULL 0
28 #endif
29
30 typedef struct _TYPE_T_stack {
31     struct _TYPE_T_stack *next;
32     TYPE_T data;
33 } *TYPE_T_stack;
34
35 #define  TYPE_T_stack_create()           ((struct _TYPE_T_stack *) NULL)
36
37 #define  TYPE_T_stack_empty(stack)       (!(stack))
38
39 #ifdef DEBUG
40 #define  TYPE_T_stack_top(stack)         ((stack) ? (stack)->data :\
41                                           (abort(),(stack)->data))
42 #else
43 #define  TYPE_T_stack_top(stack)         ((stack)->data)
44 #endif
45
46 #ifdef DEBUG
47 #define  TYPE_T_stack_pop(stack)  { TYPE_T_stack old = (stack);\
48                                     if (!old)\
49                                       abort(); /*<<<>>>*/\
50                                     (stack) = old->next;\
51                                     free(old); }
52 #else
53 #define  TYPE_T_stack_pop(stack)  { TYPE_T_stack old = (stack);\
54                                     (stack) = old->next;\
55                                     free(old); }
56 #endif
57
58 #define  TYPE_T_stack_push(stack,object) \
59            { TYPE_T_stack new = (struct _TYPE_T_stack *)\
60                malloc(sizeof (struct _TYPE_T_stack));\
61              new->next = (stack);\
62              new->data = object;\
63              (stack) = new; }
64
65 #endif