diff --git a/src/common.cpp b/src/common.cpp index 9f51039..39df460 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -282,29 +282,35 @@ bool rdConf(shared_t *share) return ret; } -string parseForParam(const string &arg, int argc, char** argv, bool argOnly, int &offs) +vector parseForList(const string &arg, int argc, char** argv, bool argOnly, int count) { - auto ret = string(); + auto argPresent = false; + auto argCount = 0; + auto ret = vector(); - for (; offs < argc; ++offs) + for (auto i = 0; i < argc; ++i) { - auto argInParams = string(argv[offs]); + auto argInParams = string(argv[i]); - if (arg.compare(argInParams) == 0) + if (argPresent) { - 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"); - } + 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; } } @@ -313,29 +319,16 @@ string parseForParam(const string &arg, int argc, char** argv, bool argOnly, int string parseForParam(const string &arg, int argc, char** argv, bool argOnly) { - auto notUsed = 0; + auto params = parseForList(arg, argc, argv, argOnly, 1); - return parseForParam(arg, argc, argv, argOnly, notUsed); -} - -vector parseForList(const string &arg, int argc, char** argv) -{ - auto offs = 0; - auto ret = vector(); - string param; - - do + if (params.empty()) { - param = parseForParam(arg, argc, argv, false, offs); - - if (!param.empty()) - { - ret.push_back(param); - } + return string(); + } + else + { + return params[0]; } - while (!param.empty()); - - return ret; } void waitForDetThreads(shared_t *share) diff --git a/src/common.h b/src/common.h index 26550c3..5c74e7f 100644 --- a/src/common.h +++ b/src/common.h @@ -35,7 +35,7 @@ using namespace cv; using namespace std; using namespace std::filesystem; -#define APP_VER "1.6" +#define APP_VER "1.6.t1" #define APP_NAME "Motion Watch" struct shared_t @@ -73,7 +73,6 @@ struct shared_t 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); @@ -84,7 +83,7 @@ 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); +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);