diff --git a/README.md b/README.md index b537f45..2b215d7 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,8 @@ of this app can be used to operate multiple cameras. Usage: mow -h : display usage information about this application. - -c : path to the config file(s). + -c : path to the config file. -v : display the current version. - -note: multiple -c config files can be passed, reading from left - to right. any conflicting values between the files will - have the latest value from the latest file overwrite the - the earliest. ``` ### Config File ### diff --git a/src/common.cpp b/src/common.cpp index efa92b7..82ac2f6 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -193,7 +193,7 @@ void rdLine(const string ¶m, const string &line, string *value) { if (line.rfind(param.c_str(), 0) == 0) { - *value = line.substr(param.size()); + *value = trim(line).substr(param.size()); } } @@ -201,7 +201,7 @@ void rdLine(const string ¶m, const string &line, int *value) { if (line.rfind(param.c_str(), 0) == 0) { - *value = strtol(line.substr(param.size()).c_str(), NULL, 10); + *value = strtol(trim(line).substr(param.size()).c_str(), NULL, 10); } } @@ -213,7 +213,7 @@ bool rdConf(const string &filePath, shared_t *share) { share->retCode = ENOENT; - cout << "wrn: config file: " << filePath << " does not exists or lack read permissions." << endl; + cerr << "err: config file: " << filePath << " does not exists or lack read permissions." << endl; } else { @@ -284,18 +284,11 @@ bool rdConf(shared_t *share) share->detSuffix = ".det."; share->recSuffix = ".rec."; - auto ret = false; - - for (auto &&confPath: share->conf) - { - if (rdConf(confPath, share)) ret = true; - } - - if (ret) + if (rdConf(share->conf, share)) { if (share->camName.empty()) { - share->camName = path(share->conf.back()).filename(); + share->camName = path(share->conf).filename(); } if (share->detectUrl.empty()) @@ -307,7 +300,6 @@ bool rdConf(shared_t *share) share->buffDir = cleanDir(share->buffDir) + "/" + share->camName; share->recLogPath = share->outDir + "/rec_log_lines.html"; share->detLogPath = share->outDir + "/det_log_lines.html"; - share->vidExt = trim(share->vidExt); share->detSuffix += share->vidExt; share->recSuffix += share->vidExt; @@ -324,43 +316,33 @@ bool rdConf(shared_t *share) createDirTree(cleanDir(share->buffDir)); createDirTree(share->outDir); } - else - { - cerr << "err: none of the expected config files could be read." << endl; - } - return ret; + return share->retCode == 0; } -vector parseForList(const string &arg, int argc, char** argv, bool argOnly, int count) +string parseForParam(const string &arg, int argc, char** argv, bool argOnly, int &offs) { - auto argPresent = false; - auto argCount = 0; - auto ret = vector(); + auto ret = string(); - for (auto i = 1; i < argc; ++i) + for (; offs < argc; ++offs) { - auto argInParams = string(argv[i]); + auto argInParams = string(argv[offs]); - if (argPresent) + if (arg.compare(argInParams) == 0) { - ret.push_back(argInParams); - - argPresent = false; - } - else if (arg.compare(argInParams) == 0) - { - argPresent = true; argCount++; - } - - if (argPresent && argOnly) - { - ret.push_back(string("true")); - } - - if (count != 0) - { - if (argCount >= count) break; + if (!argOnly) + { + offs++; + // check ahead, make sure offs + 1 won't cause out-of-range exception + if (offs <= (argc - 1)) + { + ret = string(argv[offs]); + } + } + else + { + ret = string("true"); + } } } @@ -369,16 +351,9 @@ vector parseForList(const string &arg, int argc, char** argv, bool argOn string parseForParam(const string &arg, int argc, char** argv, bool argOnly) { - auto params = parseForList(arg, argc, argv, argOnly, 1); + auto notUsed = 0; - if (params.empty()) - { - return string(); - } - else - { - return params[0]; - } + return parseForParam(arg, argc, argv, argOnly, notUsed); } void waitForDetThreads(shared_t *share) diff --git a/src/common.h b/src/common.h index 6a8f058..e10c01d 100644 --- a/src/common.h +++ b/src/common.h @@ -37,16 +37,16 @@ using namespace cv; using namespace std; using namespace std::filesystem; -#define APP_VER "1.6.t5" +#define APP_VER "1.6.t6" #define APP_NAME "Motion Watch" #define TRIM_REMOVE " \n\r\t\f\v." struct shared_t { vector detThreads; - vector conf; ofstream recLogFile; ofstream detLogFile; + string conf; string recLogPath; string detLogPath; string recordUrl; @@ -93,6 +93,7 @@ string trim(const string &str); string genDstFile(const string &dirOut, const char *fmt, const string &ext); string genTimeStr(const char *fmt); string cleanDir(const string &path); +string parseForParam(const string &arg, int argc, char** argv, bool argOnly, int &offs); string parseForParam(const string &arg, int argc, char** argv, bool argOnly); bool createDir(const string &dir); bool createDirTree(const string &full_path); @@ -103,7 +104,6 @@ void rdLine(const string ¶m, const string &line, int *value); void statOut(shared_t *share); void waitForDetThreads(shared_t *share); bool rdConf(shared_t *share); -vector parseForList(const string &arg, int argc, char** argv, bool argOnly = false, int count = 0); vector lsFilesInDir(const string &path, const string &ext = string()); vector lsDirsInDir(const string &path); diff --git a/src/main.cpp b/src/main.cpp index 6e39e18..f14c49d 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -267,19 +267,15 @@ int main(int argc, char** argv) sigaction(SIGFPE, &act, NULL); sigaction(SIGBUS, &act, NULL); - sharedRes.conf = parseForList("-c", argc, argv); + sharedRes.conf = parseForParam("-c", argc, argv, false); if (parseForParam("-h", argc, argv, true) == "true") { cout << "Motion Watch " << APP_VER << endl << endl; cout << "Usage: mow " << endl << endl; cout << "-h : display usage information about this application." << endl; - cout << "-c : path to a config file." << endl; + cout << "-c : path to the config file." << endl; cout << "-v : display the current version." << endl << endl; - cout << "note: multiple -c config files can be passed, reading from left" << endl; - cout << " to right. any conflicting values between the files will" << endl; - cout << " have the latest value from the latest file overwrite the" << endl; - cout << " the earliest." << endl; } else if (parseForParam("-v", argc, argv, true) == "true") { @@ -287,7 +283,7 @@ int main(int argc, char** argv) } else if (sharedRes.conf.empty()) { - cerr << "err: no config file(s) were given in -c" << endl; + cerr << "err: config file not given in -c" << endl; } else {