diff --git a/configfile.c b/configfile.c index f7ee9ae..f7a3174 100644 --- a/configfile.c +++ b/configfile.c @@ -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; -} - diff --git a/sectionstore.c b/sectionstore.c index 7da92be..4113af7 100644 --- a/sectionstore.c +++ b/sectionstore.c @@ -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; +} + + + // --------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------- diff --git a/sectionstore.h b/sectionstore.h index 1215eef..65424b8 100644 --- a/sectionstore.h +++ b/sectionstore.h @@ -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);