summaryrefslogtreecommitdiffstats
path: root/Source/cmDocumentation.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2003-07-08 02:44:18 (GMT)
committerBrad King <brad.king@kitware.com>2003-07-08 02:44:18 (GMT)
commit1cecf7b5aaa4a74a1a2a4545a9effda7cdc61879 (patch)
treeaaf5f7056b1e8554dcc0006e64fabb95be0faae5 /Source/cmDocumentation.cxx
parentb85f000e26fd7d00fee2073581f2c2ce8098fa2d (diff)
downloadCMake-1cecf7b5aaa4a74a1a2a4545a9effda7cdc61879.zip
CMake-1cecf7b5aaa4a74a1a2a4545a9effda7cdc61879.tar.gz
CMake-1cecf7b5aaa4a74a1a2a4545a9effda7cdc61879.tar.bz2
ENH: Added support to write multiple help options with one command line. Output files can now also be specified for the help options.
Diffstat (limited to 'Source/cmDocumentation.cxx')
-rw-r--r--Source/cmDocumentation.cxx101
1 files changed, 84 insertions, 17 deletions
diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx
index 0e853d9..390ab5b 100644
--- a/Source/cmDocumentation.cxx
+++ b/Source/cmDocumentation.cxx
@@ -178,17 +178,69 @@ void cmDocumentation::PrintDocumentation(Type ht, std::ostream& os)
}
//----------------------------------------------------------------------------
-cmDocumentation::Type cmDocumentation::CheckOptions(int argc, char** argv)
+bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
+{
+ bool result = true;
+
+ // Loop over requested documentation types.
+ for(RequestedMapType::const_iterator i = this->RequestedMap.begin();
+ i != this->RequestedMap.end(); ++i)
+ {
+ // If a file name was given, use it. Otherwise, default to the
+ // given stream.
+ std::ofstream* fout = 0;
+ std::ostream* s = &os;
+ if(i->second.length() > 0)
+ {
+#ifdef _WIN32
+ fout = new ofstream(i->second.c_str(), ios::out | ios::binary);
+#else
+ fout = new ofstream(i->second.c_str(), ios::out);
+#endif
+ if(fout)
+ {
+ s = fout;
+ }
+ else
+ {
+ result = false;
+ }
+ }
+
+ // Print this documentation type to the stream.
+ this->PrintDocumentation(i->first, *s);
+
+ // Check for error.
+ if(!*s)
+ {
+ result = false;
+ }
+
+ // Close the file if we wrote one.
+ if(fout)
+ {
+ delete fout;
+ }
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------------
+bool cmDocumentation::CheckOptions(int argc, char** argv)
{
// Providing zero arguments gives usage information.
if(argc == 1)
{
- return cmDocumentation::Usage;
+ this->RequestedMap[cmDocumentation::Usage] = "";
+ return true;
}
// Search for supported help options.
+ bool result = false;
for(int i=1; i < argc; ++i)
{
+ // Check if this is a supported help option.
+ Type type = cmDocumentation::None;
if((strcmp(argv[i], "-help") == 0) ||
(strcmp(argv[i], "--help") == 0) ||
(strcmp(argv[i], "/?") == 0) ||
@@ -196,33 +248,48 @@ cmDocumentation::Type cmDocumentation::CheckOptions(int argc, char** argv)
(strcmp(argv[i], "-h") == 0) ||
(strcmp(argv[i], "-H") == 0))
{
- return cmDocumentation::Usage;
+ type = cmDocumentation::Usage;
}
- if(strcmp(argv[i], "--help-full") == 0)
+ else if(strcmp(argv[i], "--help-full") == 0)
{
- return cmDocumentation::Full;
+ type = cmDocumentation::Full;
}
- if(strcmp(argv[i], "--help-html") == 0)
+ else if(strcmp(argv[i], "--help-html") == 0)
{
- return cmDocumentation::HTML;
+ type = cmDocumentation::HTML;
}
- if(strcmp(argv[i], "--help-man") == 0)
+ else if(strcmp(argv[i], "--help-man") == 0)
{
- return cmDocumentation::Man;
+ type = cmDocumentation::Man;
}
- if(strcmp(argv[i], "--copyright") == 0)
+ else if(strcmp(argv[i], "--copyright") == 0)
{
- return cmDocumentation::Copyright;
+ type = cmDocumentation::Copyright;
}
- if((strcmp(argv[i], "--version") == 0) ||
- (strcmp(argv[i], "-version") == 0) ||
- (strcmp(argv[i], "-V") == 0) ||
- (strcmp(argv[i], "/V") == 0))
+ else if((strcmp(argv[i], "--version") == 0) ||
+ (strcmp(argv[i], "-version") == 0) ||
+ (strcmp(argv[i], "-V") == 0) ||
+ (strcmp(argv[i], "/V") == 0))
{
- return cmDocumentation::Version;
+ type = cmDocumentation::Version;
+ }
+ if(type)
+ {
+ // This is a help option. See if there is a file name given.
+ result = true;
+ if((i+1 < argc) && (argv[i+1][0] != '-') &&
+ (strcmp(argv[i+1], "/V") != 0) && (strcmp(argv[i+1], "/?") != 0))
+ {
+ this->RequestedMap[type] = argv[i+1];
+ i = i+1;
+ }
+ else
+ {
+ this->RequestedMap[type] = "";
+ }
}
}
- return cmDocumentation::None;
+ return result;
}
//----------------------------------------------------------------------------