diff options
author | Chris Robinson <[email protected]> | 2014-02-25 19:18:59 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-02-25 19:18:59 -0800 |
commit | 89506435fa02ceea57db6e7709e8412d4b749311 (patch) | |
tree | 3a3320fd29e448ca2a4d42df7ff0587714e99bdd /Alc/hrtf.c | |
parent | 0ddb9888fe88879f6a8af29321056b692ee221c4 (diff) |
Support environment variables in the hrtf_tables config value
Diffstat (limited to 'Alc/hrtf.c')
-rw-r--r-- | Alc/hrtf.c | 38 |
1 files changed, 34 insertions, 4 deletions
@@ -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'; |