2 * Copyright (c) 2004, Free Software Foundation,
4 * & Ximbiot <http://ximbiot.com>.
6 * You may distribute under the terms of the GNU General Public License as
7 * specified in the README file that comes with the CVS source distribution.
9 * This module uses the hash.c module to implement a stack.
18 do_push (List *stack, void *elem, int isstring)
33 push (List *stack, void *elem)
35 do_push (stack, elem, 0);
41 push_string (List *stack, char *elem)
43 do_push (stack, elem, 1);
49 do_pop (List *stack, int isstring)
53 if (isempty (stack)) return NULL;
57 elem = stack->list->prev->key;
58 stack->list->prev->key = NULL;
62 elem = stack->list->prev->data;
63 stack->list->prev->data = NULL;
66 delnode (stack->list->prev);
75 return do_pop (stack, 0);
81 pop_string (List *stack)
83 return do_pop (stack, 1);
89 do_unshift (List *stack, void *elem, int isstring)
98 addnode_at_front(stack, p);
104 unshift (List *stack, void *elem)
106 do_unshift (stack, elem, 0);
112 unshift_string (List *stack, char *elem)
114 do_unshift (stack, elem, 1);
120 do_shift (List *stack, int isstring)
124 if (isempty (stack)) return NULL;
128 elem = stack->list->next->key;
129 stack->list->next->key = NULL;
133 elem = stack->list->next->data;
134 stack->list->next->data = NULL;
136 delnode (stack->list->next);
145 return do_shift (stack, 0);
151 shift_string (List *stack)
153 return do_shift (stack, 1);
159 isempty (List *stack)
161 if (stack->list == stack->list->next)