Pay attention to the timeout value passed down by the upper layer. This
[dragonfly.git] / contrib / cvs-1.12 / src / stack.c
blob7b26ec36cdf1ef42fab1dfe9568ea17b6602f772
1 /*
2 * Copyright (C) 2004-2005 The Free Software Foundation, Inc.
4 * Portions Copyright (C) 2004-2005 Derek Price, Ximbiot <http://ximbiot.com>,
5 * and others.
6 *
7 * You may distribute under the terms of the GNU General Public License as
8 * specified in the README file that comes with the CVS source distribution.
10 * This module uses the hash.c module to implement a stack.
13 #include "cvs.h"
14 #include <assert.h>
18 static void
19 do_push (List *stack, void *elem, int isstring)
21 Node *p = getnode();
23 if (isstring)
24 p->key = elem;
25 else
26 p->data = elem;
28 addnode(stack, p);
33 void
34 push (List *stack, void *elem)
36 do_push (stack, elem, 0);
41 void
42 push_string (List *stack, char *elem)
44 do_push (stack, elem, 1);
49 static void *
50 do_pop (List *stack, int isstring)
52 void *elem;
54 if (isempty (stack)) return NULL;
56 if (isstring)
58 elem = stack->list->prev->key;
59 stack->list->prev->key = NULL;
61 else
63 elem = stack->list->prev->data;
64 stack->list->prev->data = NULL;
67 delnode (stack->list->prev);
68 return elem;
73 void *
74 pop (List *stack)
76 return do_pop (stack, 0);
81 char *
82 pop_string (List *stack)
84 return do_pop (stack, 1);
89 static void
90 do_unshift (List *stack, void *elem, int isstring)
92 Node *p = getnode();
94 if (isstring)
95 p->key = elem;
96 else
97 p->data = elem;
99 addnode_at_front(stack, p);
104 void
105 unshift (List *stack, void *elem)
107 do_unshift (stack, elem, 0);
112 void
113 unshift_string (List *stack, char *elem)
115 do_unshift (stack, elem, 1);
120 static void *
121 do_shift (List *stack, int isstring)
123 void *elem;
125 if (isempty (stack)) return NULL;
127 if (isstring)
129 elem = stack->list->next->key;
130 stack->list->next->key = NULL;
132 else
134 elem = stack->list->next->data;
135 stack->list->next->data = NULL;
137 delnode (stack->list->next);
138 return elem;
143 void *
144 shift (List *stack)
146 return do_shift (stack, 0);
151 char *
152 shift_string (List *stack)
154 return do_shift (stack, 1);
160 isempty (List *stack)
162 if (stack->list == stack->list->next)
163 return 1;
164 return 0;