cmDocumentationFormatterMan.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "cmDocumentationFormatterMan.h"
  11. #include "cmDocumentationSection.h"
  12. #include "cmSystemTools.h"
  13. #include "cmVersion.h"
  14. cmDocumentationFormatterMan::cmDocumentationFormatterMan()
  15. :cmDocumentationFormatter()
  16. {
  17. }
  18. void cmDocumentationFormatterMan
  19. ::PrintSection(std::ostream& os,
  20. const cmDocumentationSection &section,
  21. const char* name)
  22. {
  23. if(name)
  24. {
  25. os << ".SH " << name << "\n";
  26. }
  27. const std::vector<cmDocumentationEntry> &entries =
  28. section.GetEntries();
  29. for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin();
  30. op != entries.end(); ++op)
  31. {
  32. if(op->Name.size())
  33. {
  34. os << ".TP\n"
  35. << ".B " << (op->Name.size()?op->Name.c_str():"*") << "\n";
  36. this->PrintFormatted(os, op->Brief.c_str());
  37. this->PrintFormatted(os, op->Full.c_str());
  38. }
  39. else
  40. {
  41. os << ".PP\n";
  42. this->PrintFormatted(os, op->Brief.c_str());
  43. }
  44. }
  45. }
  46. void cmDocumentationFormatterMan::EscapeText(std::string& man_text)
  47. {
  48. cmSystemTools::ReplaceString(man_text, "\\", "\\\\");
  49. cmSystemTools::ReplaceString(man_text, "-", "\\-");
  50. }
  51. void cmDocumentationFormatterMan::PrintPreformatted(std::ostream& os,
  52. const char* text)
  53. {
  54. std::string man_text = text;
  55. this->EscapeText(man_text);
  56. os << ".nf\n" << man_text;
  57. if (*text && man_text.at(man_text.length()-1) != '\n')
  58. os << "\n";
  59. os << ".fi\n\n";
  60. }
  61. void cmDocumentationFormatterMan::PrintParagraph(std::ostream& os,
  62. const char* text)
  63. {
  64. std::string man_text = text;
  65. this->EscapeText(man_text);
  66. os << man_text << "\n\n";
  67. }
  68. //----------------------------------------------------------------------------
  69. void cmDocumentationFormatterMan::PrintHeader(const char* docname,
  70. const char* appname,
  71. std::ostream& os)
  72. {
  73. std::string s_docname(docname), s_appname(appname);
  74. this->EscapeText(s_docname);
  75. this->EscapeText(s_appname);
  76. os << ".TH " << s_docname << " 1 \""
  77. << cmSystemTools::GetCurrentDateTime("%B %d, %Y").c_str()
  78. << "\" \"" << s_appname
  79. << " " << cmVersion::GetCMakeVersion()
  80. << "\"\n";
  81. }