Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
CMake
CMake
Commits
89d35bc8
Commit
89d35bc8
authored
Oct 18, 2004
by
Bill Hoffman
Browse files
ENH: better comments and variable names
parent
e60b8b87
Changes
1
Hide whitespace changes
Inline
Side-by-side
Source/cmSystemTools.cxx
View file @
89d35bc8
...
...
@@ -1218,7 +1218,7 @@ std::string cmSystemTools::RelativePath(const char* local, const char* remote)
}
if
(
!
cmSystemTools
::
FileIsFullPath
(
remote
))
{
cmSystemTools
::
Error
(
"RelativePath must be passed a full path to
local
: "
,
remote
);
cmSystemTools
::
Error
(
"RelativePath must be passed a full path to
remote
: "
,
remote
);
}
// check for driveletter: as the start of the path
...
...
@@ -1230,54 +1230,55 @@ std::string cmSystemTools::RelativePath(const char* local, const char* remote)
return
remote
;
}
}
std
::
string
relativePath
;
// result string
// split up both paths into arrays of strings using / as a separator
std
::
string
localString
=
local
;
std
::
vector
<
cmStdString
>
file
Split
=
cmSystemTools
::
SplitString
(
local
,
'/'
,
true
);
std
::
vector
<
cmStdString
>
re
lativ
eSplit
=
cmSystemTools
::
SplitString
(
remote
,
'/'
,
true
);
std
::
vector
<
cmStdString
>
commonPath
;
std
::
vector
<
cmStdString
>
finalPath
;
std
::
vector
<
cmStdString
>
local
Split
=
cmSystemTools
::
SplitString
(
local
,
'/'
,
true
);
std
::
vector
<
cmStdString
>
re
mot
eSplit
=
cmSystemTools
::
SplitString
(
remote
,
'/'
,
true
);
std
::
vector
<
cmStdString
>
commonPath
;
// store shared parts of path in this array
std
::
vector
<
cmStdString
>
finalPath
;
// store the final relative path here
// count up how many matching directory names there are from the start
unsigned
int
sameCount
=
0
;
while
(
((
sameCount
<=
(
file
Split
.
size
()
-
1
))
&&
(
sameCount
<=
(
re
lativ
eSplit
.
size
()
-
1
)))
((
sameCount
<=
(
local
Split
.
size
()
-
1
))
&&
(
sameCount
<=
(
re
mot
eSplit
.
size
()
-
1
)))
&&
// for windows and apple do a case insensitive string compare
#if defined(_WIN32) || defined(__APPLE__)
cmSystemTools
::
Strucmp
(
file
Split
[
sameCount
].
c_str
(),
relativ
eSplit
[
sameCount
].
c_str
())
==
0
cmSystemTools
::
Strucmp
(
local
Split
[
sameCount
].
c_str
(),
remot
eSplit
[
sameCount
].
c_str
())
==
0
#else
file
Split
[
sameCount
]
==
re
lativ
eSplit
[
sameCount
]
local
Split
[
sameCount
]
==
re
mot
eSplit
[
sameCount
]
#endif
)
{
// put the common parts of the path into the commonPath array
commonPath
.
push_back
(
file
Split
[
sameCount
]);
commonPath
.
push_back
(
local
Split
[
sameCount
]);
// erase the common parts of the path from the original path arrays
file
Split
[
sameCount
]
=
""
;
re
lativ
eSplit
[
sameCount
]
=
""
;
local
Split
[
sameCount
]
=
""
;
re
mot
eSplit
[
sameCount
]
=
""
;
sameCount
++
;
}
// for each entry that is not common in the local or file path
// add a ../ to the finalpath array
for
(
unsigned
int
i
=
0
;
i
<
fileSplit
.
size
();
++
i
)
// for each entry that is not common in the local path
// add a ../ to the finalpath array, this gets us out of the local
// path into the remote dir
for
(
unsigned
int
i
=
0
;
i
<
localSplit
.
size
();
++
i
)
{
if
(
file
Split
[
i
].
size
())
if
(
local
Split
[
i
].
size
())
{
finalPath
.
push_back
(
"../"
);
}
}
// for each entry that is not common in the remote path add it
// to the final path
for
(
std
::
vector
<
cmStdString
>::
iterator
i
=
re
lativ
eSplit
.
begin
();
i
!=
re
lativ
eSplit
.
end
();
++
i
)
// to the final path
.
for
(
std
::
vector
<
cmStdString
>::
iterator
i
=
re
mot
eSplit
.
begin
();
i
!=
re
mot
eSplit
.
end
();
++
i
)
{
if
(
i
->
size
())
{
finalPath
.
push_back
(
*
i
);
}
}
std
::
string
relativePath
;
// result string
// now turn the array of directories into a unix path by puttint /
// between each entry that does not already have one
for
(
std
::
vector
<
cmStdString
>::
iterator
i
=
finalPath
.
begin
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment