summaryrefslogtreecommitdiffstats
path: root/Source/cmDocumentationFormatterHTML.cxx
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-09-19 13:05:28 (GMT)
committerAlexander Neundorf <neundorf@kde.org>2007-09-19 13:05:28 (GMT)
commitc5f249bdbdb894d72db8211021ac2b9ff8b02fa7 (patch)
tree9378751765b4e994d93ba99cfa7e737a180e6513 /Source/cmDocumentationFormatterHTML.cxx
parentb4f02ec0bd8e102fb93230ed2ffe15c90bb33a81 (diff)
downloadCMake-c5f249bdbdb894d72db8211021ac2b9ff8b02fa7.zip
CMake-c5f249bdbdb894d72db8211021ac2b9ff8b02fa7.tar.gz
CMake-c5f249bdbdb894d72db8211021ac2b9ff8b02fa7.tar.bz2
STYLE: move the code for the different formats of the generated help into
their own classes, making cmDocumentation smaller and also making it easier to eventually add another format Alex
Diffstat (limited to 'Source/cmDocumentationFormatterHTML.cxx')
-rw-r--r--Source/cmDocumentationFormatterHTML.cxx189
1 files changed, 189 insertions, 0 deletions
diff --git a/Source/cmDocumentationFormatterHTML.cxx b/Source/cmDocumentationFormatterHTML.cxx
new file mode 100644
index 0000000..a51f718
--- /dev/null
+++ b/Source/cmDocumentationFormatterHTML.cxx
@@ -0,0 +1,189 @@
+/*=========================================================================
+
+ Program: CMake - Cross-Platform Makefile Generator
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+ Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
+ See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*/
+#include "cmDocumentationFormatterHTML.h"
+
+//----------------------------------------------------------------------------
+static bool cmDocumentationIsHyperlinkChar(char c)
+{
+ // This is not a complete list but works for CMake documentation.
+ return ((c >= 'A' && c <= 'Z') ||
+ (c >= 'a' && c <= 'z') ||
+ (c >= '0' && c <= '9') ||
+ c == '-' || c == '.' || c == '/' || c == '~' || c == '@' ||
+ c == ':' || c == '_' || c == '&' || c == '?' || c == '=');
+}
+
+//----------------------------------------------------------------------------
+static void cmDocumentationPrintHTMLChar(std::ostream& os, char c)
+{
+ // Use an escape sequence if necessary.
+ static cmDocumentationEntry escapes[] =
+ {
+ {"<", "&lt;", 0},
+ {">", "&gt;", 0},
+ {"&", "&amp;", 0},
+ {"\n", "<br>", 0},
+ {0,0,0}
+ };
+ for(const cmDocumentationEntry* op = escapes; op->name; ++op)
+ {
+ if(op->name[0] == c)
+ {
+ os << op->brief;
+ return;
+ }
+ }
+
+ // No escape sequence is needed.
+ os << c;
+}
+
+//----------------------------------------------------------------------------
+const char* cmDocumentationPrintHTMLLink(std::ostream& os, const char* begin)
+{
+ // Look for the end of the link.
+ const char* end = begin;
+ while(cmDocumentationIsHyperlinkChar(*end))
+ {
+ ++end;
+ }
+
+ // Print the hyperlink itself.
+ os << "<a href=\"";
+ for(const char* c = begin; c != end; ++c)
+ {
+ cmDocumentationPrintHTMLChar(os, *c);
+ }
+ os << "\">";
+
+ // The name of the hyperlink is the text itself.
+ for(const char* c = begin; c != end; ++c)
+ {
+ cmDocumentationPrintHTMLChar(os, *c);
+ }
+ os << "</a>";
+
+ // Return the position at which to continue scanning the input
+ // string.
+ return end;
+}
+
+
+cmDocumentationFormatterHTML::cmDocumentationFormatterHTML()
+:cmDocumentationFormatter()
+{
+}
+
+void cmDocumentationFormatterHTML::PrintSection(std::ostream& os,
+ const cmDocumentationEntry* section,
+ const char* name)
+{
+ if(name)
+ {
+ os << "<h2>" << name << "</h2>\n";
+ }
+ if(!section) { return; }
+ for(const cmDocumentationEntry* op = section; op->brief;)
+ {
+ if(op->name)
+ {
+ os << "<ul>\n";
+ for(;op->name;++op)
+ {
+ os << " <li>\n";
+ if(op->name[0])
+ {
+ os << " <b><code>";
+ this->PrintHTMLEscapes(os, op->name);
+ os << "</code></b>: ";
+ }
+ this->PrintHTMLEscapes(os, op->brief);
+ if(op->full)
+ {
+ os << "<br>\n ";
+ this->PrintFormatted(os, op->full);
+ }
+ os << "\n";
+ os << " </li>\n";
+ }
+ os << "</ul>\n";
+ }
+ else
+ {
+ this->PrintFormatted(os, op->brief);
+ os << "\n";
+ ++op;
+ }
+ }
+}
+
+void cmDocumentationFormatterHTML::PrintPreformatted(std::ostream& os,
+ const char* text)
+{
+ os << "<pre>";
+ this->PrintHTMLEscapes(os, text);
+ os << "</pre>\n ";
+}
+
+void cmDocumentationFormatterHTML::PrintParagraph(std::ostream& os,
+ const char* text)
+{
+ os << "<p>";
+ this->PrintHTMLEscapes(os, text);
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentationFormatterHTML::PrintHeader(const char* name,
+ std::ostream& os)
+{
+ os << "<html><body>\n";
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentationFormatterHTML::PrintFooter(std::ostream& os)
+{
+ os << "</body></html>\n";
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentationFormatterHTML::PrintHTMLEscapes(std::ostream& os,
+ const char* text)
+{
+ // Hyperlink prefixes.
+ static const char* hyperlinks[] = {"http://", "ftp://", "mailto:", 0};
+
+ // Print each character.
+ for(const char* p = text; *p;)
+ {
+ // Handle hyperlinks specially to make them active.
+ bool found_hyperlink = false;
+ for(const char** h = hyperlinks; !found_hyperlink && *h; ++h)
+ {
+ if(strncmp(p, *h, strlen(*h)) == 0)
+ {
+ p = cmDocumentationPrintHTMLLink(os, p);
+ found_hyperlink = true;
+ }
+ }
+
+ // Print other characters normally.
+ if(!found_hyperlink)
+ {
+ cmDocumentationPrintHTMLChar(os, *p++);
+ }
+ }
+}