diff options
author | Brad King <brad.king@kitware.com> | 2013-09-13 20:09:52 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2013-10-16 13:22:35 (GMT) |
commit | 80a3273b5e062ea163973b504f239e0832d4cdb4 (patch) | |
tree | 239144d8917c752fbdae1db46c413a29f0f3a521 /Source | |
parent | b336a1ebe48a964431734568d78256a4ebd5cdad (diff) | |
download | CMake-80a3273b5e062ea163973b504f239e0832d4cdb4.zip CMake-80a3273b5e062ea163973b504f239e0832d4cdb4.tar.gz CMake-80a3273b5e062ea163973b504f239e0832d4cdb4.tar.bz2 |
Drop all documentation formatters except Usage
We now need only the Usage formatter to support command-line options
that print basic usage, and the supporting indented=>preformatted markup
processor to support CMake message formatting. Drop all other
documentation formatters and move the remaining code up into the top
cmDocumentationFormatter class.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Source/cmDocumentation.cxx | 161 | ||||
-rw-r--r-- | Source/cmDocumentation.h | 46 | ||||
-rw-r--r-- | Source/cmDocumentationFormatter.cxx | 240 | ||||
-rw-r--r-- | Source/cmDocumentationFormatter.h | 30 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterDocbook.cxx | 254 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterDocbook.h | 43 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterHTML.cxx | 288 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterHTML.h | 42 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterMan.cxx | 102 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterMan.h | 43 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterRST.cxx | 107 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterRST.h | 34 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterText.cxx | 180 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterText.h | 40 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterUsage.cxx | 63 | ||||
-rw-r--r-- | Source/cmDocumentationFormatterUsage.h | 31 | ||||
-rw-r--r-- | Source/cmDocumentationSection.h | 12 | ||||
-rw-r--r-- | Source/cmake.cxx | 4 |
19 files changed, 202 insertions, 1524 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index d549ccb..3228f38 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -159,12 +159,6 @@ set(SRCS cmDependsJavaParserHelper.h cmDocumentation.cxx cmDocumentationFormatter.cxx - cmDocumentationFormatterHTML.cxx - cmDocumentationFormatterDocbook.cxx - cmDocumentationFormatterMan.cxx - cmDocumentationFormatterRST.cxx - cmDocumentationFormatterText.cxx - cmDocumentationFormatterUsage.cxx cmDocumentationSection.cxx cmDocumentCompileDefinitions.h cmDocumentGeneratorExpressions.h diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 3c51e7a..f66866f 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -56,9 +56,7 @@ static const char *cmDocumentationGeneratorsHeader[][3] = //---------------------------------------------------------------------------- cmDocumentation::cmDocumentation() -:CurrentFormatter(0) { - this->SetForm(TextForm, 0); this->addCommonStandardDocSections(); this->ShowGenerators = true; } @@ -83,22 +81,6 @@ bool cmDocumentation::PrintVersion(std::ostream& os) } //---------------------------------------------------------------------------- -void cmDocumentation::AddSectionToPrint(const char *section) -{ - if (this->AllSections.find(section) != this->AllSections.end()) - { - this->PrintSections.push_back(this->AllSections[section]); - } -} - -//---------------------------------------------------------------------------- -void cmDocumentation::ClearSections() -{ - this->PrintSections.erase(this->PrintSections.begin(), - this->PrintSections.end()); -} - -//---------------------------------------------------------------------------- bool cmDocumentation::PrintDocumentation(Type ht, std::ostream& os) { switch (ht) @@ -147,7 +129,6 @@ bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os) i != this->RequestedHelpItems.end(); ++i) { - this->SetForm(i->HelpForm, i->ManSection); this->CurrentArgument = i->Argument; // If a file name was given, use it. Otherwise, default to the // given stream. @@ -193,38 +174,27 @@ bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os) }; -cmDocumentation::Form cmDocumentation::GetFormFromFilename( - const std::string& filename, - int* manSection) +void cmDocumentation::WarnFormFromFilename( + cmDocumentation::RequestedHelpItem& request) { - std::string ext = cmSystemTools::GetFilenameLastExtension(filename); + std::string ext = cmSystemTools::GetFilenameLastExtension(request.Filename); ext = cmSystemTools::UpperCase(ext); if ((ext == ".HTM") || (ext == ".HTML")) { - return cmDocumentation::HTMLForm; + request.HelpType = cmDocumentation::None; + cmSystemTools::Message("Warning: HTML help format no longer supported"); } - - if (ext == ".DOCBOOK") + else if (ext == ".DOCBOOK") { - return cmDocumentation::DocbookForm; + request.HelpType = cmDocumentation::None; + cmSystemTools::Message("Warning: Docbook help format no longer supported"); } - // ".1" to ".9" should be manpages - if ((ext.length()==2) && (ext[1] >='1') && (ext[1]<='9')) + else if ((ext.length()==2) && (ext[1] >='1') && (ext[1]<='9')) { - if (manSection) - { - *manSection = ext[1] - '0'; - } - return cmDocumentation::ManForm; - } - - if (ext == ".RST") - { - return cmDocumentation::RSTForm; + request.HelpType = cmDocumentation::None; + cmSystemTools::Message("Warning: Man help format no longer supported"); } - - return cmDocumentation::TextForm; } //---------------------------------------------------------------------------- @@ -274,7 +244,6 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, { RequestedHelpItem help; help.HelpType = cmDocumentation::Usage; - help.HelpForm = cmDocumentation::UsageForm; this->RequestedHelpItems.push_back(help); return true; } @@ -298,7 +267,6 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, (strcmp(argv[i], "-H") == 0)) { help.HelpType = cmDocumentation::Usage; - help.HelpForm = cmDocumentation::UsageForm; GET_OPT_ARGUMENT(help.Argument); help.Argument = cmSystemTools::LowerCase(help.Argument); // special case for single command @@ -312,32 +280,28 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, help.HelpType = cmDocumentation::OneManual; help.Argument = "cmake-properties.7"; GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = this->GetFormFromFilename(help.Filename, - &help.ManSection); + this->WarnFormFromFilename(help); } else if(strcmp(argv[i], "--help-policies") == 0) { help.HelpType = cmDocumentation::OneManual; help.Argument = "cmake-policies.7"; GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = this->GetFormFromFilename(help.Filename, - &help.ManSection); + this->WarnFormFromFilename(help); } else if(strcmp(argv[i], "--help-variables") == 0) { help.HelpType = cmDocumentation::OneManual; help.Argument = "cmake-variables.7"; GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = this->GetFormFromFilename(help.Filename, - &help.ManSection); + this->WarnFormFromFilename(help); } else if(strcmp(argv[i], "--help-modules") == 0) { help.HelpType = cmDocumentation::OneManual; help.Argument = "cmake-modules.7"; GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = this->GetFormFromFilename(help.Filename, - &help.ManSection); + this->WarnFormFromFilename(help); } else if(strcmp(argv[i], "--help-custom-modules") == 0) { @@ -351,8 +315,7 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, help.HelpType = cmDocumentation::OneManual; help.Argument = "cmake-commands.7"; GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = this->GetFormFromFilename(help.Filename, - &help.ManSection); + this->WarnFormFromFilename(help); } else if(strcmp(argv[i], "--help-compatcommands") == 0) { @@ -385,40 +348,35 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, GET_OPT_ARGUMENT(help.Argument); GET_OPT_ARGUMENT(help.Filename); help.Argument = cmSystemTools::LowerCase(help.Argument); - help.HelpForm = this->GetFormFromFilename(help.Filename, - &help.ManSection); + this->WarnFormFromFilename(help); } else if(strcmp(argv[i], "--help-module") == 0) { help.HelpType = cmDocumentation::OneModule; GET_OPT_ARGUMENT(help.Argument); GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = this->GetFormFromFilename(help.Filename, - &help.ManSection); + this->WarnFormFromFilename(help); } else if(strcmp(argv[i], "--help-property") == 0) { help.HelpType = cmDocumentation::OneProperty; GET_OPT_ARGUMENT(help.Argument); GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = this->GetFormFromFilename(help.Filename, - &help.ManSection); + this->WarnFormFromFilename(help); } else if(strcmp(argv[i], "--help-policy") == 0) { help.HelpType = cmDocumentation::OnePolicy; GET_OPT_ARGUMENT(help.Argument); GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = this->GetFormFromFilename(help.Filename, - &help.ManSection); + this->WarnFormFromFilename(help); } else if(strcmp(argv[i], "--help-variable") == 0) { help.HelpType = cmDocumentation::OneVariable; GET_OPT_ARGUMENT(help.Argument); GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = this->GetFormFromFilename(help.Filename, - &help.ManSection); + this->WarnFormFromFilename(help); } else if(strcmp(argv[i], "--help-manual") == 0) { @@ -431,31 +389,26 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, { help.HelpType = cmDocumentation::ListCommands; GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = cmDocumentation::TextForm; } else if(strcmp(argv[i], "--help-module-list") == 0) { help.HelpType = cmDocumentation::ListModules; GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = cmDocumentation::TextForm; } else if(strcmp(argv[i], "--help-property-list") == 0) { help.HelpType = cmDocumentation::ListProperties; GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = cmDocumentation::TextForm; } else if(strcmp(argv[i], "--help-variable-list") == 0) { help.HelpType = cmDocumentation::ListVariables; GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = cmDocumentation::TextForm; } else if(strcmp(argv[i], "--help-policy-list") == 0) { help.HelpType = cmDocumentation::ListPolicies; GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = cmDocumentation::TextForm; } else if(strcmp(argv[i], "--help-manual-list") == 0) { @@ -474,7 +427,6 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, { help.HelpType = cmDocumentation::Version; GET_OPT_ARGUMENT(help.Filename); - help.HelpForm = cmDocumentation::UsageForm; } if(help.HelpType != None) { @@ -487,28 +439,6 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, } //---------------------------------------------------------------------------- -void cmDocumentation::Print(Form f, int manSection, std::ostream& os) -{ - this->SetForm(f, manSection); - this->Print(os); -} - -//---------------------------------------------------------------------------- -void cmDocumentation::Print(std::ostream& os) -{ - // if the formatter supports it, print a master index for - // all sections - this->CurrentFormatter->PrintIndex(os, this->PrintSections); - for(unsigned int i=0; i < this->PrintSections.size(); ++i) - { - std::string name = this->PrintSections[i]-> - GetName((this->CurrentFormatter->GetForm())); - this->CurrentFormatter->PrintSection(os,*this->PrintSections[i], - name.c_str()); - } -} - -//---------------------------------------------------------------------------- void cmDocumentation::SetName(const char* name) { this->NameString = name?name:""; @@ -864,46 +794,29 @@ bool cmDocumentation::PrintHelpListVariables(std::ostream& os) //---------------------------------------------------------------------------- bool cmDocumentation::PrintDocumentationUsage(std::ostream& os) { - this->ClearSections(); - this->AddSectionToPrint("Usage"); - this->AddSectionToPrint("Options"); + std::map<std::string,cmDocumentationSection*>::iterator si; + si = this->AllSections.find("Usage"); + if(si != this->AllSections.end()) + { + this->Formatter.PrintSection(os, *si->second); + } + si = this->AllSections.find("Options"); + if(si != this->AllSections.end()) + { + this->Formatter.PrintSection(os, *si->second); + } if(this->ShowGenerators) { - this->AddSectionToPrint("Generators"); + si = this->AllSections.find("Generators"); + if(si != this->AllSections.end()) + { + this->Formatter.PrintSection(os, *si->second); + } } - this->Print(os); return true; } //---------------------------------------------------------------------------- -void cmDocumentation::SetForm(Form f, int manSection) -{ - switch(f) - { - case HTMLForm: - this->CurrentFormatter = &this->HTMLFormatter; - break; - case DocbookForm: - this->CurrentFormatter = &this->DocbookFormatter; - break; - case ManForm: - this->ManFormatter.SetManSection(manSection); - this->CurrentFormatter = &this->ManFormatter; - break; - case RSTForm: - this->CurrentFormatter = &this->RSTFormatter; - break; - case TextForm: - this->CurrentFormatter = &this->TextFormatter; - break; - case UsageForm: - this->CurrentFormatter = & this->UsageFormatter; - break; - } -} - - -//---------------------------------------------------------------------------- const char* cmDocumentation::GetNameString() const { if(this->NameString.length() > 0) diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h index 31c7602..37707b4 100644 --- a/Source/cmDocumentation.h +++ b/Source/cmDocumentation.h @@ -15,12 +15,6 @@ #include "cmStandardIncludes.h" #include "cmProperty.h" #include "cmDocumentationFormatter.h" -#include "cmDocumentationFormatterHTML.h" -#include "cmDocumentationFormatterDocbook.h" -#include "cmDocumentationFormatterMan.h" -#include "cmDocumentationFormatterRST.h" -#include "cmDocumentationFormatterText.h" -#include "cmDocumentationFormatterUsage.h" #include "cmDocumentationSection.h" #include "cmake.h" @@ -89,33 +83,9 @@ public: void AppendSection(const char *sectionName, cmDocumentationEntry &docs); - /** - * Print documentation in the given form. All previously added - * sections will be generated. - */ - void Print(Form f, int manSection, std::ostream& os); - - /** - * Print documentation in the current form. All previously added - * sections will be generated. - */ - void Print(std::ostream& os); - - /** - * Add a section of documentation. This can be used to generate custom help - * documents. - */ - void AddSectionToPrint(const char *section); - - /** Clear all previously added sections of help. */ - void ClearSections(); - /** Set cmake root so we can find installed files */ void SetCMakeRoot(const char* root) { this->CMakeRoot = root;} - static Form GetFormFromFilename(const std::string& filename, - int* ManSection); - /** Add common (to all tools) documentation section(s) */ void addCommonStandardDocSections(); @@ -129,7 +99,6 @@ public: void addCPackStandardDocSections(); private: - void SetForm(Form f, int manSection); void GlobHelp(std::vector<std::string>& files, std::string const& pattern); void PrintNames(std::ostream& os, std::string const& pattern); @@ -159,27 +128,20 @@ private: std::map<std::string,cmDocumentationSection*> AllSections; std::string CMakeRoot; - std::vector<const cmDocumentationSection *> PrintSections; std::string CurrentArgument; struct RequestedHelpItem { - RequestedHelpItem():HelpForm(TextForm), HelpType(None), ManSection(1) {} - cmDocumentationEnums::Form HelpForm; + RequestedHelpItem(): HelpType(None) {} cmDocumentationEnums::Type HelpType; std::string Filename; std::string Argument; - int ManSection; }; std::vector<RequestedHelpItem> RequestedHelpItems; - cmDocumentationFormatter* CurrentFormatter; - cmDocumentationFormatterHTML HTMLFormatter; - cmDocumentationFormatterDocbook DocbookFormatter; - cmDocumentationFormatterMan ManFormatter; - cmDocumentationFormatterRST RSTFormatter; - cmDocumentationFormatterText TextFormatter; - cmDocumentationFormatterUsage UsageFormatter; + cmDocumentationFormatter Formatter; + + static void WarnFormFromFilename(RequestedHelpItem& request); }; #endif diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index a547176..29c806d 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -11,7 +11,10 @@ ============================================================================*/ #include "cmDocumentationFormatter.h" -cmDocumentationFormatter::cmDocumentationFormatter() +#include "cmDocumentationSection.h" + +cmDocumentationFormatter::cmDocumentationFormatter(): + TextWidth(77), TextIndent("") { } @@ -66,115 +69,162 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os, } } -//---------------------------------------------------------------------------- -std::string -cmDocumentationFormatter::ComputeSectionLinkPrefix(std::string const& name) +void cmDocumentationFormatter::PrintPreformatted(std::ostream& os, + const char* text) { - // Map from section name to a prefix for links pointing within the - // section. For example, the commands section should have HTML - // links to each command with names like #command:ADD_EXECUTABLE. - if(name.find("Command") != name.npos) - { - return "command"; - } - else if(name.find("Propert") != name.npos) + bool newline = true; + for(const char* ptr = text; *ptr; ++ptr) { - if(name.find("Global") != name.npos) - { - return "prop_gbl"; - } - else if(name.find("Direct") != name.npos) - { - return "prop_dir"; - } - else if(name.find("Target") != name.npos) - { - return "prop_tgt"; - } - else if(name.find("Test") != name.npos) + if(newline && *ptr != '\n') { - return "prop_test"; + os << this->TextIndent; + newline = false; } - else if(name.find("Source") != name.npos) + os << *ptr; + if(*ptr == '\n') { - return "prop_sf"; + newline = true; } - else if(name.find("Cache") != name.npos) - { - return "prop_cache"; - } - return "property"; } - else if(name.find("Variable") != name.npos) + os << "\n"; +} + +void cmDocumentationFormatter::PrintParagraph(std::ostream& os, + const char* text) +{ + os << this->TextIndent; + this->PrintColumn(os, text); + os << "\n"; +} + +void cmDocumentationFormatter::SetIndent(const char* indent) +{ + this->TextIndent = indent; +} + +void cmDocumentationFormatter::PrintColumn(std::ostream& os, + const char* text) +{ + // Print text arranged in an indented column of fixed witdh. + const char* l = text; + long column = 0; + bool newSentence = false; + bool firstLine = true; + int width = this->TextWidth - static_cast<int>(strlen(this->TextIndent)); + + // Loop until the end of the text. + while(*l) { - if(name.find("Information") != name.npos) - { - return "var_info"; - } - else if(name.find("Behavior") != name.npos) + // Parse the next word. + const char* r = l; + while(*r && (*r != '\n') && (*r != ' ')) { ++r; } + + // Does it fit on this line? + if(r-l < (width-column-(newSentence?1:0))) { - return "var_cmake"; + // Word fits on this line. + if(r > l) + { + if(column) + { + // Not first word on line. Separate from the previous word + // by a space, or two if this is a new sentence. + if(newSentence) + { + os << " "; + column += 2; + } + else + { + os << " "; + column += 1; + } + } + else + { + // First word on line. Print indentation unless this is the + // first line. + os << (firstLine?"":this->TextIndent); + } + + // Print the word. + os.write(l, static_cast<long>(r-l)); + newSentence = (*(r-1) == '.'); + } + + if(*r == '\n') + { + // Text provided a newline. Start a new line. + os << "\n"; + ++r; + column = 0; + firstLine = false; + } + else + { + // No provided newline. Continue this line. + column += static_cast<long>(r-l); + } } - else if(name.find("Describe") != name.npos) + else { - return "var_sys"; + // Word does not fit on this line. Start a new line. + os << "\n"; + firstLine = false; + if(r > l) + { + os << this->TextIndent; + os.write(l, static_cast<long>(r-l)); + column = static_cast<long>(r-l); + newSentence = (*(r-1) == '.'); + } + else + { + column = 0; + } } - else if(name.find("Control") != name.npos) + + // Move to beginning of next word. Skip over whitespace. + l = r; + while(*l && (*l == ' ')) { ++l; } + } +} + +void cmDocumentationFormatter +::PrintSection(std::ostream& os, + cmDocumentationSection const& section) +{ + os << section.GetName() << "\n"; + + const std::vector<cmDocumentationEntry> &entries = + section.GetEntries(); + for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin(); + op != entries.end(); ++op) + { + if(op->Name.size()) { - return "var_build"; + os << " " << op->Name; + this->TextIndent = " "; + int align = static_cast<int>(strlen(this->TextIndent))-4; + for(int i = static_cast<int>(op->Name.size()); i < align; ++i) + { + os << " "; + } + if (op->Name.size() > strlen(this->TextIndent)-4 ) + { + os << "\n"; + os.write(this->TextIndent, strlen(this->TextIndent)-2); + } + os << "= "; + this->PrintColumn(os, op->Brief.c_str()); + os << "\n"; } - else if(name.find("Languages") != name.npos) + else { - return "var_lang"; + os << "\n"; + this->TextIndent = ""; + this->PrintFormatted(os, op->Brief.c_str()); } - return "variable"; - } - else if(name.find("Polic") != name.npos) - { - return "policy"; - } - else if(name.find("Module") != name.npos) - { - return "module"; - } - else if(name.find("Name") != name.npos || - name.find("Introduction") != name.npos) - { - return "name"; - } - else if(name.find("Usage") != name.npos) - { - return "usage"; - } - else if(name.find("Description") != name.npos) - { - return "desc"; - } - else if(name.find("Generators") != name.npos) - { - return "generator"; - } - else if(name.find("Options") != name.npos) - { - return "opt"; - } - else if(name.find("Copyright") != name.npos) - { - return "copy"; - } - else if(name.find("See Also") != name.npos) - { - return "see"; - } - else if(name.find("SingleItem") != name.npos) - { - return "single_item"; - } - else - { - std::cerr - << "WARNING: ComputeSectionLinkPrefix failed for \"" << name << "\"" - << std::endl; - return "other"; } + os << "\n"; } diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index 0bce50c..c7da52c 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -30,15 +30,11 @@ public: ListCommands, ListModules, ListProperties, ListVariables, ListPolicies, OneManual, OneCommand, OneModule, OneProperty, OneVariable, OnePolicy }; - - /** Forms of documentation output. */ - enum Form { TextForm, HTMLForm, RSTForm, ManForm, UsageForm, DocbookForm }; }; class cmDocumentationSection; -/** Base class for printing the documentation in the various supported - formats. */ +/** Print documentation in a simple text format. */ class cmDocumentationFormatter { public: @@ -46,23 +42,15 @@ public: virtual ~cmDocumentationFormatter(); void PrintFormatted(std::ostream& os, const char* text); - virtual cmDocumentationEnums::Form GetForm() const = 0; - - virtual void PrintHeader(const char* /*docname*/, - const char* /*appname*/, - std::ostream& /*os*/) {} - virtual void PrintFooter(std::ostream& /*os*/) {} virtual void PrintSection(std::ostream& os, - const cmDocumentationSection& section, - const char* name) = 0; - virtual void PrintPreformatted(std::ostream& os, const char* text) = 0; - virtual void PrintParagraph(std::ostream& os, const char* text) = 0; - virtual void PrintIndex(std::ostream& , - std::vector<const cmDocumentationSection *>&) - {} - - /** Compute a prefix for links into a section (#\<prefix\>_SOMETHING). */ - std::string ComputeSectionLinkPrefix(std::string const& name); + cmDocumentationSection const& section); + virtual void PrintPreformatted(std::ostream& os, const char* text); + virtual void PrintParagraph(std::ostream& os, const char* text); + void PrintColumn(std::ostream& os, const char* text); + void SetIndent(const char* indent); +private: + int TextWidth; + const char* TextIndent; }; #endif diff --git a/Source/cmDocumentationFormatterDocbook.cxx b/Source/cmDocumentationFormatterDocbook.cxx deleted file mode 100644 index 706ce0a..0000000 --- a/Source/cmDocumentationFormatterDocbook.cxx +++ /dev/null @@ -1,254 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ -#include "cmDocumentationFormatterDocbook.h" -#include "cmDocumentationSection.h" -#include <algorithm> -#include <ctype.h> // for isalnum - -static int cmIsAlnum(int c) -{ - return isalnum(c); -} - -//---------------------------------------------------------------------------- - -// this function is a copy of the one in the HTML formatter -// the three functions below are slightly modified copies -static bool cmDocumentationIsHyperlinkCharDocbook(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 cmDocumentationPrintDocbookChar(std::ostream& os, char c) -{ - // Use an escape sequence if necessary. - switch(c) - { - case '<': - os << "<"; - break; - case '>': - os << ">"; - break; - case '&': - os << "&"; - break; - default: - os << c; - } -} - -//---------------------------------------------------------------------------- -const char* cmDocumentationPrintDocbookLink(std::ostream& os,const char* begin) -{ - // Look for the end of the link. - const char* end = begin; - while(cmDocumentationIsHyperlinkCharDocbook(*end)) - { - ++end; - } - - // Print the hyperlink itself. - os << "<ulink url=\""; - for(const char* c = begin; c != end; ++c) - { - cmDocumentationPrintDocbookChar(os, *c); - } - os << "\" />"; - - return end; -} - -//---------------------------------------------------------------------------- -void cmDocumentationPrintDocbookEscapes(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 = cmDocumentationPrintDocbookLink(os, p); - found_hyperlink = true; - } - } - - // Print other characters normally. - if(!found_hyperlink) - { - cmDocumentationPrintDocbookChar(os, *p++); - } - } -} - -//---------------------------------------------------------------------------- -cmDocumentationFormatterDocbook::cmDocumentationFormatterDocbook() -:cmDocumentationFormatter() -{ -} - -//---------------------------------------------------------------------------- -void cmDocumentationFormatterDocbook -::PrintSection(std::ostream& os, - const cmDocumentationSection §ion, - const char* name) -{ - os << "<sect1 id=\""; - this->PrintId(os, 0, name); - os << "\">\n<title>" << name << "</title>\n"; - - std::string prefix = this->ComputeSectionLinkPrefix(name); - const std::vector<cmDocumentationEntry> &entries = section.GetEntries(); - - bool hasSubSections = false; - for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin(); - op != entries.end(); ++op) - { - if(op->Name.size()) - { - hasSubSections = true; - break; - } - } - - bool inAbstract = false; - for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin(); - op != entries.end(); ++op) - { - if(op->Name.size()) - { - if(inAbstract) - { - os << "</abstract>\n"; - inAbstract = false; - } - os << "<sect2 id=\""; - this->PrintId(os, prefix.c_str(), op->Name); - os << "\">\n<title>"; - cmDocumentationPrintDocbookEscapes(os, op->Name.c_str()); - os << "</title>\n"; - if(op->Full.size()) - { - os << "<abstract>\n<para>"; - cmDocumentationPrintDocbookEscapes(os, op->Brief.c_str()); - os << "</para>\n</abstract>\n"; - this->PrintFormatted(os, op->Full.c_str()); - } - else - { - this->PrintFormatted(os, op->Brief.c_str()); - } - os << "</sect2>\n"; - } - else - { - if(hasSubSections && op == entries.begin()) - { - os << "<abstract>\n"; - inAbstract = true; - } - this->PrintFormatted(os, op->Brief.c_str()); - } - } - - // empty sections are not allowed in docbook. - if(entries.empty()) - { - os << "<para/>\n"; - } - - os << "</sect1>\n"; -} - -//---------------------------------------------------------------------------- -void cmDocumentationFormatterDocbook -::PrintPreformatted(std::ostream& os, const char* text) -{ - os << "<para>\n<programlisting>"; - cmDocumentationPrintDocbookEscapes(os, text); - os << "</programlisting>\n</para>\n"; -} - -void cmDocumentationFormatterDocbook -::PrintParagraph(std::ostream& os, const char* text) -{ - os << "<para>"; - cmDocumentationPrintDocbookEscapes(os, text); - os << "</para>\n"; -} - -//---------------------------------------------------------------------------- -void cmDocumentationFormatterDocbook -::PrintHeader(const char* docname, const char* appname, std::ostream& os) -{ - this->Docname = docname; - - // this one is used to ensure that we don't create multiple link targets - // with the same name. We can clear it here since we are at the - // start of a document here. - this->EmittedLinkIds.clear(); - - os << "<?xml version=\"1.0\" ?>\n" - "<!DOCTYPE article PUBLIC \"-//OASIS//DTD DocBook V4.5//EN\" " - "\"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd\" [\n" - "<!ENTITY % addindex \"IGNORE\">\n" - "<!ENTITY % English \"INCLUDE\"> ]>\n" - "<article>\n" - "<articleinfo>\n" - "<title>" << docname << " - " << appname << "</title>\n" - "</articleinfo>\n"; -} - -//---------------------------------------------------------------------------- -void cmDocumentationFormatterDocbook::PrintFooter(std::ostream& os) -{ - os << "</article>\n"; -} - -//---------------------------------------------------------------------------- -void cmDocumentationFormatterDocbook -::PrintId(std::ostream& os, const char* prefix, std::string id) -{ - std::replace_if(id.begin(), id.end(), - std::not1(std::ptr_fun(cmIsAlnum)), '_'); - if(prefix) - { - id = std::string(prefix) + "." + id; - } - os << this->Docname << '.' << id; - - // make sure that each id exists only once. Since it seems - // not easily possible to determine which link refers to which id, - // we have at least to make sure that the duplicated id's get a - // different name (by appending an increasing number), Alex - if (this->EmittedLinkIds.find(id) == this->EmittedLinkIds.end()) - { - this->EmittedLinkIds.insert(id); - } - else - { - static unsigned int i=0; - os << i++; - } -} diff --git a/Source/cmDocumentationFormatterDocbook.h b/Source/cmDocumentationFormatterDocbook.h deleted file mode 100644 index 0352d34..0000000 --- a/Source/cmDocumentationFormatterDocbook.h +++ /dev/null @@ -1,43 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ -#ifndef _cmDocumentationFormatterDocbook_h -#define _cmDocumentationFormatterDocbook_h - -#include "cmStandardIncludes.h" - -#include "cmDocumentationFormatter.h" - -/** Class to print the documentation as Docbook. - http://www.oasis-open.org/docbook/xml/4.2/ */ -class cmDocumentationFormatterDocbook : public cmDocumentationFormatter -{ -public: - cmDocumentationFormatterDocbook(); - - virtual cmDocumentationEnums::Form GetForm() const - { return cmDocumentationEnums::DocbookForm;} - - virtual void PrintHeader(const char* docname, const char* appname, - std::ostream& os); - virtual void PrintFooter(std::ostream& os); - virtual void PrintSection(std::ostream& os, - const cmDocumentationSection& section, - const char* name); - virtual void PrintPreformatted(std::ostream& os, const char* text); - virtual void PrintParagraph(std::ostream& os, const char* text); -private: - void PrintId(std::ostream& os, const char* prefix, std::string id); - std::set<std::string> EmittedLinkIds; - std::string Docname; -}; - -#endif diff --git a/Source/cmDocumentationFormatterHTML.cxx b/Source/cmDocumentationFormatterHTML.cxx deleted file mode 100644 index 7213b43..0000000 --- a/Source/cmDocumentationFormatterHTML.cxx +++ /dev/null @@ -1,288 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ -#include "cmDocumentationFormatterHTML.h" -#include "cmDocumentationSection.h" -#include "cmVersion.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. - switch (c) - { - case '<': - os << "<"; - break; - case '>': - os << ">"; - break; - case '&': - os << "&"; - break; - case '\n': - os << "<br />"; - break; - default: - os << c; - } -} - -//---------------------------------------------------------------------------- -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; - } - } -} - -//---------------------------------------------------------------------------- -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 cmDocumentationSection §ion, - const char* name) -{ - std::string prefix = this->ComputeSectionLinkPrefix(name); - - const std::vector<cmDocumentationEntry> &entries = - section.GetEntries(); - - // 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) - { - if (name) - { - os << "<h2><a name=\"section_"; - cmDocumentationPrintHTMLId(os, name); - os << "\"></a>" << name << "</h2>\n"; - } - - // Is a list needed? - for(std::vector<cmDocumentationEntry>::const_iterator op - = entries.begin(); op != entries.end(); ++ op ) - { - if (op->Name.size()) - { - os << "<ul>\n"; - for(;op != entries.end() && op->Name.size(); ++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>\n"; - } - } - os << "</ul>\n" ; - break; // Skip outer loop termination test - } - } - } - - for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin(); - op != entries.end();) - { - if(op->Name.size()) - { - os << "<ul>\n"; - for(;op != entries.end() && op->Name.size(); ++op) - { - os << " <li>\n"; - if(op->Name.size()) - { - os << " <a name=\"" << prefix << ":"; - cmDocumentationPrintHTMLId(os, op->Name.c_str()); - os << "\"></a><b><code>"; - this->PrintHTMLEscapes(os, op->Name.c_str()); - os << "</code></b>: "; - } - this->PrintHTMLEscapes(os, op->Brief.c_str()); - if(op->Full.size()) - { - os << "<br />\n "; - this->PrintFormatted(os, op->Full.c_str()); - } - os << "\n"; - os << " </li>\n"; - } - os << "</ul>\n"; - } - else - { - this->PrintFormatted(os, op->Brief.c_str()); - 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); - os << "</p>\n"; -} - -//---------------------------------------------------------------------------- -void cmDocumentationFormatterHTML::PrintHeader(const char* docname, - const char* appname, - std::ostream& os) -{ - os << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" - << " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; - os << "<html xmlns=\"http://www.w3.org/1999/xhtml\"" - << " xml:lang=\"en\" lang=\"en\">\n"; - os << "<head><meta http-equiv=\"Content-Type\" " - << "content=\"text/html;charset=utf-8\" /><title>"; - os << docname << " - " << appname; - os << "</title></head><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++); - } - } -} - -void cmDocumentationFormatterHTML -::PrintIndex(std::ostream& os, - std::vector<const cmDocumentationSection *>& sections) -{ - // 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; - } - - os << "<h2><a name=\"section_Index\"></a>Master Index " - << "CMake " << cmVersion::GetCMakeVersion() - << "</h2>\n"; - - if (!sections.empty()) - { - os << "<ul>\n"; - for(unsigned int i=0; i < sections.size(); ++i) - { - std::string name = sections[i]->GetName((this->GetForm())); - os << " <li><a href=\"#section_"; - cmDocumentationPrintHTMLId(os, name.c_str()); - os << "\"><b>" << name << "</b></a></li>\n"; - } - os << "</ul>\n"; - } -} diff --git a/Source/cmDocumentationFormatterHTML.h b/Source/cmDocumentationFormatterHTML.h deleted file mode 100644 index 44bf240..0000000 --- a/Source/cmDocumentationFormatterHTML.h +++ /dev/null @@ -1,42 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ -#ifndef _cmDocumentationFormatterHTML_h -#define _cmDocumentationFormatterHTML_h - -#include "cmStandardIncludes.h" - -#include "cmDocumentationFormatter.h" - -/** Class to print the documentation as HTML. */ -class cmDocumentationFormatterHTML : public cmDocumentationFormatter -{ -public: - cmDocumentationFormatterHTML(); - - virtual cmDocumentationEnums::Form GetForm() const - { return cmDocumentationEnums::HTMLForm;} - - virtual void PrintHeader(const char* docname, const char* appname, - std::ostream& os); - virtual void PrintFooter(std::ostream& os); - virtual void PrintSection(std::ostream& os, - const cmDocumentationSection& section, - const char* name); - virtual void PrintPreformatted(std::ostream& os, const char* text); - virtual void PrintParagraph(std::ostream& os, const char* text); - virtual void PrintIndex(std::ostream& , - std::vector<const cmDocumentationSection *>&); -private: - void PrintHTMLEscapes(std::ostream& os, const char* text); -}; - -#endif diff --git a/Source/cmDocumentationFormatterMan.cxx b/Source/cmDocumentationFormatterMan.cxx deleted file mode 100644 index 4123c85..0000000 --- a/Source/cmDocumentationFormatterMan.cxx +++ /dev/null @@ -1,102 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ - -#include "cmDocumentationFormatterMan.h" -#include "cmDocumentationSection.h" - -#include "cmSystemTools.h" -#include "cmVersion.h" - - -cmDocumentationFormatterMan::cmDocumentationFormatterMan() -:cmDocumentationFormatter() -,ManSection(1) -{ -} - -void cmDocumentationFormatterMan::SetManSection(int manSection) -{ - this->ManSection = manSection; -} - -void cmDocumentationFormatterMan -::PrintSection(std::ostream& os, - const cmDocumentationSection §ion, - const char* name) -{ - if(name) - { - os << ".SH " << name << "\n"; - } - - const std::vector<cmDocumentationEntry> &entries = - section.GetEntries(); - for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin(); - op != entries.end(); ++op) - { - if(op->Name.size()) - { - os << ".TP\n" - << ".B " << (op->Name.size()?op->Name.c_str():"*") << "\n"; - this->PrintFormatted(os, op->Brief.c_str()); - this->PrintFormatted(os, op->Full.c_str()); - } - else - { - os << ".PP\n"; - this->PrintFormatted(os, op->Brief.c_str()); - } - } -} - -void cmDocumentationFormatterMan::EscapeText(std::string& man_text) -{ - cmSystemTools::ReplaceString(man_text, "\\", "\\\\"); - cmSystemTools::ReplaceString(man_text, "-", "\\-"); -} - -void cmDocumentationFormatterMan::PrintPreformatted(std::ostream& os, - const char* text) -{ - std::string man_text = text; - this->EscapeText(man_text); - os << ".nf\n" << man_text; - if (*text && man_text.at(man_text.length()-1) != '\n') - os << "\n"; - os << ".fi\n\n"; -} - -void cmDocumentationFormatterMan::PrintParagraph(std::ostream& os, - const char* text) -{ - std::string man_text = text; - this->EscapeText(man_text); - os << man_text << "\n\n"; -} - - -//---------------------------------------------------------------------------- -void cmDocumentationFormatterMan::PrintHeader(const char* docname, - const char* appname, - std::ostream& os) -{ - std::string s_docname(docname), s_appname(appname); - - this->EscapeText(s_docname); - this->EscapeText(s_appname); - os << ".TH " << s_docname << " " << this->ManSection << " \"" - << cmSystemTools::GetCurrentDateTime("%B %d, %Y").c_str() - << "\" \"" << s_appname - << " " << cmVersion::GetCMakeVersion() - << "\"\n"; -} - diff --git a/Source/cmDocumentationFormatterMan.h b/Source/cmDocumentationFormatterMan.h deleted file mode 100644 index b3d069c..0000000 --- a/Source/cmDocumentationFormatterMan.h +++ /dev/null @@ -1,43 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ -#ifndef _cmDocumentationFormatterMan_h -#define _cmDocumentationFormatterMan_h - -#include "cmStandardIncludes.h" - -#include "cmDocumentationFormatter.h" - -/** Class to print the documentation as man page. */ -class cmDocumentationFormatterMan : public cmDocumentationFormatter -{ -public: - cmDocumentationFormatterMan(); - - void SetManSection(int manSection); - - virtual cmDocumentationEnums::Form GetForm() const - { return cmDocumentationEnums::ManForm;} - - virtual void PrintHeader(const char* docname, const char* appname, - std::ostream& os); - virtual void PrintSection(std::ostream& os, - const cmDocumentationSection& section, - const char* name); - virtual void PrintPreformatted(std::ostream& os, const char* text); - virtual void PrintParagraph(std::ostream& os, const char* text); - -private: - void EscapeText(std::string& man_text); - int ManSection; -}; - -#endif diff --git a/Source/cmDocumentationFormatterRST.cxx b/Source/cmDocumentationFormatterRST.cxx deleted file mode 100644 index 86d1fd0..0000000 --- a/Source/cmDocumentationFormatterRST.cxx +++ /dev/null @@ -1,107 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ -#include "cmDocumentationFormatterRST.h" -#include "cmDocumentationSection.h" -#include "cmVersion.h" - -#include "cmSystemTools.h" - -cmDocumentationFormatterRST::cmDocumentationFormatterRST() -:cmDocumentationFormatterText() -{ -} - -static std::string rstFileName(std::string fn) -{ - cmSystemTools::ReplaceString(fn, "<", ""); - cmSystemTools::ReplaceString(fn, ">", ""); - return fn; -} - -void cmDocumentationFormatterRST -::PrintSection(std::ostream& os, - const cmDocumentationSection §ion, - const char* name) -{ - std::string prefix = this->ComputeSectionLinkPrefix(name); - std::vector<cmDocumentationEntry> const& entries = section.GetEntries(); - this->TextWidth = 70; - - for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin(); - op != entries.end();) - { - if(op->Name.size()) - { - for(;op != entries.end() && op->Name.size(); ++op) - { - if(prefix == "opt" || prefix == "see") - { - os << "\n"; - os << "* ``" << op->Name << "``: " << op->Brief << "\n"; - this->TextIndent = " "; - if(op->Full.size()) - { - os << "\n"; - this->PrintFormatted(os, op->Full.c_str()); - } - this->TextIndent = ""; - } - else - { - cmSystemTools::MakeDirectory(prefix.c_str()); - std::string fname = prefix + "/" + rstFileName(op->Name) + ".rst"; - if(cmSystemTools::FileExists(fname.c_str())) - { - cmSystemTools::Error("Duplicate file name: ", fname.c_str()); - continue; - } - std::ofstream of(fname.c_str()); - of << op->Name << "\n"; - for(size_t i = 0; i < op->Name.size(); ++i) - { - of << "-"; - } - of << "\n\n" << op->Brief << "\n"; - if(op->Full.size()) - { - of << "\n"; - this->PrintFormatted(of, op->Full.c_str()); - } - } - } - } - else - { - this->PrintFormatted(os, op->Brief.c_str()); - os << "\n"; - ++op; - } - } -} - -void cmDocumentationFormatterRST::PrintPreformatted(std::ostream& os, - const char* text) -{ - os << this->TextIndent << "::\n\n"; - bool newline = true; - for(const char* c = text; *c; ++c) - { - if (newline) - { - os << this->TextIndent; - newline = false; - } - os << *c; - newline = (*c == '\n'); - } - os << "\n"; -} diff --git a/Source/cmDocumentationFormatterRST.h b/Source/cmDocumentationFormatterRST.h deleted file mode 100644 index c0d2e91..0000000 --- a/Source/cmDocumentationFormatterRST.h +++ /dev/null @@ -1,34 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ -#ifndef _cmDocumentationFormatterRST_h -#define _cmDocumentationFormatterRST_h - -#include "cmStandardIncludes.h" - -#include "cmDocumentationFormatterText.h" - -/** Class to print the documentation as reStructuredText. */ -class cmDocumentationFormatterRST : public cmDocumentationFormatterText -{ -public: - cmDocumentationFormatterRST(); - - virtual cmDocumentationEnums::Form GetForm() const - { return cmDocumentationEnums::RSTForm;} - - virtual void PrintSection(std::ostream& os, - const cmDocumentationSection& section, - const char* name); - virtual void PrintPreformatted(std::ostream& os, const char* text); -}; - -#endif diff --git a/Source/cmDocumentationFormatterText.cxx b/Source/cmDocumentationFormatterText.cxx deleted file mode 100644 index 5def194..0000000 --- a/Source/cmDocumentationFormatterText.cxx +++ /dev/null @@ -1,180 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ - -#include "cmDocumentationFormatterText.h" -#include "cmDocumentationSection.h" - -cmDocumentationFormatterText::cmDocumentationFormatterText() -:cmDocumentationFormatter() -,TextWidth(77) -,TextIndent("") -{ -} - -void cmDocumentationFormatterText -::PrintSection(std::ostream& os, - const cmDocumentationSection §ion, - const char* name) -{ - if(name && (strcmp(name, "SingleItem")!=0)) - { - os << - "---------------------------------------" - "---------------------------------------\n"; - os << name << "\n\n"; - } - - const std::vector<cmDocumentationEntry> &entries = - section.GetEntries(); - for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin(); - op != entries.end(); ++op) - { - if(op->Name.size()) - { - os << " " << op->Name << "\n"; - this->TextIndent = " "; - this->PrintFormatted(os, op->Brief.c_str()); - if(op->Full.size()) - { - os << "\n"; - this->PrintFormatted(os, op->Full.c_str()); - } - } - else - { - this->TextIndent = ""; - this->PrintFormatted(os, op->Brief.c_str()); - } - os << "\n"; - } -} - -void cmDocumentationFormatterText::PrintPreformatted(std::ostream& os, - const char* text) -{ - bool newline = true; - for(const char* ptr = text; *ptr; ++ptr) - { - if(newline && *ptr != '\n') - { - os << this->TextIndent; - newline = false; - } - os << *ptr; - if(*ptr == '\n') - { - newline = true; - } - } - os << "\n"; -} - -void cmDocumentationFormatterText::PrintParagraph(std::ostream& os, - const char* text) -{ - os << this->TextIndent; - this->PrintColumn(os, text); - os << "\n"; -} - -void cmDocumentationFormatterText::SetIndent(const char* indent) -{ - this->TextIndent = indent; -} - -void cmDocumentationFormatterText::PrintColumn(std::ostream& os, - const char* text) -{ - // Print text arranged in an indented column of fixed witdh. - const char* l = text; - long column = 0; - bool newSentence = false; - bool firstLine = true; - int width = this->TextWidth - static_cast<int>(strlen(this->TextIndent)); - - // Loop until the end of the text. - while(*l) - { - // Parse the next word. - const char* r = l; - while(*r && (*r != '\n') && (*r != ' ')) { ++r; } - - // Does it fit on this line? - if(r-l < (width-column-(newSentence?1:0))) - { - // Word fits on this line. - if(r > l) - { - if(column) - { - // Not first word on line. Separate from the previous word - // by a space, or two if this is a new sentence. - if(newSentence) - { - os << " "; - column += 2; - } - else - { - os << " "; - column += 1; - } - } - else - { - // First word on line. Print indentation unless this is the - // first line. - os << (firstLine?"":this->TextIndent); - } - - // Print the word. - os.write(l, static_cast<long>(r-l)); - newSentence = (*(r-1) == '.'); - } - - if(*r == '\n') - { - // Text provided a newline. Start a new line. - os << "\n"; - ++r; - column = 0; - firstLine = false; - } - else - { - // No provided newline. Continue this line. - column += static_cast<long>(r-l); - } - } - else - { - // Word does not fit on this line. Start a new line. - os << "\n"; - firstLine = false; - if(r > l) - { - os << this->TextIndent; - os.write(l, static_cast<long>(r-l)); - column = static_cast<long>(r-l); - newSentence = (*(r-1) == '.'); - } - else - { - column = 0; - } - } - - // Move to beginning of next word. Skip over whitespace. - l = r; - while(*l && (*l == ' ')) { ++l; } - } -} diff --git a/Source/cmDocumentationFormatterText.h b/Source/cmDocumentationFormatterText.h deleted file mode 100644 index d9c2af2..0000000 --- a/Source/cmDocumentationFormatterText.h +++ /dev/null @@ -1,40 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ -#ifndef _cmDocumentationFormatterText_h -#define _cmDocumentationFormatterText_h - -#include "cmStandardIncludes.h" - -#include "cmDocumentationFormatter.h" - -/** Class to print the documentation as plain text. */ -class cmDocumentationFormatterText : public cmDocumentationFormatter -{ -public: - cmDocumentationFormatterText(); - - virtual cmDocumentationEnums::Form GetForm() const - { return cmDocumentationEnums::TextForm;} - - virtual void PrintSection(std::ostream& os, - const cmDocumentationSection& section, - const char* name); - virtual void PrintPreformatted(std::ostream& os, const char* text); - virtual void PrintParagraph(std::ostream& os, const char* text); - void PrintColumn(std::ostream& os, const char* text); - void SetIndent(const char* indent); -protected: - int TextWidth; - const char* TextIndent; -}; - -#endif diff --git a/Source/cmDocumentationFormatterUsage.cxx b/Source/cmDocumentationFormatterUsage.cxx deleted file mode 100644 index a068e56..0000000 --- a/Source/cmDocumentationFormatterUsage.cxx +++ /dev/null @@ -1,63 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ - -#include "cmDocumentationFormatterUsage.h" -#include "cmDocumentationSection.h" - -cmDocumentationFormatterUsage::cmDocumentationFormatterUsage() -:cmDocumentationFormatterText() -{ -} - -void cmDocumentationFormatterUsage -::PrintSection(std::ostream& os, - const cmDocumentationSection §ion, - const char* name) -{ - if(name) - { - os << name << "\n"; - } - - const std::vector<cmDocumentationEntry> &entries = - section.GetEntries(); - for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin(); - op != entries.end(); ++op) - { - if(op->Name.size()) - { - os << " " << op->Name; - this->TextIndent = " "; - int align = static_cast<int>(strlen(this->TextIndent))-4; - for(int i = static_cast<int>(op->Name.size()); i < align; ++i) - { - os << " "; - } - if (op->Name.size() > strlen(this->TextIndent)-4 ) - { - os << "\n"; - os.write(this->TextIndent, strlen(this->TextIndent)-2); - } - os << "= "; - this->PrintColumn(os, op->Brief.c_str()); - os << "\n"; - } - else - { - os << "\n"; - this->TextIndent = ""; - this->PrintFormatted(os, op->Brief.c_str()); - } - } - os << "\n"; -} - diff --git a/Source/cmDocumentationFormatterUsage.h b/Source/cmDocumentationFormatterUsage.h deleted file mode 100644 index 3ed3442..0000000 --- a/Source/cmDocumentationFormatterUsage.h +++ /dev/null @@ -1,31 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc., Insight Software Consortium - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - 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. -============================================================================*/ -#ifndef _cmDocumentationFormatterUsage_h -#define _cmDocumentationFormatterUsage_h - -#include "cmDocumentationFormatterText.h" - -/** Class to print the documentation as usage on the command line. */ -class cmDocumentationFormatterUsage : public cmDocumentationFormatterText -{ -public: - cmDocumentationFormatterUsage(); - - virtual cmDocumentationEnums::Form GetForm() const - { return cmDocumentationEnums::UsageForm;} - - virtual void PrintSection(std::ostream& os, - const cmDocumentationSection& section, - const char* name); -}; - -#endif diff --git a/Source/cmDocumentationSection.h b/Source/cmDocumentationSection.h index 4f8c10d..fd1d505 100644 --- a/Source/cmDocumentationSection.h +++ b/Source/cmDocumentationSection.h @@ -24,8 +24,8 @@ class cmDocumentationSection { public: /** Create a cmSection, with a special name for man-output mode. */ - cmDocumentationSection(const char* name, const char* manName) - :Name(name), ManName(manName) {} + cmDocumentationSection(const char* name, const char*) + :Name(name) {} /** Has any content been added to this section or is it empty ? */ bool IsEmpty() const { return this->Entries.empty(); } @@ -33,10 +33,9 @@ public: /** Clear contents. */ void Clear() { this->Entries.clear(); } - /** Return the name of this section for the given output form. */ - const char* GetName(cmDocumentationEnums::Form form) const - { return (form==cmDocumentationEnums::ManForm ? - this->ManName.c_str() : this->Name.c_str()); } + /** Return the name of this section. */ + const char* GetName() const + { return this->Name.c_str(); } /** Return a pointer to the first entry of this section. */ const std::vector<cmDocumentationEntry> &GetEntries() const @@ -61,7 +60,6 @@ public: private: std::string Name; - std::string ManName; std::vector<cmDocumentationEntry> Entries; }; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 1daf8b5..fcda886 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -20,7 +20,7 @@ #include "cmFileTimeComparison.h" #include "cmSourceFile.h" #include "cmTest.h" -#include "cmDocumentationFormatterText.h" +#include "cmDocumentationFormatter.h" #if defined(CMAKE_BUILD_WITH_CMAKE) # include "cmGraphVizWriter.h" @@ -3009,7 +3009,7 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text, // Add the message text. { msg << ":\n"; - cmDocumentationFormatterText formatter; + cmDocumentationFormatter formatter; formatter.SetIndent(" "); formatter.PrintFormatted(msg, text.c_str()); } |