add before blanks working as long as no lines have been deleted.

main
Alan Francis 1 year ago
parent 1688eabbfd
commit 6a116e5f8d
  1. 2
      configfile.c
  2. 38
      configmodel.c
  3. 2
      configmodel.h
  4. 10
      containers/linearray.c
  5. 4
      sectionstore.c

@ -214,7 +214,7 @@ VOID ConfigFileAddVariable(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compou
// now get the section // now get the section
section = SectionStoreFindOrCreateSection(configFile->sectionStore, compoundKey); section = SectionStoreFindOrCreateSection(configFile->sectionStore, compoundKey);
// add the line to the section // add the line to the section
SectionAddLine(section, line); SectionAddLine(section, line, TRUE);
} }
} }

@ -15,7 +15,7 @@ struct Section
CONST_STRPTR primary; CONST_STRPTR primary;
CONST_STRPTR secondary; CONST_STRPTR secondary;
LineArray lines; LineArray lines;
BOOL lastLineWasEmpty; ULONG insertPos; // we want to add new entries at end, but before any blanks
}; };
enum VariableType enum VariableType
@ -248,7 +248,7 @@ SECTIONPTR SectionCreateWithNameAndSubname(CONST_STRPTR primary, CONST_STRPTR se
{ {
ULONG length = strlen(primary); ULONG length = strlen(primary);
result = AllocVec(sizeof(struct Section), MEMF_CLEAR); result = AllocVec(sizeof(struct Section), MEMF_CLEAR);
result->lastLineWasEmpty = FALSE; result->insertPos = 0;
result->primary = AllocVec(length+1, MEMF_CLEAR); result->primary = AllocVec(length+1, MEMF_CLEAR);
CopyMem(primary, (STRPTR)result->primary, length); CopyMem(primary, (STRPTR)result->primary, length);
@ -269,7 +269,7 @@ VOID SectionAddSectionLine(SECTIONPTR abstractSection, LINEPTR abstractLine)
{ {
// sets self onto line and then adds line to the collection // sets self onto line and then adds line to the collection
LineSetSection(abstractLine, abstractSection); LineSetSection(abstractLine, abstractSection);
SectionAddLine(abstractSection, abstractLine); SectionAddLine(abstractSection, abstractLine, FALSE);
} }
// we need to know if there are blank lines at the end and if this is a variable, // we need to know if there are blank lines at the end and if this is a variable,
@ -290,32 +290,30 @@ VOID SectionAddSectionLine(SECTIONPTR abstractSection, LINEPTR abstractLine)
// [baz] // [baz]
// etc // etc
VOID SectionAddLine(SECTIONPTR abstractSection, LINEPTR abstractLine) VOID SectionAddLine(SECTIONPTR abstractSection, LINEPTR abstractLine, BOOL addBeforeBlanks)
{ {
struct Section* section = (struct Section*)abstractSection; struct Section* section = (struct Section*)abstractSection;
if( section != NULL ) if( section != NULL )
{ {
//Printf("\n\SAD1 (%ld bytes avail)\n\n", AvailMem(0)); if( addBeforeBlanks==FALSE || section->insertPos == SizeOfArray(section->lines) )
// if the last line is empty and new line is NOT, insert new line before the blank.
if( section->lastLineWasEmpty && !LineIsEmpty(abstractLine) )
{ {
LINEPTR lastLine = ArrayBackValue(LINEPTR, section->lines); LineArrayAppend(section->lines, abstractLine);
ULONG lastIndex = SizeOfArray(section->lines)-1; if(!LineIsEmpty(abstractLine) )
//Printf("\n\SAD2 (%ld bytes avail)\n\n", AvailMem(0)); {
LineArrayValues(section->lines)[lastIndex] = abstractLine; section->insertPos = SizeOfArray(section->lines);
LineArrayAppend(section->lines, lastLine); printf("xx (%s) insertpos = %lu\n", SectionCanonicalName(abstractSection), section->insertPos);
//Printf("\n\SAD3 (%ld bytes avail)\n\n", AvailMem(0)); LineDump(abstractLine);
printf("xx\n");
}
} }
else else
{ {
//Printf("\n\SAD4 (%ld bytes avail)\n\n", AvailMem(0)); LineArrayInsert(section->lines, abstractLine, section->insertPos);
LineArrayAppend(section->lines, abstractLine); section->insertPos += 1;
//Printf("\n\SAD5 (%ld bytes avail)\n\n", AvailMem(0)); printf("yy (%s) insertpos = %lu\n", SectionCanonicalName(abstractSection), section->insertPos);
LineDump(abstractLine);
printf("yy\n");
} }
//Printf("\n\SAD6 (%ld bytes avail)\n\n", AvailMem(0));
section->lastLineWasEmpty = LineIsEmpty(abstractLine);
//Printf("\n\SAD7 (%ld bytes avail)\n\n", AvailMem(0));
} }
} }

@ -21,7 +21,7 @@ SECTIONPTR SectionCreateWithName(CONST_STRPTR primary);
SECTIONPTR SectionCreateWithNameAndSubname(CONST_STRPTR primary, CONST_STRPTR secondary); SECTIONPTR SectionCreateWithNameAndSubname(CONST_STRPTR primary, CONST_STRPTR secondary);
VOID SectionFree(SECTIONPTR section); VOID SectionFree(SECTIONPTR section);
VOID SectionAddSectionLine(SECTIONPTR section, LINEPTR line); VOID SectionAddSectionLine(SECTIONPTR section, LINEPTR line);
VOID SectionAddLine(SECTIONPTR section, LINEPTR line); VOID SectionAddLine(SECTIONPTR abstractSection, LINEPTR abstractLine, BOOL addBeforeBlanks);
CONST_STRPTR SectionCanonicalName(SECTIONPTR section); CONST_STRPTR SectionCanonicalName(SECTIONPTR section);
VOID SectionDump(SECTIONPTR section); VOID SectionDump(SECTIONPTR section);
CONST_STRPTR SectionSerialize(SECTIONPTR section); CONST_STRPTR SectionSerialize(SECTIONPTR section);

@ -24,8 +24,14 @@ VOID LineArrayAppend(LineArray array, LINEPTR value)
VOID LineArrayInsert(LineArray array, LINEPTR value, ULONG pos) VOID LineArrayInsert(LineArray array, LINEPTR value, ULONG pos)
{ {
AppendToArray(LINEPTR, array, value); if( InsertArrayElements(array, pos, 1) )
// InsertToArray(LINEPTR, array, pos, value); {
LineArrayValues(array)[pos] = value;
}
else
{
printf("booooo\n");
}
} }
VOID LineArrayFree(LineArray array, BOOL freeLines) VOID LineArrayFree(LineArray array, BOOL freeLines)

@ -170,13 +170,13 @@ VOID SectionStoreAddLineToCurrentSection(SECTIONSTOREPTR abstractSectionStore, L
if( variable = parseVariable(line, store->variablePatternProgram) ) if( variable = parseVariable(line, store->variablePatternProgram) )
{ {
LineSetInitialVariable(line, variable); LineSetInitialVariable(line, variable);
SectionAddLine(section, line); SectionAddLine(section, line, FALSE);
} }
else else
{ {
if( parseBlank(line, store->blankPatternProgram) ) if( parseBlank(line, store->blankPatternProgram) )
{ {
SectionAddLine(section, line); SectionAddLine(section, line, FALSE);
} }
else else
{ {

Loading…
Cancel
Save