From 1d8043cb4fd6c1bfa3091ea11cd8cde956fcfb99 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Mon, 8 May 2006 14:18:09 -0400 Subject: ENH: search for program without extensions --- Source/kwsys/SystemTools.cxx | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 1a878d5..06eccde 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -2018,7 +2018,7 @@ kwsys_stl::string SystemTools::FindProgram( } kwsys_stl::string name = nameIn; kwsys_stl::vector extensions; -#if defined (_WIN32) || defined(__CYGWIN__) | defined(__MINGW32__) +#if defined (_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) bool hasExtension = false; // check to see if the name already has a .xxx at // the end of it @@ -2034,8 +2034,8 @@ kwsys_stl::string SystemTools::FindProgram( } #endif kwsys_stl::string tryPath; - // first try the name as it was given (adding extensions - // if needed.) + + // first try with extensions if the os supports them if(extensions.size()) { for(kwsys_stl::vector::iterator i = @@ -2050,14 +2050,12 @@ kwsys_stl::string SystemTools::FindProgram( } } } - else + // now try just the name + tryPath = name; + if(SystemTools::FileExists(tryPath.c_str()) && + !SystemTools::FileIsDirectory(tryPath.c_str())) { - tryPath = name; - if(SystemTools::FileExists(tryPath.c_str()) && - !SystemTools::FileIsDirectory(tryPath.c_str())) - { - return SystemTools::CollapseFullPath(tryPath.c_str()); - } + return SystemTools::CollapseFullPath(tryPath.c_str()); } // now construct the path kwsys_stl::vector path; @@ -2080,6 +2078,7 @@ kwsys_stl::string SystemTools::FindProgram( // Remove double quotes from the path on windows SystemTools::ReplaceString(*p, "\"", ""); #endif + // first try with extensions if(extensions.size()) { for(kwsys_stl::vector::iterator ext @@ -2096,16 +2095,14 @@ kwsys_stl::string SystemTools::FindProgram( } } } - else + // now try it without them + tryPath = *p; + tryPath += "/"; + tryPath += name; + if(SystemTools::FileExists(tryPath.c_str()) && + !SystemTools::FileIsDirectory(tryPath.c_str())) { - tryPath = *p; - tryPath += "/"; - tryPath += name; - if(SystemTools::FileExists(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. -- cgit v0.12