try a wee separate app using the lib and header

main
Alan Francis 1 year ago
parent 54abd7eb68
commit 411e982ac0
  1. 36
      testapp/configfile.h
  2. 102
      testapp/main.c
  3. 22
      testapp/smakefile
  4. BIN
      testapp/testapp
  5. 20
      testapp/testconfig.cfg

@ -0,0 +1,36 @@
#ifndef __CONFIGFILE_H
#define __CONFIGFILE_H
#include <exec/types.h>
#include <dos/dos.h>
#include <proto/containerkit.h>
typedef APTR CONFIGFILEPTR;
CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename);
VOID ConfigFileFree(CONFIGFILEPTR configFile);
Array ConfigFileGetAll(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey);
STRPTR ConfigFileGet(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey);
BOOL ConfigFileSet(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey, CONST_STRPTR stringValue);
// --add
VOID ConfigFileAddVariable(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey, CONST_STRPTR stringValue);
// --replace-all
VOID ConfigFileReplaceAll(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey, CONST_STRPTR stringValue);
// --unset
VOID ConfigFileUnset(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey, CONST_STRPTR stringValue);
// --unset-all
VOID ConfigFileUnsetAll(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey, CONST_STRPTR stringValue);
// --remove-section
VOID ConfigFileRemoveSection(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR canonicalName);
VOID ConfigFileDump(CONFIGFILEPTR configFile);
VOID ConfigFileSave(CONFIGFILEPTR configFile);
VOID ConfigFileWrite(CONFIGFILEPTR abstractConfigFile, BPTR file);
Array ConfigFileSubsectionsForSection(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR primarySection);
#endif

@ -0,0 +1,102 @@
// Printf("running (%ld bytes avail)\n", AvailMem(0));
#define __CLIB_PRAGMA_LIBCALL
#include <proto/exec.h>
#include <proto/dos.h>
#define __NOLIBBASE__
// #include "containers/stringarray.h"
// #include "containers/linearray.h"
#include "configfile.h"
//#include "configmodel.h"
#include <proto/containerkit.h>
WORD DoTheWork(STRPTR filename);
VOID ProcessFile(BPTR configFile);
char *vers="\0$VER: ConfigReader (dd.mm.yyyy)";
char *stacksize = "$STACK:8192"; // only works when started from CLI
struct Library *ContainerkitBase;
WORD DoTheWork(STRPTR filename)
{
WORD result = RETURN_OK;
if (ContainerkitBase)
{
CONFIGFILEPTR config = ConfigFileRead(filename);
if( config != NULL )
{
Array values = NULL;
STRPTR var = NULL;
// values = ConfigFileGetAll(config, "branch.main.remote");
// StringArrayForEach(values, Printf("main %s\n", aString););
// StringArrayFree(values, TRUE);
// var = ConfigFileGet(config, "branch.config-file-parsing-from-book.remote");
// Printf("parse %s\n\n\n", var);
// FreeVec(var);
// ConfigFileDump(config);
// ConfigFileSet(config, "branch.main.foob", "bar");
// ConfigFileSet(config, "branch.alan.foob", "bar");
ConfigFileSet(config, "branch.main.remote", "testing");
ConfigFileSet(config, "branch.main.second", "testing");
// ConfigFileSet(config, "branch.main.third", "testing");
// ConfigFileReplaceAll(config, "branch.main.alan", "hello");
// ConfigFileAddVariable(config, "branch.main.newvar", "alan");
// ConfigFileAddVariable(config, "branch.main.newvar", "alan2");
// ConfigFileAddVariable(config, "branch.main.newvar", "alan3");
// ConfigFileReplaceAll(config, "branch.main.newvar", "goodbye");
// ConfigFileAddVariable(config, "branch.main.newvar1", "yay");
ConfigFileAddVariable(config, "foo1", "alan");
ConfigFileAddVariable(config, "test.foo1", "alan2");
ConfigFileAddVariable(config, "test.foo.foo1", "alan3");
ConfigFileAddVariable(config, "test.foo.bar.foo1", "alan4");
ConfigFileAddVariable(config, "test.foo.bar.baz.foo1", "alan5");
ConfigFileAddVariable(config, "test.foo.bar.baz.bat.foo1", "alan6");
ConfigFileAddVariable(config, "test.section.jane.foo3", "alan3");
values = ConfigFileSubsectionsForSection(config, "branch");
if( values )
{
ArrayForEach(STRPTR, aString, values, Printf("branch:[%s]\n",aString););
ArrayForEach(STRPTR, aString, values, FreeVec(aString););
DeleteArray(values);
}
ConfigFileSave(config);
ConfigFileFree(config);
}
else
{
Printf("could not read the file\n");
result = RETURN_ERROR;
}
}
return result;
}
WORD main(WORD argc, STRPTR *argv)
{
WORD result = RETURN_OK;
// this does nothing but the first call to Print drops a bunch of memory,
// I assume because of opening some resource so this means my start and
// end markers are "clean" and I can ensure I'm not leaking.
Printf("\n");
ContainerkitBase = OpenLibrary("containerkit.library", 1);
if( ContainerkitBase )
{
Printf("\n\nrunning (%ld bytes avail)\n\n", AvailMem(0));
result = DoTheWork(argv[1]);
Printf("\n\ndone (%ld bytes avail)\n\n", AvailMem(0));
CloseLibrary(ContainerkitBase);
}
else
{
Printf("failed to open library\n");
result = RETURN_ERROR;
}
return result;
}

@ -0,0 +1,22 @@
#
# :ts=8
#
###############################################################################
NAME = testapp
LFLAGS = addsym smallcode smalldata noicons batch
LIBS = lib:sc.lib lib:amiga.lib lib:debug.lib
###############################################################################
$(NAME) : main.o configfile.lib configfile.h
slink lib:c.o main.o to $(NAME) noicons lib $(LIBS) configfile.lib $(LFLAGS)
clean:
delete \#?.o $(NAME) ALL QUIET
###############################################################################
main.o : main.c

Binary file not shown.

@ -0,0 +1,20 @@
#this is a comment
[core]
repositoryformatversion = 0
precomposeunicode = true
[remote "origin.foo"] #this is also a coment
url = git@git.alancfrancis.com:acf/AmigaGit2.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
alan = yes
alan = no
alan = sure
[branch "config-file-parsing-from-book"]
remote = origin
merge = refs/heads/config-file-parsing-from-book
Loading…
Cancel
Save