get subsections

main
Alan Francis 1 year ago
parent 229c2776ed
commit 8f06578a85
  1. 7
      configfile.c
  2. 3
      configfile.h
  3. 13
      configmodel.c
  4. 2
      configmodel.h
  5. 6
      main.c
  6. 21
      sectionstore.c
  7. 2
      sectionstore.h

@ -64,6 +64,13 @@ CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename)
}
StringArray ConfigFileSubsectionsForSection(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR primarySection)
{
struct ConfigFile* configFile = (struct ConfigFile*)abstractConfigFile;
return SectionStoreSubsectionsForSection(configFile->sectionStore, primarySection);
}
// a key is "foo.bar.baz.blah" where "foo" is the primary section name
// "bar.baz" is the secondary section name and "blah" is the variable name.
// this splits foo.bar.baz.blah into foo, bar.baz amd blah.

@ -26,4 +26,7 @@ VOID ConfigFileRemoveSection(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR cano
VOID ConfigFileDump(CONFIGFILEPTR configFile);
StringArray ConfigFileSplitKeyForVar(CONST_STRPTR key);
StringArray ConfigFileSplitKeyCompletely(CONST_STRPTR key);
StringArray ConfigFileSubsectionsForSection(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR primarySection);
#endif

@ -252,6 +252,19 @@ SECTIONPTR SectionCreateWithNameAndSubname(CONST_STRPTR primary, CONST_STRPTR se
return result;
}
BOOL SectionHasName(SECTIONPTR abstractSection, CONST_STRPTR primary)
{
struct Section* section = (struct Section*)abstractSection;
return (BOOL)(strcmp(primary, section->primary) == 0);
}
CONST_STRPTR SectionGetRawSubsectionName(SECTIONPTR abstractSection)
{
struct Section* section = (struct Section*)abstractSection;
return section->secondary;
}
VOID SectionAddSectionLine(SECTIONPTR abstractSection, LINEPTR abstractLine)
{
// sets self onto line and then adds line to the collection

@ -25,6 +25,8 @@ VOID SectionAddLine(SECTIONPTR abstractSection, LINEPTR abstractLine, BOOL addBe
CONST_STRPTR SectionCanonicalName(SECTIONPTR section);
VOID SectionDump(SECTIONPTR section);
CONST_STRPTR SectionSerialize(SECTIONPTR section);
BOOL SectionHasName(SECTIONPTR section, CONST_STRPTR primary);
CONST_STRPTR SectionGetRawSubsectionName(SECTIONPTR section);
VOID SectionCollectLinesForVariable(SECTIONPTR section, CONST_STRPTR varKey, LineArray collecting);
VOID SectionRemoveLinesForVariable(SECTIONPTR section, CONST_STRPTR varKey);

@ -56,6 +56,12 @@ WORD DoTheWork(STRPTR filename)
// ConfigFileAddVariable(config, "test.foo.bar.baz.foo1", "alan5");
// ConfigFileAddVariable(config, "test.foo.bar.baz.bat.foo1", "alan6");
// ConfigFileAddVariable(config, "test.section.jane.foo3", "alan3");
// values = ConfigFileSubsectionsForSection(config, "branch");
// if( values )
// {
// StringArrayForEach(values, Printf("branch:[%s]\n",aString););
// StringArrayFree(values, TRUE);
// }
ConfigFileDump(config);
// ConfigFileFree(config);

@ -212,6 +212,27 @@ SECTIONPTR SectionStoreSectionAt(SECTIONSTOREPTR abstractSectionStore, ULONG ind
return result;
}
StringArray SectionStoreSubsectionsForSection(SECTIONSTOREPTR abstractSectionStore, CONST_STRPTR primarySection)
{
struct SectionStore* store = (struct SectionStore*)abstractSectionStore;
StringArray result = StringArrayNew();
ULONG index = 0;
for( index = 0; index < SizeOfArray(store->array); index++)
{
SECTIONPTR section = SectionArrayValues(store->array)[index];
if( SectionHasName(section, primarySection) )
{
CONST_STRPTR secondary = SectionGetRawSubsectionName(section);
if( secondary != NULL && strlen(secondary) > 0 )
{
StringArrayAppendAndRetain(result, secondary);
}
}
}
return result;
}
SECTIONPTR SectionStoreFindOrCreateSection(SECTIONSTOREPTR sectionStore, CONST_STRPTR compoundKey)
{
// now get the section

@ -22,4 +22,6 @@ VARIABLEPTR SectionStoreGet(SECTIONSTOREPTR sectionStore, CONST_STRPTR canonical
ULONG SectionStoreSectionCount(SECTIONSTOREPTR sectionStore);
SECTIONPTR SectionStoreSectionAt(SECTIONSTOREPTR sectionStore, ULONG index);
StringArray SectionStoreSubsectionsForSection(SECTIONSTOREPTR sectionStore, CONST_STRPTR primarySection);
#endif
Loading…
Cancel
Save