Make a section store to hold the sections and map to string

main
Alan Francis 1 year ago
parent a97e790238
commit 0caf66875c
  1. 9
      configmodel.c
  2. 8
      configmodel.h
  3. 2
      containers/linemap.h
  4. 28
      containers/sectionarray.c
  5. 17
      containers/sectionarray.h
  6. 45
      containers/sectionmap.c
  7. 14
      containers/sectionmap.h
  8. 1
      containers/stringarray.c
  9. 48
      sectionstore.c
  10. 18
      sectionstore.h
  11. 11
      smakefile

@ -1,4 +1,5 @@
#include "configmodel.h"
#include "sectionstore.h"
#include "cregex/cregex.h"
#include "containers/stringarray.h"
@ -43,6 +44,7 @@ struct ConfigFile
{
CONST_STRPTR filename;
LineArray lines;
SECTIONSTOREPTR sectionStore;
};
struct Section
@ -88,6 +90,10 @@ VOID ConfigFileFree(CONFIGFILEPTR abstractConfigFile)
{
LineArrayFree(configFile->lines, TRUE); //also frees lines
}
if( configFile->sectionStore != NULL )
{
SectionStoreFree(configFile->sectionStore);
}
FreeVec(configFile);
}
}
@ -99,7 +105,8 @@ CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename)
if( configFile != ZERO )
{
LINEPTR line = NULL;
SECTIONPTR currentSection = NULL;
SECTIONPTR currentSection = NULL;//SectionCreateWithName(""); // initial empty section
result->sectionStore = SectionStoreNew();
result->lines = LineArrayNew();
InitialisePatterns();
while( (line = LineReadIncludingContinuation(configFile, currentSection)) != NULL )

@ -19,4 +19,12 @@ VOID ReleasePatterns(VOID);
LINEPTR LineReadIncludingContinuation(BPTR file, SECTIONPTR currentSection);
VOID LineFree(LINEPTR abstractLine);
CONST_STRPTR LineGetRawText(LINEPTR line);
SECTIONPTR SectionCreateWithName(CONST_STRPTR primary);
SECTIONPTR SectionCreateWithNameAndSubname(CONST_STRPTR primary, CONST_STRPTR secondary);
VOID SectionFree(SECTIONPTR abstractSection);
VARIABLEPTR VariableCreate(CONST_STRPTR key, CONST_STRPTR rawValue);
VOID VariableFree(VARIABLEPTR abstractVariable);
#endif

@ -8,6 +8,6 @@
#define LineMap Map
LineMap LineMapNew(VOID);
VOID LineMapFree(LineMap map);
#endif

@ -0,0 +1,28 @@
#include "sectionarray.h"
#include <proto/exec.h>
#include <string.h>
Array SectionArrayNew(VOID)
{
#define SIZE_STRPTR 2
return NewArray(SIZE_STRPTR);
}
VOID SectionArrayAppend(SectionArray array, SECTIONPTR value)
{
AppendToArray(CONST_STRPTR, array, value);
}
VOID SectionArrayFree(SectionArray array)
{
if( array != NULL )
{
SectionArrayForEach(array, SectionFree(aSection););
DeleteArray(array);
}
}
SECTIONPTR* SectionArrayValues(SectionArray array)
{
return ArrayValues(SECTIONPTR, array);
}

@ -0,0 +1,17 @@
#ifndef __SECTIONARRAY_H
#define __SECTIONARRAY_H
#include <exec/types.h>
#include <proto/containerkit.h>
#include "configmodel.h"
#define SectionArray Array
SectionArray SectionArrayNew(VOID);
VOID SectionArrayAppend(SectionArray array, CONST_STRPTR value);
VOID SectionArrayFree(SectionArray array);
SECTIONPTR* SectionArrayValues(SectionArray array);
#define SectionArrayForEach(array, block) do {SECTIONPTR *afe_123_p = (*(SECTIONPTR **)array); SECTIONPTR aSection = *afe_123_p; int afe_123_c = (((ULONG *)array)[1]);\
for (; afe_123_c--; aSection = *(++afe_123_p)) block} while (0);
#endif

