Skip to content

Commit 9447570

Browse files
committed
Linux: move filecase to TCFoundation
1 parent ca0024c commit 9447570

File tree

4 files changed

+6
-126
lines changed

4 files changed

+6
-126
lines changed

BuildPartsCatalog/PartsCatalog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <LDLoader/LDLError.h>
2222

2323
#if !defined (WIN32) && !defined (__APPLE__)
24-
#include "filecase.h"
24+
#include <TCFoundation/filecase.h>
2525
#endif
2626

2727
namespace fs = std::filesystem;

OSMesa/ldview.cpp

Lines changed: 1 addition & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <TRE/TREMainModel.h>
2727
#include "StudLogo.h"
2828
#include "LDViewMessages.h"
29+
#include <TCFoundation/filecase.h>
2930

3031
typedef std::map<std::string, std::string> StringMap;
3132

@@ -138,129 +139,6 @@ void *setupContext(OSMesaContext &ctx)
138139
}
139140
#endif
140141

141-
bool dirExists(const std::string &path)
142-
{
143-
struct stat buf;
144-
if (stat(path.c_str(), &buf) != 0)
145-
{
146-
return false;
147-
}
148-
return S_ISDIR(buf.st_mode);
149-
}
150-
151-
bool fileOrDirExists(const std::string &path)
152-
{
153-
struct stat buf;
154-
if (stat(path.c_str(), &buf) != 0)
155-
{
156-
return false;
157-
}
158-
return S_ISREG(buf.st_mode) || S_ISDIR(buf.st_mode);
159-
}
160-
161-
bool findDirEntry(std::string &path)
162-
{
163-
size_t lastSlash = path.rfind('/');
164-
if (lastSlash >= path.size())
165-
{
166-
return false;
167-
}
168-
std::string dirName = path.substr(0, lastSlash);
169-
std::string lowerFilename = lowerCaseString(path.substr(lastSlash + 1));
170-
DIR *dir = opendir(dirName.c_str());
171-
if (dir == NULL)
172-
{
173-
return false;
174-
}
175-
bool found = false;
176-
while (!found)
177-
{
178-
struct dirent *entry = readdir(dir);
179-
if (entry == NULL)
180-
{
181-
break;
182-
}
183-
std::string name = lowerCaseString(entry->d_name);
184-
if (name == lowerFilename)
185-
{
186-
path = dirName + '/' + entry->d_name;
187-
found = true;
188-
}
189-
}
190-
closedir(dir);
191-
return found;
192-
}
193-
194-
bool fileCaseCallback(char *filename)
195-
{
196-
StringMap s_pathMap;
197-
size_t count;
198-
char **components = componentsSeparatedByString(filename, "/", count);
199-
std::string lowerFilename = lowerCaseString(filename);
200-
201-
StringMap::iterator it = s_pathMap.find(lowerFilename);
202-
if (it != s_pathMap.end())
203-
{
204-
strcpy(filename, it->second.c_str());
205-
return true;
206-
}
207-
if (count > 1)
208-
{
209-
bool ok = true;
210-
std::string builtPath = "/";
211-
for (size_t i = 1; i + 1 < count && ok; ++i)
212-
{
213-
builtPath += components[i];
214-
215-
it = s_pathMap.find(builtPath);
216-
if (it != s_pathMap.end())
217-
{
218-
// Do nothing
219-
}
220-
else if (dirExists(builtPath))
221-
{
222-
s_pathMap[lowerCaseString(builtPath)] = builtPath;
223-
}
224-
else if (findDirEntry(builtPath))
225-
{
226-
s_pathMap[lowerCaseString(builtPath)] = builtPath;
227-
if (!dirExists(builtPath))
228-
{
229-
ok = false;
230-
}
231-
}
232-
else
233-
{
234-
ok = false;
235-
}
236-
if (ok)
237-
{
238-
builtPath += '/';
239-
}
240-
}
241-
if (ok)
242-
{
243-
builtPath += components[count - 1];
244-
if (findDirEntry(builtPath))
245-
{
246-
s_pathMap[lowerCaseString(builtPath)] = builtPath;
247-
ok = fileOrDirExists(builtPath);
248-
}
249-
else
250-
{
251-
ok = false;
252-
}
253-
}
254-
if (ok)
255-
{
256-
strcpy(filename, builtPath.c_str());
257-
}
258-
deleteStringArray(components, count);
259-
return ok;
260-
}
261-
return false;
262-
}
263-
264142
#ifdef EGL
265143
void assertEGLError(const std::string& msg) {
266144
EGLint error = eglGetError();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "filecase.h"
2-
2+
#if !defined (WIN32) && !defined (__APPLE__)
33
typedef std::map<std::string, std::string> StringMap;
44

55
bool dirExists(const std::string &path)
@@ -124,4 +124,4 @@ bool fileCaseCallback(char *filename)
124124
}
125125
return false;
126126
}
127-
127+
#endif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#ifndef __FILECASE_H__
22
#define __FILECASE_H__
3+
#if !defined (WIN32) && !defined (__APPLE__)
34
#include <stdio.h>
45
#include <dirent.h>
56
#include <sys/types.h>
@@ -11,3 +12,4 @@
1112

1213
extern bool fileCaseCallback(char *filename);
1314
#endif
15+
#endif

0 commit comments

Comments
 (0)