diff options
Diffstat (limited to 'Source/WXDialog/CommandLineInfo.cpp')
-rw-r--r-- | Source/WXDialog/CommandLineInfo.cpp | 154 |
1 files changed, 97 insertions, 57 deletions
diff --git a/Source/WXDialog/CommandLineInfo.cpp b/Source/WXDialog/CommandLineInfo.cpp index 490dd61..5f6b14e 100644 --- a/Source/WXDialog/CommandLineInfo.cpp +++ b/Source/WXDialog/CommandLineInfo.cpp @@ -17,6 +17,17 @@ =========================================================================*/ +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + #include "CommandLineInfo.h" #include "cmSystemTools.h" @@ -29,7 +40,7 @@ cmCommandLineInfo::cmCommandLineInfo() this->m_WhereSource = ""; this->m_WhereBuild = ""; this->m_AdvancedValues = false; - this->m_GeneratorChoiceString = ""; + m_GeneratorChoiceString.Empty(); this->m_LastUnknownParameter = ""; this->m_ValidArguments = ""; this->m_ExitAfterLoad = false; @@ -43,23 +54,18 @@ cmCommandLineInfo::~cmCommandLineInfo() /////////////////////////////////////////////////////////////// void cmCommandLineInfo::ParseCommandLine(int argc, char* argv[]) { - int cc; - for ( cc = 1; cc < argc; cc ++ ) + for ( int cc = 1; cc < argc; cc ++ ) { - if ( strlen(argv[cc]) < 1 ) - { - continue; - } - bool valid = true; - std::string argument = argv[cc]; - if ( argument.size() > 1 && - this->m_ValidArguments.find(argument[1]) == std::string::npos ) - { - valid = false; - } - this->ParseParam(argument, valid, (cc + 1 == argc)); + if ( strlen(argv[cc]) < 1 ) + continue; + + std::string argument = argv[cc]; + bool valid = ((argument.size() > 1) && (m_ValidArguments.find(argument[1]) == std::string::npos)); + + ParseParam(argument, valid, (cc + 1 == argc)); } - this->m_ExecutablePath = cmSystemTools::GetFilenamePath(argv[0]); + + m_ExecutablePath = cmSystemTools::GetFilenamePath(argv[0]); } /////////////////////////////////////////////////////////////// @@ -88,49 +94,83 @@ int cmCommandLineInfo::GetBoolValue(const std::string& v) { void cmCommandLineInfo::ParseParam(const std::string& parameter, bool know_about, bool /*last*/) { - if(!know_about) + // this is the last parameter we know, so we assign this to be + // path to source or path to existing build + if(!know_about) + m_LastUnknownParameter = parameter; + else { - this->m_LastUnknownParameter = parameter; + std::string sParam(parameter.c_str(), 1, parameter.npos); + + // Single letter valued flag like /B=value or /B:value + std::string value; + if (sParam[1] == '=' || sParam[1] == ':') + { + value = std::string(parameter.c_str()+3); + } + else + { + value = std::string(parameter.c_str()+2); + } + int res; + + switch (sParam[0]) + { + case 'A': + res = cmCommandLineInfo::GetBoolValue(value); + if (res == 1) + { + m_AdvancedValues = true; + } + else if (res == -1) + { + m_AdvancedValues = false; + } + break; + + case 'B': + m_WhereBuild = value; + break; + + case 'G': + m_GeneratorChoiceString = GetStringParam(value.c_str()); + break; + + case 'Q': + m_ExitAfterLoad = true; + break; + + case 'H': + m_WhereSource = value; + break; + } } - else +} + +// When the string param given has string quotes around it +// we remove them and we pass back the string. If not, we +// simply pass back the string as-is +wxString cmCommandLineInfo::GetStringParam(const char *pString) +{ + wxCHECK(pString, wxEmptyString); + + wxString str(pString); + str = str.Strip(wxString::both); + + // if we have only one (or no chars return the current string) + if(str.Len() < 2) + return str; + + // if we have quotes + if(str.GetChar(0) == '\"' && str.Last() == '\"') { - std::string sParam(parameter.c_str(), 1, parameter.npos); - // Single letter valued flag like /B=value or /B:value - std::string value; - if (sParam[1] == '=' || sParam[1] == ':') - { - value = std::string(parameter.c_str()+3); - } - else - { - value = std::string(parameter.c_str()+2); - } - int res; - switch (sParam[0]) - { - case 'A': - res = cmCommandLineInfo::GetBoolValue(value); - if (res == 1) - { - this->m_AdvancedValues = true; - } - else if (res == -1) - { - this->m_AdvancedValues = false; - } - break; - case 'B': - this->m_WhereBuild = value; - break; - case 'G': - this->m_GeneratorChoiceString = value; - break; - case 'Q': - this->m_ExitAfterLoad = true; - break; - case 'H': - this->m_WhereSource = value; - break; - } + // when we only have 2 in size, return empty string + if(str.Len() == 2) + return wxEmptyString; + + // now remove the outer and inner, and return + return str.Mid(1, str.Len()-1); } + + return str; } |