CommandLineInfo.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*=========================================================================
  2. Program: WXDialog - wxWidgets X-platform GUI Front-End for CMake
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Author: Jorgen Bodde
  8. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  9. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  10. This software is distributed WITHOUT ANY WARRANTY; without even
  11. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12. PURPOSE. See the above copyright notices for more information.
  13. =========================================================================*/
  14. #include "CommandLineInfo.h"
  15. #include "cmSystemTools.h"
  16. ///////////////////////////////////////////////////////////////
  17. // cmCommandLineInfo
  18. cmCommandLineInfo::cmCommandLineInfo()
  19. {
  20. this->m_WhereSource = "";
  21. this->m_WhereBuild = "";
  22. this->m_AdvancedValues = false;
  23. this->m_GeneratorChoiceString = "";
  24. this->m_LastUnknownParameter = "";
  25. this->m_ValidArguments = "";
  26. this->m_ExitAfterLoad = false;
  27. }
  28. ///////////////////////////////////////////////////////////////
  29. cmCommandLineInfo::~cmCommandLineInfo()
  30. {
  31. }
  32. ///////////////////////////////////////////////////////////////
  33. void cmCommandLineInfo::ParseCommandLine(int argc, char* argv[])
  34. {
  35. int cc;
  36. for ( cc = 1; cc < argc; cc ++ )
  37. {
  38. if ( strlen(argv[cc]) < 1 )
  39. {
  40. continue;
  41. }
  42. bool valid = true;
  43. std::string argument = argv[cc];
  44. if ( argument.size() > 1 &&
  45. this->m_ValidArguments.find(argument[1]) == std::string::npos )
  46. {
  47. valid = false;
  48. }
  49. this->ParseParam(argument, valid, (cc + 1 == argc));
  50. }
  51. this->m_ExecutablePath = cmSystemTools::GetFilenamePath(argv[0]);
  52. }
  53. ///////////////////////////////////////////////////////////////
  54. int cmCommandLineInfo::GetBoolValue(const std::string& v) {
  55. std::string value = cmSystemTools::LowerCase(v);
  56. if (value == "1" ||
  57. value == "on" ||
  58. value == "true" ||
  59. value == "yes")
  60. {
  61. return 1;
  62. }
  63. else if (value == "0" ||
  64. value == "off" ||
  65. value == "false" ||
  66. value == "no")
  67. {
  68. return -1;
  69. }
  70. return 0;
  71. }
  72. ///////////////////////////////////////////////////////////////
  73. // Parse param
  74. void cmCommandLineInfo::ParseParam(const std::string& parameter,
  75. bool know_about, bool /*last*/)
  76. {
  77. if(!know_about)
  78. {
  79. this->m_LastUnknownParameter = parameter;
  80. }
  81. else
  82. {
  83. std::string sParam(parameter.c_str(), 1, parameter.npos);
  84. // Single letter valued flag like /B=value or /B:value
  85. std::string value;
  86. if (sParam[1] == '=' || sParam[1] == ':')
  87. {
  88. value = std::string(parameter.c_str()+3);
  89. }
  90. else
  91. {
  92. value = std::string(parameter.c_str()+2);
  93. }
  94. int res;
  95. switch (sParam[0])
  96. {
  97. case 'A':
  98. res = cmCommandLineInfo::GetBoolValue(value);
  99. if (res == 1)
  100. {
  101. this->m_AdvancedValues = true;
  102. }
  103. else if (res == -1)
  104. {
  105. this->m_AdvancedValues = false;
  106. }
  107. break;
  108. case 'B':
  109. this->m_WhereBuild = value;
  110. break;
  111. case 'G':
  112. this->m_GeneratorChoiceString = value;
  113. break;
  114. case 'Q':
  115. this->m_ExitAfterLoad = true;
  116. break;
  117. case 'H':
  118. this->m_WhereSource = value;
  119. break;
  120. }
  121. }
  122. }