MCPcopy Create free account
hub / github.com/GarageGames/Torque2D / MungeCase

Function MungeCase

engine/source/platformEmscripten/EmscriptenFileio.cpp:189–253  ·  view source on GitHub ↗

------------------------------------------------------------------------------ munge the case of the specified pathName. This means try to find the actual filename in with case-insensitive matching on the specified pathName, and store the actual found name.

Source from the content-addressed store, hash-verified

187// filename in with case-insensitive matching on the specified pathName, and
188// store the actual found name.
189static void MungeCase(char* pathName, S32 pathNameSize)
190{
191 char tempBuf[MaxPath];
192 dStrncpy(tempBuf, pathName, pathNameSize);
193
194 AssertFatal(pathName[0] == '/', "PATH must be absolute");
195
196 struct stat filestat;
197 const int MaxPathEl = 200;
198 char *currChar = pathName;
199 char testPath[MaxPath];
200 char pathEl[MaxPathEl];
201 bool done = false;
202
203 dStrncpy(tempBuf, "/", MaxPath);
204 currChar++;
205
206 while (!done)
207 {
208 char* termChar = dStrchr(currChar, '/');
209 if (termChar == NULL)
210 termChar = dStrchr(currChar, '\0');
211 AssertFatal(termChar, "Can't find / or NULL terminator");
212
213 S32 pathElLen = (termChar - currChar);
214 dStrncpy(pathEl, currChar, pathElLen);
215 pathEl[pathElLen] = '\0';
216 dStrncpy(testPath, tempBuf, MaxPath);
217 dStrcat(testPath, pathEl);
218 if (stat(testPath, &filestat) != -1)
219 {
220 dStrncpy(tempBuf, testPath, MaxPath);
221 }
222 else
223 {
224 DIR *dir = opendir(tempBuf);
225 struct dirent* ent;
226 bool foundMatch = false;
227 while (dir != NULL && (ent = readdir(dir)) != NULL)
228 {
229 if (dStricmp(pathEl, ent->d_name) == 0)
230 {
231 foundMatch = true;
232 dStrcat(tempBuf, ent->d_name);
233 break;
234 }
235 }
236
237 if (!foundMatch)
238 dStrncpy(tempBuf, testPath, MaxPath);
239 if (dir)
240 closedir(dir);
241 }
242 if (*termChar == '/')
243 {
244 dStrcat(tempBuf, "/");
245 termChar++;
246 currChar = termChar;

Callers 1

MungePathFunction · 0.70

Calls 5

dStrncpyFunction · 0.70
dStrchrFunction · 0.70
dStrcatFunction · 0.70
statClass · 0.70
dStricmpFunction · 0.70

Tested by

no test coverage detected