1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmDocumentationFormatterText.cxx,v $
6 Date: $Date: 2009-06-28 12:05:22 $
7 Version: $Revision: 1.6 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
18 #include "cmDocumentationFormatterText.h"
19 #include "cmDocumentationSection.h"
21 cmDocumentationFormatterText::cmDocumentationFormatterText()
22 :cmDocumentationFormatter()
28 void cmDocumentationFormatterText
29 ::PrintSection(std::ostream
& os
,
30 const cmDocumentationSection
§ion
,
33 if(name
&& (strcmp(name
, "SingleItem")!=0))
36 "---------------------------------------"
37 "---------------------------------------\n";
41 const std::vector
<cmDocumentationEntry
> &entries
=
43 for(std::vector
<cmDocumentationEntry
>::const_iterator op
= entries
.begin();
44 op
!= entries
.end(); ++op
)
48 os
<< " " << op
->Name
<< "\n";
49 this->TextIndent
= " ";
50 this->PrintFormatted(os
, op
->Brief
.c_str());
54 this->PrintFormatted(os
, op
->Full
.c_str());
59 this->TextIndent
= "";
60 this->PrintFormatted(os
, op
->Brief
.c_str());
66 void cmDocumentationFormatterText::PrintPreformatted(std::ostream
& os
,
70 for(const char* ptr
= text
; *ptr
; ++ptr
)
72 if(newline
&& *ptr
!= '\n')
74 os
<< this->TextIndent
;
86 void cmDocumentationFormatterText::PrintParagraph(std::ostream
& os
,
89 os
<< this->TextIndent
;
90 this->PrintColumn(os
, text
);
94 void cmDocumentationFormatterText::SetIndent(const char* indent
)
96 this->TextIndent
= indent
;
99 void cmDocumentationFormatterText::PrintColumn(std::ostream
& os
,
102 // Print text arranged in an indented column of fixed witdh.
103 const char* l
= text
;
105 bool newSentence
= false;
106 bool firstLine
= true;
107 int width
= this->TextWidth
- static_cast<int>(strlen(this->TextIndent
));
109 // Loop until the end of the text.
112 // Parse the next word.
114 while(*r
&& (*r
!= '\n') && (*r
!= ' ')) { ++r
; }
116 // Does it fit on this line?
117 if(r
-l
< (width
-column
-(newSentence
?1:0)))
119 // Word fits on this line.
124 // Not first word on line. Separate from the previous word
125 // by a space, or two if this is a new sentence.
139 // First word on line. Print indentation unless this is the
141 os
<< (firstLine
?"":this->TextIndent
);
145 os
.write(l
, static_cast<long>(r
-l
));
146 newSentence
= (*(r
-1) == '.');
151 // Text provided a newline. Start a new line.
159 // No provided newline. Continue this line.
160 column
+= static_cast<long>(r
-l
);
165 // Word does not fit on this line. Start a new line.
170 os
<< this->TextIndent
;
171 os
.write(l
, static_cast<long>(r
-l
));
172 column
= static_cast<long>(r
-l
);
173 newSentence
= (*(r
-1) == '.');
181 // Move to beginning of next word. Skip over whitespace.
183 while(*l
&& (*l
== ' ')) { ++l
; }