@ -0,0 +1,45 @@
#include "sectionmap.h"
#include "configmodel.h"
SectionMap SectionMapNew()
{
SectionMap result = NewMap(CNTKIT_KEY_STRING,
CNTKIT_CAPACITY, 8,
CNTKIT_VALUESIZE, 4,
TAG_DONE);
return result;
}
VOID SectionMapSet(SectionMap map, CONST_STRPTR canonicalName, SECTIONPTR section)
{
if( canonicalName != NULL )
{
if( section == NULL )
{
RemoveStrKey(map, (STRPTR)canonicalName);
}
else
{
MapStrToValue(map, (STRPTR)canonicalName, (ULONG)section);
}
}
}
SECTIONPTR SectionMapGet(SectionMap map, CONST_STRPTR canonicalName)
{
if( canonicalName != NULL )
{
return (SECTIONPTR)ValueOfStrKey(map, (STRPTR)canonicalName);
}
else
{
return NULL;
}
}
VOID SectionMapFree(SectionMap map)
{
// doesnt seem to delete contents
DeleteMap(map);
}

@ -0,0 +1,14 @@
#ifndef __SECTIONMAP_H
#define __SECTIONMAP_H
#include <exec/types.h>
#include <proto/containerkit.h>
#include "configmodel.h"
#define SectionMap Map // a map of string (canonical name) to Section
SectionMap SectionMapNew(VOID);
VOID SectionMapSet(SectionMap map, CONST_STRPTR canonicalName, SECTIONPTR section);
SECTIONPTR SectionMapGet(SectionMap map, CONST_STRPTR canonicalName);
VOID SectionMapFree(SectionMap map);
#endif

@ -1,4 +1,5 @@
#include "stringarray.h"
#include "configmodel.h"
#include <proto/exec.h>
#include <string.h>

@ -0,0 +1,48 @@
#include "sectionstore.h"
#include "containers/sectionmap.h"
#include "containers/sectionarray.h"
#include <proto/exec.h>
struct SectionStore
{
SectionMap map;
SectionArray array;
};
SECTIONSTOREPTR SectionStoreNew(VOID)
{
struct SectionStore* result = AllocVec(sizeof(struct SectionStore), MEMF_CLEAR);
result->map = SectionMapNew();
result->array = SectionArrayNew();
return result;
}
VOID SectionStoreFree(SECTIONSTOREPTR abstractSectionStore)
{
if( abstractSectionStore != NULL )
{
struct SectionStore* store = (struct SectionStore*)abstractSectionStore;
if( store->map != NULL ) SectionMapFree( store->map );
if( store->array != NULL ) SectionArrayFree( store->array );
FreeVec(store);
}
}
VOID SectionStoreAddSection(SECTIONPTR section)
{
}
VOID SectionStoreRemoveSection(SECTIONPTR section)
{
}
VOID SectionStoreRemoveSectionByName(CONST_STRPTR canonicalName)
{
}
SECTIONPTR SectionStoreGetSection(CONST_STRPTR canonicalName)
{
return NULL;
}

@ -0,0 +1,18 @@
#ifndef __SECTIONSTORE_H
#define __SECTIONSTORE_H
#include <exec/types.h>
typedef APTR SECTIONSTOREPTR;
#include "configmodel.h"
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);
#endif

@ -11,14 +11,14 @@ LIBS = lib:sc.lib lib:amiga.lib lib:debug.lib
###############################################################################
$(NAME) : main.o configmodel.o cregex/cregex.lib containers/containers.lib
slink lib:c.o main.o configmodel.o to $(NAME) noicons lib $(LIBS) cregex/cregex.lib containers/containers.lib $(LFLAGS)
$(NAME) : main.o configmodel.o sectionstore.o cregex/cregex.lib containers/containers.lib
slink lib:c.o main.o configmodel.o sectionstore.o to $(NAME) noicons lib $(LIBS) cregex/cregex.lib containers/containers.lib $(LFLAGS)
cregex/cregex.lib : cregex/cregex_compile.o cregex/cregex_parse.o cregex/cregex_vm.o
JOIN cregex/cregex_compile.o cregex/cregex_parse.o cregex/cregex_vm.o AS cregex/cregex.lib
containers/containers.lib : containers/stringarray.o containers/linearray.o containers/linemap.o
JOIN containers/stringarray.o containers/linearray.o containers/linemap.o AS containers/containers.lib
containers/containers.lib : containers/stringarray.o containers/linearray.o containers/linemap.o containers/sectionarray.o containers/sectionmap.o
JOIN containers/stringarray.o containers/linearray.o containers/linemap.o containers/sectionarray.o containers/sectionmap.o AS containers/containers.lib
clean:
delete \#?.o $(NAME) ALL QUIET
@ -30,6 +30,7 @@ cleanlibs:
main.o : main.c
configmodel.o : configmodel.c configmodel.h
sectionstore.o : sectionstore.c sectionstore.h
cregex/cregex_compile.o : cregex/cregex_compile.c cregex/cregex.h
cregex/cregex_parse.o : cregex/cregex_parse.c cregex/cregex.h
@ -38,3 +39,5 @@ 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

Loading…
Cancel
Save