ENH: undo last change because it broke the dashboard

This commit is contained in:
Bill Hoffman 2006-03-10 17:37:47 -05:00
parent ac432c7e7c
commit d2f7b0c64f
1 changed files with 49 additions and 40 deletions

View File

@ -1922,11 +1922,7 @@ kwsys_stl::string SystemTools::FindProgram(
{ {
return ""; return "";
} }
bool extensionIncluded = false;
kwsys_stl::string ext = SystemTools::GetExecutableExtension(); 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()) if(ext.size())
{ {
unsigned int len = strlen(name); unsigned int len = strlen(name);
@ -1934,72 +1930,85 @@ kwsys_stl::string SystemTools::FindProgram(
{ {
if(strcmp(name+(len-ext.size()), ext.c_str()) == 0) if(strcmp(name+(len-ext.size()), ext.c_str()) == 0)
{ {
extensionIncluded = true; ext = ""; // name already has Executable extension
} }
else }
}
// See if the executable exists as written.
if(SystemTools::FileExists(name) &&
!SystemTools::FileIsDirectory(name))
{ {
searchName += ext; return SystemTools::CollapseFullPath(name);
} }
} if(ext.size())
else
{ {
searchName += ext; kwsys_stl::string tryPath = name;
} tryPath += ext;
} if(SystemTools::FileExists(tryPath.c_str()) &&
// searchName now has the extension in it. !SystemTools::FileIsDirectory(tryPath.c_str()))
// See if the executable exists as written
if(SystemTools::FileExists(searchName.c_str()) &&
!SystemTools::FileIsDirectory(searchName.c_str()))
{ {
return SystemTools::CollapseFullPath(searchName.c_str()); return SystemTools::CollapseFullPath(tryPath.c_str());
}
} }
kwsys_stl::vector<kwsys_stl::string> path; kwsys_stl::vector<kwsys_stl::string> path;
// Add the system search path to our path if asked for // Add the system search path to our path.
if (!no_system_path) if (!no_system_path)
{ {
SystemTools::GetPath(path); SystemTools::GetPath(path);
} }
// now add the additional paths // now add the additional paths
for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i = for(kwsys_stl::vector<kwsys_stl::string>::const_iterator i = userPaths.begin();
userPaths.begin(); i != userPaths.end(); ++i) i != userPaths.end(); ++i)
{ {
path.push_back(*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(); for(kwsys_stl::vector<kwsys_stl::string>::iterator p = path.begin();
p != path.end(); ++p) p != path.end(); ++p)
{ {
#ifdef _WIN32 #ifdef _WIN32
// Remove double quotes from the path on windows // Remove double quotes from the path on windows
SystemTools::ReplaceString(*p, "\"", ""); SystemTools::ReplaceString(*p, "\"", "");
// if the extension was not specified then look #endif
// for .com before the ext version
if(!extensionIncluded)
{
// first try .com instead .exe
kwsys_stl::string tryPath = *p; kwsys_stl::string tryPath = *p;
tryPath += "/"; tryPath += "/";
tryPath += searchName; 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)
{
SystemTools::ReplaceString(tryPath, ".exe", ".com"); SystemTools::ReplaceString(tryPath, ".exe", ".com");
SystemTools::ReplaceString(tryPath, ".EXE", ".com"); SystemTools::ReplaceString(tryPath, ".EXE", ".com");
}
else
{
tryPath += ".com";
}
if(SystemTools::FileExists(tryPath.c_str()) && if(SystemTools::FileExists(tryPath.c_str()) &&
!SystemTools::FileIsDirectory(tryPath.c_str())) !SystemTools::FileIsDirectory(tryPath.c_str()))
{ {
return SystemTools::CollapseFullPath(tryPath.c_str()); return SystemTools::CollapseFullPath(tryPath.c_str());
} }
}
#endif #endif
// now try to add ext if it is different than name
if(ext.size())
{
tryPath = *p; tryPath = *p;
tryPath += "/"; tryPath += "/";
tryPath += searchName; tryPath += name;
tryPath += ext;
if(SystemTools::FileExists(tryPath.c_str()) && if(SystemTools::FileExists(tryPath.c_str()) &&
!SystemTools::FileIsDirectory(tryPath.c_str())) !SystemTools::FileIsDirectory(tryPath.c_str()))
{ {
return SystemTools::CollapseFullPath(tryPath.c_str()); return SystemTools::CollapseFullPath(tryPath.c_str());
} }
} }
}
// Couldn't find the program. // Couldn't find the program.
return ""; return "";