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