From 89506435fa02ceea57db6e7709e8412d4b749311 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 25 Feb 2014 19:18:59 -0800 Subject: Support environment variables in the hrtf_tables config value --- Alc/hrtf.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file 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'; -- cgit v1.2.3