blob: da087139096a66f0f6ca6d2fe7b55409ef44a51e (
plain) (
blame)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/**
* VOTSTACK.C -- (Private) Methods to manage the parser Element stack.
*
* @file votStack.c
* @author Mike Fitzpatrick and Eric Timmermann
* @date 8/03/09
*
* @brief (Private) Methods to manage the parser Element stack.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include "votParseP.h"
/**
* vot_newStack -- Makes a new stack (private method)
*
* @brief Makes a new stack (private method)
* @fn Stack *vot_newStack (void)
*
* @return A pointer to a new Stack.
*/
Stack *
vot_newStack (void)
{
return ( (Stack *) calloc (1, sizeof (Stack)) );
}
/**
* votPop -- Return a Node from the top of the stack (private method)
*
* @brief Return a Node from the top of the stack (private method)
* @fn Element *votPop (Stack *st)
*
* @param st A pointer to a Stack
* @return A pointer to the popped Element.
*/
Element *
votPop (Stack *st)
{
Node *old;
Element *elem;
st->level--;
if (vot_isEmpty (st))
return (NULL);
else {
old = st->head;
st->head = (Node *) old->next;
}
elem = old->element;
free (old);
return (elem);
}
/**
* votPush -- Push a Node to the top of the stack (private method)
*
* @brief Push a Node to the top of the stack (private method)
* @fn votPush (Stack *st, Element *elem)
*
* @param st A pointer to a Stack
* @param elem A pointer to an element to be put on the stack
* @return nothing
*/
void
votPush (Stack *st, Element *elem)
{
Node *new = (Node *) calloc (1, sizeof (Node));
st->level++;
new->element = elem;
if (vot_isEmpty (st)) {
st->head = new;
new->next = NULL;
} else {
new->next = (Node *) st->head;
st->head = new;
}
}
/**
* votPeek -- Peek at Element on top of the Stack (private method)
*
* @brief Peek at Element on top of the Stack (private method)
* @fn Element *votPeek (Stack *st)
*
* @param st A pointer to a Stack
* @return A pointer to the head Element, or NULL if empty
*/
Element *
votPeek (Stack *st)
{
if (!vot_isEmpty (st))
return (st->head->element);
else
return (NULL);
}
/**
* vot_isEmpty -- Checks to see if the stack is empty (private method)
*
* @brief Checks to see if the stack is empty (private method)
* @fn int vot_isEmpty (Stack *st)
*
* @param st A pointer to a Stack
* @return \a 1 if true, \a 0 if false.
*/
int
vot_isEmpty (Stack *st) { return (!st->head); }
/**
* vot_clearStack -- Clear the stack (private method)
*
* @brief Clear the stack (private method)
* @fn vot_clearStack (Stack *st)
*
* @param st A pointer to a Stack
* @return nothing
*/
void
vot_clearStack (Stack *st)
{
while (!vot_isEmpty (st))
votPop (st);
}
/**
* vot_printStack -- Print the name of all the stack elements (private method)
*
* @brief Print the name of all the stack elements (private method)
* @fn vot_printStack (Stack *st)
*
* @param st A pointer to a Stack
* @return nothing
*/
void
vot_printStack (Stack *st)
{
Node *cur;
for (cur=st->head; cur != NULL; cur = cur->next)
printf ("%s\n", vot_elemName (cur->element));
}
|