remove array function added to config, still needs testing

This commit is contained in:
herbglitch 2025-03-24 20:33:43 -06:00
parent e2c1a25cca
commit a6a34a933b

View file

@ -312,6 +312,10 @@ void ARC_Config_GroupDataHashtableDestroyKeyValueFn(void *key, void *value){
free(typeData);
}
//private empty function to avoid removing references or data freed from an array
void ARC_ConfigType_EmptyDestroyFn(void *type){
}
//<variableLine> -> <whitespace> <type> <whitespace> <variable> <whitespace> <array> <whitespace> EQUAL <whitespace> <value> <whitespace> SEMICOLON
void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config *config){
//skip whitespace and check for group name
@ -341,8 +345,25 @@ void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config
ARC_String_Create(&variableString, NULL, 0);
ARC_ParserData_HelperRecurseStringAdd(&variableString, childTagToken);
//check if the value is an array
childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, 5);
ARC_Bool isArray = (ARC_Bool)(ARC_Vector_GetSize(childTagToken->tagTokens) != 0);
//check if removing
if(config->load == ARC_False){
if(isArray == ARC_True){
ARC_ConfigTypeData *removingType = ARC_Hashtable_Get(config->currentGroup, (void *)variableString->data);
ARC_Array *array = (ARC_Array *)removingType->data;
for(uint32_t index = 0; index < array->size; index++){
removingType->destroyFn(array->data + index);
}
removingType->destroyFn = ARC_ConfigType_EmptyDestroyFn;
ARC_Hashtable_Remove(config->currentGroup, (void *)variableString->data);
return;
}
ARC_Hashtable_Remove(config->currentGroup, (void *)variableString->data);
ARC_String_Destroy(variableString);
return;
@ -364,10 +385,6 @@ void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config
nameVariableCStr[variableString->length] = '\0';
ARC_String_Destroy(variableString);
//check if the value is an array
childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, 5);
ARC_Bool isArray = (ARC_Bool)(ARC_Vector_GetSize(childTagToken->tagTokens) != 0);
//get <value>
childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, 9);
@ -438,8 +455,11 @@ void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config
memcpy(array->data, typeVectorArray.data, typeVectorArray.size);
}
//set the type data as an array
typeData->data = array;
//add the array to the group hashtable
ARC_Hashtable_Add(config->currentGroup, (void *)nameVariableCStr, (void *)array);
ARC_Hashtable_Add(config->currentGroup, (void *)nameVariableCStr, (void *)typeData);
//cleanup
ARC_VectorInline_Destroy(typeVector);