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 *separator;
|
||||||
ARC_String_Create(&separator, "::", 2);
|
ARC_String_Create(&separator, "::", 2);
|
||||||
uint64_t length = ARC_String_Find(keyname, separator);
|
uint64_t length = ARC_String_Find(keyname, separator);
|
||||||
|
ARC_String_Destroy(separator);
|
||||||
|
|
||||||
if(arc_errno){
|
if(arc_errno){
|
||||||
//TODO: Debug info here
|
//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));
|
ARC_ConfigTypeTemplate *templateVal = (ARC_ConfigTypeTemplate *) malloc(sizeof(ARC_ConfigTypeTemplate));
|
||||||
templateVal->Delete = NULL;
|
templateVal->Delete = NULL;
|
||||||
|
templateVal->data = NULL;
|
||||||
|
|
||||||
uint8_t reference = key->Read(config, value, &(templateVal->data));
|
uint8_t reference = key->Read(config, value, &(templateVal->data));
|
||||||
if(!reference){
|
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)){
|
if(ARC_String_EqualsCString(keyType, "group", 5)){
|
||||||
ARC_Config_SetKeyGroup(config, data, command);
|
ARC_Config_SetKeyGroup(config, data, command);
|
||||||
|
ARC_String_Destroy(keyType);
|
||||||
if(arc_errno){
|
if(arc_errno){
|
||||||
ARC_String_Destroy(keyType);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -313,10 +315,12 @@ void ARC_Config_Recurse(ARC_Config *config, ARC_String **data, ARC_String *group
|
||||||
// load from key
|
// load from key
|
||||||
if(*command == ARC_CONFIG_FILE_IO_LOAD){
|
if(*command == ARC_CONFIG_FILE_IO_LOAD){
|
||||||
ARC_Config_LoadFromKey(config, keyType, name, value);
|
ARC_Config_LoadFromKey(config, keyType, name, value);
|
||||||
|
|
||||||
|
ARC_String_Destroy(keyType);
|
||||||
|
ARC_String_Destroy(name );
|
||||||
|
ARC_String_Destroy(value );
|
||||||
|
|
||||||
if(arc_errno){
|
if(arc_errno){
|
||||||
ARC_String_Destroy(keyType);
|
|
||||||
ARC_String_Destroy(name );
|
|
||||||
ARC_String_Destroy(value );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -326,10 +330,12 @@ void ARC_Config_Recurse(ARC_Config *config, ARC_String **data, ARC_String *group
|
||||||
// unload from key
|
// unload from key
|
||||||
if(*command == ARC_CONFIG_FILE_IO_UNLOAD){
|
if(*command == ARC_CONFIG_FILE_IO_UNLOAD){
|
||||||
ARC_Config_UnloadFromKey(config, keyType, name);
|
ARC_Config_UnloadFromKey(config, keyType, name);
|
||||||
|
|
||||||
|
ARC_String_Destroy(keyType);
|
||||||
|
ARC_String_Destroy(name );
|
||||||
|
ARC_String_Destroy(value );
|
||||||
|
|
||||||
if(arc_errno){
|
if(arc_errno){
|
||||||
ARC_String_Destroy(keyType);
|
|
||||||
ARC_String_Destroy(name );
|
|
||||||
ARC_String_Destroy(value );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -358,6 +364,7 @@ void ARC_Config_StripComment(ARC_String *original, ARC_String **stripped, ARC_St
|
||||||
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_ERR("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);
|
||||||
*stripped = NULL;
|
*stripped = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -480,22 +487,37 @@ void ARC_Config_FileIO(ARC_Config *config, ARC_String *path, uint8_t command){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ARC_String *noCommentData;
|
char *tempData = (char *)malloc((char) data->length + 1);
|
||||||
ARC_Config_RemoveComments(data, &noCommentData);
|
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_Destroy(data);
|
||||||
|
|
||||||
ARC_String *noCommandData;
|
ARC_Config_RemoveComments(temp, &data);
|
||||||
ARC_Config_RemoveAndRunCommands(config, noCommentData, &noCommandData);
|
ARC_String_Destroy(temp);
|
||||||
ARC_String_Destroy(noCommentData);
|
|
||||||
|
|
||||||
ARC_Config_Recurse(config, &noCommandData, NULL, &command);
|
temp = data;
|
||||||
if(noCommandData){
|
ARC_Config_RemoveAndRunCommands(config, temp, &data);
|
||||||
ARC_String_Destroy(noCommandData);
|
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){
|
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);
|
return strncmp((const char *)key1, (const char *)key2, *key1size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,13 @@ uint8_t ARC_ConfigKey_Read_Uint8_t(ARC_Config* config, ARC_String *string, void
|
||||||
|
|
||||||
ARC_Config_Get(config, current, value);
|
ARC_Config_Get(config, current, value);
|
||||||
if(*value){
|
if(*value){
|
||||||
|
ARC_String_Destroy(current);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*value = (uint8_t *) malloc(sizeof(uint8_t));
|
*value = (uint8_t *) malloc(sizeof(uint8_t));
|
||||||
*((uint8_t *)(*value)) = (uint8_t) ARC_String_ToUint64_t(string);
|
*((uint8_t *)(*value)) = (uint8_t) ARC_String_ToUint64_t(current);
|
||||||
|
ARC_String_Destroy(current);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,4 +33,5 @@ void ARC_IO_FileToStr(ARC_String *path, ARC_String **data){
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
ARC_String_Create(data, fileData, length);
|
ARC_String_Create(data, fileData, length);
|
||||||
|
free(fileData);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue