2009-10-02 01:21:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2007-09-19 17:05:28 +04:00
|
|
|
|
2009-10-02 01:21:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2007-09-19 17:05:28 +04:00
|
|
|
|
2009-10-02 01:21:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2007-09-19 17:05:28 +04:00
|
|
|
#include "cmDocumentationFormatterHTML.h"
|
2007-10-22 20:49:09 +04:00
|
|
|
#include "cmDocumentationSection.h"
|
2009-09-15 04:54:22 +04:00
|
|
|
#include "cmVersion.h"
|
2007-09-19 17:05:28 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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.
|
2008-02-19 22:33:43 +03:00
|
|
|
switch (c)
|
2008-02-17 20:31:29 +03:00
|
|
|
{
|
2008-02-19 22:33:43 +03:00
|
|
|
case '<':
|
|
|
|
os << "<";
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
os << ">";
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
os << "&";
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
os << "<br>";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << c;
|
|
|
|
}
|
2007-09-19 17:05:28 +04:00
|
|
|
}
|
|
|
|
|
2008-05-05 20:02:36 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmDocumentationHTMLIsIdChar(char c)
|
|
|
|
{
|
|
|
|
// From the HTML specification:
|
|
|
|
// ID and NAME tokens must begin with a letter ([A-Za-z]) and may
|
|
|
|
// be followed by any number of letters, digits ([0-9]), hyphens
|
|
|
|
// ("-"), underscores ("_"), colons (":"), and periods (".").
|
|
|
|
return ((c >= 'A' && c <= 'Z') ||
|
|
|
|
(c >= 'a' && c <= 'z') ||
|
|
|
|
(c >= '0' && c <= '9') ||
|
|
|
|
c == '-' || c == '_' || c == ':' || c == '.');
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmDocumentationPrintHTMLId(std::ostream& os, const char* begin)
|
|
|
|
{
|
|
|
|
for(const char* c = begin; *c; ++c)
|
|
|
|
{
|
|
|
|
if(cmDocumentationHTMLIsIdChar(*c))
|
|
|
|
{
|
|
|
|
os << *c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-19 17:05:28 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-10-22 20:49:09 +04:00
|
|
|
void cmDocumentationFormatterHTML
|
|
|
|
::PrintSection(std::ostream& os,
|
|
|
|
const cmDocumentationSection §ion,
|
|
|
|
const char* name)
|
2007-09-19 17:05:28 +04:00
|
|
|
{
|
2008-05-05 20:02:36 +04:00
|
|
|
std::string prefix = this->ComputeSectionLinkPrefix(name);
|
|
|
|
|
2007-10-22 20:49:09 +04:00
|
|
|
const std::vector<cmDocumentationEntry> &entries =
|
|
|
|
section.GetEntries();
|
2007-10-24 19:36:47 +04:00
|
|
|
|
2008-07-22 01:52:59 +04:00
|
|
|
// skip the index if the help for only a single item (--help-command,
|
|
|
|
// --help-policy, --help-property, --help-module) is printed
|
|
|
|
bool isSingleItemHelp = ((name!=0) && (strcmp(name, "SingleItem")==0));
|
|
|
|
|
|
|
|
if (!isSingleItemHelp)
|
2007-10-24 19:36:47 +04:00
|
|
|
{
|
2008-07-22 01:52:59 +04:00
|
|
|
if (name)
|
2007-10-24 19:36:47 +04:00
|
|
|
{
|
2008-07-22 01:52:59 +04:00
|
|
|
os << "<h2><a name=\"section_" << name << "\"/>" << name << "</h2>\n";
|
2007-10-24 19:36:47 +04:00
|
|
|
}
|
2008-07-22 01:52:59 +04:00
|
|
|
|
|
|
|
os << "<ul>\n";
|
|
|
|
for(std::vector<cmDocumentationEntry>::const_iterator op
|
|
|
|
= entries.begin(); op != entries.end(); ++ op )
|
|
|
|
{
|
|
|
|
if(op->Name.size())
|
|
|
|
{
|
|
|
|
os << " <li><a href=\"#" << prefix << ":";
|
|
|
|
cmDocumentationPrintHTMLId(os, op->Name.c_str());
|
|
|
|
os << "\"><b><code>";
|
|
|
|
this->PrintHTMLEscapes(os, op->Name.c_str());
|
|
|
|
os << "</code></b></a></li>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "</ul>\n" ;
|
2007-10-24 19:36:47 +04:00
|
|
|
}
|
|
|
|
|
2007-10-22 20:49:09 +04:00
|
|
|
for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin();
|
|
|
|
op != entries.end();)
|
2007-09-19 17:05:28 +04:00
|
|
|
{
|
2007-10-22 20:49:09 +04:00
|
|
|
if(op->Name.size())
|
2007-09-19 17:05:28 +04:00
|
|
|
{
|
|
|
|
os << "<ul>\n";
|
2007-10-22 20:49:09 +04:00
|
|
|
for(;op != entries.end() && op->Name.size(); ++op)
|
2007-09-19 17:05:28 +04:00
|
|
|
{
|
|
|
|
os << " <li>\n";
|
2007-10-22 20:49:09 +04:00
|
|
|
if(op->Name.size())
|
2007-09-19 17:05:28 +04:00
|
|
|
{
|
2008-05-05 20:02:36 +04:00
|
|
|
os << " <a name=\"" << prefix << ":";
|
|
|
|
cmDocumentationPrintHTMLId(os, op->Name.c_str());
|
|
|
|
os << "\"><b><code>";
|
2007-10-22 20:49:09 +04:00
|
|
|
this->PrintHTMLEscapes(os, op->Name.c_str());
|
2007-10-24 19:36:47 +04:00
|
|
|
os << "</code></b></a>: ";
|
2007-09-19 17:05:28 +04:00
|
|
|
}
|
2007-10-22 20:49:09 +04:00
|
|
|
this->PrintHTMLEscapes(os, op->Brief.c_str());
|
|
|
|
if(op->Full.size())
|
2007-09-19 17:05:28 +04:00
|
|
|
{
|
|
|
|
os << "<br>\n ";
|
2007-10-22 20:49:09 +04:00
|
|
|
this->PrintFormatted(os, op->Full.c_str());
|
2007-09-19 17:05:28 +04:00
|
|
|
}
|
|
|
|
os << "\n";
|
|
|
|
os << " </li>\n";
|
|
|
|
}
|
|
|
|
os << "</ul>\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-22 20:49:09 +04:00
|
|
|
this->PrintFormatted(os, op->Brief.c_str());
|
2007-09-19 17:05:28 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-10-10 19:23:35 +04:00
|
|
|
void cmDocumentationFormatterHTML::PrintHeader(const char* docname,
|
|
|
|
const char* appname,
|
2007-09-19 17:05:28 +04:00
|
|
|
std::ostream& os)
|
|
|
|
{
|
2008-10-10 19:23:35 +04:00
|
|
|
os << "<html><head><title>";
|
|
|
|
os << docname << " - " << appname;
|
|
|
|
os << "</title></head><body>\n";
|
2007-09-19 17:05:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-05 19:05:22 +03:00
|
|
|
|
|
|
|
void cmDocumentationFormatterHTML
|
|
|
|
::PrintIndex(std::ostream& os,
|
|
|
|
std::vector<const cmDocumentationSection *>& sections)
|
|
|
|
{
|
2008-07-22 01:52:59 +04:00
|
|
|
// skip the index if only the help for a single item is printed
|
|
|
|
if ((sections.size() == 1)
|
|
|
|
&& (sections[0]->GetName(this->GetForm()) != 0 )
|
|
|
|
&& (std::string(sections[0]->GetName(this->GetForm())) == "SingleItem"))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-15 04:54:22 +04:00
|
|
|
os << "<h2><a name=\"section_Index\"/>Master Index "
|
|
|
|
<< "CMake " << cmVersion::GetCMakeVersion()
|
|
|
|
<< "</h2>\n";
|
2008-03-05 19:05:22 +03:00
|
|
|
os << "<ul>\n";
|
|
|
|
for(unsigned int i=0; i < sections.size(); ++i)
|
|
|
|
{
|
|
|
|
std::string name = sections[i]->
|
|
|
|
GetName((this->GetForm()));
|
2008-03-06 19:34:23 +03:00
|
|
|
os << " <li><a href=\"#section_"
|
|
|
|
<< name << "\"<b>" << name << "</b></a></li>\n";
|
2008-03-05 19:05:22 +03:00
|
|
|
}
|
|
|
|
os << "</ul>\n";
|
|
|
|
}
|