Support environment variables in the hrtf_tables config value
This commit is contained in:
+34
-4
@@ -787,22 +787,53 @@ static struct Hrtf *LoadHrtf(ALuint deviceRate)
|
||||
{
|
||||
struct Hrtf *Hrtf = NULL;
|
||||
char fname[PATH_MAX];
|
||||
const char *next;
|
||||
ALchar magic[8];
|
||||
ALuint i;
|
||||
FILE *f;
|
||||
|
||||
i = 0;
|
||||
while(isspace(*fnamelist) || *fnamelist == ',')
|
||||
fnamelist++;
|
||||
i = 0;
|
||||
while(*fnamelist != '\0' && *fnamelist != ',')
|
||||
next = fnamelist;
|
||||
while(*(fnamelist=next) != '\0' && *fnamelist != ',')
|
||||
{
|
||||
const char *next = strpbrk(fnamelist, "%,");
|
||||
next = strpbrk(fnamelist, "%,$");
|
||||
while(fnamelist != next && *fnamelist && i < sizeof(fname))
|
||||
fname[i++] = *(fnamelist++);
|
||||
|
||||
if(!next || *next == ',')
|
||||
break;
|
||||
|
||||
if(*next == '$')
|
||||
{
|
||||
next++;
|
||||
if(*next == '$')
|
||||
{
|
||||
/* '$$' becomes a single '$'. */
|
||||
if(i < sizeof(fname))
|
||||
fname[i++] = '$';
|
||||
next++;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *str;
|
||||
char envname[1024];
|
||||
size_t k = 0;
|
||||
|
||||
while((isalnum(*next) || *next == '_') && k < sizeof(envname)-1)
|
||||
envname[k++] = *(next++);
|
||||
envname[k++] = '\0';
|
||||
|
||||
if((str=getenv(envname)) != NULL)
|
||||
{
|
||||
int wrote = snprintf(&fname[i], sizeof(fname)-i, "%s", str);
|
||||
i += minu(wrote, sizeof(fname)-i);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* *next == '%' */
|
||||
next++;
|
||||
if(*next == 'r')
|
||||
@@ -819,7 +850,6 @@ static struct Hrtf *LoadHrtf(ALuint deviceRate)
|
||||
}
|
||||
else
|
||||
ERR("Invalid marker '%%%c'\n", *next);
|
||||
fnamelist = next;
|
||||
}
|
||||
i = minu(i, sizeof(fname)-1);
|
||||
fname[i] = '\0';
|
||||
|
||||
Reference in New Issue
Block a user