1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 #include "collectdircontent.hxx"
3 #include <rtl/character.hxx>
7 PathFilePair
IncludesCollection::split_path(const string
& filePath
) {
10 string::size_type pos
= filePath
.rfind (sepU
);
11 string::size_type posW
= filePath
.rfind (sepW
);
12 if ((posW
!= string::npos
) && ((posW
> pos
) || (pos
== string::npos
))) pos
= posW
;
13 if (pos
!= string::npos
) {
14 string dirName
= filePath
.substr(0, pos
);
15 return PathFilePair(dirName
, filePath
.substr(pos
+ 1, filePath
.length()));
17 return PathFilePair(".", filePath
);
20 void IncludesCollection::add_to_collection(const string
& dirPath
) {
21 DirContent dirContent
;
23 WIN32_FIND_DATA FindFileData
;
25 hFind
= FindFirstFile((dirPath
+ "\\*").c_str(), &FindFileData
);
26 if (hFind
== INVALID_HANDLE_VALUE
) {
27 // Invalid File Handle - no need to try it anymore
28 allIncludes
.insert(EntriesPair(dirPath
, DirContent()));
32 string
winFileName(FindFileData
.cFileName
);
34 winFileName
.begin(), winFileName
.end(), winFileName
.begin(),
36 return rtl::toAsciiLowerCase(static_cast<unsigned char>(c
));
38 dirContent
.insert(winFileName
);
39 } while (FindNextFile(hFind
, &FindFileData
));
43 pdir
= opendir(dirPath
.c_str()); //"." refers to the current dir
45 // Invalid File Handle - no need to try it anymore
46 allIncludes
.insert(EntriesPair(dirPath
, DirContent()));
49 while ((pent
= readdir(pdir
))) {
50 dirContent
.insert(pent
->d_name
);
53 #endif // defined( WNT )
54 allIncludes
.insert(EntriesPair(dirPath
, dirContent
));
57 bool IncludesCollection::exists(string filePath
) {
60 filePath
.begin(), filePath
.end(), filePath
.begin(),
62 return rtl::toAsciiLowerCase(static_cast<unsigned char>(c
));
64 #endif // defined( WNT )
65 PathFilePair dirFile
= split_path(filePath
);
66 string dirPath
= dirFile
.first
;
67 string fileName
= dirFile
.second
;
68 DirMap::iterator mapIter
= allIncludes
.find(dirPath
);
69 if (mapIter
== allIncludes
.end()) {
70 add_to_collection(dirPath
);
71 mapIter
= allIncludes
.find(dirPath
);
73 DirContent dirContent
= (*mapIter
).second
;
74 DirContent::iterator dirIter
= dirContent
.find(fileName
);
75 if (dirIter
== dirContent
.end()) {
84 IncludesCollection
* create_IncludesCollection() {
85 return new IncludesCollection
;
88 void delete_IncludesCollection(IncludesCollection
*m
) {
92 int call_IncludesCollection_exists(IncludesCollection
* m
, const char * filePath
) {
93 return m
->exists(filePath
);
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */