This commit is contained in:
2025-04-07 17:57:06 -05:00
parent 7a3d7a5868
commit a779da6c72
98 changed files with 655 additions and 8974 deletions

55
src/error/error.c Normal file
View File

@@ -0,0 +1,55 @@
/**
* 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();
}
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;
}