Support brace-enclosed environment variable names

This makes it possible to append alpha-numeric characters directly to an
environment variable value, e.g. ${FOO}bar will use "FOO" as the variable name
and keep the "bar" as-is, whereas $FOObar will take "FOObar" as the variable
name.
This commit is contained in:
Chris Robinson 2014-08-19 14:48:13 -07:00
parent 3c13e1e333
commit e3d72ccd15

View File

@ -38,6 +38,7 @@
#include "alMain.h"
#include "compat.h"
#include "bool.h"
typedef struct ConfigEntry {
@ -137,13 +138,21 @@ static char *expdup(const char *str)
}
else
{
bool hasbraces;
char envname[1024];
size_t k = 0;
hasbraces = (*str == '{');
if(hasbraces) str++;
while((isalnum(*str) || *str == '_') && k < sizeof(envname)-1)
envname[k++] = *(str++);
envname[k++] = '\0';
if(hasbraces && *str != '}')
continue;
if(hasbraces) str++;
if((addstr=getenv(envname)) == NULL)
continue;
addstrlen = strlen(addstr);