You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
configreader/main.c

77 lines
1.9 KiB

// 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 "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;
STRPTR joined = NULL;
if (ContainerkitBase)
{
CONFIGFILEPTR config = ConfigFileRead(filename);
if( config != NULL )
{
StringArray 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);
ConfigFileAdd(config, "branch.alan.foob", "bar");
// ConfigFileDump(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;
}