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

@ -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));
if(arc_errno && arc_errno != ARC_ERRNO_NULL){
return;
}
arc_errno = 0;
// if(arc_errno && arc_errno != ARC_ERRNO_NULL){
// return;
// }
if(config->currgroup){
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);
if(arc_errno){
//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;
return;
}
@ -141,7 +143,7 @@ void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value){
ARC_Hashtable *currgroup = config->currgroup;
ARC_Config_SetGroup(config, group);
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);
*value = NULL;
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);
if(key == NULL){
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){
@ -406,7 +408,7 @@ void ARC_Config_StripComment(ARC_String *original, ARC_String **stripped, ARC_St
uint64_t endIndex = ARC_String_Find(commentString, lineEnd);
ARC_String_Destroy(commentString);
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_String_Destroy(current);
*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){
arc_errno = 0; //TODO: Remove this, just testing
ARC_String *data;
ARC_IO_FileToStr(path, &data);
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;
}
char *tempData = (char *)malloc(sizeof(char) * (data->length + 1));
strncpy(tempData, data->data, data->length);
tempData[data->length] = '\n';
ARC_String_AppendCStringWithStrlen(&data, "\n");
ARC_String *temp = data;
ARC_String_Create(&temp, tempData, data->length + 1);
free(tempData);
ARC_String_Destroy(data);
ARC_Config_RemoveComments(temp, &data);
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] != '"'){
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;
}
@ -214,7 +214,7 @@ void ARC_ConfigKey_StringArray_ReadString(ARC_Config* config, ARC_String *stripp
//reading in value
ARC_ConfigKey_Read_String(config, substr, (void **) &tempString);
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);
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] != '}'){
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;
}

View file

@ -11,10 +11,10 @@ struct ARC_Handler {
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));
ARC_Vector_Create(&((*handler)->data));
ARC_Vector_Create(&((*handler)->trash));
ARC_Vector_Create(&((*handler)->data), NULL);
ARC_Vector_Create(&((*handler)->trash), compareFn);
(*handler)->cleanfn = cleanfn;
}
@ -32,13 +32,13 @@ void ARC_Handler_Add(ARC_Handler *handler, void *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_Remove(handler->data, data, (ARC_Vector_CompareDataFn) compare);
ARC_Vector_Remove(handler->data, data);
}
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;
}
@ -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){
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));
}
}
void ARC_Handler_Clear(ARC_Handler *handler){
uint32_t zeroIndex = 0;
while(ARC_Vector_Size(handler->data)){
while(ARC_Vector_GetSize(handler->data)){
ARC_Handler_RemoveIndex(handler, zeroIndex);
}
}
void ARC_Handler_Clean(ARC_Handler *handler){
uint32_t i = 0;
while(ARC_Vector_Size(handler->trash)){
while(ARC_Vector_GetSize(handler->trash)){
void *data = ARC_Vector_Get(handler->trash, i);
if(handler->cleanfn){
@ -73,6 +73,6 @@ void ARC_Handler_Clean(ARC_Handler *handler){
}
}
uint32_t ARC_Handler_Size(ARC_Handler *handler){
return ARC_Vector_Size(handler->data);
uint32_t ARC_Handler_GetSize(ARC_Handler *handler){
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");
if(!file){
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;
*data = NULL;
return;
@ -23,7 +23,7 @@ void ARC_IO_ReadFileToUint8t(ARC_String *path, uint8_t **data, uint64_t *length)
if(*data == NULL){
fclose(file);
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;
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)){
fclose(file);
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;
*data = NULL;
return;
@ -44,7 +44,7 @@ void ARC_IO_FileToStr(ARC_String *path, ARC_String **data){
FILE *file = fopen(path->data, "rb");
if(!file){
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;
}
@ -56,7 +56,7 @@ void ARC_IO_FileToStr(ARC_String *path, ARC_String **data){
if(fileData == NULL){
fclose(file);
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;
return;
}
@ -64,7 +64,7 @@ void ARC_IO_FileToStr(ARC_String *path, ARC_String **data){
if(1 != fread(fileData, length, 1, file)){
fclose(file);
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;
return;
}
@ -78,14 +78,14 @@ void ARC_IO_WriteStrToFile(ARC_String *path, ARC_String *data){
FILE *file = fopen(path->data, "wb");
if(!file){
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;
}
if(1 != fwrite(data->data, data->length, 1, file)){
fclose(file);
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;
}

View file

@ -24,7 +24,7 @@ void ARC_Queue_Create(ARC_Queue **queue){
void ARC_Queue_Destroy(ARC_Queue *queue){
if(queue->currentSize != 0 || queue->node != NULL){
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;
}
@ -34,7 +34,7 @@ void ARC_Queue_Destroy(ARC_Queue *queue){
void ARC_Queue_Push(ARC_Queue *queue, void *data){
if(queue->currentSize == ~(uint32_t)0){
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;
}
@ -53,7 +53,7 @@ void ARC_Queue_Push(ARC_Queue *queue, void *data){
for(uint32_t i = 1; i < queue->currentSize; i++){
if(end->next == 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;
}
@ -72,14 +72,14 @@ void ARC_Queue_Push(ARC_Queue *queue, void *data){
void *ARC_Queue_Pop(ARC_Queue *queue){
if(queue->currentSize == 0){
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;
}
ARC_QueueNode *node = queue->node;
if(node == 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;
}

View file

@ -24,7 +24,7 @@ void ARC_Stack_Create(ARC_Stack **stack){
void ARC_Stack_Destroy(ARC_Stack *stack){
if(stack->currentSize != 0 || stack->node != NULL){
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;
}
@ -34,7 +34,7 @@ void ARC_Stack_Destroy(ARC_Stack *stack){
void ARC_Stack_Push(ARC_Stack *stack, void *data){
if(stack->currentSize == ~(uint32_t)0){
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;
}
@ -51,14 +51,14 @@ void ARC_Stack_Push(ARC_Stack *stack, void *data){
void *ARC_Stack_Pop(ARC_Stack *stack){
if(stack->currentSize == 0){
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;
}
ARC_StackNode *node = stack->node;
if(node == 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;
}

View file

@ -204,7 +204,7 @@ double ARC_String_ToDouble(ARC_String *string){
uint64_t ARC_String_Find(ARC_String *string, ARC_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;
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){
if(!string || !cstring){
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;
}
@ -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){
if(!string || !substring){
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;
}
@ -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){
if(!string || !cstring){
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;
}
@ -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
if(original == NULL || pattern == NULL || replacement == 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;
}
@ -551,20 +551,11 @@ void ARC_String_CopyReplaceMatching(ARC_String **newString, ARC_String *original
(*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){
//TODO: probs want to check if the replacement goes over a uint64_t size
if(*string == NULL || patternCString == NULL || replacementCString == 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;
}