1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 #include "collectdircontent.hxx"
4 PathFilePair
IncludesCollection::split_path(const string
& filePath
) {
7 string::size_type pos
= filePath
.rfind (sepU
);
8 string::size_type posW
= filePath
.rfind (sepW
);
9 if ((posW
!= string::npos
) && ((posW
> pos
) || (pos
== string::npos
))) pos
= posW
;
10 if (pos
!= string::npos
) {
11 string dirName
= filePath
.substr(0, pos
);
12 return PathFilePair(dirName
, filePath
.substr(pos
+ 1, filePath
.length()));
14 return PathFilePair(".", filePath
);
17 void IncludesCollection::add_to_collection(const string
& dirPath
) {
18 DirContent dirContent
;
20 WIN32_FIND_DATA FindFileData
;
22 hFind
= FindFirstFile((dirPath
+ "\\*").c_str(), &FindFileData
);
23 if (hFind
== INVALID_HANDLE_VALUE
) {
24 // Invalid File Handle - no need to try it anymore
25 allIncludes
.insert(EntriesPair(dirPath
, DirContent()));
29 string
winFileName(FindFileData
.cFileName
);
30 transform(winFileName
.begin(), winFileName
.end(), winFileName
.begin(), ::tolower
);
31 dirContent
.insert(winFileName
);
32 } while (FindNextFile(hFind
, &FindFileData
));
36 pdir
= opendir(dirPath
.c_str()); //"." refers to the current dir
38 // Invalid File Handle - no need to try it anymore
39 allIncludes
.insert(EntriesPair(dirPath
, DirContent()));
42 while ((pent
= readdir(pdir
))) {
43 dirContent
.insert(pent
->d_name
);
46 #endif // defined( WNT )
47 allIncludes
.insert(EntriesPair(dirPath
, dirContent
));
50 bool IncludesCollection::exists(string filePath
) {
52 transform(filePath
.begin(), filePath
.end(), filePath
.begin(), ::tolower
);
53 #endif // defined( WNT )
54 PathFilePair dirFile
= split_path(filePath
);
55 string dirPath
= dirFile
.first
;
56 string fileName
= dirFile
.second
;
57 DirMap::iterator mapIter
= allIncludes
.find(dirPath
);
58 if (mapIter
== allIncludes
.end()) {
59 add_to_collection(dirPath
);
60 mapIter
= allIncludes
.find(dirPath
);
62 DirContent dirContent
= (*mapIter
).second
;
63 DirContent::iterator dirIter
= dirContent
.find(fileName
);
64 if (dirIter
== dirContent
.end()) {
73 IncludesCollection
* create_IncludesCollection() {
74 return new IncludesCollection
;
77 void delete_IncludesCollection(IncludesCollection
*m
) {
81 int call_IncludesCollection_exists(IncludesCollection
* m
, const char * filePath
) {
82 return m
->exists(filePath
);
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */