diff --git a/configmodel.c b/configmodel.c index fb629ff..ca036ef 100644 --- a/configmodel.c +++ b/configmodel.c @@ -130,6 +130,25 @@ StringArray ConfigFileSplitKey(CONST_STRPTR key) return result; } +STRPTR ConfigFileGet(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey) +{ + STRPTR result = NULL; + struct ConfigFile* configFile = (struct ConfigFile*)abstractConfigFile; + if( configFile != NULL ) + { + StringArray split = ConfigFileSplitKey(compoundKey); + VARIABLEPTR var = SectionStoreGet(configFile->sectionStore, StringArrayValues(split)[0], StringArrayValues(split)[1]); + if( var != NULL ) + { + CONST_STRPTR value = VariableGetRawValue(var); + result = AllocVec(strlen(value)+1, MEMF_CLEAR); + CopyMem(value, result, strlen(value)); + } + StringArrayFree(split, TRUE); + } + return result; +} + StringArray ConfigFileGetAll(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey) { StringArray result = StringArrayNew(); diff --git a/configmodel.h b/configmodel.h index b86cc8a..c2ef699 100644 --- a/configmodel.h +++ b/configmodel.h @@ -8,6 +8,7 @@ VOID ConfigFileFree(CONFIGFILEPTR configFile); VOID ConfigFileDump(CONFIGFILEPTR configFile); StringArray ConfigFileSplitKey(CONST_STRPTR key); StringArray ConfigFileGetAll(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey); +STRPTR ConfigFileGet(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey); LINEPTR LineNew(CONST_STRPTR buffer, ULONG size); VOID LineFree(LINEPTR abstractLine); diff --git a/main.c b/main.c index 10f1f16..4f2ae6f 100644 --- a/main.c +++ b/main.c @@ -26,16 +26,15 @@ WORD DoTheWork(STRPTR filename) if( config != NULL ) { StringArray values = NULL; + STRPTR var = NULL; values = ConfigFileGetAll(config, "branch.main.remote"); StringArrayForEach(values, Printf("main %s\n", aString);); StringArrayFree(values, TRUE); - values = ConfigFileGetAll(config, "branch.config-file-parsing-from-book.remote"); - StringArrayForEach(values, Printf("parse %s\n", aString);); - StringArrayFree(values, TRUE); - - + var = ConfigFileGet(config, "branch.config-file-parsing-from-book.remote"); + Printf("parse %s\n", var); + FreeVec(var); ConfigFileFree(config); }