cmDocumentationFormatter.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #include "cmDocumentationFormatter.h"
  14. cmDocumentationFormatter::cmDocumentationFormatter()
  15. {
  16. }
  17. cmDocumentationFormatter::~cmDocumentationFormatter()
  18. {
  19. }
  20. void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
  21. const char* text)
  22. {
  23. if(!text)
  24. {
  25. return;
  26. }
  27. const char* ptr = text;
  28. while(*ptr)
  29. {
  30. // Any ptrs starting in a space are treated as preformatted text.
  31. std::string preformatted;
  32. while(*ptr == ' ')
  33. {
  34. for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
  35. {
  36. preformatted.append(1, ch);
  37. }
  38. if(*ptr)
  39. {
  40. ++ptr;
  41. preformatted.append(1, '\n');
  42. }
  43. }
  44. if(preformatted.length())
  45. {
  46. this->PrintPreformatted(os, preformatted.c_str());
  47. }
  48. // Other ptrs are treated as paragraphs.
  49. std::string paragraph;
  50. for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
  51. {
  52. paragraph.append(1, ch);
  53. }
  54. if(*ptr)
  55. {
  56. ++ptr;
  57. paragraph.append(1, '\n');
  58. }
  59. if(paragraph.length())
  60. {
  61. this->PrintParagraph(os, paragraph.c_str());
  62. }
  63. }
  64. }
  65. //----------------------------------------------------------------------------
  66. std::string
  67. cmDocumentationFormatter::ComputeSectionLinkPrefix(std::string const& name)
  68. {
  69. // Map from section name to a prefix for links pointing within the
  70. // section. For example, the commands section should have HTML
  71. // links to each command with names like #command:ADD_EXECUTABLE.
  72. if(name.find("Command") != name.npos)
  73. {
  74. return "command";
  75. }
  76. else if(name.find("Propert") != name.npos)
  77. {
  78. if(name.find("Global") != name.npos)
  79. {
  80. return "prop_global";
  81. }
  82. else if(name.find("Direct") != name.npos)
  83. {
  84. return "prop_dir";
  85. }
  86. else if(name.find("Target") != name.npos)
  87. {
  88. return "prop_tgt";
  89. }
  90. else if(name.find("Test") != name.npos)
  91. {
  92. return "prop_test";
  93. }
  94. else if(name.find("Source") != name.npos)
  95. {
  96. return "prop_sf";
  97. }
  98. return "property";
  99. }
  100. else if(name.find("Variable") != name.npos)
  101. {
  102. return "variable";
  103. }
  104. else if(name.find("Polic") != name.npos)
  105. {
  106. return "policy";
  107. }
  108. else if(name.find("Module") != name.npos)
  109. {
  110. return "module";
  111. }
  112. else if(name.find("Name") != name.npos)
  113. {
  114. return "name";
  115. }
  116. else if(name.find("Usage") != name.npos)
  117. {
  118. return "usage";
  119. }
  120. else if(name.find("Description") != name.npos)
  121. {
  122. return "desc";
  123. }
  124. else if(name.find("Generators") != name.npos)
  125. {
  126. return "gen";
  127. }
  128. else if(name.find("Options") != name.npos)
  129. {
  130. return "opt";
  131. }
  132. else if(name.find("Copyright") != name.npos)
  133. {
  134. return "copy";
  135. }
  136. else if(name.find("See Also") != name.npos)
  137. {
  138. return "see";
  139. }
  140. else
  141. {
  142. std::cerr
  143. << "WARNING: ComputeSectionLinkPrefix failed for \"" << name << "\""
  144. << std::endl;
  145. return "other";
  146. }
  147. }