Lines Matching refs:stack

24  * pointer stack routines
27 static const char id_stack[] = "\n@(#)$Id: stack (AT&T Bell Laboratories) 1984-05-01 $\0\n";
30 #include <stack.h>
33 * create a new stack
39 register STACK stack;
43 if (!(stack = newof(0, struct stacktable, 1, 0))) return(0);
46 free(stack);
49 if (!(b->stack = newof(0, void*, size, 0)))
52 free(stack);
55 stack->blocks = b;
56 stack->size = size;
57 stack->error = error;
58 stack->position.block = b;
59 stack->position.index = -1;
62 return(stack);
66 * remove a stack
70 stackfree(register STACK stack)
75 b = stack->blocks;
79 free(p->stack);
82 free(stack);
86 * clear stack
90 stackclear(register STACK stack)
92 stack->position.block = stack->blocks;
93 stack->position.index = -1;
97 * get value on top of stack
101 stackget(register STACK stack)
103 if (stack->position.index < 0) return(stack->error);
104 else return(stack->position.block->stack[stack->position.index]);
108 * push value on to stack
112 stackpush(register STACK stack, void* value)
116 if (++stack->position.index >= stack->size)
118 b = stack->position.block;
125 if (!(b->stack = newof(0, void*, stack->size, 0)))
127 b->prev = stack->position.block;
130 stack->position.block = b;
131 stack->position.index = 0;
133 stack->position.block->stack[stack->position.index] = value;
138 * pop value off stack
142 stackpop(register STACK stack)
147 * -1 if stack empty before pop
148 * 0 if stack empty after pop
149 * 1 if stack not empty before & after pop
152 if (stack->position.index < 0) return(-1);
153 else if (--stack->position.index < 0)
155 if (!stack->position.block->prev) return(0);
156 stack->position.block = stack->position.block->prev;
157 stack->position.index = stack->size - 1;
164 * set|get stack position
168 stacktell(register STACK stack, int set, STACKPOS* position)
170 if (set) stack->position = *position;
171 else *position = stack->position;