aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-02-25 19:18:59 -0800
committerChris Robinson <[email protected]>2014-02-25 19:18:59 -0800
commit89506435fa02ceea57db6e7709e8412d4b749311 (patch)
tree3a3320fd29e448ca2a4d42df7ff0587714e99bdd
parent0ddb9888fe88879f6a8af29321056b692ee221c4 (diff)
Support environment variables in the hrtf_tables config value
-rw-r--r--Alc/hrtf.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index d1448d5c..d326191a 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -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';