From aad25014992a230f183bfc1f72eeee07b6ca39d7 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 23 Aug 2013 22:15:18 +0200 Subject: [PATCH] Bugfix, -l option now works --- wordref/CMakeLists.txt | 2 +- wordref/src/main.cpp | 53 +++++++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/wordref/CMakeLists.txt b/wordref/CMakeLists.txt index fa04683..9f28c8d 100644 --- a/wordref/CMakeLists.txt +++ b/wordref/CMakeLists.txt @@ -11,7 +11,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") set(PROJ_VER_MAJOR "0") set(PROJ_VER_MINOR "1") -set(PROJ_VER_REVISION "1") +set(PROJ_VER_REVISION "2") get_git_head_revision(GIT_REFSPEC PROJ_GIT_SHA1) configure_file ( diff --git a/wordref/src/main.cpp b/wordref/src/main.cpp index 8e8ce97..9e5e2d8 100644 --- a/wordref/src/main.cpp +++ b/wordref/src/main.cpp @@ -47,7 +47,20 @@ namespace { ///------------------------------------------------------------------------ ///------------------------------------------------------------------------ - bool GetCommandLine (boost::program_options::variables_map& parVarMap, int parArgc, const char* const parArgv[]) { + void ShowVersion() { + std::cout << APP_NAME << " v" << APP_VER_MAJOR << "." << APP_VER_MINOR << "." << APP_VER_REVISION << "\n"; + std::cout << "rev: " << APP_VER_GIT << "\n"; + } + + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + void ShowHelp (const boost::program_options::options_description& parDesc) { + std::cout << parDesc << "\n"; + } + + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + bool GetCommandLine (boost::program_options::variables_map& parVarMap, int parArgc, const char* const parArgv[], const std::vector& parOverrideArgs) { const char* const programName = parArgv[0]; std::ostringstream oss; oss << "Usage is " << GetBaseName(parArgv[0]) << " [options] ; parameters"; @@ -76,20 +89,31 @@ namespace { boost::program_options::notify(parVarMap); bool shownSomething = false; - if (parVarMap.count("version") == 0) { - const bool enoughParams = static_cast( - parVarMap.count("source-lang") == 1 and - parVarMap.count("dest-lang") == 1 and - parVarMap.count("word") > 0 - ); - if (parVarMap.count("help") or not enoughParams) { - std::cout << desc << "\n"; - shownSomething = true; - } + const bool enoughParams = static_cast( + parVarMap.count("source-lang") == 1 and + parVarMap.count("dest-lang") == 1 and + parVarMap.count("word") > 0 + ); + bool ignoreFewerParams = false; + if (parVarMap.count("help")) { + ShowHelp(desc); + shownSomething = true; + } + else if (parVarMap.count("version")) { + ShowVersion(); + shownSomething = true; } else { - std::cout << APP_NAME << " v" << APP_VER_MAJOR << "." << APP_VER_MINOR << "." << APP_VER_REVISION << "\n"; - std::cout << "rev: " << APP_VER_GIT << "\n"; + for (std::vector::const_iterator itCur = parOverrideArgs.begin(), itCurEND = parOverrideArgs.end(); itCur != itCurEND; ++itCur) { + if (parVarMap.count(*itCur)) { + ignoreFewerParams = true; + break; + } + } + } + + if (not (shownSomething or ignoreFewerParams or enoughParams)) { + ShowHelp(desc); shownSomething = true; } return shownSomething; @@ -102,7 +126,8 @@ int main (int parArgc, const char* const parArgv[]) { //std::setlocale(LC_CTYPE, "UTF-8"); std::setlocale(LC_CTYPE, ""); boost::program_options::variables_map vm; - if (GetCommandLine(vm, parArgc, parArgv)) + const std::vector paramsSkipCompulsoryInput = {"listlanguages"}; + if (GetCommandLine(vm, parArgc, parArgv, paramsSkipCompulsoryInput)) return 0; if (vm.count("listlanguages")) {