summaryrefslogtreecommitdiffstats
path: root/soltools/mkdepend/collectdircontent.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /soltools/mkdepend/collectdircontent.cxx
parentInitial commit. (diff)
downloadlibreoffice-upstream.tar.xz
libreoffice-upstream.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'soltools/mkdepend/collectdircontent.cxx')
-rw-r--r--soltools/mkdepend/collectdircontent.cxx93
1 files changed, 93 insertions, 0 deletions
diff --git a/soltools/mkdepend/collectdircontent.cxx b/soltools/mkdepend/collectdircontent.cxx
new file mode 100644
index 000000000..7ea5fa272
--- /dev/null
+++ b/soltools/mkdepend/collectdircontent.cxx
@@ -0,0 +1,93 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+#include "collectdircontent.hxx"
+#include <rtl/character.hxx>
+
+using namespace std;
+
+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(_WIN32)
+ 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(),
+ [](char c) {
+ return rtl::toAsciiLowerCase(static_cast<unsigned char>(c));
+ });
+ 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);
+ }
+ closedir(pdir);
+#endif // defined( _WIN32 )
+ allIncludes.insert(EntriesPair(dirPath, dirContent));
+}
+
+bool IncludesCollection::exists(string filePath) {
+#if defined(_WIN32)
+ transform(
+ filePath.begin(), filePath.end(), filePath.begin(),
+ [](char c) {
+ return rtl::toAsciiLowerCase(static_cast<unsigned char>(c));
+ });
+#endif // defined( _WIN32 )
+ 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);
+ return dirIter != dirContent.end();
+}
+
+extern "C" {
+
+ IncludesCollection * create_IncludesCollection() {
+ return new IncludesCollection;
+ }
+
+ void delete_IncludesCollection(IncludesCollection *m) {
+ delete m;
+ }
+
+ int call_IncludesCollection_exists(IncludesCollection* m, const char * filePath) {
+ return m->exists(filePath);
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */