| 1970 | //----------------------------------------------------------------------------- |
| 1971 | |
| 1972 | void addPathExpando(const char* pExpandoName, const char* pPath) |
| 1973 | { |
| 1974 | // Sanity! |
| 1975 | AssertFatal(pExpandoName != NULL, "Expando name cannot be NULL."); |
| 1976 | AssertFatal(pPath != NULL, "Expando path cannot be NULL."); |
| 1977 | |
| 1978 | // Fetch expando name. |
| 1979 | StringTableEntry expandoName = StringTable->insert(pExpandoName); |
| 1980 | |
| 1981 | // Fetch the length of the path. |
| 1982 | S32 pathLength = dStrlen(pPath); |
| 1983 | |
| 1984 | char pathBuffer[1024]; |
| 1985 | |
| 1986 | // Sanity! |
| 1987 | if (pathLength == 0 || pathLength >= sizeof(pathBuffer)) |
| 1988 | { |
| 1989 | Con::warnf("Cannot add path expando '%s' with path '%s' as the path is an invalid length.", pExpandoName, pPath); |
| 1990 | return; |
| 1991 | } |
| 1992 | |
| 1993 | // Strip repeat slashes. |
| 1994 | if (!Con::stripRepeatSlashes(pathBuffer, pPath, sizeof(pathBuffer))) |
| 1995 | { |
| 1996 | Con::warnf("Cannot add path expando '%s' with path '%s' as the path is an invalid length.", pExpandoName, pPath); |
| 1997 | return; |
| 1998 | } |
| 1999 | |
| 2000 | // Fetch new path length. |
| 2001 | pathLength = dStrlen(pathBuffer); |
| 2002 | |
| 2003 | // Sanity! |
| 2004 | if (pathLength == 0) |
| 2005 | { |
| 2006 | Con::warnf("Cannot add path expando '%s' with path '%s' as the path is an invalid length.", pExpandoName, pPath); |
| 2007 | return; |
| 2008 | } |
| 2009 | |
| 2010 | // Remove any terminating slash. |
| 2011 | if (pathBuffer[pathLength - 1] == '/') |
| 2012 | pathBuffer[pathLength - 1] = 0; |
| 2013 | |
| 2014 | // Fetch expanded path. |
| 2015 | StringTableEntry expandedPath = StringTable->insert(pathBuffer); |
| 2016 | |
| 2017 | // Info. |
| 2018 | #if defined(TORQUE_DEBUG) |
| 2019 | Con::printf("Adding path expando of '%s' as '%s'.", expandoName, expandedPath); |
| 2020 | #endif |
| 2021 | |
| 2022 | // Find any existing path expando. |
| 2023 | typePathExpandoMap::iterator expandoItr = PathExpandos.find(pExpandoName); |
| 2024 | |
| 2025 | // Does the expando exist? |
| 2026 | if (expandoItr != PathExpandos.end()) |
| 2027 | { |
| 2028 | // Yes, so modify the path. |
| 2029 | expandoItr->value = expandedPath; |