office-gobmx/soltools/mkdepend/collectdircontent.cxx
Vladimir Glazounov 024e577dc3 CWS-TOOLING: integrate CWS mingwport16
2009-01-15 13:11:20 +0100 releng  r266363 : tidy-up tabs
2008-11-28 15:33:23 +0100 tono  r264557 : i95203: mingw build without stlport
2008-11-22 07:19:50 +0100 tono  r264180 : i96436: make mingw bridge conform with reg-struct-return
2008-11-22 05:14:58 +0100 tono  r264179 : i96436: make mingw bridge conform with reg-struct-return
2008-11-21 17:09:04 +0100 tono  r264153 : i95203: mingw build without stlport
2008-11-21 16:59:55 +0100 tono  r264152 : i96436: make mingw bridge conform with reg-struct-return
2008-11-21 16:59:18 +0100 tono  r264151 : i96436: make mingw bridge conform with reg-struct-return
2008-11-21 16:57:01 +0100 tono  r264150 : i96436: make mingw bridge conform with reg-struct-return
2008-11-21 16:53:19 +0100 tono  r264149 : i96100: mingw port for icu 4.0
2008-11-13 13:41:13 +0100 tono  r263643 : i95203: mingw: Build without stlport
2008-11-13 13:29:38 +0100 tono  r263640 : i96100: MinGW port for icu 4.0
2008-11-13 13:17:10 +0100 tono  r263634 : i96098: MinGW port fix for new Windows API
2008-11-09 15:22:59 +0100 tono  r263497 : i95198: mingwport do not interfere with Cygwin
2008-11-09 14:44:54 +0100 tono  r263496 : i95190: mingwport avoid use of MS assembler
2008-11-09 14:32:26 +0100 tono  r263495 : i95190: mingwport trivial build fixes
2009-01-20 16:36:21 +00:00

79 lines
2.6 KiB
C++
Executable file

#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);
}
}