BUG: fix split program from args to not get stuck in an infinite loop in some cases
This commit is contained in:
parent
e78a57563c
commit
1ed5888d91
|
@ -1828,14 +1828,18 @@ bool SystemTools::GetShortPath(const char* path, kwsys_stl::string& shortPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemTools::SplitProgramFromArgs(const char* path,
|
void SystemTools::SplitProgramFromArgs(const char* path,
|
||||||
kwsys_stl::string& program, kwsys_stl::string& args)
|
kwsys_stl::string& program, kwsys_stl::string& args)
|
||||||
{
|
{
|
||||||
|
// see if this is a full path to a program
|
||||||
|
// if so then set program to path and args to nothing
|
||||||
if(SystemTools::FileExists(path))
|
if(SystemTools::FileExists(path))
|
||||||
{
|
{
|
||||||
program = path;
|
program = path;
|
||||||
args = "";
|
args = "";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Try to find the program in the path, note the program
|
||||||
|
// may have spaces in its name so we have to look for it
|
||||||
kwsys_stl::vector<kwsys_stl::string> e;
|
kwsys_stl::vector<kwsys_stl::string> e;
|
||||||
kwsys_stl::string findProg = SystemTools::FindProgram(path, e);
|
kwsys_stl::string findProg = SystemTools::FindProgram(path, e);
|
||||||
if(findProg.size())
|
if(findProg.size())
|
||||||
|
@ -1844,32 +1848,48 @@ void SystemTools::SplitProgramFromArgs(const char* path,
|
||||||
args = "";
|
args = "";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now try and peel off space separated chunks from the end of the string
|
||||||
|
// so the largest path possible is found allowing for spaces in the path
|
||||||
kwsys_stl::string dir = path;
|
kwsys_stl::string dir = path;
|
||||||
kwsys_stl::string::size_type spacePos = dir.rfind(' ');
|
kwsys_stl::string::size_type spacePos = dir.rfind(' ');
|
||||||
if(spacePos == kwsys_stl::string::npos)
|
|
||||||
{
|
|
||||||
program = "";
|
|
||||||
args = "";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while(spacePos != kwsys_stl::string::npos)
|
while(spacePos != kwsys_stl::string::npos)
|
||||||
{
|
{
|
||||||
kwsys_stl::string tryProg = dir.substr(0, spacePos);
|
kwsys_stl::string tryProg = dir.substr(0, spacePos);
|
||||||
|
// See if the file exists
|
||||||
if(SystemTools::FileExists(tryProg.c_str()))
|
if(SystemTools::FileExists(tryProg.c_str()))
|
||||||
{
|
{
|
||||||
program = tryProg;
|
program = tryProg;
|
||||||
|
// remove trailing spaces from program
|
||||||
|
kwsys_stl::string::size_type pos = program.size()-1;
|
||||||
|
while(program[pos] == ' ')
|
||||||
|
{
|
||||||
|
program.erase(pos);
|
||||||
|
pos--;
|
||||||
|
}
|
||||||
args = dir.substr(spacePos, dir.size()-spacePos);
|
args = dir.substr(spacePos, dir.size()-spacePos);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Now try and find the the program in the path
|
||||||
findProg = SystemTools::FindProgram(tryProg.c_str(), e);
|
findProg = SystemTools::FindProgram(tryProg.c_str(), e);
|
||||||
if(findProg.size())
|
if(findProg.size())
|
||||||
{
|
{
|
||||||
program = findProg;
|
program = findProg;
|
||||||
|
// remove trailing spaces from program
|
||||||
|
kwsys_stl::string::size_type pos = program.size()-1;
|
||||||
|
while(program[pos] == ' ')
|
||||||
|
{
|
||||||
|
program.erase(pos);
|
||||||
|
pos--;
|
||||||
|
}
|
||||||
args = dir.substr(spacePos, dir.size()-spacePos);
|
args = dir.substr(spacePos, dir.size()-spacePos);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
spacePos = dir.rfind(' ', spacePos--);
|
// move past the space for the next search
|
||||||
|
spacePos--;
|
||||||
|
spacePos = dir.rfind(' ', spacePos);
|
||||||
}
|
}
|
||||||
|
|
||||||
program = "";
|
program = "";
|
||||||
args = "";
|
args = "";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue