Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
KWSys
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sylvain Joubert
KWSys
Commits
30140c03
Commit
30140c03
authored
20 years ago
by
Bill Hoffman
Browse files
Options
Downloads
Patches
Plain Diff
BUG: fix split program from args to not get stuck in an infinite loop in some cases
parent
492b769b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SystemTools.cxx
+29
-9
29 additions, 9 deletions
SystemTools.cxx
with
29 additions
and
9 deletions
SystemTools.cxx
+
29
−
9
View file @
30140c03
...
...
@@ -1828,14 +1828,18 @@ bool SystemTools::GetShortPath(const char* path, kwsys_stl::string& shortPath)
}
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
))
{
program
=
path
;
args
=
""
;
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
::
string
findProg
=
SystemTools
::
FindProgram
(
path
,
e
);
if
(
findProg
.
size
())
...
...
@@ -1844,32 +1848,48 @@ void SystemTools::SplitProgramFromArgs(const char* path,
args
=
""
;
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
::
size_type
spacePos
=
dir
.
rfind
(
' '
);
if
(
spacePos
==
kwsys_stl
::
string
::
npos
)
{
program
=
""
;
args
=
""
;
return
;
}
while
(
spacePos
!=
kwsys_stl
::
string
::
npos
)
{
kwsys_stl
::
string
tryProg
=
dir
.
substr
(
0
,
spacePos
);
// See if the file exists
if
(
SystemTools
::
FileExists
(
tryProg
.
c_str
()))
{
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
);
return
;
}
}
// Now try and find the the program in the path
findProg
=
SystemTools
::
FindProgram
(
tryProg
.
c_str
(),
e
);
if
(
findProg
.
size
())
{
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
);
return
;
}
spacePos
=
dir
.
rfind
(
' '
,
spacePos
--
);
// move past the space for the next search
spacePos
--
;
spacePos
=
dir
.
rfind
(
' '
,
spacePos
);
}
program
=
""
;
args
=
""
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment