Compare commits

...

4 Commits

Author SHA1 Message Date
5f93db596e further cleanup and organization 2026-06-10 09:06:08 -05:00
7350a8cdfc create better file structure 2026-06-10 08:51:45 -05:00
84025f52cc Fix clangd slop 2026-06-10 08:40:09 -05:00
d523097f2e Fix naming and unintended definition 2026-06-10 08:39:58 -05:00
9 changed files with 141 additions and 98 deletions

View File

@@ -1,2 +1,2 @@
CompileFlags:
Add: [-xc]
Add: [-xc, -DL_ARRAY_IMPLEMENTATION]

34
Makefile Normal file
View File

@@ -0,0 +1,34 @@
CC = gcc
SHELL := /bin/bash
INCLUDE := include
CFLAGS = -Wall -Wextra -I$(INCLUDE) -ggdb
BUILD_DIR := build
TEST_BUILD_DIR := $(BUILD_DIR)/test
TEST_BUILD_FILES := $(TEST_BUILD_DIR)/test.o \
$(TEST_BUILD_DIR)/array.o \
INCLUDE_INSTALL_PATH := /usr/local/include/LTypes
all: test
test: $(TEST_BUILD_FILES)
$(CC) $(CFLAGS) -I./test/include -o $(TEST_BUILD_DIR)/test $(TEST_BUILD_FILES)
@echo ""
$(TEST_BUILD_DIR)/test
$(TEST_BUILD_DIR)/%.o: test/%.c | $(TEST_BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(TEST_BUILD_DIR):
mkdir -p $(TEST_BUILD_DIR)
$(INCLUDE_INSTALL_PATH):
mkdir -p $(INCLUDE_INSTALL_PATH)
install: $(INCLUDE_INSTALL_PATH)
cp $(INCLUDE)/* $(INCLUDE_INSTALL_PATH)
clean:
rm -rf $(BUILD_DIR)

56
array.h
View File

@@ -1,56 +0,0 @@
#ifndef LTYPES_ARRAY_H
#define LTYPES_ARRAY_H
#define L_ARRAY_IMPLEMENTATION // for development to fix clangd
#define L_TYPES_AUTHOR "Lucielle <luci@git.lunarware.tech"
#define L_TYPES_REPO "https://git.lunarware.tech/lucielle/ltypes.git"
#define L_TYPES_VERSION "0.1.0"
#define L_TYPES_LICENSE "GNU GPL v3"
#include <stddef.h>
typedef struct {
size_t count;
size_t capacity;
void** items;
} l_array;
l_array* l_array_create();
void l_array_delete(l_array* array);
int l_array_append(l_array* array, void* item);
void l_array_clear(l_array* array);
#ifdef L_ARRAY_IMPLEMENTATION
#include <stdlib.h>
l_array* l_array_create() {
return (l_array*) calloc(1, sizeof(l_array));
}
void l_array_delete(l_array* array) {
free(array);
}
int l_array_append(l_array* array, void* item) {
if (array->count >= array->capacity) {
if (array->capacity == 0) array->capacity = 8;
else array->capacity *= 2;
array->items = realloc(array->items, array->capacity * sizeof(*array->items));
}
array->items[array->count++] = item;
return 0;
}
void l_array_clear(l_array* array) {
free(array->items);
array->items = NULL;
array->capacity = 0;
array->count = 0;
}
#endif
#endif

1
include/README.md Normal file
View File

@@ -0,0 +1 @@
To use any single header file, either include `version.h` or remove the include from the top.

51
include/array.h Normal file
View File

@@ -0,0 +1,51 @@
#ifndef LTYPES_ARRAY_H
#define LTYPES_ARRAY_H
#include "version.h"
#include <stddef.h>
typedef struct {
size_t count;
size_t capacity;
void** items;
} LArray;
LArray* l_array_create();
void l_array_delete(LArray* array);
int l_array_append(LArray* array, void* item);
void l_array_clear(LArray* array);
#ifdef L_ARRAY_IMPLEMENTATION
#include <stdlib.h>
LArray* l_array_create() {
return (LArray*) calloc(1, sizeof(LArray));
}
void l_array_delete(LArray* array) {
free(array);
}
int l_array_append(LArray* array, void* item) {
if (array->count >= array->capacity) {
if (array->capacity == 0) array->capacity = 8;
else array->capacity *= 2;
array->items = realloc(array->items, array->capacity * sizeof(*array->items));
}
array->items[array->count++] = item;
return 0;
}
void l_array_clear(LArray* array) {
free(array->items);
array->items = NULL;
array->capacity = 0;
array->count = 0;
}
#endif
#endif

9
include/version.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef LTYPES_VERSION_H
#define LTYPES_VERSION_H
#define L_TYPES_AUTHOR "Lucielle <luci@git.lunarware.tech"
#define L_TYPES_REPO "https://git.lunarware.tech/lucielle/ltypes.git"
#define L_TYPES_VERSION "0.1.0"
#define L_TYPES_LICENSE "GNU GPL v3"
#endif

41
test.c
View File

@@ -1,41 +0,0 @@
#include <stdio.h>
#define L_ARRAY_IMPLEMENTATION
#include "array.h"
#include "assert.h"
#define TEST_FUNCTION
static int test_l_array() {
int RETURN_CODE = 0;
l_array* array = l_array_create();
int number_1 = 5;
int number_2 = 15;
l_array_append(array, &number_2);
l_array_append(array, &number_1);
assert(*(int*)array->items[0] == 15);
assert(*(int*)array->items[1] == 5);
assert(array->count == 2);
assert(array->capacity == 8);
l_array_clear(array);
assert(array->items == NULL);
return RETURN_CODE;
}
int main(void) {
printf("AUTHOR: %s\n", L_TYPES_AUTHOR);
printf("REPO: %s\n", L_TYPES_REPO);
printf("VERSION: %s\n", L_TYPES_VERSION);
printf("LICENSE: %s\n\n", L_TYPES_LICENSE);
if (
test_l_array()
) return 1;
return 0;
}

27
test/array.c Normal file
View File

@@ -0,0 +1,27 @@
#define L_ARRAY_IMPLEMENTATION
#include "../include/array.h"
#include <stdio.h>
int test_l_array() {
int RETURN_CODE = 0;
printf("test_l_array() : ");
LArray* array = l_array_create();
int number_1 = 5;
int number_2 = 15;
l_array_append(array, &number_2);
l_array_append(array, &number_1);
if (*(int*)array->items[0] != 15) RETURN_CODE++;
if (*(int*)array->items[1] != 5) RETURN_CODE++;
if (array->count != 2) RETURN_CODE++;
if (array->capacity != 8) RETURN_CODE++;
l_array_clear(array);
if (array->items != NULL) RETURN_CODE++;
printf("%d\n", RETURN_CODE);
return RETURN_CODE;
}

18
test/test.c Normal file
View File

@@ -0,0 +1,18 @@
#include <stdio.h>
#include "../include/version.h"
int test_l_array();
int main(void) {
printf("AUTHOR: %s\n", L_TYPES_AUTHOR);
printf("REPO: %s\n", L_TYPES_REPO);
printf("VERSION: %s\n", L_TYPES_VERSION);
printf("LICENSE: %s\n\n", L_TYPES_LICENSE);
int RETURN_CODE = 0;
RETURN_CODE += test_l_array();
printf("\nError Total: %d\n", RETURN_CODE);
return RETURN_CODE;
}