Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmDocumentationFormatterMan.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12
13 #include "cmDocumentationFormatterMan.h"
14 #include "cmDocumentationSection.h"
15
16 #include "cmSystemTools.h"
17 #include "cmVersion.h"
18
19
20 cmDocumentationFormatterMan::cmDocumentationFormatterMan()
21 :cmDocumentationFormatter()
22 ,ManSection(1)
23 {
24 }
25
26 void cmDocumentationFormatterMan::SetManSection(int manSection)
27 {
28   this->ManSection = manSection;
29 }
30
31 void cmDocumentationFormatterMan
32 ::PrintSection(std::ostream& os,
33                const cmDocumentationSection &section,
34                const char* name)
35 {
36   if(name)
37     {
38     os << ".SH " << name << "\n";
39     }
40
41   const std::vector<cmDocumentationEntry> &entries =
42     section.GetEntries();
43   for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin();
44       op != entries.end(); ++op)
45     {
46     if(op->Name.size())
47       {
48       os << ".TP\n"
49          << ".B " << (op->Name.size()?op->Name.c_str():"*") << "\n";
50       this->PrintFormatted(os, op->Brief.c_str());
51       this->PrintFormatted(os, op->Full.c_str());
52       }
53     else
54       {
55       os << ".PP\n";
56       this->PrintFormatted(os, op->Brief.c_str());
57       }
58     }
59 }
60
61 void cmDocumentationFormatterMan::EscapeText(std::string& man_text)
62 {
63   cmSystemTools::ReplaceString(man_text, "\\", "\\\\");
64   cmSystemTools::ReplaceString(man_text, "-", "\\-");
65 }
66
67 void cmDocumentationFormatterMan::PrintPreformatted(std::ostream& os,
68                                                     const char* text)
69 {
70   std::string man_text = text;
71   this->EscapeText(man_text);
72   os << ".nf\n" << man_text;
73   if (*text && man_text.at(man_text.length()-1) != '\n')
74       os << "\n";
75   os << ".fi\n\n";
76 }
77
78 void cmDocumentationFormatterMan::PrintParagraph(std::ostream& os,
79                                                  const char* text)
80 {
81   std::string man_text = text;
82   this->EscapeText(man_text);
83   os << man_text << "\n\n";
84 }
85
86
87 //----------------------------------------------------------------------------
88 void cmDocumentationFormatterMan::PrintHeader(const char* docname,
89                                               const char* appname,
90                                               std::ostream& os)
91 {
92   std::string s_docname(docname), s_appname(appname);
93
94   this->EscapeText(s_docname);
95   this->EscapeText(s_appname);
96   os << ".TH " << s_docname << " " << this->ManSection << " \""
97     << cmSystemTools::GetCurrentDateTime("%B %d, %Y").c_str()
98     << "\" \"" << s_appname
99     << " " << cmVersion::GetCMakeVersion()
100     << "\"\n";
101 }
102