X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=dialogs.c;h=84ac4465ca845a9172cffba14626af16ac916b83;hb=95244a1c40718e9ad8bda9e2df66677e180354d6;hp=2be171f24753ff0ad1acb45e38b6d4a7d156e1a2;hpb=677d32ecebe49075a6889451de4e24c4c5947e44;p=xboard.git diff --git a/dialogs.c b/dialogs.c index 2be171f..84ac446 100644 --- a/dialogs.c +++ b/dialogs.c @@ -66,6 +66,7 @@ extern char *getenv(); int values[MAX_OPTIONS]; ChessProgramState *currentCps; +char manDir[MSG_SIZ] = MANDIR; //----------------------------Generic dialog -------------------------------------------- @@ -545,7 +546,7 @@ Pick (int n) } gameInfo.variant = v; - appData.variant = VariantName(v); + ASSIGN(appData.variant, VariantName(v)); shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */ startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */ @@ -554,8 +555,9 @@ Pick (int n) appData.NrFiles = filesTmp; appData.holdingsSize = sizeTmp; appData.pieceToCharTable = NULL; - appData.pieceNickNames = ""; - appData.colorNickNames = ""; + ASSIGN(appData.pieceNickNames, ""); + ASSIGN(appData.colorNickNames, ""); + ASSIGN(appData.men, ""); PopDown(TransientDlg); Reset(True, True); return; @@ -1605,10 +1607,10 @@ static Option shuffleOptions[] = { static void SetRandom (int n) { - int r = n==2 ? -1 : random() & (1<<30)-1; + int r = n==3 ? -1 : random() & (1<<30)-1; char buf[MSG_SIZ]; snprintf(buf, MSG_SIZ, "%d", r); - SetWidgetText(&shuffleOptions[1], buf, TransientDlg); + SetWidgetText(&shuffleOptions[2], buf, TransientDlg); SetWidgetState(&shuffleOptions[0], True); } @@ -2118,6 +2120,10 @@ void ConsoleWrite(char *message, int count) { if(shellUp[ChatDlg] && chatOptions[CHAT_ICS].type != Skip) { // in Xaw this is a no-op + if(*message == 7) { + message++; // remove bell + if(strcmp(message, "\n")) return; + } AppendColorized(&chatOptions[CHAT_ICS], message, count); SetInsertPos(&chatOptions[CHAT_ICS], 999999); } @@ -2296,7 +2302,7 @@ ErrorPopDown () if (errorExitStatus != -1) ExitEvent(errorExitStatus); } -static int +int ErrorOK (int n) { dialogError = errorUp = False; @@ -2445,12 +2451,22 @@ DisplayTitle (char *text) 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; } @@ -2460,20 +2476,34 @@ GetHelpText (FILE *f, char *name) { char *line, buf[MSG_SIZ], title[MSG_SIZ], text[10000], *p = text, *q = text; int len, cnt = 0; + while(*name == '\n') name++; snprintf(buf, MSG_SIZ, ".B %s", name); len = strlen(buf); - for(len=1; buf[len] == ' ' || buf[len] == '-' || isalpha(buf[len]) || isdigit(buf[len]); len++); + for(len=3; buf[len] && buf[len] != '(' && buf[len] != ':' && buf[len] != '.' && buf[len] != '?' && buf[len] != '\n'; len++); buf[len] = NULLCHAR; 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++; } @@ -2491,19 +2521,46 @@ GetHelpText (FILE *f, char *name) void DisplayHelp (char *name) { - char buf[MSG_SIZ]; + 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(currentCps) snprintf(buf, MSG_SIZ, "/usr/local/share/man/man6/%s.6", currentCps->program); - else snprintf(buf, MSG_SIZ, "%s/man6/xboard.6", MANDIR); - f = fopen(buf, "r"); - if(!f && currentCps) { // engine manual could be in two places - snprintf(buf, MSG_SIZ, "/usr/share/man/man6/%s.6", currentCps->program); - f= fopen(buf, "r"); + 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) { + char *msg = "Right-clicking menu item or dialog text pops up help on it"; + ASSIGN(appData.suppress, msg); + 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); - } + } else if(currentCps) DisplayNote("No manual is installed for this engine"); } #define PAUSE_BUTTON "P"