#include #include "strstack.h" static char * buf = 0; static size_t buf_size = 0; static char * top = 0; void strstack_use_buffer(char * mem, size_t mem_size) { buf = mem; buf_size = mem_size; } void strstack_clear() { top = buf; } int strstack_push(const char * s) { size_t len = strlen(s) + 1; if (buf + buf_size - top >= len) { strcpy(top, s); top += len; return 1; } else return 0; } const char * strstack_pop() { if (top == buf) return 0; --top; while (top != buf && *(top - 1) != 0) --top; return top; }