- Moved ExpandEnvVars() from d_main.cpp to cmdlib.cpp.
- AutoExec paths now support the same variable expansion as the search paths. Additionally, on Windows, the default autoexec path is now relative to $PROGDIR, rather than using a fixed path to the executable's current directory. - All usable Autoload and AutoExec sections are now created at the top of the config file along with some brief explanatory notes so they are readily visible to anyone who wants to edit them. SVN r1307 (trunk)
This commit is contained in:
parent
fb75c46806
commit
ef3b57fb8f
8 changed files with 466 additions and 101 deletions
|
|
@ -469,3 +469,68 @@ int strbin (char *str)
|
|||
*str = 0;
|
||||
return str - start;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// ExpandEnvVars
|
||||
//
|
||||
// Expands environment variable references in a string. Intended primarily
|
||||
// for use with IWAD search paths in config files.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FString ExpandEnvVars(const char *searchpathstring)
|
||||
{
|
||||
static const char envvarnamechars[] =
|
||||
"01234567890"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"_"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
if (searchpathstring == NULL)
|
||||
return FString("");
|
||||
|
||||
const char *dollar = strchr(searchpathstring, '$');
|
||||
if (dollar == NULL)
|
||||
{
|
||||
return FString(searchpathstring);
|
||||
}
|
||||
|
||||
const char *nextchars = searchpathstring;
|
||||
FString out = FString(searchpathstring, dollar - searchpathstring);
|
||||
while ( (dollar != NULL) && (*nextchars != 0) )
|
||||
{
|
||||
size_t length = strspn(dollar + 1, envvarnamechars);
|
||||
if (length != 0)
|
||||
{
|
||||
FString varname = FString(dollar + 1, length);
|
||||
if (stricmp(varname, "progdir") == 0)
|
||||
{
|
||||
out += progdir;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *varvalue = getenv(varname);
|
||||
if ( (varvalue != NULL) && (strlen(varvalue) != 0) )
|
||||
{
|
||||
out += varvalue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
out += '$';
|
||||
}
|
||||
nextchars = dollar + length + 1;
|
||||
dollar = strchr(nextchars, '$');
|
||||
if (dollar != NULL)
|
||||
{
|
||||
out += FString(nextchars, dollar - nextchars);
|
||||
}
|
||||
}
|
||||
if (*nextchars != 0)
|
||||
{
|
||||
out += nextchars;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue