// Printf("running (%ld bytes avail)\n", AvailMem(0)); #define __CLIB_PRAGMA_LIBCALL #include #include #define __NOLIBBASE__ #include "containers/stringarray.h" #include "containers/linearray.h" #include "configfile.h" #include "configmodel.h" #include 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 = ConfigFileReadName(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); // 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 ) { StringArrayForEach(values, Printf("branch:[%s]\n",aString);); StringArrayFree(values, TRUE); } ConfigFileSaveOverwrite(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; }