diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 23bbd8faa..a26230ef5 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -101,6 +101,11 @@ SET(SRCS cmDependsJavaParserHelper.cxx cmDependsJavaParserHelper.h cmDocumentation.cxx + cmDocumentationFormatter.cxx + cmDocumentationFormatterHTML.cxx + cmDocumentationFormatterMan.cxx + cmDocumentationFormatterText.cxx + cmDocumentationFormatterUsage.cxx cmDynamicLoader.cxx cmDynamicLoader.h cmExprLexer.cxx diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 64d76884c..455d60efc 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -277,11 +277,10 @@ cmDocumentation::cmDocumentation() "SOURCEFILE PROPERTIES") ,VariablePropertiesSection ("Variables", "VARIABLES") ,CachedVariablePropertiesSection("Cached Variables", "CACHE VARIABLES") +,CurrentFormatter(0) { - this->CurrentForm = TextForm; - this->TextIndent = ""; - this->TextWidth = 77; - + this->SetForm(TextForm); + this->PropertySections[cmProperty::GLOBAL] = &this->GlobalPropertiesSection; this->PropertySections[cmProperty::DIRECTORY] = &this->DirectoryPropertiesSection; @@ -314,13 +313,13 @@ bool cmDocumentation::PrintCopyright(std::ostream& os) if(op->name) { os << " * "; - this->TextIndent = " "; - this->PrintColumn(os, op->brief); + this->TextFormatter.SetIndent(" "); + this->TextFormatter.PrintColumn(os, op->brief); } else { - this->TextIndent = ""; - this->PrintColumn(os, op->brief); + this->TextFormatter.SetIndent(""); + this->TextFormatter.PrintColumn(os, op->brief); } os << "\n"; } @@ -348,7 +347,7 @@ void cmDocumentation::AddSection(const cmSection& section) { if (!section.IsEmpty()) { - this->Names.push_back(section.GetName(this->CurrentForm)); + this->Names.push_back(section.GetName(this->CurrentFormatter->GetForm())); this->Sections.push_back(section.GetEntries()); } } @@ -363,7 +362,8 @@ void cmDocumentation::ClearSections() //---------------------------------------------------------------------------- bool cmDocumentation::PrintDocumentation(Type ht, std::ostream& os) { - if ((this->CurrentForm != HTMLForm) && (this->CurrentForm != ManForm)) + if ((this->CurrentFormatter->GetForm() != HTMLForm) + && (this->CurrentFormatter->GetForm() != ManForm)) { this->PrintVersion(os); } @@ -532,7 +532,7 @@ bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os) i != this->RequestedHelpItems.end(); ++i) { - this->CurrentForm = i->HelpForm; + this->SetForm(i->HelpForm); this->CurrentArgument = i->Argument; // If a file name was given, use it. Otherwise, default to the // given stream. @@ -739,7 +739,7 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv) //---------------------------------------------------------------------------- void cmDocumentation::Print(Form f, std::ostream& os) { - this->CurrentForm = f; + this->SetForm(f); Print(os); } @@ -748,7 +748,7 @@ void cmDocumentation::Print(std::ostream& os) { for(unsigned int i=0; i < this->Sections.size(); ++i) { - this->PrintSection(os, this->Sections[i], this->Names[i]); + this->CurrentFormatter->PrintSection(os,this->Sections[i], this->Names[i]); } } @@ -865,483 +865,6 @@ void cmDocumentation::SetSeeAlsoList(const cmDocumentationEntry* also) this->SeeAlsoSection.Append(e); } -//---------------------------------------------------------------------------- -void cmDocumentation::PrintSection(std::ostream& os, - const cmDocumentationEntry* section, - const char* name) -{ - switch (this->CurrentForm) - { - case TextForm: this->PrintSectionText(os, section, name); break; - case HTMLForm: this->PrintSectionHTML(os, section, name); break; - case ManForm: this->PrintSectionMan(os, section, name); break; - case UsageForm: this->PrintSectionUsage(os, section, name); break; - } -} - -//---------------------------------------------------------------------------- -void cmDocumentation::PrintSectionText(std::ostream& os, - const cmDocumentationEntry* section, - const char* name) -{ - if(name) - { - os << - "---------------------------------------" - "---------------------------------------\n"; - os << name << "\n\n"; - } - if(!section) { return; } - for(const cmDocumentationEntry* op = section; op->brief; ++op) - { - if(op->name) - { - if(op->name[0]) - { - os << " " << op->name << "\n"; - } - this->TextIndent = " "; - this->PrintFormatted(os, op->brief); - if(op->full) - { - os << "\n"; - this->PrintFormatted(os, op->full); - } - } - else - { - this->TextIndent = ""; - this->PrintFormatted(os, op->brief); - } - os << "\n"; - } -} - -//---------------------------------------------------------------------------- -void cmDocumentation::PrintSectionHTML(std::ostream& os, - const cmDocumentationEntry* section, - const char* name) -{ - if(name) - { - os << "
";
- this->PrintHTMLEscapes(os, op->name);
- os << "
: ";
- }
- this->PrintHTMLEscapes(os, op->brief);
- if(op->full)
- {
- os << ""; - this->PrintHTMLEscapes(os, text); - os << "\n "; -} - -//---------------------------------------------------------------------------- -void cmDocumentation::PrintParagraphHTML(std::ostream& os, const char* text) -{ - os << "
";
- this->PrintHTMLEscapes(os, text);
-}
-
-//----------------------------------------------------------------------------
-void cmDocumentation::PrintPreformattedMan(std::ostream& os, const char* text)
-{
- std::string man_text = text;
- cmSystemTools::ReplaceString(man_text, "\\", "\\\\");
- os << man_text << "\n";
-}
-
-//----------------------------------------------------------------------------
-void cmDocumentation::PrintParagraphMan(std::ostream& os, const char* text)
-{
- std::string man_text = text;
- cmSystemTools::ReplaceString(man_text, "\\", "\\\\");
- os << man_text << "\n\n";
-}
-
-//----------------------------------------------------------------------------
-void cmDocumentation::PrintColumn(std::ostream& os, const char* text)
-{
- // Print text arranged in an indented column of fixed witdh.
- const char* l = text;
- int column = 0;
- bool newSentence = false;
- bool firstLine = true;
- int width = this->TextWidth - static_cast ";
+ this->PrintHTMLEscapes(os, text);
+}
+
+//----------------------------------------------------------------------------
+void cmDocumentationFormatterHTML::PrintHeader(const char* name,
+ std::ostream& os)
+{
+ os << "
", 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 << "";
-
- // The name of the hyperlink is the text itself.
- for(const char* c = begin; c != end; ++c)
- {
- cmDocumentationPrintHTMLChar(os, *c);
- }
- os << "";
-
- // Return the position at which to continue scanning the input
- // string.
- return end;
-}
-
-//----------------------------------------------------------------------------
-void cmDocumentation::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++);
- }
- }
-}
-
//----------------------------------------------------------------------------
bool cmDocumentation::PrintDocumentationSingle(std::ostream& os)
{
@@ -1545,9 +1068,9 @@ bool cmDocumentation::PrintDocumentationUsage(std::ostream& os)
bool cmDocumentation::PrintDocumentationFull(std::ostream& os)
{
this->CreateFullDocumentation();
- this->PrintHeader(GetNameString(), os);
+ this->CurrentFormatter->PrintHeader(GetNameString(), os);
this->Print(os);
- this->PrintFooter(os);
+ this->CurrentFormatter->PrintFooter(os);
return true;
}
@@ -1555,9 +1078,9 @@ bool cmDocumentation::PrintDocumentationFull(std::ostream& os)
bool cmDocumentation::PrintDocumentationModules(std::ostream& os)
{
this->CreateModulesDocumentation();
- this->PrintHeader(GetNameString(), os);
+ this->CurrentFormatter->PrintHeader(GetNameString(), os);
this->Print(os);
- this->PrintFooter(os);
+ this->CurrentFormatter->PrintFooter(os);
return true;
}
@@ -1565,9 +1088,9 @@ bool cmDocumentation::PrintDocumentationModules(std::ostream& os)
bool cmDocumentation::PrintDocumentationProperties(std::ostream& os)
{
this->CreatePropertiesDocumentation();
- this->PrintHeader(GetNameString(), os);
+ this->CurrentFormatter->PrintHeader(GetNameString(), os);
this->Print(os);
- this->PrintFooter(os);
+ this->CurrentFormatter->PrintFooter(os);
return true;
}
@@ -1575,9 +1098,9 @@ bool cmDocumentation::PrintDocumentationProperties(std::ostream& os)
bool cmDocumentation::PrintDocumentationCurrentCommands(std::ostream& os)
{
this->CreateCurrentCommandsDocumentation();
- this->PrintHeader(GetNameString(), os);
+ this->CurrentFormatter->PrintHeader(GetNameString(), os);
this->Print(os);
- this->PrintFooter(os);
+ this->CurrentFormatter->PrintFooter(os);
return true;
}
@@ -1585,48 +1108,12 @@ bool cmDocumentation::PrintDocumentationCurrentCommands(std::ostream& os)
bool cmDocumentation::PrintDocumentationCompatCommands(std::ostream& os)
{
this->CreateCompatCommandsDocumentation();
- this->PrintHeader(GetNameString(), os);
+ this->CurrentFormatter->PrintHeader(GetNameString(), os);
this->Print(os);
- this->PrintFooter(os);
+ this->CurrentFormatter->PrintFooter(os);
return true;
}
-//----------------------------------------------------------------------------
-void cmDocumentation::PrintHeader(const char* name, std::ostream& os)
-{
- switch(this->CurrentForm)
- {
- case HTMLForm:
- os << "\n";
- break;
- case ManForm:
- os << ".TH " << name << " 1 \""
- << cmSystemTools::GetCurrentDateTime("%B %d, %Y").c_str()
- << "\" \"" << this->GetNameString()
- << " " << cmVersion::GetCMakeVersion()
- << "\"\n";
- break;
- case TextForm:
- case UsageForm:
- break;
- }
-}
-
-//----------------------------------------------------------------------------
-void cmDocumentation::PrintFooter(std::ostream& os)
-{
- switch(this->CurrentForm)
- {
- case HTMLForm:
- os << "\n";
- break;
- case ManForm:
- case TextForm:
- case UsageForm:
- break;
- }
-}
-
//----------------------------------------------------------------------------
void cmDocumentation::PrintDocumentationCommand(std::ostream& os,
const cmDocumentationEntry* entry)
@@ -1671,10 +1158,10 @@ void cmDocumentation::CreateFullDocumentation()
this->AddSection(this->VariablePropertiesSection);
this->AddSection(this->CachedVariablePropertiesSection);
- this->AddSection(this->CopyrightSection.GetName(this->CurrentForm),
- cmDocumentationCopyright);
+ this->AddSection(this->CopyrightSection.GetName(
+ this->CurrentFormatter->GetForm()), cmDocumentationCopyright);
- if(this->CurrentForm == ManForm)
+ if(this->CurrentFormatter->GetForm() == ManForm)
{
this->AddSection(this->SeeAlsoSection);
this->AddSection(this->AuthorSection.GetName(ManForm),
@@ -1691,22 +1178,23 @@ void cmDocumentation::CreateCurrentCommandsDocumentation()
{
this->ClearSections();
this->AddSection(this->CommandsSection);
- this->AddSection(this->CopyrightSection.GetName(CurrentForm),
- cmDocumentationCopyright);
- this->AddSection(this->SeeAlsoSection.GetName(CurrentForm),
- cmDocumentationStandardSeeAlso);
+ this->AddSection(this->CopyrightSection.GetName(
+ this->CurrentFormatter->GetForm()), cmDocumentationCopyright);
+ this->AddSection(this->SeeAlsoSection.GetName(
+ this->CurrentFormatter->GetForm()), cmDocumentationStandardSeeAlso);
}
void cmDocumentation::CreateCompatCommandsDocumentation()
{
this->ClearSections();
- this->AddSection(this->DescriptionSection.GetName(CurrentForm),
- cmCompatCommandsDocumentationDescription);
+ this->AddSection(this->DescriptionSection.GetName(
+ this->CurrentFormatter->GetForm()),
+ cmCompatCommandsDocumentationDescription);
this->AddSection(this->CompatCommandsSection);
- this->AddSection(this->CopyrightSection.GetName(CurrentForm),
- cmDocumentationCopyright);
- this->AddSection(this->SeeAlsoSection.GetName(CurrentForm),
- cmDocumentationStandardSeeAlso);
+ this->AddSection(this->CopyrightSection.GetName(
+ this->CurrentFormatter->GetForm()), cmDocumentationCopyright);
+ this->AddSection(this->SeeAlsoSection.GetName(
+ this->CurrentFormatter->GetForm()), cmDocumentationStandardSeeAlso);
}
//----------------------------------------------------------------------------
@@ -1714,21 +1202,21 @@ void cmDocumentation::CreateModulesDocumentation()
{
this->ClearSections();
this->CreateModulesSection();
- this->AddSection(this->DescriptionSection.GetName(CurrentForm),
- cmModulesDocumentationDescription);
+ this->AddSection(this->DescriptionSection.GetName(
+ this->CurrentFormatter->GetForm()), cmModulesDocumentationDescription);
this->AddSection(this->ModulesSection);
- this->AddSection(this->CopyrightSection.GetName(CurrentForm),
- cmDocumentationCopyright);
- this->AddSection(this->SeeAlsoSection.GetName(CurrentForm),
- cmDocumentationStandardSeeAlso);
+ this->AddSection(this->CopyrightSection.GetName(
+ this->CurrentFormatter->GetForm()), cmDocumentationCopyright);
+ this->AddSection(this->SeeAlsoSection.GetName(
+ this->CurrentFormatter->GetForm()), cmDocumentationStandardSeeAlso);
}
//----------------------------------------------------------------------------
void cmDocumentation::CreatePropertiesDocumentation()
{
this->ClearSections();
- this->AddSection(this->DescriptionSection.GetName(CurrentForm),
- cmPropertiesDocumentationDescription);
+ this->AddSection(this->DescriptionSection.GetName(
+ this->CurrentFormatter->GetForm()), cmPropertiesDocumentationDescription);
this->AddSection(this->GlobalPropertiesSection);
this->AddSection(this->DirectoryPropertiesSection);
this->AddSection(this->TargetPropertiesSection);
@@ -1736,12 +1224,33 @@ void cmDocumentation::CreatePropertiesDocumentation()
this->AddSection(this->SourceFilePropertiesSection);
this->AddSection(this->VariablePropertiesSection);
this->AddSection(this->CachedVariablePropertiesSection);
- this->AddSection(this->CopyrightSection.GetName(CurrentForm),
- cmDocumentationCopyright);
- this->AddSection(this->SeeAlsoSection.GetName(CurrentForm),
- cmDocumentationStandardSeeAlso);
+ this->AddSection(this->CopyrightSection.GetName(
+ this->CurrentFormatter->GetForm()), cmDocumentationCopyright);
+ this->AddSection(this->SeeAlsoSection.GetName(
+ this->CurrentFormatter->GetForm()), cmDocumentationStandardSeeAlso);
}
+//----------------------------------------------------------------------------
+void cmDocumentation::SetForm(Form f)
+{
+ switch(f)
+ {
+ case HTMLForm:
+ this->CurrentFormatter = &this->HTMLFormatter;
+ break;
+ case ManForm:
+ this->CurrentFormatter = &this->ManFormatter;
+ break;
+ case TextForm:
+ this->CurrentFormatter = &this->TextFormatter;
+ break;
+ case UsageForm:
+ this->CurrentFormatter = & this->UsageFormatter;
+ break;
+ }
+}
+
+
//----------------------------------------------------------------------------
void cmDocumentation::cmSection::Set(const cmDocumentationEntry* header,
const cmDocumentationEntry* section,
diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h
index bac58b931..90e6e6983 100644
--- a/Source/cmDocumentation.h
+++ b/Source/cmDocumentation.h
@@ -19,26 +19,11 @@
#include "cmStandardIncludes.h"
#include "cmProperty.h"
-
-/** This is just a helper class to make it build with MSVC 6.0.
-Actually the enums and internal classes could directly go into
-cmDocumentation, but then MSVC6 complains in RequestedHelpItem that
-cmDocumentation is an undefined type and so it doesn't know the enums.
-Moving the enums to a class which is then already completely parsed helps.
-against this. */
-class cmDocumentationEnums
-{
-public:
- /** Types of help provided. */
- enum Type
- { None, Usage, Single, SingleModule, SingleProperty,
- List, ModuleList, PropertyList,
- Full, Properties, Modules, Commands, CompatCommands,
- Copyright, Version };
-
- /** Forms of documentation output. */
- enum Form { TextForm, HTMLForm, ManForm, UsageForm };
-};
+#include "cmDocumentationFormatter.h"
+#include "cmDocumentationFormatterHTML.h"
+#include "cmDocumentationFormatterMan.h"
+#include "cmDocumentationFormatterText.h"
+#include "cmDocumentationFormatterUsage.h"
/** Class to generate documentation. */
@@ -176,34 +161,7 @@ public:
static Form GetFormFromFilename(const std::string& filename);
private:
- void PrintHeader(const char* title, std::ostream& os);
- void PrintFooter(std::ostream& os);
-
- void PrintSection(std::ostream& os,
- const cmDocumentationEntry* section,
- const char* name);
- void PrintSectionText(std::ostream& os,
- const cmDocumentationEntry* section,
- const char* name);
- void PrintSectionHTML(std::ostream& os,
- const cmDocumentationEntry* section,
- const char* name);
- void PrintSectionMan(std::ostream& os, const cmDocumentationEntry* section,
- const char* name);
- void PrintSectionUsage(std::ostream& os,
- const cmDocumentationEntry* section,
- const char* name);
- void PrintFormatted(std::ostream& os, const char* text);
- void PrintPreformatted(std::ostream& os, const char* text);
- void PrintPreformattedText(std::ostream& os, const char* text);
- void PrintPreformattedHTML(std::ostream& os, const char* text);
- void PrintPreformattedMan(std::ostream& os, const char* text);
- void PrintParagraph(std::ostream& os, const char* text);
- void PrintParagraphText(std::ostream& os, const char* text);
- void PrintParagraphHTML(std::ostream& os, const char* text);
- void PrintParagraphMan(std::ostream& os, const char* text);
- void PrintColumn(std::ostream& os, const char* text);
- void PrintHTMLEscapes(std::ostream& os, const char* text);
+ void SetForm(Form f);
bool CreateSingleModule(const char* fname, const char* moduleName);
bool CreateModulesSection();
@@ -223,7 +181,7 @@ private:
bool PrintDocumentationCompatCommands(std::ostream& os);
void PrintDocumentationCommand(std::ostream& os,
const cmDocumentationEntry* entry);
-
+
void CreateUsageDocumentation();
void CreateFullDocumentation();
void CreateCurrentCommandsDocumentation();
@@ -264,10 +222,7 @@ private:
std::vector< char* > ModuleStrings;
std::vector< const char* > Names;
std::vector< const cmDocumentationEntry* > Sections;
- Form CurrentForm;
std::string CurrentArgument;
- const char* TextIndent;
- int TextWidth;
struct RequestedHelpItem
{
@@ -279,6 +234,12 @@ private:
};
std::vector
", 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 << "";
+
+ // The name of the hyperlink is the text itself.
+ for(const char* c = begin; c != end; ++c)
+ {
+ cmDocumentationPrintHTMLChar(os, *c);
+ }
+ os << "";
+
+ // 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 << "" << name << "
\n";
+ }
+ if(!section) { return; }
+ for(const cmDocumentationEntry* op = section; op->brief;)
+ {
+ if(op->name)
+ {
+ os << "\n";
+ for(;op->name;++op)
+ {
+ os << "
\n";
+ }
+ else
+ {
+ this->PrintFormatted(os, op->brief);
+ os << "\n";
+ ++op;
+ }
+ }
+}
+
+void cmDocumentationFormatterHTML::PrintPreformatted(std::ostream& os,
+ const char* text)
+{
+ os << "";
+ this->PrintHTMLEscapes(os, op->name);
+ os << "
: ";
+ }
+ this->PrintHTMLEscapes(os, op->brief);
+ if(op->full)
+ {
+ os << "
\n ";
+ this->PrintFormatted(os, op->full);
+ }
+ os << "\n";
+ os << " ";
+ this->PrintHTMLEscapes(os, text);
+ os << "
\n ";
+}
+
+void cmDocumentationFormatterHTML::PrintParagraph(std::ostream& os,
+ const char* text)
+{
+ os << "