Merge /u/jrubio/cdesktopenv/ branch delete-incomplete into master
[oweals/cde.git] / cde / programs / dthelp / parser.ccdf / volumegen / Pstack.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: Pstack.c /main/4 1995/11/08 11:47:39 rswiston $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  *
27  * File:         PStack.c
28  *
29  * Project:      Cache Creek (Rivers) Project
30  * Description:  Utility functions for volumegen program
31  * Author:       Brian Cripe
32  *               Modifications by (Mike Wilson)
33  * Language:     C
34  *
35  * (C) Copyright 1992, Hewlett-Packard, all rights reserved.
36  *
37  ****************************************************************************
38  ************************************<+>*************************************/
39
40
41 #include <stdio.h>
42 #include "PstackI.h"
43
44 #define REALLOC_INCR  10
45
46
47
48
49 \f
50 /*****************************************************************************
51  * Function:        PStack PStackCreate();
52  *
53  * Parameters:      NONE.
54  *
55  * Return Value:    PStack.
56  *
57  * Purpose:         Generates a PStack structure and returns it to the 
58  *                  caller.
59  *
60  *****************************************************************************/
61 PStack PStackCreate()
62 {
63     PStack stack;
64     stack = (PStack) malloc (sizeof (struct PStackRec));
65     stack->count = 0;
66     stack->size = REALLOC_INCR;
67     stack->items = (void **) malloc (stack->size * sizeof (void **));
68
69     return (stack);
70 }
71
72
73 \f
74 /*****************************************************************************
75  * Function:        PStack PStackDestroy();
76  *
77  * Parameters:      stack:
78  *
79  * Return Value:    void.
80  *
81  * Purpose:         Destroys a PStack structure.
82  *
83  *****************************************************************************/
84 void PStackDestroy(
85      PStack stack)
86 {
87     free (stack->items);
88     free (stack);
89 }
90
91
92
93
94 \f
95 /*****************************************************************************
96  * Function:        PStack PStackPush();
97  *
98  * Parameters:      stack:
99  *                  ptr:
100  *
101  * Return Value:    void
102  *
103  * Purpose:         Pushes a PStack structure on the current stack.
104  *
105  *****************************************************************************/
106 void PStackPush(
107      PStack stack,
108      void *ptr)
109 {
110     if (stack->count == stack->size) {
111         stack->size += REALLOC_INCR;
112         stack->items = (void **) realloc (stack->items, 
113                                           stack->size * sizeof (void **));
114     }
115
116     *(stack->items + stack->count) = ptr;
117     stack->count++;
118 }
119
120
121 \f
122 /*****************************************************************************
123  * Function:        PStack *PStackPeek();
124  *
125  * Parameters:      stack:
126  *
127  * Return Value:    void.
128  *
129  * Purpose:         Gets a PStack.
130  *
131  *****************************************************************************/
132 void *PStackPeek(
133      PStack stack)
134
135 {
136     if (stack->count == 0)
137         return (NULL);
138
139     else
140         return (*(stack->items + stack->count - 1));
141 }
142
143 \f
144 /*****************************************************************************
145  * Function:        PStack *PStackPop();
146  *
147  * Parameters:      stack:
148  *
149  * Return Value:    void.
150  *
151  * Purpose:         Pops the top element off the stack
152  *
153  *****************************************************************************/
154 void *PStackPop(
155      PStack stack)
156 {
157     if (stack->count == 0)
158         return (NULL);
159
160     else {
161         stack->count--;
162         return (*(stack->items + stack->count));
163     }
164 }
165
166             
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182