From c15195637056690c641ab14feb60094b2f3b4c49 Mon Sep 17 00:00:00 2001 From: Alan C Francis Date: Thu, 4 Jan 2024 21:04:59 +0000 Subject: [PATCH] read via a BPTR --- configfile.c | 35 ++++++++++++++++++++++++----------- configfile.h | 6 +++++- main.c | 2 +- testapp/configfile.h | 3 ++- testapp/containerkit.library | Bin 0 -> 4272 bytes testapp/main.c | 5 +++-- testapp/testconfig.cfg | 23 ++++++++++++++++++++++- 7 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 testapp/containerkit.library diff --git a/configfile.c b/configfile.c index 2edd781..269eb97 100644 --- a/configfile.c +++ b/configfile.c @@ -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; } diff --git a/configfile.h b/configfile.h index 265bc4a..29c39e9 100644 --- a/configfile.h +++ b/configfile.h @@ -5,7 +5,11 @@ #include 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); diff --git a/main.c b/main.c index e49ac19..00f5144 100644 --- a/main.c +++ b/main.c @@ -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; diff --git a/testapp/configfile.h b/testapp/configfile.h index 265bc4a..e988f47 100644 --- a/testapp/configfile.h +++ b/testapp/configfile.h @@ -5,7 +5,8 @@ #include 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); diff --git a/testapp/containerkit.library b/testapp/containerkit.library new file mode 100644 index 0000000000000000000000000000000000000000..1bcac3fc1ad68c299dc3610fda833e5a3dfd1fa0 GIT binary patch literal 4272 zcmb7I4QvzF9si$wa}LK;*UZXH6_LmFa6QM^BxMoWBK2&d=ISJFh_g18s?Jcb!x|DV zODZZMbdDenFeLNUkBL=nRiUaC5URD(DpmzlRdjSy_}IoY1WmyW&}B%hs@5op_j`Aj z1p1+EC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c b/testapp/main.c index b9b8f49..6dcf0d8 100644 --- a/testapp/main.c +++ b/testapp/main.c @@ -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; diff --git a/testapp/testconfig.cfg b/testapp/testconfig.cfg index 367d98b..b73753d 100644 --- a/testapp/testconfig.cfg +++ b/testapp/testconfig.cfg @@ -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