ENH: add possibility to add doc strings to varibles created by find type commands

This commit is contained in:
Bill Hoffman 2001-11-26 18:24:47 -05:00
parent b170d21c98
commit 3e24edcd04
8 changed files with 115 additions and 34 deletions

View File

@ -45,22 +45,38 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// cmFindFileCommand // cmFindFileCommand
bool cmFindFileCommand::InitialPass(std::vector<std::string> const& args) bool cmFindFileCommand::InitialPass(std::vector<std::string> const& argsIn)
{ {
if(args.size() < 2) if(argsIn.size() < 2)
{ {
this->SetError("called with incorrect number of arguments"); this->SetError("called with incorrect number of arguments");
return false; return false;
} }
std::string helpString = "Where can the ";
helpString += argsIn[1] + " file be found";
unsigned int size = argsIn.size();
std::vector<std::string> args;
for(unsigned int j = 0; j < size; ++j)
{
if(argsIn[j] != "DOC")
{
args.push_back(argsIn[j]);
}
else
{
if(j+1 < size)
{
helpString = argsIn[j+1];
}
break;
}
}
std::vector<std::string>::const_iterator i = args.begin(); std::vector<std::string>::const_iterator i = args.begin();
// Use the first argument as the name of something to be defined // Use the first argument as the name of something to be defined
const char* define = (*i).c_str(); const char* define = (*i).c_str();
i++; // move iterator to next arg i++; // move iterator to next arg
// Now check and see if the value has been stored in the cache // Now check and see if the value has been stored in the cache
// already, if so use that value and don't look for the program // already, if so use that value and don't look for the program
std::string helpString = "Where can the ";
helpString += args[1] + " file be found";
const char* cacheValue const char* cacheValue
= m_Makefile->GetDefinition(define); = m_Makefile->GetDefinition(define);
if(cacheValue && strcmp(cacheValue, "NOTFOUND")) if(cacheValue && strcmp(cacheValue, "NOTFOUND"))

View File

@ -94,7 +94,11 @@ public:
virtual const char* GetFullDocumentation() virtual const char* GetFullDocumentation()
{ {
return return
"FIND_FILE(NAME file extrapath extrapath ...)"; "FIND_FILE(NAME file extrapath extrapath ... [DOC docstring])"
"Find a file in the system PATH or in any extra paths specified in the command."
"A cache entry called NAME is created to store the result. NOTFOUND is the value"
" used if the file was not found. If DOC is specified the next argument is the "
"documentation string for the cache entry NAME.";
} }
cmTypeMacro(cmFindFileCommand, cmCommand); cmTypeMacro(cmFindFileCommand, cmCommand);

View File

@ -44,11 +44,28 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// cmFindLibraryCommand // cmFindLibraryCommand
bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn) bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
{ {
std::vector<std::string> args = argsIn; if(argsIn.size() < 2)
if(args.size() < 2)
{ {
this->SetError("called with incorrect number of arguments"); this->SetError("called with incorrect number of arguments");
return false; return false;
}
std::string helpString;
unsigned int size = argsIn.size();
std::vector<std::string> args;
for(unsigned int j = 0; j < size; ++j)
{
if(argsIn[j] != "DOC")
{
args.push_back(argsIn[j]);
}
else
{
if(j+1 < size)
{
helpString = argsIn[j+1];
}
break;
}
} }
std::vector<std::string> path; std::vector<std::string> path;
@ -101,26 +118,28 @@ bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
cmSystemTools::GlobDirs(exp.c_str(), path); cmSystemTools::GlobDirs(exp.c_str(), path);
} }
} }
if(helpString.size() == 0)
std::string helpString = "Where can ";
if (names.size() == 0)
{ {
helpString += "the (unknown) library be found"; helpString = "Where can ";
} if (names.size() == 0)
else if (names.size() == 1)
{
helpString += "the " + names[0] + " library be found";
}
else
{
helpString += "one of the " + names[0];
for (unsigned int j = 1; j < names.size() - 1; ++j)
{ {
helpString += ", " + names[j]; helpString += "the (unknown) library be found";
}
else if (names.size() == 1)
{
helpString += "the " + names[0] + " library be found";
}
else
{
helpString += "one of the " + names[0];
for (unsigned int j = 1; j < names.size() - 1; ++j)
{
helpString += ", " + names[j];
}
helpString += " or " + names[names.size() - 1] + " libraries be found";
} }
helpString += " or " + names[names.size() - 1] + " libraries be found";
} }
const char* cacheValue const char* cacheValue
= m_Makefile->GetDefinition(args[0].c_str()); = m_Makefile->GetDefinition(args[0].c_str());
if(cacheValue && strcmp(cacheValue, "NOTFOUND")) if(cacheValue && strcmp(cacheValue, "NOTFOUND"))

View File

