MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / expandOldScriptFilename

Function expandOldScriptFilename

Engine/source/console/scriptFilename.cpp:217–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215//-----------------------------------------------------------------------------
216
217bool expandOldScriptFilename(char *filename, U32 size, const char *src)
218{
219 const StringTableEntry cbName = CodeBlock::getCurrentCodeBlockName();
220 if (!cbName)
221 {
222 dStrcpy(filename, src);
223 return true;
224 }
225
226 const char *slash;
227 if (dStrncmp(src, "~/", 2) == 0)
228 // tilde path means load from current codeblock/mod root
229 slash = dStrchr(cbName, '/');
230 else if (dStrncmp(src, "./", 2) == 0)
231 // dot path means load from current codeblock/mod path
232 slash = dStrrchr(cbName, '/');
233 else if (dStrncmp(src, "^", 1) == 0)
234 {
235 Platform::makeFullPathName(src + 1, filename, size);
236 return true;
237 }
238 else
239 {
240 // otherwise path must be fully specified
241 if (dStrlen(src) > size)
242 {
243 Con::errorf("Buffer overflow attempting to expand filename: %s", src);
244 *filename = 0;
245 return false;
246 }
247 dStrcpy(filename, src);
248 return true;
249 }
250
251 if (slash == NULL)
252 {
253 Con::errorf("Illegal CodeBlock path detected (no mod directory): %s", cbName);
254 *filename = 0;
255 return false;
256 }
257
258 U32 length = slash-cbName;
259 if ((length+dStrlen(src)) > size)
260 {
261 Con::errorf("Buffer overflow attempting to expand filename: %s", src);
262 *filename = 0;
263 return false;
264 }
265
266 dStrncpy(filename, cbName, length);
267 dStrcpy(filename+length, src+1);
268 return true;
269}
270
271//-----------------------------------------------------------------------------
272

Callers 2

expandScriptFilenameFunction · 0.85
scriptFilename.cppFile · 0.85

Calls 7

dStrcpyFunction · 0.85
dStrncmpFunction · 0.85
errorfFunction · 0.85
dStrncpyFunction · 0.85
dStrchrFunction · 0.50
dStrrchrFunction · 0.50
dStrlenFunction · 0.50

Tested by

no test coverage detected