fixed after breaking everything with errno.h and vector.h changes, config still borked

This commit is contained in:
herbglitch 2024-08-28 02:57:29 -06:00
parent 2df9f318a5
commit cdd6c3976b
18 changed files with 86 additions and 84 deletions

View file

@ -16,7 +16,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif() endif()
add_compile_options( add_compile_options(
"-Wall" "-Wextra" "-Werror" "-Wpedantic" "-fexceptions" "-Wall" "-Werror" "-fexceptions"
"$<$<CONFIG:DEBUG>:-O0;-g3;-ggdb;-DARC_DEBUG;>" "$<$<CONFIG:DEBUG>:-O0;-g3;-ggdb;-DARC_DEBUG;>"
"$<$<CONFIG:RELEASE>:-02;-g;>" "$<$<CONFIG:RELEASE>:-02;-g;>"
) )

View file

@ -7,6 +7,9 @@ set(ARCHEUS_STD_SDL2_INPUT_SOURCES
packages/input/sdl/input.c packages/input/sdl/input.c
packages/input/sdl/keyboard.c packages/input/sdl/keyboard.c
packages/input/sdl/mouse.c packages/input/sdl/mouse.c
#TODO: remove this
packages/audio/sdl/config.c
) )
set(ARCHEUS_STD_SDL2_GRAPHICS_SOURCES set(ARCHEUS_STD_SDL2_GRAPHICS_SOURCES
@ -45,7 +48,15 @@ function(sdl2_check_and_init_needed _ARCHEUS_STD_SOURCES _ARCHEUS_STD_INCLUDE_DI
endif() endif()
if(${ARCHEUS_STD_INPUT_BACKEND} STREQUAL "SDL2") if(${ARCHEUS_STD_INPUT_BACKEND} STREQUAL "SDL2")
#TODO: remove this
find_package(SDL2_mixer REQUIRED)
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_INPUT_SOURCES}) list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_INPUT_SOURCES})
#TODO: remove this
list(APPEND ${_ARCHEUS_STD_LINK_LIBRARIES}
PUBLIC SDL2_mixer::SDL2_mixer
)
endif() endif()
if(${ARCHEUS_STD_GRAPHICS_BACKEND} STREQUAL "SDL2") if(${ARCHEUS_STD_GRAPHICS_BACKEND} STREQUAL "SDL2")

View file

@ -5,6 +5,7 @@
extern "C" { extern "C" {
#endif #endif
#include "arc/std/bool.h"
#include <stdint.h> #include <stdint.h>
/** /**
@ -22,7 +23,7 @@ typedef struct ARC_Handler ARC_Handler;
* *
* @return 0 when a == b * @return 0 when a == b
*/ */
typedef uint32_t (* ARC_Handler_CompareDataFn)(void *a, void *b); typedef ARC_Bool (* ARC_Handler_CompareDataFn)(void *a, void *b);
/** /**
* @brief a function that will take iterated data * @brief a function that will take iterated data
@ -42,10 +43,11 @@ typedef void (* ARC_Handler_CleanDataFn)(void *data);
* @brief creates ARC_Handler type * @brief creates ARC_Handler type
* *
* @param config ARC_Handler to initialize * @param config ARC_Handler to initialize
* @param cleanfn function to clean data in handler * @param compareFn function to remove handler data
* @param cleanFn function to clean data in handler
* can be null * can be null
*/ */
void ARC_Handler_Create(ARC_Handler **handler, ARC_Handler_CleanDataFn cleanfn); void ARC_Handler_Create(ARC_Handler **handler, ARC_Handler_CompareDataFn *compareFn, ARC_Handler_CleanDataFn cleanFn);
/** /**
* @brief destroyes ARC_Handler type * @brief destroyes ARC_Handler type
@ -72,7 +74,7 @@ void ARC_Handler_Add(ARC_Handler *handler, void *data);
* @param handler ARC_Handler to remove from * @param handler ARC_Handler to remove from
* @param data data that is being removed * @param data data that is being removed
*/ */
void ARC_Handler_Remove(ARC_Handler *handler, void *data, ARC_Handler_CompareDataFn compare); void ARC_Handler_Remove(ARC_Handler *handler, void *data);
/** /**
* @brief remove from handler * @brief remove from handler
@ -115,7 +117,7 @@ void ARC_Handler_Clean(ARC_Handler *handler);
* *
* @param handler ARC_handler to get size from * @param handler ARC_handler to get size from
*/ */
uint32_t ARC_Handler_Size(ARC_Handler *handler); uint32_t ARC_Handler_GetSize(ARC_Handler *handler);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -20,7 +20,7 @@ uint8_t ARC_Audio_Read(ARC_Config *config, ARC_String *string, void **value){
} }
if(string->data[0] != '"' || string->data[string->length - 1] != '"'){ if(string->data[0] != '"' || string->data[string->length - 1] != '"'){
ARC_DEBUG_LOG(arc_errno, "in ARC_Point_Read(config, string, value); no matching quotes: %s", string->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_Point_Read(config, string, value); no matching quotes: %s", string->data);
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
return 0; return 0;
} }

View file

@ -127,7 +127,7 @@ uint8_t ARC_Spritesheet_Read(ARC_Config* config, ARC_String *string, void **valu
ARC_String_StripEndsWhitespace(&textureStr, temp); ARC_String_StripEndsWhitespace(&textureStr, temp);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);
ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 1)); ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 2));
ARC_String_StripEndsWhitespace(&sizeStr, temp); ARC_String_StripEndsWhitespace(&sizeStr, temp);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);

View file

@ -10,7 +10,7 @@
void ARC_Renderer_CreateWithEngineData(ARC_Renderer **renderer, ARC_EngineData *data){ void ARC_Renderer_CreateWithEngineData(ARC_Renderer **renderer, ARC_EngineData *data){
if(!data){ if(!data){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_Renderer_CreateWithEngineData(**renderer, NULL)"); ARC_DEBUG_LOG_ERROR("ARC_Renderer_CreateWithEngineData(**renderer, NULL)");
return; return;
} }
@ -18,7 +18,7 @@ void ARC_Renderer_CreateWithEngineData(ARC_Renderer **renderer, ARC_EngineData *
if(!*renderer){ if(!*renderer){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_LOG(arc_errno, "SDL_CreateRenderer(%p, %d, %u);", data->window, -1, SDL_RENDERER_ACCELERATED); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("SDL_CreateRenderer(%p, %d, %u);", data->window, -1, SDL_RENDERER_ACCELERATED);
free(renderer); free(renderer);
} }

View file

@ -63,7 +63,7 @@ void ARC_Sprite_RenderRotated(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Re
void ARC_Sprite_SetFrameIndex(ARC_Sprite *sprite, uint32_t index){ void ARC_Sprite_SetFrameIndex(ARC_Sprite *sprite, uint32_t index){
if(sprite->frames->size <= index){ if(sprite->frames->size <= index){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG(arc_errno, "in ARC_Sprite_SetFrameIndex(sprite, %d); index out of bounds", index); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_Sprite_SetFrameIndex(sprite, %d); index out of bounds", index);
return; return;
} }
*sprite->frameIndex = index; *sprite->frameIndex = index;

View file

@ -7,7 +7,7 @@
void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){ void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){
if(!info){ if(!info){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_Window_Create(**window, NULL)"); ARC_DEBUG_LOG_ERROR("ARC_Window_Create(**window, NULL)");
return; return;
} }
@ -21,7 +21,7 @@ void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){
if(!*window){ if(!*window){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_LOG(arc_errno, "SDL_CreateWindow(%s, %d, %d, %d, %d, %x);", info->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, info->w, info->h, 0); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("SDL_CreateWindow(%s, %d, %d, %d, %d, %x);", info->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, info->w, info->h, 0);
free(window); free(window);
} }
} }

View file

@ -19,7 +19,8 @@ void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanF
(*data)->keyboard = NULL; (*data)->keyboard = NULL;
(*data)->mouse = NULL; (*data)->mouse = NULL;
ARC_Handler_Create(&((*data)->state), cleanFn); //TODO: set the destroy callback
ARC_Handler_Create(&((*data)->state), NULL, cleanFn);
(*data)->dt = 0.0; (*data)->dt = 0.0;
(*data)->running = ARC_False; (*data)->running = ARC_False;

View file

@ -23,7 +23,7 @@ uint8_t ARC_CSV_Read(ARC_Config *config, ARC_String *string, void **value){
ARC_String *fileData; ARC_String *fileData;
ARC_IO_FileToStr(string, &fileData); ARC_IO_FileToStr(string, &fileData);
if(arc_errno){ if(arc_errno){
ARC_DEBUG_LOG(arc_errno, "ARC_CSV_Read(config, string, value) could not read in csv file: \"%s\"", string->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_CSV_Read(config, string, value) could not read in csv file: \"%s\"", string->data);
ARC_String_Destroy(fileData); ARC_String_Destroy(fileData);
return 0; return 0;
} }
@ -57,7 +57,7 @@ uint8_t ARC_CSV_Read(ARC_Config *config, ARC_String *string, void **value){
if(!width){ if(!width){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG(arc_errno, "ARC_CSV_Read(config, string, value) no width of line %d", y); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_CSV_Read(config, string, value) no width of line %d", y);
ARC_String_Destroy(fileData); ARC_String_Destroy(fileData);
return 0; return 0;
} }

View file

@ -34,7 +34,7 @@ uint8_t ARC_Point_Read(ARC_Config *config, ARC_String *string, void **value){
} }
if(string->data[0] != '{' || string->data[string->length - 1] != '}'){ if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
ARC_DEBUG_LOG(arc_errno, "in ARC_Point_Read(config, string, value); no matching curly braces: %s", string->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_Point_Read(config, string, value); no matching curly braces: %s", string->data);
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
return 0; return 0;
} }
@ -67,7 +67,7 @@ uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){
if(string->data[0] != '{' || string->data[string->length - 1] != '}'){ if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG(arc_errno, "in ARC_Rect_Read(config, string, value); no matching curly braces: %s", string->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_Rect_Read(config, string, value); no matching curly braces: %s", string->data);
return 0; return 0;
} }
@ -168,7 +168,7 @@ void ARC_RectArray_ReadRect(ARC_Config* config, ARC_String *stripped, uint64_t i
//reading in value //reading in value
ARC_Rect_Read(config, substr, (void **) &tempRect); ARC_Rect_Read(config, substr, (void **) &tempRect);
if(arc_errno){ if(arc_errno){
ARC_DEBUG_LOG(arc_errno, "in ARC_RectArray_ReadRect(config, string, index, length, arrayIndex, value); failed to read rect: %s", substr->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_RectArray_ReadRect(config, string, index, length, arrayIndex, value); failed to read rect: %s", substr->data);
ARC_String_Destroy(substr); ARC_String_Destroy(substr);
return; return;
} }
@ -188,7 +188,7 @@ uint8_t ARC_RectArray_Read(ARC_Config* config, ARC_String *string, void **value)
if(string->data[0] != '{' || string->data[string->length - 1] != '}'){ if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG(arc_errno, "in ARC_RectArray_Read(config, string, value); no matching curly braces: %s", string->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_RectArray_Read(config, string, value); no matching curly braces: %s", string->data);
return 0; return 0;
} }

View file

@ -103,9 +103,11 @@ void ARC_Config_SetGroup(ARC_Config *config, ARC_String *groupname){
} }
ARC_Hashtable_Get(config->groups, (void *)groupname->data, groupname->length, (void **)&(config->currgroup)); ARC_Hashtable_Get(config->groups, (void *)groupname->data, groupname->length, (void **)&(config->currgroup));
if(arc_errno && arc_errno != ARC_ERRNO_NULL){ arc_errno = 0;
return;
} // if(arc_errno && arc_errno != ARC_ERRNO_NULL){
// return;
// }
if(config->currgroup){ if(config->currgroup){
return; return;
@ -125,7 +127,7 @@ void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value){
uint64_t length = ARC_String_FindCString(keyname, "::", 2); uint64_t length = ARC_String_FindCString(keyname, "::", 2);
if(arc_errno){ if(arc_errno){
//TODO: Debug info here //TODO: Debug info here
ARC_DEBUG_ERR("in ARC_Config_Get(config, keyname, value); length threw error"); ARC_DEBUG_LOG_ERROR("in ARC_Config_Get(config, keyname, value); length threw error");
*value = NULL; *value = NULL;
return; return;
} }
@ -141,7 +143,7 @@ void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value){
ARC_Hashtable *currgroup = config->currgroup; ARC_Hashtable *currgroup = config->currgroup;
ARC_Config_SetGroup(config, group); ARC_Config_SetGroup(config, group);
if(arc_errno){ if(arc_errno){
ARC_DEBUG_ERR("in ARC_Config_Get(config, keyname, value); setting group threw error"); ARC_DEBUG_LOG_ERROR("in ARC_Config_Get(config, keyname, value); setting group threw error");
ARC_String_Destroy(group); ARC_String_Destroy(group);
*value = NULL; *value = NULL;
return; return;
@ -211,7 +213,7 @@ void ARC_Config_LoadFromKey(ARC_Config *config, ARC_String *keyType, ARC_String
ARC_Hashtable_Get(config->keys, keyType->data, keyType->length, (void **)&key); ARC_Hashtable_Get(config->keys, keyType->data, keyType->length, (void **)&key);
if(key == NULL){ if(key == NULL){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG(arc_errno, "in ARC_Config_LoadFromKey(config, string, value); no matching key: %s", keyType->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_Config_LoadFromKey(config, string, value); no matching key: %s", keyType->data);
} }
if(arc_errno){ if(arc_errno){
@ -406,7 +408,7 @@ void ARC_Config_StripComment(ARC_String *original, ARC_String **stripped, ARC_St
uint64_t endIndex = ARC_String_Find(commentString, lineEnd); uint64_t endIndex = ARC_String_Find(commentString, lineEnd);
ARC_String_Destroy(commentString); ARC_String_Destroy(commentString);
if(endIndex == ~(uint64_t)0){ if(endIndex == ~(uint64_t)0){
ARC_DEBUG_ERR("ARC_Config_RemoveComments(original, commentRemoved); No newline found when stripping single line comment"); ARC_DEBUG_LOG_ERROR("ARC_Config_RemoveComments(original, commentRemoved); No newline found when stripping single line comment");
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_String_Destroy(current); ARC_String_Destroy(current);
*stripped = NULL; *stripped = NULL;
@ -524,22 +526,17 @@ void ARC_Config_RemoveAndRunCommands(ARC_Config *config, ARC_String *original, A
} }
void ARC_Config_FileIO(ARC_Config *config, ARC_String *path, uint8_t command){ void ARC_Config_FileIO(ARC_Config *config, ARC_String *path, uint8_t command){
arc_errno = 0; //TODO: Remove this, just testing
ARC_String *data; ARC_String *data;
ARC_IO_FileToStr(path, &data); ARC_IO_FileToStr(path, &data);
if(arc_errno){ if(arc_errno){
ARC_DEBUG_LOG(arc_errno, "ARC_IO_FileToStr(%s, &data, &size);\n", path->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_IO_FileToStr(%s, &data, &size);\n", path->data);
return; return;
} }
char *tempData = (char *)malloc(sizeof(char) * (data->length + 1)); ARC_String_AppendCStringWithStrlen(&data, "\n");
strncpy(tempData, data->data, data->length);
tempData[data->length] = '\n';
ARC_String *temp = data; ARC_String *temp = data;
ARC_String_Create(&temp, tempData, data->length + 1);
free(tempData);
ARC_String_Destroy(data);
ARC_Config_RemoveComments(temp, &data); ARC_Config_RemoveComments(temp, &data);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);

View file

@ -185,7 +185,7 @@ uint8_t ARC_ConfigKey_Read_String(ARC_Config* config, ARC_String *string, void *
if(string->data[0] != '"' || string->data[string->length - 1] != '"'){ if(string->data[0] != '"' || string->data[string->length - 1] != '"'){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG(arc_errno, "in ARC_ConfigKey_Read_String(config, string, value); no matching quotes: %s", string->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_ConfigKey_Read_String(config, string, value); no matching quotes: %s", string->data);
return 0; return 0;
} }
@ -214,7 +214,7 @@ void ARC_ConfigKey_StringArray_ReadString(ARC_Config* config, ARC_String *stripp
//reading in value //reading in value
ARC_ConfigKey_Read_String(config, substr, (void **) &tempString); ARC_ConfigKey_Read_String(config, substr, (void **) &tempString);
if(arc_errno){ if(arc_errno){
ARC_DEBUG_LOG(arc_errno, "in ARC_RectArray_ReadRect(config, string, index, length, arrayIndex, value); failed to read string: %s", substr->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_RectArray_ReadRect(config, string, index, length, arrayIndex, value); failed to read string: %s", substr->data);
ARC_String_Destroy(substr); ARC_String_Destroy(substr);
return; return;
} }
@ -233,7 +233,7 @@ uint8_t ARC_ConfigKey_Read_StringArray(ARC_Config* config, ARC_String *string, v
if(string->data[0] != '{' || string->data[string->length - 1] != '}'){ if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG(arc_errno, "in ARC_ConfigKey_Read_StringArray(config, string, value); no matching curly braces: %s", string->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_ConfigKey_Read_StringArray(config, string, value); no matching curly braces: %s", string->data);
return 0; return 0;
} }

View file

@ -11,10 +11,10 @@ struct ARC_Handler {
ARC_Handler_CleanDataFn cleanfn; ARC_Handler_CleanDataFn cleanfn;
}; };
void ARC_Handler_Create(ARC_Handler **handler, ARC_Handler_CleanDataFn cleanfn){ void ARC_Handler_Create(ARC_Handler **handler, ARC_Handler_CompareDataFn *compareFn, ARC_Handler_CleanDataFn cleanfn){
*handler = (ARC_Handler *) malloc(sizeof(ARC_Handler)); *handler = (ARC_Handler *) malloc(sizeof(ARC_Handler));
ARC_Vector_Create(&((*handler)->data)); ARC_Vector_Create(&((*handler)->data), NULL);
ARC_Vector_Create(&((*handler)->trash)); ARC_Vector_Create(&((*handler)->trash), compareFn);
(*handler)->cleanfn = cleanfn; (*handler)->cleanfn = cleanfn;
} }
@ -32,13 +32,13 @@ void ARC_Handler_Add(ARC_Handler *handler, void *data){
ARC_Vector_Add(handler->data, data); ARC_Vector_Add(handler->data, data);
} }
void ARC_Handler_Remove(ARC_Handler *handler, void *data, ARC_Handler_CompareDataFn compare){ void ARC_Handler_Remove(ARC_Handler *handler, void *data){
ARC_Vector_Add(handler->trash, data); ARC_Vector_Add(handler->trash, data);
ARC_Vector_Remove(handler->data, data, (ARC_Vector_CompareDataFn) compare); ARC_Vector_Remove(handler->data, data);
} }
void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t index){ void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t index){
if(ARC_Vector_Size(handler->data) == 0){ if(ARC_Vector_GetSize(handler->data) == 0){
return; return;
} }
@ -48,21 +48,21 @@ void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t index){
} }
void ARC_Handler_Iterate(ARC_Handler *handler, ARC_Handler_DataFn datafn){ void ARC_Handler_Iterate(ARC_Handler *handler, ARC_Handler_DataFn datafn){
for(uint32_t i = 0; i < ARC_Vector_Size(handler->data); i++){ for(uint32_t i = 0; i < ARC_Vector_GetSize(handler->data); i++){
datafn(ARC_Vector_Get(handler->data, i)); datafn(ARC_Vector_Get(handler->data, i));
} }
} }
void ARC_Handler_Clear(ARC_Handler *handler){ void ARC_Handler_Clear(ARC_Handler *handler){
uint32_t zeroIndex = 0; uint32_t zeroIndex = 0;
while(ARC_Vector_Size(handler->data)){ while(ARC_Vector_GetSize(handler->data)){
ARC_Handler_RemoveIndex(handler, zeroIndex); ARC_Handler_RemoveIndex(handler, zeroIndex);
} }
} }
void ARC_Handler_Clean(ARC_Handler *handler){ void ARC_Handler_Clean(ARC_Handler *handler){
uint32_t i = 0; uint32_t i = 0;
while(ARC_Vector_Size(handler->trash)){ while(ARC_Vector_GetSize(handler->trash)){
void *data = ARC_Vector_Get(handler->trash, i); void *data = ARC_Vector_Get(handler->trash, i);
if(handler->cleanfn){ if(handler->cleanfn){
@ -73,6 +73,6 @@ void ARC_Handler_Clean(ARC_Handler *handler){
} }
} }
uint32_t ARC_Handler_Size(ARC_Handler *handler){ uint32_t ARC_Handler_GetSize(ARC_Handler *handler){
return ARC_Vector_Size(handler->data); return ARC_Vector_GetSize(handler->data);
} }

View file

@ -9,7 +9,7 @@ void ARC_IO_ReadFileToUint8t(ARC_String *path, uint8_t **data, uint64_t *length)
FILE *file = fopen(path->data, "rb"); FILE *file = fopen(path->data, "rb");
if(!file){ if(!file){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_LOG(arc_errno, "ARC_IO_FileToStr(ARC_String *path, ARC_String **data), could not open file \"%s\"", path->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_IO_FileToStr(ARC_String *path, ARC_String **data), could not open file \"%s\"", path->data);
*length = 0; *length = 0;
*data = NULL; *data = NULL;
return; return;
@ -23,7 +23,7 @@ void ARC_IO_ReadFileToUint8t(ARC_String *path, uint8_t **data, uint64_t *length)
if(*data == NULL){ if(*data == NULL){
fclose(file); fclose(file);
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_IO_FileToStr(ARC_String *path, ARC_String **data), file data is NULL"); ARC_DEBUG_LOG_ERROR("ARC_IO_FileToStr(ARC_String *path, ARC_String **data), file data is NULL");
*length = 0; *length = 0;
return; return;
} }
@ -31,7 +31,7 @@ void ARC_IO_ReadFileToUint8t(ARC_String *path, uint8_t **data, uint64_t *length)
if(1 != fread(*data, *length, 1, file)){ if(1 != fread(*data, *length, 1, file)){
fclose(file); fclose(file);
arc_errno = ARC_ERRNO_COPY; arc_errno = ARC_ERRNO_COPY;
ARC_DEBUG_ERR("ARC_IO_FileToStr(ARC_String *path, ARC_String **data), could not copy file data"); ARC_DEBUG_LOG_ERROR("ARC_IO_FileToStr(ARC_String *path, ARC_String **data), could not copy file data");
*length = 0; *length = 0;
*data = NULL; *data = NULL;
return; return;
@ -44,7 +44,7 @@ void ARC_IO_FileToStr(ARC_String *path, ARC_String **data){
FILE *file = fopen(path->data, "rb"); FILE *file = fopen(path->data, "rb");
if(!file){ if(!file){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_LOG(arc_errno, "ARC_IO_FileToStr(ARC_String *path, ARC_String **data), could not open file \"%s\"", path->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_IO_FileToStr(ARC_String *path, ARC_String **data), could not open file \"%s\"", path->data);
return; return;
} }
@ -56,7 +56,7 @@ void ARC_IO_FileToStr(ARC_String *path, ARC_String **data){
if(fileData == NULL){ if(fileData == NULL){
fclose(file); fclose(file);
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_IO_FileToStr(ARC_String *path, ARC_String **data), file data is NULL"); ARC_DEBUG_LOG_ERROR("ARC_IO_FileToStr(ARC_String *path, ARC_String **data), file data is NULL");
*data = NULL; *data = NULL;
return; return;
} }
@ -64,7 +64,7 @@ void ARC_IO_FileToStr(ARC_String *path, ARC_String **data){
if(1 != fread(fileData, length, 1, file)){ if(1 != fread(fileData, length, 1, file)){
fclose(file); fclose(file);
arc_errno = ARC_ERRNO_COPY; arc_errno = ARC_ERRNO_COPY;
ARC_DEBUG_ERR("ARC_IO_FileToStr(ARC_String *path, ARC_String **data), could not copy file data"); ARC_DEBUG_LOG_ERROR("ARC_IO_FileToStr(ARC_String *path, ARC_String **data), could not copy file data");
*data = NULL; *data = NULL;
return; return;
} }
@ -78,14 +78,14 @@ void ARC_IO_WriteStrToFile(ARC_String *path, ARC_String *data){
FILE *file = fopen(path->data, "wb"); FILE *file = fopen(path->data, "wb");
if(!file){ if(!file){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_LOG(arc_errno, "ARC_IO_WriteStrToFile(ARC_String *path, ARC_String *data), could not open file \"%s\"", path->data); ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_IO_WriteStrToFile(ARC_String *path, ARC_String *data), could not open file \"%s\"", path->data);
return; return;
} }
if(1 != fwrite(data->data, data->length, 1, file)){ if(1 != fwrite(data->data, data->length, 1, file)){
fclose(file); fclose(file);
arc_errno = ARC_ERRNO_COPY; arc_errno = ARC_ERRNO_COPY;
ARC_DEBUG_ERR("ARC_IO_WriteStrToFile(ARC_String *path, ARC_String **data), could not write file data"); ARC_DEBUG_LOG_ERROR("ARC_IO_WriteStrToFile(ARC_String *path, ARC_String **data), could not write file data");
return; return;
} }

View file

@ -24,7 +24,7 @@ void ARC_Queue_Create(ARC_Queue **queue){
void ARC_Queue_Destroy(ARC_Queue *queue){ void ARC_Queue_Destroy(ARC_Queue *queue){
if(queue->currentSize != 0 || queue->node != NULL){ if(queue->currentSize != 0 || queue->node != NULL){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_ERR("ARC_Queue_Destroy(queue) called, but queue was not empty"); ARC_DEBUG_LOG_ERROR("ARC_Queue_Destroy(queue) called, but queue was not empty");
return; return;
} }
@ -34,7 +34,7 @@ void ARC_Queue_Destroy(ARC_Queue *queue){
void ARC_Queue_Push(ARC_Queue *queue, void *data){ void ARC_Queue_Push(ARC_Queue *queue, void *data){
if(queue->currentSize == ~(uint32_t)0){ if(queue->currentSize == ~(uint32_t)0){
arc_errno = ARC_ERRNO_OVERFLOW; arc_errno = ARC_ERRNO_OVERFLOW;
ARC_DEBUG_ERR("ARC_Queue_Push(queue) called, size of queue is maxed, cannot add another node"); ARC_DEBUG_LOG_ERROR("ARC_Queue_Push(queue) called, size of queue is maxed, cannot add another node");
return; return;
} }
@ -53,7 +53,7 @@ void ARC_Queue_Push(ARC_Queue *queue, void *data){
for(uint32_t i = 1; i < queue->currentSize; i++){ for(uint32_t i = 1; i < queue->currentSize; i++){
if(end->next == NULL){ if(end->next == NULL){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_Queue_Push(queue), when getting end node encountered a NULL node"); ARC_DEBUG_LOG_ERROR("ARC_Queue_Push(queue), when getting end node encountered a NULL node");
return; return;
} }
@ -72,14 +72,14 @@ void ARC_Queue_Push(ARC_Queue *queue, void *data){
void *ARC_Queue_Pop(ARC_Queue *queue){ void *ARC_Queue_Pop(ARC_Queue *queue){
if(queue->currentSize == 0){ if(queue->currentSize == 0){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_ERR("ARC_Queue_Pop(queue) called, but queue was empty"); ARC_DEBUG_LOG_ERROR("ARC_Queue_Pop(queue) called, but queue was empty");
return NULL; return NULL;
} }
ARC_QueueNode *node = queue->node; ARC_QueueNode *node = queue->node;
if(node == NULL){ if(node == NULL){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_Queue_Pop(queue) called, but node was NULL"); ARC_DEBUG_LOG_ERROR("ARC_Queue_Pop(queue) called, but node was NULL");
return NULL; return NULL;
} }

View file

@ -24,7 +24,7 @@ void ARC_Stack_Create(ARC_Stack **stack){
void ARC_Stack_Destroy(ARC_Stack *stack){ void ARC_Stack_Destroy(ARC_Stack *stack){
if(stack->currentSize != 0 || stack->node != NULL){ if(stack->currentSize != 0 || stack->node != NULL){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_ERR("ARC_Stack_Destroy(stack) called, but stack was not empty"); ARC_DEBUG_LOG_ERROR("ARC_Stack_Destroy(stack) called, but stack was not empty");
return; return;
} }
@ -34,7 +34,7 @@ void ARC_Stack_Destroy(ARC_Stack *stack){
void ARC_Stack_Push(ARC_Stack *stack, void *data){ void ARC_Stack_Push(ARC_Stack *stack, void *data){
if(stack->currentSize == ~(uint32_t)0){ if(stack->currentSize == ~(uint32_t)0){
arc_errno = ARC_ERRNO_OVERFLOW; arc_errno = ARC_ERRNO_OVERFLOW;
ARC_DEBUG_ERR("ARC_Stack_Push(stack) called, size of stack is maxed, cannot add another node"); ARC_DEBUG_LOG_ERROR("ARC_Stack_Push(stack) called, size of stack is maxed, cannot add another node");
return; return;
} }
@ -51,14 +51,14 @@ void ARC_Stack_Push(ARC_Stack *stack, void *data){
void *ARC_Stack_Pop(ARC_Stack *stack){ void *ARC_Stack_Pop(ARC_Stack *stack){
if(stack->currentSize == 0){ if(stack->currentSize == 0){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_ERR("ARC_Stack_Pop(stack) called, but stack was not empty"); ARC_DEBUG_LOG_ERROR("ARC_Stack_Pop(stack) called, but stack was not empty");
return NULL; return NULL;
} }
ARC_StackNode *node = stack->node; ARC_StackNode *node = stack->node;
if(node == NULL){ if(node == NULL){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_Stack_Pop(stack) called, but node was NULL"); ARC_DEBUG_LOG_ERROR("ARC_Stack_Pop(stack) called, but node was NULL");
return NULL; return NULL;
} }

View file

@ -204,7 +204,7 @@ double ARC_String_ToDouble(ARC_String *string){
uint64_t ARC_String_Find(ARC_String *string, ARC_String *substring){ uint64_t ARC_String_Find(ARC_String *string, ARC_String *substring){
if(!string || !substring){ if(!string || !substring){
ARC_DEBUG_ERR("ARC_String_Find(string, substring), string or substring was null"); ARC_DEBUG_LOG_ERROR("ARC_String_Find(string, substring), string or substring was null");
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
return ~(uint64_t)0; return ~(uint64_t)0;
} }
@ -226,7 +226,7 @@ uint64_t ARC_String_Find(ARC_String *string, ARC_String *substring){
uint64_t ARC_String_FindCString(ARC_String *string, const char *cstring, uint64_t length){ uint64_t ARC_String_FindCString(ARC_String *string, const char *cstring, uint64_t length){
if(!string || !cstring){ if(!string || !cstring){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_String_FindCString(string, cstring, length), string or cstring was null"); ARC_DEBUG_LOG_ERROR("ARC_String_FindCString(string, cstring, length), string or cstring was null");
return ~(uint64_t)0; return ~(uint64_t)0;
} }
@ -251,7 +251,7 @@ uint64_t ARC_String_FindCStringWithStrlen(ARC_String *string, const char *cstrin
uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring){ uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring){
if(!string || !substring){ if(!string || !substring){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_String_FindBack(string, substring), string or substring was null"); ARC_DEBUG_LOG_ERROR("ARC_String_FindBack(string, substring), string or substring was null");
return ~(uint64_t)0; return ~(uint64_t)0;
} }
@ -272,7 +272,7 @@ uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring){
uint64_t ARC_String_FindBackCString(ARC_String *string, const char *cstring, uint64_t length){ uint64_t ARC_String_FindBackCString(ARC_String *string, const char *cstring, uint64_t length){
if(!string || !cstring){ if(!string || !cstring){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_String_FindBack(string, substring), string or substring was null"); ARC_DEBUG_LOG_ERROR("ARC_String_FindBack(string, substring), string or substring was null");
return ~(uint64_t)0; return ~(uint64_t)0;
} }
@ -512,7 +512,7 @@ void ARC_String_CopyReplaceMatching(ARC_String **newString, ARC_String *original
//TODO: probs want to check if the replacement goes over a uint64_t size //TODO: probs want to check if the replacement goes over a uint64_t size
if(original == NULL || pattern == NULL || replacement == NULL){ if(original == NULL || pattern == NULL || replacement == NULL){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_String_CopyReplaceMatching(newString, original, pattern, replacement), original, pattern, or replacement was null"); ARC_DEBUG_LOG_ERROR("ARC_String_CopyReplaceMatching(newString, original, pattern, replacement), original, pattern, or replacement was null");
return; return;
} }
@ -551,20 +551,11 @@ void ARC_String_CopyReplaceMatching(ARC_String **newString, ARC_String *original
(*newString)->data[(*newString)->length] = '\0'; (*newString)->data[(*newString)->length] = '\0';
} }
/**
* @brief replaces characters in string matching the given pattern
*
* @param string the string that will be modified, will discard changes and set arc_errno on fail
* @param patternCString the cstring pattern to replace in the string on match
* @param patternLength the lenght of the cstring pattern
* @param replacementCstring the cstring that will replace the matched pattern
* @param replacementLength the length of the cstring replacement
*/
void ARC_String_ReplaceMatchingCString(ARC_String **string, char *patternCString, uint64_t patternLength, char *replacementCString, uint64_t replacementLength){ void ARC_String_ReplaceMatchingCString(ARC_String **string, char *patternCString, uint64_t patternLength, char *replacementCString, uint64_t replacementLength){
//TODO: probs want to check if the replacement goes over a uint64_t size //TODO: probs want to check if the replacement goes over a uint64_t size
if(*string == NULL || patternCString == NULL || replacementCString == NULL){ if(*string == NULL || patternCString == NULL || replacementCString == NULL){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR("ARC_String_ReplaceMatchingCString(string, patternCString, patternLength, replacementCString, replacementLength), *string, patternCString, or replacementCString was null"); ARC_DEBUG_LOG_ERROR("ARC_String_ReplaceMatchingCString(string, patternCString, patternLength, replacementCString, replacementLength), *string, patternCString, or replacementCString was null");
return; return;
} }