STYLE: Nightly Date Stamp
[cmake.git] / Source / cmDocumentationFormatter.cxx
blobf2a33be2d6241dc6393f469844a790ed5c48e21e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmDocumentationFormatter.cxx,v $
5 Language: C++
6 Date: $Date: 2008-07-21 21:52:58 $
7 Version: $Revision: 1.3 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmDocumentationFormatter.h"
19 cmDocumentationFormatter::cmDocumentationFormatter()
23 cmDocumentationFormatter::~cmDocumentationFormatter()
27 void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
28 const char* text)
30 if(!text)
32 return;
34 const char* ptr = text;
35 while(*ptr)
37 // Any ptrs starting in a space are treated as preformatted text.
38 std::string preformatted;
39 while(*ptr == ' ')
41 for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
43 preformatted.append(1, ch);
45 if(*ptr)
47 ++ptr;
48 preformatted.append(1, '\n');
51 if(preformatted.length())
53 this->PrintPreformatted(os, preformatted.c_str());
56 // Other ptrs are treated as paragraphs.
57 std::string paragraph;
58 for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
60 paragraph.append(1, ch);
62 if(*ptr)
64 ++ptr;
65 paragraph.append(1, '\n');
67 if(paragraph.length())
69 this->PrintParagraph(os, paragraph.c_str());
74 //----------------------------------------------------------------------------
75 std::string
76 cmDocumentationFormatter::ComputeSectionLinkPrefix(std::string const& name)
78 // Map from section name to a prefix for links pointing within the
79 // section. For example, the commands section should have HTML
80 // links to each command with names like #command:ADD_EXECUTABLE.
81 if(name.find("Command") != name.npos)
83 return "command";
85 else if(name.find("Propert") != name.npos)
87 if(name.find("Global") != name.npos)
89 return "prop_global";
91 else if(name.find("Direct") != name.npos)
93 return "prop_dir";
95 else if(name.find("Target") != name.npos)
97 return "prop_tgt";
99 else if(name.find("Test") != name.npos)
101 return "prop_test";
103 else if(name.find("Source") != name.npos)
105 return "prop_sf";
107 return "property";
109 else if(name.find("Variable") != name.npos)
111 return "variable";
113 else if(name.find("Polic") != name.npos)
115 return "policy";
117 else if(name.find("Module") != name.npos)
119 return "module";
121 else if(name.find("Name") != name.npos)
123 return "name";
125 else if(name.find("Usage") != name.npos)
127 return "usage";
129 else if(name.find("Description") != name.npos)
131 return "desc";
133 else if(name.find("Generators") != name.npos)
135 return "gen";
137 else if(name.find("Options") != name.npos)
139 return "opt";
141 else if(name.find("Copyright") != name.npos)
143 return "copy";
145 else if(name.find("See Also") != name.npos)
147 return "see";
149 else if(name.find("SingleItem") != name.npos)
151 return "single_item";
153 else
155 std::cerr
156 << "WARNING: ComputeSectionLinkPrefix failed for \"" << name << "\""
157 << std::endl;
158 return "other";