From 834c692ee6347494998c3c8cf2bf0e63dc9ad264 Mon Sep 17 00:00:00 2001 From: Alan C Francis Date: Sun, 31 Dec 2023 21:42:18 +0000 Subject: [PATCH] keep track of insertPos even when removing. --- configmodel.c | 9 ++++++++- main.c | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/configmodel.c b/configmodel.c index f91dc85..8ce6f85 100644 --- a/configmodel.c +++ b/configmodel.c @@ -351,6 +351,7 @@ VOID SectionRemoveLinesForVariable(SECTIONPTR abstractSection, CONST_STRPTR varK { ULONG lineCount = SizeOfArray(section->lines); ULONG index = 0; + ULONG newInsertPos = 0; LineArray newLineArray = LineArrayNew(); STRPTR normalizedKey = AllocVec(strlen(varKey)+1, MEMF_CLEAR); CopyMem(varKey, normalizedKey, strlen(varKey)); @@ -363,15 +364,21 @@ VOID SectionRemoveLinesForVariable(SECTIONPTR abstractSection, CONST_STRPTR varK if( LineHasVariable(line, normalizedKey) ) { LineFree(line); - LineArrayValues(section->lines)[index] = NULL; // dont crash when we cann LineArrayFree + LineArrayValues(section->lines)[index] = NULL; // dont crash when we call LineArrayFree } else { LineArrayAppend(newLineArray, line); + if( !LineIsEmpty(line) ) + { + // keep track of where we can insert before blanks + newInsertPos++; + } } } LineArrayFree(section->lines, FALSE);//dont free the lines, the newArray will do that later section->lines = newLineArray; + section->insertPos = newInsertPos; FreeVec(normalizedKey); } } diff --git a/main.c b/main.c index 37b267a..749d282 100644 --- a/main.c +++ b/main.c @@ -39,11 +39,26 @@ WORD DoTheWork(STRPTR filename) // ConfigFileDump(config); // ConfigFileSet(config, "branch.main.foob", "bar"); // ConfigFileSet(config, "branch.alan.foob", "bar"); - ConfigFileSet(config, "branch.main.remote", "testing"); - ConfigFileReplaceAll(config, "branch.main.alan", "hello"); + ConfigFileSet(config, "branch.main.remote", "testing"); +// ConfigFileSet(config, "branch.main.second", "testing"); +// ConfigFileSet(config, "branch.main.third", "testing"); + ConfigFileReplaceAll(config, "branch.main.alan", "hello"); + ConfigFileAddVariable(config, "branch.main.newvar", "alan"); + ConfigFileAddVariable(config, "branch.main.newvar", "alan2"); + ConfigFileAddVariable(config, "branch.main.newvar", "alan3"); + ConfigFileReplaceAll(config, "branch.main.newvar", "goodbye"); + ConfigFileAddVariable(config, "branch.main.newvar1", "yay"); + +// ConfigFileAddVariable(config, "foo1", "alan"); +// ConfigFileAddVariable(config, "test.foo1", "alan2"); +// ConfigFileAddVariable(config, "test.foo.foo1", "alan3"); +// ConfigFileAddVariable(config, "test.foo.bar.foo1", "alan4"); +// ConfigFileAddVariable(config, "test.foo.bar.baz.foo1", "alan5"); +// ConfigFileAddVariable(config, "test.foo.bar.baz.bat.foo1", "alan6"); +// ConfigFileAddVariable(config, "test.section.jane.foo3", "alan3"); ConfigFileDump(config); - ConfigFileFree(config); +// ConfigFileFree(config); } else {