keep track of insertPos even when removing.

main
Alan Francis 1 year ago
parent 6a116e5f8d
commit 834c692ee6
  1. 9
      configmodel.c
  2. 17
      main.c

@ -351,6 +351,7 @@ VOID SectionRemoveLinesForVariable(SECTIONPTR abstractSection, CONST_STRPTR varK
{ {
ULONG lineCount = SizeOfArray(section->lines); ULONG lineCount = SizeOfArray(section->lines);
ULONG index = 0; ULONG index = 0;
ULONG newInsertPos = 0;
LineArray newLineArray = LineArrayNew(); LineArray newLineArray = LineArrayNew();
STRPTR normalizedKey = AllocVec(strlen(varKey)+1, MEMF_CLEAR); STRPTR normalizedKey = AllocVec(strlen(varKey)+1, MEMF_CLEAR);
CopyMem(varKey, normalizedKey, strlen(varKey)); CopyMem(varKey, normalizedKey, strlen(varKey));
@ -363,15 +364,21 @@ VOID SectionRemoveLinesForVariable(SECTIONPTR abstractSection, CONST_STRPTR varK
if( LineHasVariable(line, normalizedKey) ) if( LineHasVariable(line, normalizedKey) )
{ {
LineFree(line); 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 else
{ {
LineArrayAppend(newLineArray, line); 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 LineArrayFree(section->lines, FALSE);//dont free the lines, the newArray will do that later
section->lines = newLineArray; section->lines = newLineArray;
section->insertPos = newInsertPos;
FreeVec(normalizedKey); FreeVec(normalizedKey);
} }
} }

@ -40,10 +40,25 @@ WORD DoTheWork(STRPTR filename)
// ConfigFileSet(config, "branch.main.foob", "bar"); // ConfigFileSet(config, "branch.main.foob", "bar");
// ConfigFileSet(config, "branch.alan.foob", "bar"); // ConfigFileSet(config, "branch.alan.foob", "bar");
ConfigFileSet(config, "branch.main.remote", "testing"); ConfigFileSet(config, "branch.main.remote", "testing");
// ConfigFileSet(config, "branch.main.second", "testing");
// ConfigFileSet(config, "branch.main.third", "testing");
ConfigFileReplaceAll(config, "branch.main.alan", "hello"); 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); ConfigFileDump(config);
ConfigFileFree(config); // ConfigFileFree(config);
} }
else else
{ {

Loading…
Cancel
Save