1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
13 #include "cmDocumentationFormatterText.h"
14 #include "cmDocumentationSection.h"
16 cmDocumentationFormatterText::cmDocumentationFormatterText()
17 :cmDocumentationFormatter()
23 void cmDocumentationFormatterText
24 ::PrintSection(std::ostream& os,
25 const cmDocumentationSection §ion,
28 if(name && (strcmp(name, "SingleItem")!=0))
31 "---------------------------------------"
32 "---------------------------------------\n";
36 const std::vector<cmDocumentationEntry> &entries =
38 for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin();
39 op != entries.end(); ++op)
43 os << " " << op->Name << "\n";
44 this->TextIndent = " ";
45 this->PrintFormatted(os, op->Brief.c_str());
49 this->PrintFormatted(os, op->Full.c_str());
54 this->TextIndent = "";
55 this->PrintFormatted(os, op->Brief.c_str());
61 void cmDocumentationFormatterText::PrintPreformatted(std::ostream& os,
65 for(const char* ptr = text; *ptr; ++ptr)
67 if(newline && *ptr != '\n')
69 os << this->TextIndent;
81 void cmDocumentationFormatterText::PrintParagraph(std::ostream& os,
84 os << this->TextIndent;
85 this->PrintColumn(os, text);
89 void cmDocumentationFormatterText::SetIndent(const char* indent)
91 this->TextIndent = indent;
94 void cmDocumentationFormatterText::PrintColumn(std::ostream& os,
97 // Print text arranged in an indented column of fixed witdh.
100 bool newSentence = false;
101 bool firstLine = true;
102 int width = this->TextWidth - static_cast<int>(strlen(this->TextIndent));
104 // Loop until the end of the text.
107 // Parse the next word.
109 while(*r && (*r != '\n') && (*r != ' ')) { ++r; }
111 // Does it fit on this line?
112 if(r-l < (width-column-(newSentence?1:0)))
114 // Word fits on this line.
119 // Not first word on line. Separate from the previous word
120 // by a space, or two if this is a new sentence.
134 // First word on line. Print indentation unless this is the
136 os << (firstLine?"":this->TextIndent);
140 os.write(l, static_cast<long>(r-l));
141 newSentence = (*(r-1) == '.');
146 // Text provided a newline. Start a new line.
154 // No provided newline. Continue this line.
155 column += static_cast<long>(r-l);
160 // Word does not fit on this line. Start a new line.
165 os << this->TextIndent;
166 os.write(l, static_cast<long>(r-l));
167 column = static_cast<long>(r-l);
168 newSentence = (*(r-1) == '.');
176 // Move to beginning of next word. Skip over whitespace.
178 while(*l && (*l == ' ')) { ++l; }