more on the sectionstore

main
Alan Francis 1 year ago
parent 663dab64ed
commit 7c4677feb4
  1. 25
      configmodel.c
  2. 9
      configmodel.h
  3. 2
      containers/sectionarray.h
  4. 32
      sectionstore.c
  5. 13
      sectionstore.h
  6. 14
      smakefile
  7. 14
      types.h

@ -109,7 +109,7 @@ CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename)
result->sectionStore = SectionStoreNew();
result->lines = LineArrayNew();
InitialisePatterns();
while( (line = LineReadIncludingContinuation(configFile, currentSection)) != NULL )
while( (line = LineReadIncludingContinuation(configFile, result->sectionStore, currentSection)) != NULL )
{
// add it to the flat list of lines
LineArrayAppend(result->lines, line);
@ -131,7 +131,7 @@ VOID ConfigFileSave(CONFIGFILEPTR config)
{
}
LINEPTR LineCreate(CONST_STRPTR buffer, ULONG size)
LINEPTR LineCreate(CONST_STRPTR buffer, ULONG size, SECTIONSTOREPTR sectionStore)
{
struct Line* result = NULL;
StringArray matches = NULL;
@ -144,13 +144,19 @@ LINEPTR LineCreate(CONST_STRPTR buffer, ULONG size)
if( matches = RunPattern(result->rawText, sectionPatternProgram) )
{
SECTIONPTR section = NULL;
if( SizeOfArray(matches) == 3 )
{
result->section = SectionCreateWithName(StringArrayValues(matches)[1]);
section = SectionCreateWithName(StringArrayValues(matches)[1]);
}
else if( SizeOfArray(matches) == 5 )
{
result->section = SectionCreateWithNameAndSubname(StringArrayValues(matches)[1], StringArrayValues(matches)[3]);
section = SectionCreateWithNameAndSubname(StringArrayValues(matches)[1], StringArrayValues(matches)[3]);
}
if( section != NULL )
{
SectionStoreAddSection(sectionStore, section);
result->section = section;
}
StringArrayFree(matches);
}
@ -217,7 +223,7 @@ VOID LineDump(LINEPTR abstractLine)
}
}
LINEPTR LineReadIncludingContinuation(BPTR file, SECTIONPTR currentSection)
LINEPTR LineReadIncludingContinuation(BPTR file, SECTIONSTOREPTR sectionStore, SECTIONPTR currentSection)
{
UBYTE* buffer = AllocVec(512, MEMF_CLEAR);
ULONG bufLength = 512;
@ -236,7 +242,7 @@ LINEPTR LineReadIncludingContinuation(BPTR file, SECTIONPTR currentSection)
// make a line
if( bytesReadTotal > 0 )
{
result = LineCreate(buffer, bytesReadTotal);
result = LineCreate(buffer, bytesReadTotal, sectionStore);
if( result->variable != NULL && result->section == NULL )
{
result->section = currentSection;
@ -276,12 +282,7 @@ VOID LineFree(LINEPTR abstractLine)
{
FreeVec(line->rawText);
}
if( line->section != NULL && line->variable == NULL )
{
//only free the section in a section line,
//not a variable line as thats just a weak ref
SectionFree(line->section);
}
// we dont free the section as its stored in the section store
if( line->variable != NULL )
{
VariableFree(line->variable);

@ -1,13 +1,8 @@
#ifndef __CONFIGMODEL_H
#define __CONFIGMODEL_H
#include <exec/types.h>
#include "types.h"
#include <dos/dos.h>
typedef APTR LINEPTR;
typedef APTR SECTIONPTR;
typedef APTR VARIABLEPTR;
typedef APTR CONFIGFILEPTR;
CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename);
VOID ConfigFileFree(CONFIGFILEPTR abstractConfigFile);
@ -16,7 +11,7 @@ VOID ConfigFileSave(CONFIGFILEPTR config);
VOID InitialisePatterns(VOID);
VOID ReleasePatterns(VOID);
LINEPTR LineReadIncludingContinuation(BPTR file, SECTIONPTR currentSection);
LINEPTR LineReadIncludingContinuation(BPTR file, SECTIONPTR currentSection, SECTIONSTOREPTR sectionStore);
VOID LineFree(LINEPTR abstractLine);
CONST_STRPTR LineGetRawText(LINEPTR line);

@ -7,7 +7,7 @@
#define SectionArray Array
SectionArray SectionArrayNew(VOID);
VOID SectionArrayAppend(SectionArray array, CONST_STRPTR value);
VOID SectionArrayAppend(SectionArray array, SECTIONPTR value);
VOID SectionArrayFree(SectionArray array);
SECTIONPTR* SectionArrayValues(SectionArray array);

@ -30,19 +30,29 @@ VOID SectionStoreFree(SECTIONSTOREPTR abstractSectionStore)
}
}
VOID SectionStoreAddSection(SECTIONPTR section)
{
}
VOID SectionStoreRemoveSection(SECTIONPTR section)
{
}
VOID SectionStoreRemoveSectionByName(CONST_STRPTR canonicalName)
VOID SectionStoreAddSection(SECTIONSTOREPTR abstractSectionStore, SECTIONPTR section)
{
struct SectionStore* store = (struct SectionStore*)abstractSectionStore;
if( store != NULL && section != NULL )
{
CONST_STRPTR canonicalName = SectionCanonicalName(section);
if( canonicalName != NULL )
{
// the array acts as storage as it can free its contents
SectionArrayAppend(store->array, section);
// the map will copy the string key and free it, but not the section
SectionMapSet(store->map, canonicalName, section);
//free the canonical name as the map has copied it.
FreeVec((STRPTR)canonicalName);
}
}
}
SECTIONPTR SectionStoreGetSection(CONST_STRPTR canonicalName)
SECTIONPTR SectionStoreGetSection(SECTIONSTOREPTR abstractSectionStore, CONST_STRPTR canonicalName)
{
return NULL;
struct SectionStore* store = (struct SectionStore*)abstractSectionStore;
if( store != NULL && canonicalName != NULL )
{
return SectionMapGet(store->map, canonicalName);
}
}

@ -1,18 +1,13 @@
#ifndef __SECTIONSTORE_H
#define __SECTIONSTORE_H
#include <exec/types.h>
#include "types.h"
typedef APTR SECTIONSTOREPTR;
SECTIONPTR SectionStoreGetSection(SECTIONSTOREPTR sectionStore, CONST_STRPTR canonicalName);
#include "configmodel.h"
VOID SectionStoreAddSection(SECTIONSTOREPTR sectionStore, SECTIONPTR section);
SECTIONSTOREPTR SectionStoreNew(VOID);
VOID SectionStoreFree(SECTIONSTOREPTR sectionStore);
VOID SectionStoreAddSection(SECTIONPTR section);
VOID SectionStoreRemoveSection(SECTIONPTR section);
VOID SectionStoreRemoveSectionByName(CONST_STRPTR canonicalName);
SECTIONPTR SectionStoreGetSection(CONST_STRPTR canonicalName);
VOID SectionStoreFree(SECTIONSTOREPTR sectionStore);
#endif

@ -29,15 +29,15 @@ cleanlibs:
###############################################################################
main.o : main.c
configmodel.o : configmodel.c configmodel.h
sectionstore.o : sectionstore.c sectionstore.h
configmodel.o : configmodel.c configmodel.h types.h
sectionstore.o : sectionstore.c sectionstore.h types.h
cregex/cregex_compile.o : cregex/cregex_compile.c cregex/cregex.h
cregex/cregex_parse.o : cregex/cregex_parse.c cregex/cregex.h
cregex/cregex_vm.o : cregex/cregex_vm.c cregex/cregex.h
containers/stringarray.o : containers/stringarray.c containers/stringarray.h
containers/linearray.o : containers/linearray.c containers/linearray.h
containers/linemap.o : containers/linemap.c containers/linemap.h
containers/sectionarray.o : containers/sectionarray.c containers/sectionarray.h
containers/sectionmap.o : containers/sectionmap.c containers/sectionmap.h
containers/stringarray.o : containers/stringarray.c containers/stringarray.h types.h
containers/linearray.o : containers/linearray.c containers/linearray.h types.h
containers/linemap.o : containers/linemap.c containers/linemap.h types.h
containers/sectionarray.o : containers/sectionarray.c containers/sectionarray.h types.h
containers/sectionmap.o : containers/sectionmap.c containers/sectionmap.h types.h

@ -0,0 +1,14 @@
#ifndef __TYPES_H
#define __TYPES_H
#include <exec/types.h>
typedef APTR LINEPTR;
typedef APTR SECTIONPTR;
typedef APTR VARIABLEPTR;
typedef APTR CONFIGFILEPTR;
typedef APTR SECTIONSTOREPTR;
#endif
Loading…
Cancel
Save