diff options
author | Vladimir Glazounov <vg@openoffice.org> | 2006-09-22 07:56:18 +0000 |
---|---|---|
committer | Vladimir Glazounov <vg@openoffice.org> | 2006-09-22 07:56:18 +0000 |
commit | a6d5936851b04096bba87144d6b02ad56e48e6c5 (patch) | |
tree | 086fc6acba20bcef15f227d6e8b23c9827661e14 /soltools/mkdepend/collectdircontent.cxx | |
parent | d8a02a76b8b02ed3f19dbf76517fdb2ec01c213a (diff) |
INTEGRATION: CWS vgbugs04 (1.1.2); FILE ADDED
2006/09/15 15:19:53 vg 1.1.2.4: #i69015# -n switsh for windows-native slashes
2006/08/23 13:54:39 vg 1.1.2.3: #137785# case insensitive paths for Windows
2006/08/23 13:43:49 vg 1.1.2.2: #137785# case insensitive paths for Windows
2006/07/04 10:37:13 vg 1.1.2.1: #137785# optimize makedepend
Diffstat (limited to 'soltools/mkdepend/collectdircontent.cxx')
-rwxr-xr-x | soltools/mkdepend/collectdircontent.cxx | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/soltools/mkdepend/collectdircontent.cxx b/soltools/mkdepend/collectdircontent.cxx new file mode 100755 index 000000000000..50da374841cd --- /dev/null +++ b/soltools/mkdepend/collectdircontent.cxx @@ -0,0 +1,79 @@ +#include "collectdircontent.hxx" + +PathFilePair IncludesCollection::split_path(const string& filePath) { + string sepU = "/"; + string sepW = "\\"; + string::size_type pos = filePath.rfind (sepU); + string::size_type posW = filePath.rfind (sepW); + if ((posW != string::npos) && ((posW > pos) || (pos == string::npos))) pos = posW; + if (pos != string::npos) { + string dirName = filePath.substr(0, pos); + return PathFilePair(dirName, filePath.substr(pos + 1, filePath.length())); + } else + return PathFilePair(".", filePath); +}; + +void IncludesCollection::add_to_collection(const string& dirPath) { + DirContent dirContent; +#if defined( WNT ) + WIN32_FIND_DATA FindFileData; + HANDLE hFind; + hFind = FindFirstFile((dirPath + "\\*").c_str(), &FindFileData); + if (hFind == INVALID_HANDLE_VALUE) { + // Invalid File Handle - no need to try it anymore + allIncludes.insert(EntriesPair(dirPath, DirContent())); + return; + }; + do { + string winFileName(FindFileData.cFileName); + transform(winFileName.begin(), winFileName.end(), winFileName.begin(), tolower); + dirContent.insert(winFileName); + } while (FindNextFile(hFind, &FindFileData)); +#else + DIR *pdir; + dirent *pent; + pdir = opendir(dirPath.c_str()); //"." refers to the current dir + if (!pdir) { + // Invalid File Handle - no need to try it anymore + allIncludes.insert(EntriesPair(dirPath, DirContent())); + return; + } + while ((pent = readdir(pdir))) { + dirContent.insert(pent->d_name); + }; +#endif // defined( WNT ) + allIncludes.insert(EntriesPair(dirPath, dirContent)); +}; + +bool IncludesCollection::exists(string filePath) { +#if defined( WNT ) + transform(filePath.begin(), filePath.end(), filePath.begin(), tolower); +#endif // defined( WNT ) + PathFilePair dirFile = split_path(filePath); + string dirPath = dirFile.first; + string fileName = dirFile.second; + DirMap::iterator mapIter = allIncludes.find(dirPath); + if (mapIter == allIncludes.end()) { + add_to_collection(dirPath); + mapIter = allIncludes.find(dirPath); + }; + DirContent dirContent = (*mapIter).second; + DirContent::iterator dirIter = dirContent.find(fileName); + if (dirIter == dirContent.end()) { + return false; + } else { + return true; + }; + return false; +}; + +extern "C" { + + IncludesCollection * create_IncludesCollection() { + return new IncludesCollection; + } + + int call_IncludesCollection_exists(IncludesCollection* m, const char * filePath) { + return m->exists(filePath); + } +} |