cmDocumentationFormatterRST.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "cmDocumentationFormatterRST.h"
  11. #include "cmDocumentationSection.h"
  12. #include "cmVersion.h"
  13. #include "cmSystemTools.h"
  14. cmDocumentationFormatterRST::cmDocumentationFormatterRST()
  15. :cmDocumentationFormatterText()
  16. {
  17. }
  18. static std::string rstFileName(std::string fn)
  19. {
  20. cmSystemTools::ReplaceString(fn, "<", "");
  21. cmSystemTools::ReplaceString(fn, ">", "");
  22. return fn;
  23. }
  24. void cmDocumentationFormatterRST
  25. ::PrintSection(std::ostream& os,
  26. const cmDocumentationSection &section,
  27. const char* name)
  28. {
  29. std::string prefix = this->ComputeSectionLinkPrefix(name);
  30. std::vector<cmDocumentationEntry> const& entries = section.GetEntries();
  31. this->TextWidth = 70;
  32. for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin();
  33. op != entries.end();)
  34. {
  35. if(op->Name.size())
  36. {
  37. for(;op != entries.end() && op->Name.size(); ++op)
  38. {
  39. if(prefix == "opt" || prefix == "see")
  40. {
  41. os << "\n";
  42. os << "* ``" << op->Name << "``: " << op->Brief << "\n";
  43. this->TextIndent = " ";
  44. if(op->Full.size())
  45. {
  46. os << "\n";
  47. this->PrintFormatted(os, op->Full.c_str());
  48. }
  49. this->TextIndent = "";
  50. }
  51. else
  52. {
  53. cmSystemTools::MakeDirectory(prefix.c_str());
  54. std::string fname = prefix + "/" + rstFileName(op->Name) + ".rst";
  55. if(cmSystemTools::FileExists(fname.c_str()))
  56. {
  57. cmSystemTools::Error("Duplicate file name: ", fname.c_str());
  58. continue;
  59. }
  60. std::ofstream of(fname.c_str());
  61. of << op->Name << "\n";
  62. for(size_t i = 0; i < op->Name.size(); ++i)
  63. {
  64. of << "-";
  65. }
  66. of << "\n\n" << op->Brief << "\n";
  67. if(op->Full.size())
  68. {
  69. of << "\n";
  70. this->PrintFormatted(of, op->Full.c_str());
  71. }
  72. }
  73. }
  74. }
  75. else
  76. {
  77. this->PrintFormatted(os, op->Brief.c_str());
  78. os << "\n";
  79. ++op;
  80. }
  81. }
  82. }
  83. void cmDocumentationFormatterRST::PrintPreformatted(std::ostream& os,
  84. const char* text)
  85. {
  86. os << this->TextIndent << "::\n\n";
  87. bool newline = true;
  88. for(const char* c = text; *c; ++c)
  89. {
  90. if (newline)
  91. {
  92. os << this->TextIndent;
  93. newline = false;
  94. }
  95. os << *c;
  96. newline = (*c == '\n');
  97. }
  98. os << "\n";
  99. }