From: H.G. Muller Date: Sat, 14 Aug 2010 12:01:44 +0000 (+0200) Subject: Improved patch for expansion of WB settings-file name X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=0e26c6ad0a2958900703e77da3fdbe7fabfa620c;p=xboard.git Improved patch for expansion of WB settings-file name The expansion of environment variables now allows multiple environment variables in the path name. Tested on %HOMEDRIVE%%HOMEPATH%\winboard.ini and %APPDATA%\winboard.ini. --- diff --git a/winboard/winboard.c b/winboard/winboard.c index 9cc79da..8c47c62 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -1222,13 +1222,18 @@ PrintCommPortSettings(FILE *f, char *name) int MySearchPath(char *installDir, char *name, char *fullname) { - char *dummy, buf[MSG_SIZ]; - if(name[0] == '%' && strchr(name+1, '%')) { // [HGM] recognize %*% as environment variable - strcpy(buf, name+1); - *strchr(buf, '%') = 0; - installDir = getenv(buf); - sprintf(fullname, "%s\\%s", installDir, strchr(name+1, '%')+1); - return strlen(fullname); + char *dummy, buf[MSG_SIZ], *p = name, *q; + if(name[0]== '%') { + fullname[0] = 0; // [HGM] first expand any environment variables in the given name + while(*p == '%' && (q = strchr(p+1, '%'))) { // [HGM] recognize %*% as environment variable + strcpy(buf, p+1); + *strchr(buf, '%') = 0; + strcat(fullname, getenv(buf)); + p = q+1; while(*p == '\\') { strcat(fullname, "\\"); p++; } + } + strcat(fullname, p); // after environment variables (if any), take the remainder of the given name + if(appData.debugMode) fprintf(debugFP, "name = '%s', expanded name = '%s'\n", name, fullname); + return (int) strlen(fullname); } return (int) SearchPath(installDir, name, NULL, MSG_SIZ, fullname, &dummy); }