restructure

main
Alan Francis 1 year ago
parent 30b093f985
commit 69fa45e1ba
  1. 7
      arraytypes/linearray.c
  2. 2
      arraytypes/linearray.h
  3. 0
      arraytypes/stringarray.c
  4. 0
      arraytypes/stringarray.h
  5. 53
      configmodel.c
  6. 6
      configmodel.h
  7. 0
      cregex/cregex.h
  8. 0
      cregex/cregex_compile.c
  9. 0
      cregex/cregex_parse.c
  10. 0
      cregex/cregex_vm.c
  11. 19
      main.c
  12. 31
      smakefile

@ -20,9 +20,12 @@ VOID LineArrayAppend(LineArray array, LINEPTR value)
AppendToArray(LINEPTR, array, value);
}
VOID LineArrayFree(LineArray array)
VOID LineArrayFree(LineArray array, BOOL freeLines)
{
ArrayForEach(LINEPTR, aLine, array, LineFree(aLine););
if( freeLines )
{
ArrayForEach(LINEPTR, aLine, array, LineFree(aLine););
}
DeleteArray(array);
}

@ -10,7 +10,7 @@
LineArray LineArrayNew(VOID);
VOID LineArrayAppend(LineArray array, LINEPTR value);
VOID LineArrayFree(LineArray array);
VOID LineArrayFree(LineArray array, BOOL freeLines);
LINEPTR* LineArrayValues(LineArray array);
#endif

@ -1,13 +1,16 @@
#include "configmodel.h"
#include "cregex.h"
#include "stringarray.h"
#include "cregex/cregex.h"
#include "arraytypes/stringarray.h"
#include "arraytypes/linearray.h"
#include <proto/exec.h>
#include <proto/dos.h>
#include <string.h>
#include <stdio.h>
#define ZERO ((BPTR)0)
cregex_program_t* InitialisePattern(CONST_STRPTR pattern);
Array RunPattern(CONST_STRPTR text, cregex_program_t* patternProgram);
@ -23,9 +26,16 @@ STATIC cregex_program_t* variablePatternProgram = NULL;
STATIC cregex_program_t* blankPatternProgram = NULL;
STATIC cregex_program_t* integerPatternProgram = NULL;
struct ConfigFile
{
CONST_STRPTR filename;
LineArray lines;
};
struct Section
{
StringArray names;
StringArray nameComponents;
LineArray lines;
};
enum VariableType
@ -58,6 +68,43 @@ struct Line
object;
};
VOID ConfigFileFree(CONFIGFILEPTR abstractConfigFile)
{
struct ConfigFile* configFile = (struct ConfigFile*)abstractConfigFile;
if( configFile != NULL )
{
if( configFile->lines != NULL )
{
LineArrayFree(configFile->lines, TRUE); //also frees lines
}
FreeVec(configFile);
}
}
CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename)
{
struct ConfigFile* result = AllocVec(sizeof(struct ConfigFile), MEMF_CLEAR);
BPTR configFile = Open(filename, MODE_OLDFILE);
if( configFile != ZERO )
{
LINEPTR line = NULL;
result->lines = LineArrayNew();
InitialisePatterns();
while( (line = LineReadIncludingContinuation(configFile)) != NULL )
{
// Printf("successfully read line {%s}\n", LineGetRawText(line));
LineArrayAppend(result->lines, line);
}
ReleasePatterns();
Close(configFile);
}
return result;
}
VOID ConfigFileSave(CONFIGFILEPTR config);
VOID InitialisePatterns(VOID)
{
sectionPatternProgram = InitialisePattern(RX_SECTION_LINE);

@ -6,6 +6,12 @@
typedef APTR LINEPTR;
typedef APTR SECTIONPTR;
typedef APTR VARIABLEPTR;
typedef APTR CONFIGFILEPTR;
CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename);
VOID ConfigFileFree(CONFIGFILEPTR abstractConfigFile);
VOID ConfigFileSave(CONFIGFILEPTR config);
VOID InitialisePatterns(VOID);
VOID ReleasePatterns(VOID);

@ -3,15 +3,11 @@
#include <proto/exec.h>
#include <proto/dos.h>
#define __NOLIBBASE__
#include "stringarray.h"
#include "linearray.h"
#include "arraytypes/stringarray.h"
#include "arraytypes/linearray.h"
#include "configmodel.h"
#include <proto/containerkit.h>
#include "cregex.h"
#define ZERO ((BPTR)0)
WORD DoTheWork(STRPTR filename);
VOID ProcessFile(BPTR configFile);
@ -34,7 +30,7 @@ VOID ProcessFile(BPTR configFile)
LineArrayAppend(lineArray, line);
line = LineReadIncludingContinuation(configFile);
}
LineArrayFree(lineArray);
LineArrayFree(lineArray, TRUE);
ReleasePatterns();
}
@ -43,16 +39,13 @@ WORD DoTheWork(STRPTR filename)
WORD result = RETURN_OK;
if (ContainerkitBase)
{
BPTR configFile = ZERO;
configFile = Open(filename, MODE_OLDFILE);
if( configFile != ZERO )
CONFIGFILEPTR config = ConfigFileRead(filename);
if( config != NULL )
{
ProcessFile(configFile);
Close(configFile);
ConfigFileFree(config);
}
else
{
Printf("file open failed!\n");
result = RETURN_ERROR;
}
}

@ -11,24 +11,29 @@ LIBS = lib:sc.lib lib:amiga.lib lib:debug.lib
###############################################################################
$(NAME) : main.o configmodel.o cregex.lib arraytypes.lib
slink lib:c.o main.o configmodel.o to $(NAME) noicons lib $(LIBS) cregex.lib arraytypes.lib $(LFLAGS)
$(NAME) : main.o configmodel.o cregex/cregex.lib arraytypes/arraytypes.lib
slink lib:c.o main.o configmodel.o to $(NAME) noicons lib $(LIBS) cregex/cregex.lib arraytypes/arraytypes.lib $(LFLAGS)
cregex.lib : cregex_compile.o cregex_parse.o cregex_vm.o
JOIN cregex_compile.o cregex_parse.o cregex_vm.o AS cregex.lib
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
arraytypes.lib : stringarray.o linearray.o
JOIN stringarray.o linearray.o AS arraytypes.lib
arraytypes/arraytypes.lib : arraytypes/stringarray.o arraytypes/linearray.o
JOIN arraytypes/stringarray.o arraytypes/linearray.o AS arraytypes/arraytypes.lib
clean:
delete \#?.o \#?.lib $(NAME) ALL
delete \#?.o $(NAME) ALL QUIET
cleanlibs:
delete arraytypes/arraytypes.lib arraytypes/\#?.o cregex/cregex.lib cregex/\#?.o ALL QUIET
###############################################################################
main.o : main.c stringarray.h
stringarray.o : stringarray.c stringarray.h
linearray.o : linearray.c linearray.h
main.o : main.c
configmodel.o : configmodel.c configmodel.h
cregex_compile.o : cregex_compile.c cregex.h
cregex_parse.o : cregex_parse.c cregex.h
cregex_vm.o : cregex_vm.c cregex.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
arraytypes/stringarray.o : arraytypes/stringarray.c arraytypes/stringarray.h
arraytypes/linearray.o : arraytypes/linearray.c arraytypes/linearray.h

Loading…
Cancel
Save