int values[MAX_OPTIONS];
ChessProgramState *currentCps;
+char dataDir[MSG_SIZ] = DATADIR, manDir[MSG_SIZ] = MANDIR;
//----------------------------Generic dialog --------------------------------------------
if(tagsText) free(tagsText); tagsText = strdup(text);
tagsOptions[0].name = msg;
MarkMenu("View.Tags", TagsDlg);
- GenericPopUp(tagsOptions, title, TagsDlg, BoardWindow, NONMODAL, appData.topLevel);
+ GenericPopUp(tagsOptions + (msg == NULL), title, TagsDlg, BoardWindow, NONMODAL, appData.topLevel);
}
void
if (errorExitStatus != -1) ExitEvent(errorExitStatus);
}
-static int
+int
ErrorOK (int n)
{
dialogError = errorUp = False;
SetWindowTitle(text, title, icon);
}
+char *textPtr;
+char *texEscapes[] = { "s-1", "s0", "&", "*(L", "*(R", NULL };
+
+int
+GetNext(FILE *f)
+{
+ if(textPtr) return *textPtr ? *textPtr++ : EOF;
+ return fgetc(f);
+}
+
static char *
ReadLine (FILE *f)
{
static char buf[MSG_SIZ];
int i = 0, c;
- while((c = fgetc(f)) != '\n') { if(c == EOF) return NULL; buf[i++] = c; }
+ while((c = GetNext(f)) != '\n') { if(c == EOF) return NULL; buf[i++] = c; }
buf[i] = NULLCHAR;
return buf;
}
while(buf[--len] == ' ') buf[len] = NULLCHAR;
snprintf(title, MSG_SIZ, "Help on '%s'", buf+3);
while((line = ReadLine(f))) {
- if(!strncmp(line, buf, len) || !strncmp(line, ".SS ", 4) && !strncmp(line+4, buf+3, len-3)) {
- while((line = ReadLine(f)) && (cnt == 0 || strncmp(line, ".B ", 3) && strncmp(line, ".SS ", 4))) {
+ if(!strncmp(line, buf, len) || !strncmp(line, ".SS ", 4) && !strncmp(line+4, buf+3, len-3)
+ || !strncmp(line, ".IX Item \"", 10) && !strncmp(line+10, buf+3, len-3)) {
+ while((line = ReadLine(f)) && (cnt == 0 || strncmp(line, ".B ", 3) && strncmp(line, ".SS ", 4) && strncmp(line, ".IX ", 4))) {
if(!*line) { *p++ = '\n'; *p++ = '\n'; q = p; continue; }
if(*line == '.') continue;
*p++ = ' '; cnt++;
while(*line) {
if(*line < ' ') { line++; continue;}
+ if(*line == '\\') {
+ char **esc;
+ line++;
+ for(esc = texEscapes; *esc; esc++) {
+ len = strlen(*esc);
+ if(!strncmp(*esc, line, len)) {
+ line += len;
+ break;
+ }
+ }
+ continue;
+ }
if(*line == ' ' && p - q > 80) *line = '\n', q = p;
*p++ = *line++;
}
void
DisplayHelp (char *name)
{
- char *manFile = MANDIR "/man6/xboard.6";
- FILE *f = fopen(manFile, "r");
+ static char *xboardMan, *manText[2], tidy[MSG_SIZ], engMan[MSG_SIZ];
+ char buf[MSG_SIZ], adapter[MSG_SIZ], *eng;
+ int n = 0;
+ FILE *f;
+ if(!xboardMan) {
+ xboardMan = BufferCommandOutput("man -w xboard", MSG_SIZ); // obtain path to XBoard's man file
+ if(xboardMan) xboardMan[strlen(xboardMan)-1] = NULLCHAR; // strip off traling linefeed
+ }
+ if(currentCps) { // for engine options we have to look in engine manual
+ snprintf(buf, MSG_SIZ, "man -w "); // get (tidied) engine name in buf
+ TidyProgramName(currentCps->program, "localhost", adapter); // name of binary we are actually running
+ TidyProgramName(currentCps == &first ? appData.firstChessProgram : appData.secondChessProgram, "localhost", buf+7);
+ if(strcmp(buf+7, adapter) && StrCaseStr(name, adapter) == name) { // option starts with name of apparent proxy for engine
+ safeStrCpy(buf+7, adapter, MSG_SIZ-7); // use adapter manual
+ name += strlen(adapter); // strip adapter name of option
+ while(*name == ' ') name++;
+ }
+ 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
+ if(!manText[n]) { // unzipped text not buffered yet
+ snprintf(tidy, MSG_SIZ, "gunzip -c %s", buf);
+ manText[n] = BufferCommandOutput(tidy, 250000); // store unzipped in buffer
+ }
+ textPtr = manText[n];// use buffered unzipped text
+ } else textPtr = NULL; // use plaintext man file directly
GetHelpText(f, name);
fclose(f);
}