/* Functions for a stack which remain constant across variations in 
   implementation */

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#include "stack.h"

struct string_stack * 
initialize (void)
{
  struct string_stack * stack = malloc (sizeof(struct string_stack));

  if (stack==NULL) {
    perror("Unable to allocate stack");
    return NULL;
  }
  stack->topPosition = -1;
  return stack;
} // initialize


size_t
size (const struct string_stack * stack)
{
  return stack->topPosition+1;
} // size


bool
isEmpty (const struct string_stack * stack)
{
  return (stack->topPosition == -1);
} // isEmpty


bool
isFull (const struct string_stack* stack)
{
  return (stack->topPosition == (MAX_STACK_SIZE-1));
} // isFull


void
print (const struct string_stack * stack)
{
  printf ("contents of stack from top to bottom:\n");
  for (int i = stack->topPosition; i >= 0; i--)
    printf ("    %s\n", stack->items[i]);
  printf ("end of stack\n");
} // print
