summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemTools.cxx
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2006-03-10 21:52:28 (GMT)
committerBill Hoffman <bill.hoffman@kitware.com>2006-03-10 21:52:28 (GMT)
commit7387cb58505de65fea2622b443c1cc9d471818a2 (patch)
tree8d92202c8e978133be1afbfd87edc1053c8aace6 /Source/kwsys/SystemTools.cxx
parent8e7d92049ea7766133bd38cb0e82c5efe93e2d48 (diff)
downloadCMake-7387cb58505de65fea2622b443c1cc9d471818a2.zip
CMake-7387cb58505de65fea2622b443c1cc9d471818a2.tar.gz
CMake-7387cb58505de65fea2622b443c1cc9d471818a2.tar.bz2
ENH: fix find program to look for .com and .exe correctly and not return files with no extension on windows
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r--Source/kwsys/SystemTools.cxx89
1 files changed, 40 insertions, 49 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index bb81a19..8704bf9 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -1922,7 +1922,11 @@ kwsys_stl::string SystemTools::FindProgram(
{
return "";
}
+ bool extensionIncluded = false;
kwsys_stl::string ext = SystemTools::GetExecutableExtension();
+ std::string searchName = name;
+ // check to see if the extension was included in the name
+ // if not, add it
if(ext.size())
{
unsigned int len = strlen(name);
@@ -1930,84 +1934,71 @@ kwsys_stl::string SystemTools::FindProgram(
{
if(strcmp(name+(len-ext.size()), ext.c_str()) == 0)
{
- ext = ""; // name already has Executable extension
+ extensionIncluded = true;
+ }
+ else
+ {
+ searchName += ext;
}
}
- }
- // See if the executable exists as written.
- if(SystemTools::FileExists(name) &&
- !SystemTools::FileIsDirectory(name))
- {
- return SystemTools::CollapseFullPath(name);
- }
- if(ext.size())
- {
- kwsys_stl::string tryPath = name;
- tryPath += ext;
- if(SystemTools::FileExists(tryPath.c_str()) &&
- !SystemTools::FileIsDirectory(tryPath.c_str()))
+ else
{
- return SystemTools::CollapseFullPath(tryPath.c_str());
+ searchName += ext;
}
}
+ // searchName now has the extension in it.
+
+ // See if the executable exists as written
+ if(SystemTools::FileExists(searchName.c_str()) &&
+ !SystemTools::FileIsDirectory(searchName.c_str()))
+ {
+ return SystemTools::CollapseFullPath(searchName.c_str());
+ }
kwsys_stl::vector<kwsys_stl::string> path;
- // Add the system search path to our path.
+ // Add the system search path to our path if asked for
if (!no_system_path)
{
SystemTools::GetPath(path);
}
-
// now add the additional paths
- for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i = userPaths.begin();
- i != userPaths.end(); ++i)
+ for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i =
+ userPaths.begin(); i != userPaths.end(); ++i)
{
path.push_back(*i);
}
+ kwsys_stl::string tryPath;
+ // now search the paths specified
for(kwsys_stl::vector<kwsys_stl::string>::iterator p = path.begin();
p != path.end(); ++p)
{
#ifdef _WIN32
// Remove double quotes from the path on windows
SystemTools::ReplaceString(*p, "\"", "");
-#endif
- kwsys_stl::string tryPath = *p;
- tryPath += "/";
- tryPath += name;
- if(SystemTools::FileExists(tryPath.c_str()) &&
- !SystemTools::FileIsDirectory(tryPath.c_str()))
- {
- return SystemTools::CollapseFullPath(tryPath.c_str());
- }
-#ifdef _WIN32
- // on windows try .com before .exe
- if(ext.size() == 0)
+ // if the extension was not specified then look
+ // for .com before the ext version
+ if(!extensionIncluded)
{
+ // first try .com instead .exe
+ kwsys_stl::string tryPath = *p;
+ tryPath += "/";
+ tryPath += searchName;
SystemTools::ReplaceString(tryPath, ".exe", ".com");
SystemTools::ReplaceString(tryPath, ".EXE", ".com");
- }
- else
- {
- tryPath += ".com";
- }
- if(SystemTools::FileExists(tryPath.c_str()) &&
- !SystemTools::FileIsDirectory(tryPath.c_str()))
- {
- return SystemTools::CollapseFullPath(tryPath.c_str());
- }
-#endif
- // now try to add ext if it is different than name
- if(ext.size())
- {
- tryPath = *p;
- tryPath += "/";
- tryPath += name;
- tryPath += ext;
if(SystemTools::FileExists(tryPath.c_str()) &&
!SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
}
}
+#endif
+ tryPath = *p;
+ tryPath += "/";
+ tryPath += searchName;
+ if(SystemTools::FileExists(tryPath.c_str()) &&
+ !SystemTools::FileIsDirectory(tryPath.c_str()))
+ {
+ return SystemTools::CollapseFullPath(tryPath.c_str());
+ }
}
// Couldn't find the program.