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
section = SectionStoreFindOrCreateSection(configFile->sectionStore, compoundKey);
// add the line to the section
SectionAddLine(section, line);
SectionAddLine(section, line, TRUE);
}
}

@ -15,7 +15,7 @@ struct Section
CONST_STRPTR primary;
CONST_STRPTR secondary;
LineArray lines;
BOOL lastLineWasEmpty;
ULONG insertPos; // we want to add new entries at end, but before any blanks
};
enum VariableType
@ -248,7 +248,7 @@ SECTIONPTR SectionCreateWithNameAndSubname(CONST_STRPTR primary, CONST_STRPTR se
{
ULONG length = strlen(primary);
result = AllocVec(sizeof(struct Section), MEMF_CLEAR);
result->lastLineWasEmpty = FALSE;
result->insertPos = 0;
result->primary = AllocVec(length+1, MEMF_CLEAR);
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
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,
@ -290,32 +290,30 @@ VOID SectionAddSectionLine(SECTIONPTR abstractSection, LINEPTR abstractLine)
// [baz]
// etc
VOID SectionAddLine(SECTIONPTR abstractSection, LINEPTR abstractLine)
VOID SectionAddLine(SECTIONPTR abstractSection, LINEPTR abstractLine, BOOL addBeforeBlanks)
{
struct Section* section = (struct Section*)abstractSection;
if( section != NULL )
{
//Printf("\n\SAD1 (%ld bytes avail)\n\n", AvailMem(0));
// if the last line is empty and new line is NOT, insert new line before the blank.
if( section->lastLineWasEmpty && !LineIsEmpty(abstractLine) )
if( addBeforeBlanks==FALSE || section->insertPos == SizeOfArray(section->lines) )
{
LINEPTR lastLine = ArrayBackValue(LINEPTR, section->lines);
ULONG lastIndex = SizeOfArray(section->lines)-1;
//Printf("\n\SAD2 (%ld bytes avail)\n\n", AvailMem(0));
LineArrayValues(section->lines)[lastIndex] = abstractLine;
LineArrayAppend(section->lines, lastLine);
//Printf("\n\SAD3 (%ld bytes avail)\n\n", AvailMem(0));
LineArrayAppend(section->lines, abstractLine);
if(!LineIsEmpty(abstractLine) )
{
section->insertPos = SizeOfArray(section->lines);
printf("xx (%s) insertpos = %lu\n", SectionCanonicalName(abstractSection), section->insertPos);
LineDump(abstractLine);
printf("xx\n");
}
}
else
{
//Printf("\n\SAD4 (%ld bytes avail)\n\n", AvailMem(0));
LineArrayAppend(section->lines, abstractLine);
//Printf("\n\SAD5 (%ld bytes avail)\n\n", AvailMem(0));
LineArrayInsert(section->lines, abstractLine, section->insertPos);
section->insertPos += 1;
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);
VOID SectionFree(SECTIONPTR section);
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);
VOID SectionDump(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)
{
AppendToArray(LINEPTR, array, value);
// InsertToArray(LINEPTR, array, pos, value);
if( InsertArrayElements(array, pos, 1) )
{
LineArrayValues(array)[pos] = value;
}
else
{
printf("booooo\n");
}
}
VOID LineArrayFree(LineArray array, BOOL freeLines)

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

Loading…
Cancel
Save