cmDocumentation: use ofstream local variable

This commit is contained in:
Daniel Pfeifer 2017-04-21 19:19:29 +02:00
parent ba8571ff2d
commit 1ef22a26c9

View File

@ -129,28 +129,19 @@ bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
this->CurrentArgument = i->Argument;
// If a file name was given, use it. Otherwise, default to the
// given stream.
cmsys::ofstream* fout = CM_NULLPTR;
cmsys::ofstream fout;
std::ostream* s = &os;
if (!i->Filename.empty()) {
fout = new cmsys::ofstream(i->Filename.c_str());
if (fout) {
s = fout;
} else {
result = false;
}
fout.open(i->Filename.c_str());
s = &fout;
} else if (++count > 1) {
os << "\n\n";
}
// Print this documentation type to the stream.
if (!this->PrintDocumentation(i->HelpType, *s) || !*s) {
if (!this->PrintDocumentation(i->HelpType, *s) || s->fail()) {
result = false;
}
// Close the file if we wrote one.
if (fout) {
delete fout;
}
}
return result;
}