SimpCfg: Keep compiler happy, also add newline wrt alt logging def

This commit is contained in:
HanishKVC 2024-04-28 12:34:57 +05:30
parent f4687fa5d4
commit aea6850131

View file

@ -16,7 +16,7 @@
#define TEST_LOGIC #define TEST_LOGIC
#ifdef TEST_LOGIC #ifdef TEST_LOGIC
#define LOG_TEELN(FMT, ...) printf(FMT, __VA_ARGS__) #define LOG_TEELN(FMT, ...) printf(FMT"\n", __VA_ARGS__)
#else #else
#include "log.h" #include "log.h"
#endif #endif
@ -50,13 +50,13 @@ std::string str_trim(std::string sin) {
return sin; return sin;
} }
bool sc_load(std::string &fname) { void sc_load(std::string &fname) {
std::ifstream f {fname}; std::ifstream f {fname};
if (!f) { if (!f) {
LOG_TEELN("ERRR:%s:%s:failed to load...", __func__, fname); LOG_TEELN("ERRR:%s:%s:failed to load...", __func__, fname.c_str());
throw std::runtime_error { "ERRR:SimpCfg:File not found" }; throw std::runtime_error { "ERRR:SimpCfg:File not found" };
} else { } else {
LOG_TEELN("DBUG:%s:%s", __func__, fname); LOG_TEELN("DBUG:%s:%s", __func__, fname.c_str());
} }
std::string group; std::string group;
int iLine = 0; int iLine = 0;
@ -74,24 +74,24 @@ bool sc_load(std::string &fname) {
curL = str_trim(curL); curL = str_trim(curL);
if (bGroup) { if (bGroup) {
group = curL; group = curL;
LOG_TEELN("DBUG:%s:%s:%s:%s", __func__, group); LOG_TEELN("DBUG:%s:%s", __func__, group.c_str());
continue; continue;
} }
auto dPos = curL.find(':'); auto dPos = curL.find(':');
if (dPos == std::string::npos) { if (dPos == std::string::npos) {
LOG_TEELN("ERRR:%s:%d:invalid key value line:%s", __func__, iLine, curL); LOG_TEELN("ERRR:%s:%d:invalid key value line:%s", __func__, iLine, curL.c_str());
throw std::runtime_error { "ERRR:SimpCfg:Invalid key value line" }; throw std::runtime_error { "ERRR:SimpCfg:Invalid key value line" };
} }
auto dEnd = curL.length() - dPos; auto dEnd = curL.length() - dPos;
if ((dPos == 0) || (dEnd < 2)) { if ((dPos == 0) || (dEnd < 2)) {
LOG_TEELN("ERRR:%s:%d:invalid key value line:%s", __func__, iLine, curL); LOG_TEELN("ERRR:%s:%d:invalid key value line:%s", __func__, iLine, curL.c_str());
throw std::runtime_error { "ERRR:SimpCfg:Invalid key value line" }; throw std::runtime_error { "ERRR:SimpCfg:Invalid key value line" };
} }
std::string key = curL.substr(0, dPos); std::string key = curL.substr(0, dPos);
key = str_trim(key); key = str_trim(key);
std::string value = curL.substr(dPos+1); std::string value = curL.substr(dPos+1);
value = str_trim(value); value = str_trim(value);
LOG_TEELN("DBUG:%s:%s:%s:%s", __func__, group, key, value); LOG_TEELN("DBUG:%s:%s:%s:%s", __func__, group.c_str(), key.c_str(), value.c_str());
sc_set_string(group, key, value); sc_set_string(group, key, value);
} }
} }