/* implement simple, breakable stack for storing simple generic data, 
** such as strings or XmStrings, essentially queueing them for later freeing
*/

#include <stdio.h>
#include "Stack.h"
#include "memory.h"

#if NeedFunctionPrototypes
Stack *InitStack(void)
#else
Stack *InitStack()
#endif
{
    return (Stack *) XtCalloc(1,sizeof(Stack)); /* implicit init to 0 */
}

#if NeedFunctionPrototypes
void FreeStack (Stack *stack)
#else
void FreeStack (stack)
Stack *stack;
#endif
{
    XtFree((char*)stack->data);
    XtFree((char*)stack);
}

#if NeedFunctionPrototypes
XtArgVal PushStack (Stack *stack, XtArgVal value)
#else
XtArgVal PushStack (stack, value)
Stack *stack;
XtArgVal value;
#endif
{
    if (stack->top == stack->allocated) {
	stack->allocated += 8;
	stack->data = (XtArgVal *)
	    XtRealloc((char *)stack->data,
		      sizeof(XtArgVal) * stack->allocated);
    }
    stack->data[stack->top] = value;
    stack->top++;
    
    return value;
}



