This commit is contained in:
2025-06-08 14:38:22 -05:00
parent 8411c2981b
commit 0b6b33721b
69 changed files with 210 additions and 3384 deletions

View File

@@ -1,10 +0,0 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
error.c
)

View File

@@ -1,56 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "error.h"
errorstack_t ERROR_STACK;
errorret_t error(const char_t *message, ...) {
return errorCode(1, message);
}
errorret_t errorCode(const errorret_t code, const char_t *message, ...) {
if(ERROR_STACK.code != ERROR_OK) {
snprintf(
ERROR_STACK.message,
ERROR_STACK_SIZE,
"Multiple errors encountered."
);
errorPrint();
return code;
}
va_list args;
va_start(args, message);
vsnprintf(ERROR_STACK.message, ERROR_STACK_SIZE, message, args);
va_end(args);
return ERROR_STACK.code = code;
}
bool_t errorCheck() {
return ERROR_STACK.code != ERROR_OK;
}
const char_t * errorString() {
if(!errorCheck()) return NULL;
return ERROR_STACK.message;
}
void errorFlush() {
if(!errorCheck()) return;
ERROR_STACK.code = ERROR_OK;
ERROR_STACK.message[0] = '\0';
}
errorret_t errorPrint() {
if(!errorCheck()) return ERROR_OK;
printf("Error: %s\n", errorString());
errorret_t code = ERROR_STACK.code;
errorFlush();
return code;
}

View File

@@ -1,60 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
typedef int32_t errorret_t;
#define ERROR_OK 0
#define ERROR_STACK_SIZE 256
typedef struct {
char_t message[ERROR_STACK_SIZE + 1];
errorret_t code;
} errorstack_t;
extern errorstack_t ERROR_STACK;
/**
* Pushes an error message to the error stack.
*
* @param message Message to push to the error stack.
* @param ... Arguments to format the message with.
*/
errorret_t error(const char_t *message, ...);
/**
* Pushes an error message to the error stack with a given error code.
*
* @param code Error code to push to the error stack.
* @param message Message to push to the error stack.
* @param ... Arguments to format the message with.
*/
errorret_t errorCode(const errorret_t code, const char_t *message, ...);
/**
* Checks if an error has been pushed to the error stack.
*
* @return True if an error has been pushed to the error stack.
*/
bool_t errorCheck();
/**
* Retrieves the error message from the error stack.
*/
const char_t * errorString();
/**
* Clears the error stack.
*/
void errorFlush();
/**
* Prints the error stack to the console. This also clears the error stack.
*/
errorret_t errorPrint();