| 2142 | //----------------------------------------------------------------------------- |
| 2143 | |
| 2144 | bool 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); |
no test coverage detected