MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / expandPath

Function expandPath

Engine/source/console/console.cpp:2144–2304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2142//-----------------------------------------------------------------------------
2143
2144bool expandPath(char* pDstPath, U32 size, const char* pSrcPath, const char* pWorkingDirectoryHint, const bool ensureTrailingSlash)
2145{
2146 char pathBuffer[2048];
2147 const char* pSrc = pSrcPath;
2148 char* pSlash;
2149
2150 // Fetch leading character.
2151 const char leadingToken = *pSrc;
2152
2153 // Fetch following token.
2154 const char followingToken = leadingToken != 0 ? pSrc[1] : 0;
2155
2156 // Expando.
2157 if (leadingToken == '^')
2158 {
2159 // Initial prefix search.
2160 const char* pPrefixSrc = pSrc + 1;
2161 char* pPrefixDst = pathBuffer;
2162
2163 // Search for end of expando.
2164 while (*pPrefixSrc != '/' && *pPrefixSrc != 0)
2165 {
2166 // Copy prefix character.
2167 *pPrefixDst++ = *pPrefixSrc++;
2168 }
2169
2170 // Yes, so terminate the expando string.
2171 *pPrefixDst = 0;
2172
2173 // Fetch the expando path.
2174 StringTableEntry expandoPath = getPathExpando(pathBuffer);
2175
2176 // Does the expando exist?
2177 if (expandoPath == NULL)
2178 {
2179 // No, so error.
2180 Con::errorf("expandPath() : Could not find path expando '%s' for path '%s'.", pathBuffer, pSrcPath);
2181
2182 // Are we ensuring the trailing slash?
2183 if (ensureTrailingSlash)
2184 {
2185 // Yes, so ensure it.
2186 Con::ensureTrailingSlash(pDstPath, pSrcPath, size);
2187 }
2188 else
2189 {
2190 // No, so just use the source path.
2191 dStrcpy(pDstPath, pSrcPath, size);
2192 }
2193
2194 return false;
2195 }
2196
2197 // Skip the expando and the following slash.
2198 pSrc += dStrlen(pathBuffer) + 1;
2199
2200 // Format the output path.
2201 dSprintf(pathBuffer, sizeof(pathBuffer), "%s/%s", expandoPath, pSrc);

Callers 10

isBasePathFunction · 0.85
copyModuleMethod · 0.85
canMergeModulesMethod · 0.85
mergeModulesMethod · 0.85
expandAssetFilePathMethod · 0.85
loadAssetTagsMethod · 0.85
saveAssetTagsMethod · 0.85
visitMethod · 0.85
deleteDirectoryMethod · 0.85

Calls 10

getPathExpandoFunction · 0.85
ensureTrailingSlashFunction · 0.85
dStrcpyFunction · 0.85
dSprintfFunction · 0.85
stripRepeatSlashesFunction · 0.85
dStrncpyFunction · 0.85
dStrncatFunction · 0.85
errorfFunction · 0.70
dStrlenFunction · 0.50
dStrrchrFunction · 0.50

Tested by

no test coverage detected