summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/PythonUtil.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2004-11-18 19:32:20 +0000
committerMark Spruiell <mes@zeroc.com>2004-11-18 19:32:20 +0000
commit28153fcb4aea2eda93d3f457725579f62eb61313 (patch)
tree55efed09d84f108b7048396132a813ef4d8cb638 /cpp/src/Slice/PythonUtil.cpp
parentWindows fixes (diff)
downloadice-28153fcb4aea2eda93d3f457725579f62eb61313.tar.bz2
ice-28153fcb4aea2eda93d3f457725579f62eb61313.tar.xz
ice-28153fcb4aea2eda93d3f457725579f62eb61313.zip
Win32 fixes
Diffstat (limited to 'cpp/src/Slice/PythonUtil.cpp')
-rw-r--r--cpp/src/Slice/PythonUtil.cpp42
1 files changed, 30 insertions, 12 deletions
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index cd09013f67a..1482f5f80f3 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -1587,33 +1587,50 @@ Slice::Python::CodeVisitor::collectExceptionMembers(const ExceptionPtr& p, Membe
}
static string
-changeInclude(const string& orig, const vector<string>& includePaths)
+normalizePath(const string& path)
{
- string file = orig;
- replace(file.begin(), file.end(), '\\', '/');
+ string result = path;
+ replace(result.begin(), result.end(), '\\', '/');
+ string::size_type pos;
+ while((pos = result.find("//")) != string::npos)
+ {
+ result.replace(pos, 2, "/");
+ }
+ return result;
+}
+static string
+changeInclude(const string& inc, const vector<string>& includePaths)
+{
+ string orig = normalizePath(inc);
+ string curr = orig; // The current shortest pathname.
+
+ //
+ // Compare the pathname of the included file against each of the include directories.
+ // If any of the include directories match the leading part of the included file,
+ // then select the include directory whose removal results in the shortest pathname.
+ //
for(vector<string>::const_iterator p = includePaths.begin(); p != includePaths.end(); ++p)
{
string includePath = *p;
- replace(includePath.begin(), includePath.end(), '\\', '/');
- if(orig.compare(0, includePath.length(), *p) == 0)
+ if(orig.compare(0, p->size(), *p) == 0)
{
- string s = orig.substr(includePath.length());
- if(s.size() < file.size())
+ string s = orig.substr(p->size());
+ if(s.size() < curr.size())
{
- file = s;
+ curr = s;
}
}
}
- string::size_type pos = file.rfind('.');
+ string::size_type pos = curr.rfind('.');
if(pos != string::npos)
{
- file.erase(pos);
+ curr.erase(pos);
}
- return file;
+ return curr;
}
void
@@ -1626,10 +1643,11 @@ Slice::Python::generate(const UnitPtr& un, bool all, bool checksum, const vector
vector<string> paths = includePaths;
for(vector<string>::iterator p = paths.begin(); p != paths.end(); ++p)
{
- if(p->length() && (*p)[p->length() - 1] != '/')
+ if(p->size() && (*p)[p->size() - 1] != '/')
{
*p += '/';
}
+ *p = normalizePath(*p);
}
StringList includes = un->includeFiles();