public findOrCreate

main
Alan Francis 1 year ago
parent 60ea8cfdbc
commit 0d2fd66b6a
  1. 27
      configfile.c
  2. 25
      sectionstore.c
  3. 2
      sectionstore.h

@ -15,7 +15,6 @@
#define ZERO ((BPTR)0)
STATIC SECTIONPTR findOrCreateSection(SECTIONSTOREPTR sectionStore, CONST_STRPTR compoundKey);
STATIC LINEPTR configFileReadLine(BPTR file);
@ -213,7 +212,7 @@ VOID ConfigFileAddVariable(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compou
StringArrayFree(canonicalParts, TRUE);
// now get the section
section = findOrCreateSection(configFile->sectionStore, compoundKey);
section = SectionStoreFindOrCreateSection(configFile->sectionStore, compoundKey);
// add the line to the section
SectionAddLine(section, line);
}
@ -333,27 +332,3 @@ STATIC LINEPTR configFileReadLine(BPTR file)
FreeVec(buffer);
return result;
}
STATIC SECTIONPTR findOrCreateSection(SECTIONSTOREPTR sectionStore, CONST_STRPTR compoundKey)
{
// now get the section
StringArray canonicalParts = ConfigFileSplitKeyForVar(compoundKey);
SECTIONPTR section = section = SectionStoreGetSection(sectionStore, StringArrayValues(canonicalParts)[0]);
if( section == NULL )
{
StringArray separateParts = ConfigFileSplitKeyCompletely(compoundKey);
CONST_STRPTR sectionLineText = NULL;
LINEPTR sectionLine = NULL;
section = SectionCreateWithNameAndSubname(StringArrayValues(separateParts)[0], StringArrayValues(separateParts)[1]);
sectionLineText = SectionSerialize(section);
sectionLine = LineNew(sectionLineText);
SectionAddSectionLine(section, sectionLine);
FreeVec((STRPTR)sectionLineText);
SectionStoreAddSection(sectionStore, section); //section store will free it for us
StringArrayFree(separateParts, TRUE);
}
StringArrayFree(canonicalParts, TRUE);
return section;
}

@ -211,6 +211,31 @@ SECTIONPTR SectionStoreSectionAt(SECTIONSTOREPTR abstractSectionStore, ULONG ind
return result;
}
SECTIONPTR SectionStoreFindOrCreateSection(SECTIONSTOREPTR sectionStore, CONST_STRPTR compoundKey)
{
// now get the section
StringArray canonicalParts = ConfigFileSplitKeyForVar(compoundKey);
SECTIONPTR section = section = SectionStoreGetSection(sectionStore, StringArrayValues(canonicalParts)[0]);
if( section == NULL )
{
StringArray separateParts = ConfigFileSplitKeyCompletely(compoundKey);
CONST_STRPTR sectionLineText = NULL;
LINEPTR sectionLine = NULL;
section = SectionCreateWithNameAndSubname(StringArrayValues(separateParts)[0], StringArrayValues(separateParts)[1]);
sectionLineText = SectionSerialize(section);
sectionLine = LineNew(sectionLineText);
SectionAddSectionLine(section, sectionLine);
FreeVec((STRPTR)sectionLineText);
SectionStoreAddSection(sectionStore, section); //section store will free it for us
StringArrayFree(separateParts, TRUE);
}
StringArrayFree(canonicalParts, TRUE);
return section;
}
// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------

@ -13,6 +13,8 @@ SECTIONPTR SectionStoreGetSection(SECTIONSTOREPTR sectionStore, CONST_STRPTR can
VOID SectionStoreAddLineToCurrentSection(SECTIONSTOREPTR sectionStore, LINEPTR line);
VOID SectionStoreRemoveLines(SECTIONSTOREPTR sectionStore, CONST_STRPTR canonicalSectionName, CONST_STRPTR varKey);
SECTIONPTR SectionStoreFindOrCreateSection(SECTIONSTOREPTR sectionStore, CONST_STRPTR compoundKey);
LineArray SectionStoreFindLines(SECTIONSTOREPTR sectionStore, CONST_STRPTR canonicalSectionName, CONST_STRPTR varKey);
VariableArray SectionStoreGetAll(SECTIONSTOREPTR sectionStore, CONST_STRPTR canonicalSectionName, CONST_STRPTR varKey);
VARIABLEPTR SectionStoreGet(SECTIONSTOREPTR sectionStore, CONST_STRPTR canonicalSectionName, CONST_STRPTR varKey);

Loading…
Cancel
Save