1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 #include "collectdircontent.hxx"
6 PathFilePair
IncludesCollection::split_path(const string
& filePath
) {
9 string::size_type pos
= filePath
.rfind (sepU
);
10 string::size_type posW
= filePath
.rfind (sepW
);
11 if ((posW
!= string::npos
) && ((posW
> pos
) || (pos
== string::npos
))) pos
= posW
;
12 if (pos
!= string::npos
) {
13 string dirName
= filePath
.substr(0, pos
);
14 return PathFilePair(dirName
, filePath
.substr(pos
+ 1, filePath
.length()));
16 return PathFilePair(".", filePath
);
19 void IncludesCollection::add_to_collection(const string
& dirPath
) {
20 DirContent dirContent
;
22 WIN32_FIND_DATA FindFileData
;
24 hFind
= FindFirstFile((dirPath
+ "\\*").c_str(), &FindFileData
);
25 if (hFind
== INVALID_HANDLE_VALUE
) {
26 // Invalid File Handle - no need to try it anymore
27 allIncludes
.insert(EntriesPair(dirPath
, DirContent()));
31 string
winFileName(FindFileData
.cFileName
);
32 transform(winFileName
.begin(), winFileName
.end(), winFileName
.begin(), ::tolower
);
33 dirContent
.insert(winFileName
);
34 } while (FindNextFile(hFind
, &FindFileData
));
38 pdir
= opendir(dirPath
.c_str()); //"." refers to the current dir
40 // Invalid File Handle - no need to try it anymore
41 allIncludes
.insert(EntriesPair(dirPath
, DirContent()));
44 while ((pent
= readdir(pdir
))) {
45 dirContent
.insert(pent
->d_name
);
48 #endif // defined( WNT )
49 allIncludes
.insert(EntriesPair(dirPath
, dirContent
));
52 bool IncludesCollection::exists(string filePath
) {
54 transform(filePath
.begin(), filePath
.end(), filePath
.begin(), ::tolower
);
55 #endif // defined( WNT )
56 PathFilePair dirFile
= split_path(filePath
);
57 string dirPath
= dirFile
.first
;
58 string fileName
= dirFile
.second
;
59 DirMap::iterator mapIter
= allIncludes
.find(dirPath
);
60 if (mapIter
== allIncludes
.end()) {
61 add_to_collection(dirPath
);
62 mapIter
= allIncludes
.find(dirPath
);
64 DirContent dirContent
= (*mapIter
).second
;
65 DirContent::iterator dirIter
= dirContent
.find(fileName
);
66 if (dirIter
== dirContent
.end()) {
75 IncludesCollection
* create_IncludesCollection() {
76 return new IncludesCollection
;
79 void delete_IncludesCollection(IncludesCollection
*m
) {
83 int call_IncludesCollection_exists(IncludesCollection
* m
, const char * filePath
) {
84 return m
->exists(filePath
);
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */