From ff643dd314e19007c6050738315fa3a5efd83adc Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 15 Feb 2024 16:30:54 -0500 Subject: [PATCH] Added cfg. file parsing. --- src/proj/main.cfg | 3 +++ src/proj/main.cpp | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/proj/main.cfg diff --git a/src/proj/main.cfg b/src/proj/main.cfg new file mode 100644 index 0000000..20077e7 --- /dev/null +++ b/src/proj/main.cfg @@ -0,0 +1,3 @@ +{ + param: "hello" +} \ No newline at end of file diff --git a/src/proj/main.cpp b/src/proj/main.cpp index ba18a08..e7e7f37 100644 --- a/src/proj/main.cpp +++ b/src/proj/main.cpp @@ -1,6 +1,10 @@ #include "cwCommon.h" #include "cwLog.h" #include "cwCommonImpl.h" +#include "cwText.h" +#include "cwObject.h" + +using namespace cw; void print( void* arg, const char* text ) { @@ -9,10 +13,37 @@ void print( void* arg, const char* text ) int main( int argc, char* argv[] ) { + rc_t rc = kOkRC; + object_t* cfg = nullptr; cw::log::createGlobal(); - cwLogInfo("Project template"); + cwLogInfo("Project template: args:%i", argc); + if( argc < 2 || textLength(argv[1])==0 ) + { + cwLogError(kInvalidArgRC,"No cfg. file was given."); + goto errLabel; + } + else + { + const char* val = nullptr; + + if((rc = objectFromFile(argv[1],cfg)) != kOkRC ) + { + cwLogError(rc,"The file '%s'.",argv[1]); + goto errLabel; + } + + if((rc = cfg->getv("param",val)) != kOkRC ) + { + cwLogError(kSyntaxErrorRC,"The 'param' cfg. field was not found."); + goto errLabel; + } + + cwLogInfo("param=%s",cwStringNullGuard(val)); + } + +errLabel: cw::log::destroyGlobal(); return 0;