#include "stack.h" #include "structs.h" #include "error.h" #include "curses.h" /* Required by error.h */ #include "stdio.h" /* Required by error.h */ PositionStack ps_new(void) { PositionStack ps; ps.top = 0; return ps; } int ps_push(PositionStack *ps, Position pos) { if (ps->top >= STACK_SIZE) return -1; /* FIXME: do a dynamic stack */ ps->arr[ps->top] = pos; ps->top += 1; return 0; } Position ps_pop(PositionStack *ps) { if (ps->top == 0) error("Stack underflow\n"); ps->top -= 1; return ps->arr[ps->top]; } Position ps_peek(PositionStack ps) { if (ps.top == 0) error("Stack underflow\n"); return ps.arr[ps.top - 1]; }