@ -94,8 +94,10 @@ public:
virtual const char* GetFullDocumentation() virtual const char* GetFullDocumentation()
{ {
return return
"FIND_LIBRARY(DEFINE_PATH libraryName [NAMES] name1 name2 name3 [PATHS path1 path2 path3...])\n" "FIND_LIBRARY(DEFINE_PATH libraryName [NAMES] name1 name2 name3 [PATHS path1 path2 path3...] [DOC docstring] )\n"
"If the library is found, then DEFINE_PATH is set to the full path where it was found"; "If the library is found, then DEFINE_PATH is set to the full path where it was found. "
"If DOC is specified the next argument is the "
"documentation string for the cache entry NAME.";
} }
cmTypeMacro(cmFindLibraryCommand, cmCommand); cmTypeMacro(cmFindLibraryCommand, cmCommand);

View File

@ -42,9 +42,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cmCacheManager.h" #include "cmCacheManager.h"
// cmFindPathCommand // cmFindPathCommand
bool cmFindPathCommand::InitialPass(std::vector<std::string> const& args) bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn)
{ {
if(args.size() < 2) if(argsIn.size() < 2)
{ {
this->SetError("called with incorrect number of arguments"); this->SetError("called with incorrect number of arguments");
return false; return false;
@ -53,7 +53,24 @@ bool cmFindPathCommand::InitialPass(std::vector<std::string> const& args)
// Now check and see if the value has been stored in the cache // Now check and see if the value has been stored in the cache
// already, if so use that value and don't look for the program // already, if so use that value and don't look for the program
std::string helpString = "What is the path where the file "; std::string helpString = "What is the path where the file ";
helpString += args[1] + " can be found"; helpString += argsIn[1] + " can be found";
std::vector<std::string> args;
unsigned int size = argsIn.size();
for(unsigned int j = 0; j < size; ++j)
{
if(argsIn[j] != "DOC")
{
args.push_back(argsIn[j]);
}
else
{
if(j+1 < size)
{
helpString = argsIn[j+1];
}
break;
}
}
const char* cacheValue const char* cacheValue
= m_Makefile->GetDefinition(args[0].c_str()); = m_Makefile->GetDefinition(args[0].c_str());
if(cacheValue && strcmp(cacheValue, "NOTFOUND")) if(cacheValue && strcmp(cacheValue, "NOTFOUND"))

View File

@ -70,7 +70,9 @@ public:
{ {
return return
"FIND_PATH(PATH_DEFINE fileName path1 path2 path3...)\n" "FIND_PATH(PATH_DEFINE fileName path1 path2 path3...)\n"
"If the file is found, then PATH_DEFINE is set to the path where it was found"; "If the file is found, then PATH_DEFINE is set to the path where it was found."
"If DOC is specified the next argument is the "
"documentation string for the cache entry NAME.";
} }
cmTypeMacro(cmFindPathCommand, cmCommand); cmTypeMacro(cmFindPathCommand, cmCommand);

View File

@ -52,7 +52,24 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
this->SetError("called with incorrect number of arguments"); this->SetError("called with incorrect number of arguments");
return false; return false;
} }
std::vector<std::string> args = argsIn; std::string doc = "Path to a program.";
unsigned int size = argsIn.size();
std::vector<std::string> args;
for(unsigned int j = 0; j < size; ++j)
{
if(argsIn[j] != "DOC")
{
args.push_back(argsIn[j]);
}
else
{
if(j+1 < size)
{
doc = argsIn[j+1];
}
break;
}
}
std::vector<std::string>::iterator i = args.begin(); std::vector<std::string>::iterator i = args.begin();
// Use the first argument as the name of something to be defined // Use the first argument as the name of something to be defined
const char* define = (*i).c_str(); const char* define = (*i).c_str();
@ -125,7 +142,7 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
// Save the value in the cache // Save the value in the cache
m_Makefile->AddCacheDefinition(define, m_Makefile->AddCacheDefinition(define,
result.c_str(), result.c_str(),
"Path to a program.", doc.c_str(),
cmCacheManager::FILEPATH); cmCacheManager::FILEPATH);
return true; return true;
@ -133,7 +150,7 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
} }
m_Makefile->AddCacheDefinition(args[0].c_str(), m_Makefile->AddCacheDefinition(args[0].c_str(),
"NOTFOUND", "NOTFOUND",
"Path to a program", doc.c_str(),
cmCacheManager::FILEPATH); cmCacheManager::FILEPATH);
return true; return true;
} }

View File

@ -94,7 +94,11 @@ public:
virtual const char* GetFullDocumentation() virtual const char* GetFullDocumentation()
{ {
return return
"FIND_PROGRAM(NAME executable1 extrapath extrapath ...)"; "FIND_PROGRAM(NAME executable1 extrapath extrapath ... [DOC helpstring]) "
"Find the executable in the system PATH or in any extra paths specified in the command."
"A cache entry called NAME is created to store the result. NOTFOUND is the value"
" used if the program was not found. If DOC is specified the next argument is the "
"documentation string for the cache entry NAME.";
} }
cmTypeMacro(cmFindProgramCommand, cmCommand); cmTypeMacro(cmFindProgramCommand, cmCommand);