From: H.G.Muller Date: Thu, 17 Mar 2016 10:32:02 +0000 (+0100) Subject: Also buffer engine man page X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=c118cf9cee0e6d5a3f78c8b409100948a3a22a16;p=xboard.git Also buffer engine man page The path to the engine man file, and possibly its unzipped text, are now also buffered, together with the name of the engine they are for, so that they can be re-used when the engine has not changed. --- diff --git a/dialogs.c b/dialogs.c index c939ea5..30b2ad5 100644 --- a/dialogs.c +++ b/dialogs.c @@ -2502,8 +2502,8 @@ GetHelpText (FILE *f, char *name) void DisplayHelp (char *name) { - static char *xboardMan, *manText[2]; - char buf[MSG_SIZ], tidy[MSG_SIZ], *eng; + static char *xboardMan, *manText[2], tidy[MSG_SIZ], engMan[MSG_SIZ]; + char buf[MSG_SIZ], *eng; int n = 0; FILE *f; if(!xboardMan) { @@ -2511,13 +2511,17 @@ DisplayHelp (char *name) if(xboardMan) xboardMan[strlen(xboardMan)-1] = NULLCHAR; // strip off traling linefeed } if(currentCps) { // for engine options we have to look in engine manual - snprintf(tidy, MSG_SIZ, "man -w "); - TidyProgramName(currentCps == &first ? appData.firstChessProgram : appData.secondChessProgram, "localhost", tidy+7); - eng = BufferCommandOutput(tidy, MSG_SIZ); - safeStrCpy(buf, eng, strlen(eng)); - FREE(eng); - n = 1; - } else snprintf(buf, MSG_SIZ, "%s", xboardMan); + snprintf(buf, MSG_SIZ, "man -w "); // get (tidied) engine name in buf + TidyProgramName(currentCps == &first ? appData.firstChessProgram : appData.secondChessProgram, "localhost", buf+7); + if(strcmp(buf, tidy)) { // is different engine from last time + FREE(manText[1]); manText[1] = NULL; // so any currently held text is worthless + safeStrCpy(tidy, buf, MSG_SIZ); // remember current engine + eng = BufferCommandOutput(tidy, MSG_SIZ); // obtain path to its man file + safeStrCpy(engMan, eng, strlen(eng)); // and remember that too + FREE(eng); + } + safeStrCpy(buf, engMan, MSG_SIZ); n = 1; // use engine man + } else snprintf(buf, MSG_SIZ, "%s", xboardMan); // use xboard man f = fopen(buf, "r"); if(f) { if(strstr(buf, ".gz")) { // man file is gzipped @@ -2525,11 +2529,10 @@ DisplayHelp (char *name) snprintf(tidy, MSG_SIZ, "gunzip -c %s", buf); manText[n] = BufferCommandOutput(tidy, 250000); // store unzipped in buffer } - textPtr = manText[n]; - } else textPtr = NULL; + textPtr = manText[n];// use buffered unzipped text + } else textPtr = NULL; // use plaintext man file directly GetHelpText(f, name); fclose(f); - if(currentCps) free(manText[1]), manText[1] = NULL; // never reuse engine text } }