added newline to end of files that are read in
This commit is contained in:
parent
f8d987da8e
commit
2b2e40921d
3 changed files with 42 additions and 17 deletions
|
|
@ -110,6 +110,7 @@ void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value){
|
|||
ARC_String *separator;
|
||||
ARC_String_Create(&separator, "::", 2);
|
||||
uint64_t length = ARC_String_Find(keyname, separator);
|
||||
ARC_String_Destroy(separator);
|
||||
|
||||
if(arc_errno){
|
||||
//TODO: Debug info here
|
||||
|
|
@ -187,6 +188,7 @@ void ARC_Config_LoadFromKey(ARC_Config *config, ARC_String *keyType, ARC_String
|
|||
|
||||
ARC_ConfigTypeTemplate *templateVal = (ARC_ConfigTypeTemplate *) malloc(sizeof(ARC_ConfigTypeTemplate));
|
||||
templateVal->Delete = NULL;
|
||||
templateVal->data = NULL;
|
||||
|
||||
uint8_t reference = key->Read(config, value, &(templateVal->data));
|
||||
if(!reference){
|
||||
|
|
@ -265,8 +267,8 @@ void ARC_Config_Recurse(ARC_Config *config, ARC_String **data, ARC_String *group
|
|||
|
||||
if(ARC_String_EqualsCString(keyType, "group", 5)){
|
||||
ARC_Config_SetKeyGroup(config, data, command);
|
||||
ARC_String_Destroy(keyType);
|
||||
if(arc_errno){
|
||||
ARC_String_Destroy(keyType);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -313,10 +315,12 @@ void ARC_Config_Recurse(ARC_Config *config, ARC_String **data, ARC_String *group
|
|||
// load from key
|
||||
if(*command == ARC_CONFIG_FILE_IO_LOAD){
|
||||
ARC_Config_LoadFromKey(config, keyType, name, value);
|
||||
|
||||
ARC_String_Destroy(keyType);
|
||||
ARC_String_Destroy(name );
|
||||
ARC_String_Destroy(value );
|
||||
|
||||
if(arc_errno){
|
||||
ARC_String_Destroy(keyType);
|
||||
ARC_String_Destroy(name );
|
||||
ARC_String_Destroy(value );
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -326,10 +330,12 @@ void ARC_Config_Recurse(ARC_Config *config, ARC_String **data, ARC_String *group
|
|||
// unload from key
|
||||
if(*command == ARC_CONFIG_FILE_IO_UNLOAD){
|
||||
ARC_Config_UnloadFromKey(config, keyType, name);
|
||||
|
||||
ARC_String_Destroy(keyType);
|
||||
ARC_String_Destroy(name );
|
||||
ARC_String_Destroy(value );
|
||||
|
||||
if(arc_errno){
|
||||
ARC_String_Destroy(keyType);
|
||||
ARC_String_Destroy(name );
|
||||
ARC_String_Destroy(value );
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -358,6 +364,7 @@ void ARC_Config_StripComment(ARC_String *original, ARC_String **stripped, ARC_St
|
|||
if(endIndex == ~(uint64_t)0){
|
||||
ARC_DEBUG_ERR("ARC_Config_RemoveComments(original, commentRemoved); No newline found when stripping single line comment");
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
ARC_String_Destroy(current);
|
||||
*stripped = NULL;
|
||||
break;
|
||||
}
|
||||
|
|
@ -480,22 +487,37 @@ void ARC_Config_FileIO(ARC_Config *config, ARC_String *path, uint8_t command){
|
|||
return;
|
||||
}
|
||||
|
||||
ARC_String *noCommentData;
|
||||
ARC_Config_RemoveComments(data, &noCommentData);
|
||||
char *tempData = (char *)malloc((char) data->length + 1);
|
||||
strncpy(tempData, data->data, data->length);
|
||||
tempData[data->length] = '\n';
|
||||
|
||||
ARC_String *temp = data;
|
||||
ARC_String_Create(&temp, tempData, data->length + 1);
|
||||
free(tempData);
|
||||
ARC_String_Destroy(data);
|
||||
|
||||
ARC_String *noCommandData;
|
||||
ARC_Config_RemoveAndRunCommands(config, noCommentData, &noCommandData);
|
||||
ARC_String_Destroy(noCommentData);
|
||||
ARC_Config_RemoveComments(temp, &data);
|
||||
ARC_String_Destroy(temp);
|
||||
|
||||
ARC_Config_Recurse(config, &noCommandData, NULL, &command);
|
||||
if(noCommandData){
|
||||
ARC_String_Destroy(noCommandData);
|
||||
temp = data;
|
||||
ARC_Config_RemoveAndRunCommands(config, temp, &data);
|
||||
ARC_String_Destroy(temp);
|
||||
|
||||
temp = data;
|
||||
ARC_String_StripEndsWhitespace(temp, &data);
|
||||
ARC_String_Destroy(temp);
|
||||
|
||||
ARC_Config_Recurse(config, &data, NULL, &command);
|
||||
if(data){
|
||||
ARC_String_Destroy(data);
|
||||
}
|
||||
}
|
||||
|
||||
int8_t ARC_Config_KeyComp(void *key1, size_t *key1size, void *key2, size_t *key2size){
|
||||
if(*key1size - *key2size){ return -1; }
|
||||
if(*key1size - *key2size){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return strncmp((const char *)key1, (const char *)key2, *key1size);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue