get a single (string) value

main
Alan Francis 1 year ago
parent e4037b112a
commit 999eae88a0
  1. 19
      configmodel.c
  2. 1
      configmodel.h
  3. 9
      main.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();

@ -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);

@ -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);
}

Loading…
Cancel
Save