cmElseCommand.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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. #include "cmElseCommand.h"
  14. #include "cmCacheManager.h"
  15. bool cmElseCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 1 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. // create a function blocker
  23. cmIfFunctionBlocker *f = NULL;
  24. // check for the different signatures
  25. const char *def;
  26. const char *def2;
  27. if (args.size() == 1)
  28. {
  29. def = m_Makefile->GetDefinition(args[0].c_str());
  30. if(!cmSystemTools::IsOff(def))
  31. {
  32. f = new cmIfFunctionBlocker();
  33. }
  34. }
  35. if (args.size() == 2 && (args[0] == "COMMAND"))
  36. {
  37. if(m_Makefile->CommandExists(args[1].c_str()))
  38. {
  39. f = new cmIfFunctionBlocker();
  40. }
  41. }
  42. if (args.size() == 2 && (args[0] == "EXISTS"))
  43. {
  44. if(cmSystemTools::FileExists(args[1].c_str()))
  45. {
  46. f = new cmIfFunctionBlocker();
  47. }
  48. }
  49. if (args.size() == 2 && (args[0] == "NOT"))
  50. {
  51. def = m_Makefile->GetDefinition(args[1].c_str());
  52. if(cmSystemTools::IsOff(def))
  53. {
  54. f = new cmIfFunctionBlocker();
  55. }
  56. }
  57. if (args.size() == 3 && (args[1] == "AND"))
  58. {
  59. def = m_Makefile->GetDefinition(args[0].c_str());
  60. def2 = m_Makefile->GetDefinition(args[2].c_str());
  61. if(!cmSystemTools::IsOff(def) && !cmSystemTools::IsOff(def2))
  62. {
  63. f = new cmIfFunctionBlocker();
  64. }
  65. }
  66. if (args.size() == 3 && (args[1] == "OR"))
  67. {
  68. def = m_Makefile->GetDefinition(args[0].c_str());
  69. def2 = m_Makefile->GetDefinition(args[2].c_str());
  70. if(!cmSystemTools::IsOff(def) || !cmSystemTools::IsOff(def2))
  71. {
  72. f = new cmIfFunctionBlocker();
  73. }
  74. }
  75. if (args.size() == 3 && (args[1] == "LESS"))
  76. {
  77. def = m_Makefile->GetDefinition(args[0].c_str());
  78. def2 = m_Makefile->GetDefinition(args[2].c_str());
  79. if (!def)
  80. {
  81. def = args[0].c_str();
  82. }
  83. if (!def2)
  84. {
  85. def2 = args[2].c_str();
  86. }
  87. if(atof(def) < atof(def2))
  88. {
  89. f = new cmIfFunctionBlocker();
  90. }
  91. }
  92. if (args.size() == 3 && (args[1] == "GREATER"))
  93. {
  94. def = m_Makefile->GetDefinition(args[0].c_str());
  95. def2 = m_Makefile->GetDefinition(args[2].c_str());
  96. if (!def)
  97. {
  98. def = args[0].c_str();
  99. }
  100. if (!def2)
  101. {
  102. def2 = args[2].c_str();
  103. }
  104. if(atof(def) > atof(def2))
  105. {
  106. f = new cmIfFunctionBlocker();
  107. }
  108. }
  109. if (args.size() == 3 && (args[1] == "STRLESS"))
  110. {
  111. def = m_Makefile->GetDefinition(args[0].c_str());
  112. def2 = m_Makefile->GetDefinition(args[2].c_str());
  113. if(strcmp(def,def2) < 0)
  114. {
  115. f = new cmIfFunctionBlocker();
  116. }
  117. }
  118. if (args.size() == 3 && (args[1] == "STRGREATER"))
  119. {
  120. def = m_Makefile->GetDefinition(args[0].c_str());
  121. def2 = m_Makefile->GetDefinition(args[2].c_str());
  122. if(strcmp(def,def2) > 0)
  123. {
  124. f = new cmIfFunctionBlocker();
  125. }
  126. }
  127. if (args.size() == 3 && (args[1] == "MATCHES"))
  128. {
  129. def = m_Makefile->GetDefinition(args[0].c_str());
  130. cmRegularExpression regEntry(args[2].c_str());
  131. // check for black line or comment
  132. if (def && regEntry.find(def))
  133. {
  134. f = new cmIfFunctionBlocker();
  135. }
  136. }
  137. // if we created a function blocker then set its args
  138. if (f)
  139. {
  140. for(std::vector<std::string>::const_iterator j = args.begin();
  141. j != args.end(); ++j)
  142. {
  143. f->m_Args.push_back(*j);
  144. }
  145. m_Makefile->AddFunctionBlocker(f);
  146. }
  147. else
  148. {
  149. // remove any function blockers for this define
  150. m_Makefile->RemoveFunctionBlocker("ENDIF",args);
  151. }
  152. return true;
  153. }