read via a BPTR

main
Alan Francis 1 year ago
parent 411e982ac0
commit c151956370
  1. 35
      configfile.c
  2. 6
      configfile.h
  3. 2
      main.c
  4. 3
      testapp/configfile.h
  5. BIN
      testapp/containerkit.library
  6. 5
      testapp/main.c
  7. 23
      testapp/testconfig.cfg

@ -46,26 +46,39 @@ VOID ConfigFileFree(CONFIGFILEPTR abstractConfigFile)
}
}
CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename)
CONFIGFILEPTR ConfigFileReadName(CONST_STRPTR filename)
{
struct ConfigFile* result = NULL;
BPTR configFile = Open(filename, MODE_OLDFILE);
if( configFile != ZERO )
{
result = ConfigFileRead(configFile);
Close(configFile);
}
LINEPTR line = NULL;
result = AllocVec(sizeof(struct ConfigFile), MEMF_CLEAR);
result->sectionStore = SectionStoreNew();
result->filename = AllocVec(strlen(filename)+1, MEMF_CLEAR);
CopyMem(filename, result->filename, strlen(filename));
while( (line = configFileReadLine(configFile)) != NULL )
return result;
}
CONFIGFILEPTR ConfigFileRead(BPTR configFile)
{
struct ConfigFile* result = NULL;
LINEPTR line = NULL;
if( configFile != 0 )
{
UBYTE buffer[256];
if(NameFromFH(configFile, buffer, 256))// if we opened with a filename this is a waste, if not its necessary
{
SectionStoreAddLineToCurrentSection(result->sectionStore, line);
//LineDump(line);
result = AllocVec(sizeof(struct ConfigFile), MEMF_CLEAR);
result->sectionStore = SectionStoreNew();
result->filename = AllocVec(strlen(buffer)+1, MEMF_CLEAR);
CopyMem(buffer, result->filename, strlen(buffer));
while( (line = configFileReadLine(configFile)) != NULL )
{
SectionStoreAddLineToCurrentSection(result->sectionStore, line);
//LineDump(line);
}
}
Close(configFile);
}
return result;
}

@ -5,7 +5,11 @@
#include <proto/containerkit.h>
typedef APTR CONFIGFILEPTR;
CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename);
// added the BPTR version so we can use WorkspaceOpenFile.
// We still need a file name to be able to save though I should probably
// get that from the file
CONFIGFILEPTR ConfigFileRead(BPTR configFile);
CONFIGFILEPTR ConfigFileReadName(CONST_STRPTR filename);
VOID ConfigFileFree(CONFIGFILEPTR configFile);
Array ConfigFileGetAll(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey);

@ -22,7 +22,7 @@ WORD DoTheWork(STRPTR filename)
WORD result = RETURN_OK;
if (ContainerkitBase)
{
CONFIGFILEPTR config = ConfigFileRead(filename);
CONFIGFILEPTR config = ConfigFileReadName(filename);
if( config != NULL )
{
StringArray values = NULL;

@ -5,7 +5,8 @@
#include <proto/containerkit.h>
typedef APTR CONFIGFILEPTR;
CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename);
CONFIGFILEPTR ConfigFileRead(BPTR configFile, CONST_STRPTR saveName);
CONFIGFILEPTR ConfigFileReadName(CONST_STRPTR filename);
VOID ConfigFileFree(CONFIGFILEPTR configFile);
Array ConfigFileGetAll(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey);

Binary file not shown.

@ -12,7 +12,7 @@
WORD DoTheWork(STRPTR filename);
VOID ProcessFile(BPTR configFile);
char *vers="\0$VER: ConfigReader (dd.mm.yyyy)";
char *vers="\0$VER: testapp (dd.mm.yyyy)";
char *stacksize = "$STACK:8192"; // only works when started from CLI
struct Library *ContainerkitBase;
@ -22,7 +22,8 @@ WORD DoTheWork(STRPTR filename)
WORD result = RETURN_OK;
if (ContainerkitBase)
{
CONFIGFILEPTR config = ConfigFileRead(filename);
BPTR file = Open(filename, MODE_READWRITE);
CONFIGFILEPTR config = ConfigFileRead(file);
if( config != NULL )
{
Array values = NULL;

@ -1,4 +1,6 @@
#this is a comment
foo1 = alan
foo1 = alan
[core]
repositoryformatversion = 0
precomposeunicode = true
@ -8,13 +10,32 @@
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
remote = testing
merge = refs/heads/main
alan = yes
alan = no
alan = sure
second = testing
[branch "config-file-parsing-from-book"]
remote = origin
merge = refs/heads/config-file-parsing-from-book
[test]
foo1 = alan2
foo1 = alan2
[test "foo"]
foo1 = alan3
foo1 = alan3
[test "foo.bar"]
foo1 = alan4
foo1 = alan4
[test "foo.bar.baz"]
foo1 = alan5
foo1 = alan5
[test "foo.bar.baz.bat"]
foo1 = alan6
foo1 = alan6
[test "section.jane"]
foo3 = alan3
foo3 = alan3

Loading…
Cancel
Save