--- /dev/null
+AUTOMAKE_OPTIONS = gnu
+
+ACLOCAL_AMFLAGS = -I m4
+
+SUBDIRS = \
+ src
+
+EXTRA_DIST = \
+ autogen.sh \
+ AUTHORS \
+ ChangeLog \
+ NEWS \
+ README
+
--- /dev/null
+#!/bin/sh
+
+if [ ! -e m4 ]; then
+ mkdir m4
+fi
+
+if [ ! -e auxdir ]; then
+ mkdir auxdir
+fi
+
+aclocal -I m4 \
+ && libtoolize --force --copy \
+ && autoheader \
+ && automake --add-missing --gnu --copy \
+ && autoconf \
+ && ./configure --enable-maintainer-mode $@
--- /dev/null
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.72])
+AC_INIT([C library],[0.1.0],[mir@datanom.net])
+AC_COPYRIGHT([Copyright (c) 2024 Michael Rasmussen.])
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_AUX_DIR(auxdir)
+AC_CANONICAL_TARGET
+
+AC_CONFIG_SRCDIR([src/stack.c])
+AM_INIT_AUTOMAKE([gnu no-dist-gzip dist-bzip2 1.10])
+AM_MAINTAINER_MODE
+
+CFLAGS="-Wall"
+
+if test "x$USE_MAINTAINER_MODE" = "xyes"; then
+ CFLAGS="${CFLAGS} -g -DDEBUG"
+ AC_DEFINE_UNQUOTED(DEBUG, [1], [Enable debug mode.])
+else
+ CFLAGS="${CFLAGS} -O -O2"
+fi
+
+GLIB_REQUIRED=2.50.0
+
+AC_SUBST(GLIB_REQUIRED)
+
+AC_CONFIG_HEADERS(config.h)
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_INSTALL
+AC_PROG_LN_S
+AC_PROG_MAKE_SET
+LT_INIT
+
+if test -n "$lt_prog_compiler_pic"; then
+ CFLAGS="$CFLAGS $lt_prog_compiler_pic"
+fi
+
+AC_SYS_LARGEFILE
+
+PKG_PROG_PKG_CONFIG
+AC_LIB_PREFIX
+
+# Checks for libraries.
+PKG_CHECK_MODULES([GLIB],
+ [glib-2.0 >= $GLIB_REQUIRED
+ gobject-2.0 >= $GOBJECT_REQUIRED
+ gmodule-2.0]
+)
+AC_SUBST(GLIB_CFLAGS)
+AC_SUBST(GLIB_LIBS)
+
+# Checks for header files.
+AC_CHECK_HEADER([assert.h],
+ AC_DEFINE([HAVE_ASSERT_H], [1], [Define to 1 if you have the <assert.h> header file.]))
+
+# Checks for typedefs, structures, and compiler characteristics.
+
+# Checks for library functions.
+
+AC_CONFIG_FILES([
+ Makefile
+ src/Makefile
+])
+
+AC_OUTPUT
+echo ""
+echo "$PACKAGE $VERSION"
+echo "
+Configuration:
+
+ Source code: ${ac_pwd}
+ Compiler: ${CC} $($CC -dumpversion)
+ CFLAGS: ${CFLAGS}
+"
+echo ""
+echo "The binary will be installed in $prefix/bin"
+echo ""
+echo "Configure finished, type 'make' to build."
+
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include "queue.h"
+#include "stack.h"
+
+int main() {
+/*
+ Stack* stack = stack_init();
+ if (stack_empty(stack))
+ printf("Stack is empty\n");
+
+ int* i = malloc(sizeof(int*));
+ *i = 10;
+ stack_push(stack, i);
+ int* j = malloc(sizeof(int*));
+ *j = 5;
+ stack_push(stack, j);
+ int* val = stack_pop(stack);
+ printf("Stack back: %i\n", *val);
+ free(val);
+ void** elems = stack_clear(&stack);
+ for (int i = 0; elems[i]; i++)
+ free(elems[i]);
+ free(elems);
+*/
+ return 0;
+}
+
--- /dev/null
+AUTOMAKE_OPTIONS = gnu
+
+AM_CPPFLAGS = \
+ -I${top_srcdir} \
+ -I${top_builddir} \
+ @GLIB_CFLAGS@
+
+noinst_LIBRARIES = libclib.a
+
+libclib_a_SOURCES = \
+ queue.c \
+ queue.h \
+ stack.c \
+ stack.h
+
+libclib_a_LIBADD = \
+ $(LIBOBJS) \
+ $(ALLOCA) \
+ @LIBS@
+
--- /dev/null
+#include <stdlib.h>
+#include "queue.h"
+
+typedef struct _Queue {
+ void** elems;
+ int size;
+ QueueFreeFunc free;
+} Queue;
+
+static void free_elem(Queue* queue) {
+ if (queue->free) {
+ for (int i = 0; i < queue->size; i++)
+ queue->free(queue->elems[i]);
+ }
+ free(queue->elems);
+}
+
+Queue* queue_new() {
+ Queue* q = malloc(sizeof(Queue));
+ q->size = 0;
+ q->elems = NULL;
+ q->free = NULL;
+ return q;
+}
+
+Queue* queue_new_full(QueueFreeFunc free){
+ Queue* q = malloc(sizeof(Queue));
+ q->size = 0;
+ q->elems = NULL;
+ q->free = free;
+ return q;
+}
+
+void queue_destroy(Queue* queue) {
+ free_elem(queue);
+ free(queue);
+}
+
+/*
+static void extend(Queue* queue, void* elem) {
+ while (int i = queue->size - 1; i > 0; i--) {
+ queue->elems[i] = queue->elems[i - 1]
+ }
+ queue->elems[0] elem;
+}
+*/
+void* queue_dequeue(Queue* queue) {
+ if (queue_empty(queue))
+ return NULL;
+ queue->size -= 1;
+ void* elem = queue->elems[queue->size];
+ queue->elems[queue->size] = NULL;
+ queue->elems = realloc(queue->elems, queue->size * sizeof(void*));
+
+ return elem;
+}
+
+void queue_enqueue(Queue* queue, void* elem) {
+ if (queue == NULL)
+ return;
+
+ queue->size += 1;
+ queue->elems = realloc(queue->elems, queue->size * sizeof(void*));
+ for (int i = queue->size - 1; i > 0; i--) {
+ queue->elems[i] = queue->elems[i - 1];
+ }
+ queue->elems[0] = elem;
+}
+
+void* queue_front(Queue* queue) {
+ if (queue_empty(queue))
+ return NULL;
+ return queue->elems[0];
+}
+
+void* queue_back(Queue* queue) {
+ if (queue_empty(queue))
+ return NULL;
+ return queue->elems[queue->size - 1];
+}
+
+bool queue_empty(Queue* queue) {
+ return (queue == NULL || queue->size == 0);
+}
+
+void queue_clear(Queue* queue) {
+ if (queue == NULL)
+ return;
+
+ free_elem(queue);
+ queue->size = 0;
+ queue->elems = NULL;
+}
+
+int queue_size(Queue* queue) {
+ if (queue_empty(queue))
+ return 0;
+ return queue->size;
+}
--- /dev/null
+
+#ifndef _QUEUE_H_
+#define _QUEUE_H_
+
+#include <stdbool.h>
+
+typedef struct _Queue Queue;
+typedef void (*QueueFreeFunc)(void*);
+
+Queue* queue_new();
+Queue* queue_new_full(QueueFreeFunc free);
+void queue_destroy(Queue*);
+void* queue_dequeue(Queue*);
+void queue_enqueue(Queue*, void*);
+void* queue_front(Queue*);
+void* queue_back(Queue*);
+void queue_clear(Queue*);
+bool queue_empty(Queue*);
+int queue_size(Queue*);
+
+#endif
--- /dev/null
+#include <stdlib.h>
+#include "stack.h"
+
+#define INIT_SIZE 100
+
+struct _Stack {
+ int size;
+ void** elems;
+ StackFreeFunc free;
+};
+
+static void free_elem(Stack* stack) {
+ if (stack->free) {
+ for (int i = 0; i < stack->size; i++)
+ stack->free(stack->elems[i]);
+ }
+ free(stack->elems);
+}
+
+static Stack* stack_new_common() {
+ Stack* s = malloc(sizeof(Stack));
+ s->elems = malloc(sizeof(void*) * INIT_SIZE);
+ s->size = 0;
+ s->free = NULL;
+ return s;
+}
+
+Stack* stack_new() {
+ return stack_new_common();
+}
+
+Stack* stack_new_full(StackFreeFunc free) {
+ Stack* s = stack_new_common();
+ s->free = free;
+ return s;
+}
+
+void stack_destroy(Stack* stack) {
+ free_elem(stack);
+ free(stack);
+}
+
+void* stack_pop(Stack* stack) {
+ if (stack_empty(stack))
+ return NULL;
+ stack->size -= 1;
+ void* elem = stack->elems[stack->size];
+ stack->elems[stack->size] = NULL;
+
+ return elem;
+}
+
+void stack_push(Stack* stack, void* elem) {
+ if (stack == NULL)
+ return;
+
+ stack->size += 1;
+ if (stack->size == INIT_SIZE) {
+ stack->elems = realloc(stack->elems, (INIT_SIZE + stack->size) * sizeof(void*));
+ }
+
+ stack->elems[stack->size - 1] = elem;
+}
+
+void* stack_peek(Stack* stack) {
+ if (stack_empty(stack))
+ return NULL;
+ return stack->elems[stack->size - 1];
+}
+
+bool stack_empty(Stack* stack) {
+ return (stack == NULL || stack->size == 0);
+}
+
+void stack_clear(Stack* stack) {
+ if (stack == NULL)
+ return;
+
+ free_elem(stack);
+ stack->size = 0;
+}
+
+int stack_size(Stack* stack) {
+ if (stack_empty(stack))
+ return 0;
+ return stack->size;
+}
+
+/*
+typedef struct _Stack {
+ void** elems;
+ int size;
+ StackFreeFunc free;
+} Stack;
+
+static void free_elem(Stack* stack) {
+ if (stack->free) {
+ for (int i = 0; i < stack->size; i++)
+ stack->free(stack->elems[i]);
+ }
+ free(stack->elems);
+}
+
+Stack* stack_new() {
+ Stack* s = malloc(sizeof(Stack));
+ s->size = 0;
+ s->elems = NULL;
+ s->free = NULL;
+ return s;
+}
+
+Stack* stack_new_full(StackFreeFunc free) {
+ Stack* s = malloc(sizeof(Stack));
+ s->size = 0;
+ s->elems = NULL;
+ s->free = free;
+ return s;
+}
+
+void stack_destroy(Stack* stack) {
+ free_elem(stack);
+ free(stack);
+}
+
+void* stack_pop(Stack* stack) {
+ if (stack_empty(stack))
+ return NULL;
+ stack->size -= 1;
+ void* elem = stack->elems[stack->size];
+ stack->elems[stack->size] = NULL;
+ stack->elems = realloc(stack->elems, stack->size * sizeof(void*));
+
+ return elem;
+}
+
+void stack_push(Stack* stack, void* elem) {
+ if (stack == NULL)
+ return;
+
+ stack->size += 1;
+ stack->elems = realloc(stack->elems, stack->size * sizeof(void*));
+ stack->elems[stack->size - 1] = elem;
+}
+
+void* stack_peek(Stack* stack) {
+ if (stack_empty(stack))
+ return NULL;
+ return stack->elems[stack->size - 1];
+}
+
+bool stack_empty(Stack* stack) {
+ return (stack == NULL || stack->size == 0);
+}
+
+void stack_clear(Stack* stack) {
+ if (stack == NULL)
+ return;
+
+ free_elem(stack);
+ stack->size = 0;
+ stack->elems = NULL;
+}
+
+int stack_size(Stack* stack) {
+ if (stack_empty(stack))
+ return 0;
+ return stack->size;
+}
+*/
--- /dev/null
+#ifndef _STACK_H_
+#define _STACK_H_
+
+#include <stdbool.h>
+
+typedef struct _Stack Stack;
+typedef void (*StackFreeFunc)(void*);
+
+Stack* stack_new();
+Stack* stack_new_full(StackFreeFunc free);
+void stack_destroy(Stack*);
+void* stack_pop(Stack*);
+void stack_push(Stack*, void*);
+void* stack_peek(Stack*);
+bool stack_empty(Stack*);
+void stack_clear(Stack*);
+int stack_size(Stack*);
+
+#endif