cmWXCommandLineInfo.cxx 3.4 KB

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