diff options
author | Brad King <brad.king@kitware.com> | 2003-02-14 18:28:46 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2003-02-14 18:28:46 (GMT) |
commit | 0005e70c054ac55a536ffbc68447b7aa57e909d2 (patch) | |
tree | 606ff2bc7599a1a0bdb4436967c6ded38b563581 /Source/cmDocumentation.cxx | |
parent | 2c7a05edd21ad6a33c7dffc46e7fec53035d5bb9 (diff) | |
download | CMake-0005e70c054ac55a536ffbc68447b7aa57e909d2.zip CMake-0005e70c054ac55a536ffbc68447b7aa57e909d2.tar.gz CMake-0005e70c054ac55a536ffbc68447b7aa57e909d2.tar.bz2 |
ENH: Further improved formatting. HTML/man/help now all have a consistent appearance.
Diffstat (limited to 'Source/cmDocumentation.cxx')
-rw-r--r-- | Source/cmDocumentation.cxx | 131 |
1 files changed, 88 insertions, 43 deletions
diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 7971e79..852abed 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -101,7 +101,10 @@ void cmDocumentation::PrintManSection(std::ostream& os, os << ".TP\n" << ".B " << op->name << "\n" << op->brief << "\n\n"; - if(op->full) { os << op->full << "\n"; } + if(op->full) + { + this->PrintFull(os, op->full, 0, 0); + } } else { @@ -171,47 +174,11 @@ void cmDocumentation::PrintHTMLEscapes(std::ostream& os, const char* text) } //---------------------------------------------------------------------------- -void cmDocumentation::PrintHTMLFull(std::ostream& os, const char* text) +void cmDocumentation::PrintHTMLPreformatted(std::ostream& os, const char* text) { - const char* line = text; - while(*line) - { - // Any lines starting in a space are treated as a preformatted - // section. - std::string preformatted; - while(*line == ' ') - { - for(char ch = *line; ch && ch != '\n'; ++line, ch = *line) - { - preformatted.append(1, ch); - } - if(*line) - { - ++line; - preformatted.append(1, '\n'); - } - } - if(preformatted.length()) - { - os << "<pre>"; - this->PrintHTMLEscapes(os, preformatted.c_str()); - os << "</pre>"; - } - std::string normal; - for(char ch = *line; ch && ch != '\n'; ++line, ch = *line) - { - normal.append(1, ch); - } - if(*line) - { - ++line; - normal.append(1, '\n'); - } - if(normal.length()) - { - this->PrintHTMLEscapes(os, normal.c_str()); - } - } + os << "<pre>"; + cmDocumentation::PrintHTMLEscapes(os, text); + os << "</pre>"; } //---------------------------------------------------------------------------- @@ -239,7 +206,9 @@ void cmDocumentation::PrintHelpHTMLSection(std::ostream& os, if(op->full) { os << "<br>"; - this->PrintHTMLFull(os, op->full); + this->PrintFull(os, op->full, + &cmDocumentation::PrintHTMLPreformatted, + &cmDocumentation::PrintHTMLEscapes); } os << "\n"; os << " </li>\n"; @@ -379,7 +348,8 @@ void cmDocumentation::PrintColumn(std::ostream& os, int width, int column = 0; bool newSentence = false; bool firstLine = true; - + bool lastHadBlanks = false; + // Count leading blanks in the text. int blanks = 0; for(const char* b = l; *b == ' '; ++b) { ++blanks; } @@ -414,6 +384,22 @@ void cmDocumentation::PrintColumn(std::ostream& os, int width, } else { + // If this is the first line not beginning in a blank after + // a sequence of lines beginning in blanks, add an extra + // newline. + if(blanks) + { + lastHadBlanks = true; + } + else + { + if(lastHadBlanks) + { + os << "\n"; + } + lastHadBlanks = false; + } + // First word on line. Print indentation unless this is the // first line. os << (firstLine?"":indent); @@ -471,6 +457,65 @@ void cmDocumentation::PrintColumn(std::ostream& os, int width, } //---------------------------------------------------------------------------- +void cmDocumentation::PrintFull(std::ostream& os, const char* text, + void (*pPreform)(std::ostream&, const char*), + void (*pNormal)(std::ostream&, const char*)) +{ + const char* line = text; + while(*line) + { + // Any lines starting in a space are treated as preformatted text. + std::string preformatted; + while(*line == ' ') + { + for(char ch = *line; ch && ch != '\n'; ++line, ch = *line) + { + preformatted.append(1, ch); + } + if(*line) + { + ++line; + preformatted.append(1, '\n'); + } + } + if(preformatted.length()) + { + if(pPreform) + { + pPreform(os, preformatted.c_str()); + } + else + { + os << preformatted << "\n"; + } + } + + // Other lines are treated as normal text. + std::string normal; + for(char ch = *line; ch && ch != '\n'; ++line, ch = *line) + { + normal.append(1, ch); + } + if(*line) + { + ++line; + normal.append(1, '\n'); + } + if(normal.length()) + { + if(pNormal) + { + pNormal(os, normal.c_str()); + } + else + { + os << normal << "\n"; + } + } + } +} + +//---------------------------------------------------------------------------- void cmDocumentation::Print(Type ht, std::ostream& os) { switch (ht) |