cmDocumentationFormatter.cxx 3.7 KB

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