From f9872179518f21d3b43acaac610b01216a552806 Mon Sep 17 00:00:00 2001 From: Cyrille Valladeau <cyrille.valladeau@c-s.fr> Date: Fri, 4 Nov 2011 16:01:47 +0100 Subject: [PATCH] ENH: add control on key prefix --- .../otbWrapperCommandLineLauncher.cxx | 35 +++++++++++++++++++ .../otbWrapperCommandLineLauncher.h | 6 ++++ .../otbWrapperCommandLineParser.cxx | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx index 3f180ec298..578d8e15ed 100644 --- a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx @@ -107,6 +107,12 @@ CommandLineLauncher::Load() itkExceptionMacro("No expression specified..."); } + if( this->CheckParametersPrefix() == false ) + { + std::cerr<<"ERROR: Parameter keys have to set using \"--\""<<std::endl; + return false; + } + if( this->CheckUnicity() == false ) { std::cerr<<"ERROR: At least one key is not unique in the expression..."<<std::endl; @@ -798,6 +804,35 @@ CommandLineLauncher::CheckUnicity() return res; } +bool +CommandLineLauncher::CheckParametersPrefix() +{ + bool res = true; + // Extract Expression elements + std::vector<itksys::String> spaceSplittedExp = itksys::SystemTools::SplitString(m_Expression.c_str(), ' ', false); + // if the chain is " module", SplitString will return: [ ], [module] + for(unsigned int i=0; i<spaceSplittedExp.size(); i++) + { + if( spaceSplittedExp[i] == " ") + { + spaceSplittedExp.erase(spaceSplittedExp.begin()+i); + i--; + } + } + + // If the expression contains parameters + if( spaceSplittedExp.size() > 2 ) + { + // Check if the chain "--" appears at least one time + if( m_Expression.find("--") == std::string::npos) + { + res = false; + } + } + + return res; +} + bool CommandLineLauncher::CheckKeyValidity() { diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h index 27faf7ebc9..d1bb02327c 100644 --- a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h @@ -141,6 +141,12 @@ protected: /** Check if each key is unique in the expression. */ bool CheckUnicity(); + /** Check if option contains at least one "--". + * return false if m_Expression contains more than 2 element (module + * name and path) and doesn't contains "--" + */ + bool CheckParametersPrefix(); + /** Check if each key is valid for the application. */ bool CheckKeyValidity(); diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineParser.cxx b/Code/Wrappers/CommandLine/otbWrapperCommandLineParser.cxx index 73f40dfa9c..4dedf5155b 100644 --- a/Code/Wrappers/CommandLine/otbWrapperCommandLineParser.cxx +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineParser.cxx @@ -100,7 +100,7 @@ CommandLineParser::GetPaths( std::vector<std::string> & paths, const std::string std::string fullPath = itksys::SystemTools::CollapseFullPath(pathAttribut[i].c_str()); if( !itksys::SystemTools::FileIsDirectory(fullPath.c_str()) ) { - std::cout<<"module path INVALIDMODULEPATH"<<std::endl; + std::cerr<<"module path Inavlid module path"<<std::endl; return INVALIDMODULEPATH; } paths.push_back(fullPath); -- GitLab