X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xboard.c;h=033c53bc7601dc1497effd155e39302298d9fb1a;hb=c69beebf3decbe67eb92beab56bbc34c41c39831;hp=452255eb9b456ef011104ddd8606652c73b58024;hpb=4befbb88fd4688d1613e32b14f5ac3933cb56657;p=xboard.git diff --git a/xboard.c b/xboard.c index 452255e..033c53b 100644 --- a/xboard.c +++ b/xboard.c @@ -142,6 +142,10 @@ extern char *getenv(); # endif #endif +#if ENABLE_NLS +#include +#endif + #include #include #include @@ -243,6 +247,7 @@ RETSIGTYPE CmailSigHandler P((int sig)); RETSIGTYPE IntSigHandler P((int sig)); RETSIGTYPE TermSizeSigHandler P((int sig)); void CreateGCs P((int redo)); +void CreateAnyPieces P((void)); void CreateXIMPieces P((void)); void CreateXPMPieces P((void)); void CreateXPMBoard P((char *s, int n)); @@ -250,7 +255,12 @@ void CreatePieces P((void)); void CreatePieceMenus P((void)); Widget CreateMenuBar P((Menu *mb)); Widget CreateButtonBar P ((MenuItem *mi)); +#if ENABLE_NLS +char *InsertPxlSize P((char *pattern, int targetPxlSize)); +XFontSet CreateFontSet P((char *base_fnt_lst)); +#else char *FindFont P((char *pattern, int targetPxlSize)); +#endif void PieceMenuPopup P((Widget w, XEvent *event, String *params, Cardinal *num_params)); static void PieceMenuSelect P((Widget w, ChessSquare piece, caddr_t junk)); @@ -453,6 +463,7 @@ void TimeControlProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)) void OptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void NewVariantProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void IcsTextProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void LoadEngineProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void FirstSettingsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void SecondSettingsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void GameListOptionsPopUp P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); @@ -461,9 +472,9 @@ void SoundOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms) void BoardOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void LoadOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void SaveOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void EditBookProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void SelectMove P((Widget w, XEvent * event, String * params, Cardinal * nParams)); void GameListOptionsPopDown P(()); -void ShufflePopDown P(()); -void TimeControlPopDown P(()); void GenericPopDown P(()); void update_ics_width P(()); int get_term_width P(()); @@ -496,8 +507,14 @@ int hOffset; // [HGM] dual XSegment secondSegments[BOARD_RANKS + BOARD_FILES + 2]; XSegment gridSegments[BOARD_RANKS + BOARD_FILES + 2]; XSegment jailGridSegments[BOARD_RANKS + BOARD_FILES + 6]; -Font clockFontID, coordFontID, countFontID; -XFontStruct *clockFontStruct, *coordFontStruct, *countFontStruct; +#if ENABLE_NLS +XFontSet fontSet, clockFontSet; +#else +Font clockFontID; +XFontStruct *clockFontStruct; +#endif +Font coordFontID, countFontID; +XFontStruct *coordFontStruct, *countFontStruct; XtAppContext appContext; char *layoutName; char *oldICSInteractionTitle; @@ -630,6 +647,7 @@ MenuItem editMenu[] = { {N_("Edit Position Ctrl+Shift+E"), "Edit Position", EditPositionProc}, {N_("Edit Tags"), "Edit Tags", EditTagsProc}, {N_("Edit Comment"), "Edit Comment", EditCommentProc}, + {N_("Edit Book"), "Edit Book", EditBookProc}, {"----", NULL, NothingProc}, {N_("Revert Home"), "Revert", RevertProc}, {N_("Annotate"), "Annotate", AnnotateProc}, @@ -698,6 +716,8 @@ MenuItem actionMenu[] = { }; MenuItem engineMenu[] = { + {N_("Load New Engine ..."), "Load Engine", LoadEngineProc}, + {"----", NULL, NothingProc}, {N_("Engine #1 Settings ..."), "Engine #1 Settings", FirstSettingsProc}, {N_("Engine #2 Settings ..."), "Engine #2 Settings", SecondSettingsProc}, {"----", NULL, NothingProc}, @@ -797,7 +817,7 @@ String pieceMenuStrings[2][PIECE_MENU_SIZE] = { N_("Archbishop"), N_("Chancellor"), "----", N_("Promote"), N_("Demote"), N_("Empty square"), N_("Clear board") } }; -/* must be in same order as PieceMenuStrings! */ +/* must be in same order as pieceMenuStrings! */ ChessSquare pieceMenuTranslation[2][PIECE_MENU_SIZE] = { { WhitePlay, (ChessSquare) 0, WhitePawn, WhiteKnight, WhiteBishop, WhiteRook, WhiteQueen, WhiteKing, (ChessSquare) 0, WhiteAlfil, @@ -813,7 +833,7 @@ ChessSquare pieceMenuTranslation[2][PIECE_MENU_SIZE] = { String dropMenuStrings[DROP_MENU_SIZE] = { "----", N_("Pawn"), N_("Knight"), N_("Bishop"), N_("Rook"), N_("Queen") }; -/* must be in same order as PieceMenuStrings! */ +/* must be in same order as dropMenuStrings! */ ChessSquare dropMenuTranslation[DROP_MENU_SIZE] = { (ChessSquare) 0, WhitePawn, WhiteKnight, WhiteBishop, WhiteRook, WhiteQueen @@ -938,6 +958,7 @@ XtActionsRec boardActions[] = { { "ShowGameListProc", ShowGameListProc }, { "ShowMoveListProc", HistoryShowProc}, { "EditTagsProc", EditCommentProc }, + { "EditBookProc", EditBookProc }, { "EditCommentProc", EditCommentProc }, { "IcsInputBoxProc", IcsInputBoxProc }, { "PauseProc", PauseProc }, @@ -1016,13 +1037,11 @@ XtActionsRec boardActions[] = { { "GameListPopDown", (XtActionProc) GameListPopDown }, { "GameListOptionsPopDown", (XtActionProc) GameListOptionsPopDown }, { "PromotionPopDown", (XtActionProc) PromotionPopDown }, - { "HistoryPopDown", (XtActionProc) HistoryPopDown }, { "EngineOutputPopDown", (XtActionProc) EngineOutputPopDown }, { "EvalGraphPopDown", (XtActionProc) EvalGraphPopDown }, - { "ShufflePopDown", (XtActionProc) ShufflePopDown }, - { "TimeControlPopDown", (XtActionProc) TimeControlPopDown }, { "GenericPopDown", (XtActionProc) GenericPopDown }, { "CopyMemoProc", (XtActionProc) CopyMemoProc }, + { "SelectMove", (XtActionProc) SelectMove }, }; char globalTranslations[] = @@ -1032,6 +1051,8 @@ char globalTranslations[] = :Ctrlo: LoadGameProc() \n \ :MetaNext: LoadNextGameProc() \n \ :MetaPrior: LoadPrevGameProc() \n \ + :CtrlDown: LoadSelectedProc(3) \n \ + :CtrlUp: LoadSelectedProc(-3) \n \ :Ctrls: SaveGameProc() \n \ :Ctrlc: CopyGameProc() \n \ :Ctrlv: PasteGameProc() \n \ @@ -1068,6 +1089,8 @@ char globalTranslations[] = :MetaRight: ForwardProc() \n \ :MetaHome: ToStartProc() \n \ :MetaLeft: BackwardProc() \n \ + :Left: BackwardProc() \n \ + :Right: ForwardProc() \n \ :Home: RevertProc() \n \ :End: TruncateGameProc() \n \ :Ctrlm: MoveNowProc() \n \ @@ -1111,8 +1134,12 @@ char boardTranslations[] = Any: XawPositionSimpleMenu(menuB) XawPositionSimpleMenu(menuD) \ PieceMenuPopup(menuB) \n"; -char whiteTranslations[] = ": WhiteClock()\n"; -char blackTranslations[] = ": BlackClock()\n"; +char whiteTranslations[] = + "Shift: WhiteClock(1)\n \ + : WhiteClock(0)\n"; +char blackTranslations[] = + "Shift: BlackClock(1)\n \ + : BlackClock(0)\n"; char ICSInputTranslations[] = "Up: UpKeyProc() \n " @@ -1262,8 +1289,8 @@ xpm_closest_to(dirname, size, ext) fprintf(stderr, _("\ Warning: No DIR structure found on this system --\n\ Unable to autosize for XPM/XIM pieces.\n\ - Please report this error to frankm@hiwaay.net.\n\ - Include system type & operating system in message.\n")); + Please report this error to %s.\n\ + Include system type & operating system in message.\n"), PACKAGE_BUGREPORT);); return size; } #endif /* HAVE_DIR_STRUCT */ @@ -1410,7 +1437,7 @@ colorVariable[] = { // [HGM] font: keep a font for each square size, even non-stndard ones #define NUM_SIZES 18 #define MAX_SIZE 130 -Boolean fontSet[NUM_FONTS], fontValid[NUM_FONTS][MAX_SIZE]; +Boolean fontIsSet[NUM_FONTS], fontValid[NUM_FONTS][MAX_SIZE]; char *fontTable[NUM_FONTS][MAX_SIZE]; void @@ -1439,7 +1466,7 @@ ParseFont(char *name, int number) default: return; } - fontSet[number] = True; // [HGM] font: indicate a font was specified (not from settings file) + fontIsSet[number] = True; // [HGM] font: indicate a font was specified (not from settings file) } void @@ -1509,7 +1536,7 @@ SaveFontArg(FILE *f, ArgDescriptor *ad) break; } for(i=0; iargName, i, fontTable[n][i]); + fprintf(f, OPTCHAR "%s" SEPCHAR "\"size%d:%s\"\n", ad->argName, i, fontTable[n][i]); } void @@ -1570,8 +1597,8 @@ GetWindowCoords() { // wrapper to shield use of window handles from back-end (make addressible by number?) // In XBoard this will have to wait until awareness of window parameters is implemented GetActualPlacement(shellWidget, &wpMain); - if(EngineOutputIsUp()) GetActualPlacement(engineOutputShell, &wpEngineOutput); else - if(MoveHistoryIsUp()) GetActualPlacement(historyShell, &wpMoveHistory); + if(EngineOutputIsUp()) GetActualPlacement(engineOutputShell, &wpEngineOutput); + if(MoveHistoryIsUp()) GetActualPlacement(shells[7], &wpMoveHistory); if(EvalGraphIsUp()) GetActualPlacement(evalGraphShell, &wpEvalGraph); if(GameListIsUp()) GetActualPlacement(gameListShell, &wpGameList); if(shellUp[1]) GetActualPlacement(shells[1], &wpComment); @@ -1629,7 +1656,7 @@ ConvertToLine(int argc, char **argv) line[0] = NULLCHAR; for(i=1; i BOARD_FILES || appData.NrRanks > BOARD_RANKS ) @@ -2062,11 +2117,11 @@ main(argc, argv) tinyLayout = szd->tinyLayout; // [HGM] font: use defaults from settings file if available and not overruled } - if(!fontSet[CLOCK_FONT] && fontValid[CLOCK_FONT][squareSize]) + if(!fontIsSet[CLOCK_FONT] && fontValid[CLOCK_FONT][squareSize]) appData.clockFont = fontTable[CLOCK_FONT][squareSize]; - if(!fontSet[MESSAGE_FONT] && fontValid[MESSAGE_FONT][squareSize]) + if(!fontIsSet[MESSAGE_FONT] && fontValid[MESSAGE_FONT][squareSize]) appData.font = fontTable[MESSAGE_FONT][squareSize]; - if(!fontSet[COORD_FONT] && fontValid[COORD_FONT][squareSize]) + if(!fontIsSet[COORD_FONT] && fontValid[COORD_FONT][squareSize]) appData.coordFont = fontTable[COORD_FONT][squareSize]; /* Now, using squareSize as a hint, find a good XPM/XIM set size */ @@ -2112,19 +2167,42 @@ XBoard square size (hint): %d\n\ /* * Determine what fonts to use. */ +#if ENABLE_NLS + appData.font = InsertPxlSize(appData.font, fontPxlSize); + appData.clockFont = InsertPxlSize(appData.clockFont, clockFontPxlSize); + appData.coordFont = InsertPxlSize(appData.coordFont, coordFontPxlSize); + fontSet = CreateFontSet(appData.font); + clockFontSet = CreateFontSet(appData.clockFont); + { + /* For the coordFont, use the 0th font of the fontset. */ + XFontSet coordFontSet = CreateFontSet(appData.coordFont); + XFontStruct **font_struct_list; + char **font_name_list; + XFontsOfFontSet(coordFontSet, &font_struct_list, &font_name_list); + coordFontID = XLoadFont(xDisplay, font_name_list[0]); + coordFontStruct = XQueryFont(xDisplay, coordFontID); + } +#else + appData.font = FindFont(appData.font, fontPxlSize); appData.clockFont = FindFont(appData.clockFont, clockFontPxlSize); + appData.coordFont = FindFont(appData.coordFont, coordFontPxlSize); clockFontID = XLoadFont(xDisplay, appData.clockFont); clockFontStruct = XQueryFont(xDisplay, clockFontID); - appData.coordFont = FindFont(appData.coordFont, coordFontPxlSize); coordFontID = XLoadFont(xDisplay, appData.coordFont); coordFontStruct = XQueryFont(xDisplay, coordFontID); - appData.font = FindFont(appData.font, fontPxlSize); - countFontID = XLoadFont(xDisplay, appData.coordFont); // [HGM] holdings - countFontStruct = XQueryFont(xDisplay, countFontID); -// appData.font = FindFont(appData.font, fontPxlSize); +#endif + countFontID = coordFontID; // [HGM] holdings + countFontStruct = coordFontStruct; xdb = XtDatabase(xDisplay); +#if ENABLE_NLS + XrmPutLineResource(&xdb, "*international: True"); + vTo.size = sizeof(XFontSet); + vTo.addr = (XtPointer) &fontSet; + XrmPutResource(&xdb, "*fontSet", XtRFontSet, &vTo); +#else XrmPutStringResource(&xdb, "*font", appData.font); +#endif /* * Detect if there are not enough colors available and adapt. @@ -2138,10 +2216,7 @@ XBoard square size (hint): %d\n\ if (forceMono) { fprintf(stderr, _("%s: too few colors available; trying monochrome mode\n"), programName); - - if (appData.bitmapDirectory == NULL || - appData.bitmapDirectory[0] == NULLCHAR) - appData.bitmapDirectory = DEF_BITMAP_DIR; + appData.monoMode = True; } if (appData.lowTimeWarning && !appData.monoMode) { @@ -2197,7 +2272,11 @@ XBoard square size (hint): %d\n\ widgetList[j++] = whiteTimerWidget = XtCreateWidget("whiteTime", labelWidgetClass, formWidget, timerArgs, XtNumber(timerArgs)); +#if ENABLE_NLS + XtSetArg(args[0], XtNfontSet, clockFontSet); +#else XtSetArg(args[0], XtNfont, clockFontStruct); +#endif XtSetArg(args[1], XtNtop, XtChainTop); XtSetArg(args[2], XtNbottom, XtChainTop); XtSetValues(whiteTimerWidget, args, 3); @@ -2205,7 +2284,11 @@ XBoard square size (hint): %d\n\ widgetList[j++] = blackTimerWidget = XtCreateWidget("blackTime", labelWidgetClass, formWidget, timerArgs, XtNumber(timerArgs)); +#if ENABLE_NLS + XtSetArg(args[0], XtNfontSet, clockFontSet); +#else XtSetArg(args[0], XtNfont, clockFontStruct); +#endif XtSetArg(args[1], XtNtop, XtChainTop); XtSetArg(args[2], XtNbottom, XtChainTop); XtSetValues(blackTimerWidget, args, 3); @@ -2551,19 +2634,7 @@ XBoard square size (hint): %d\n\ CreateGCs(False); CreateGrid(); -#if HAVE_LIBXPM - if (appData.bitmapDirectory[0] != NULLCHAR) { - CreatePieces(); - } else { - CreateXPMPieces(); - CreateXPMBoard(appData.liteBackTextureFile, 1); - CreateXPMBoard(appData.darkBackTextureFile, 0); - } -#else - CreateXIMPieces(); - /* Create regular pieces */ - if (!useImages) CreatePieces(); -#endif + CreateAnyPieces(); CreatePieceMenus(); @@ -2622,13 +2693,16 @@ XBoard square size (hint): %d\n\ } gameInfo.boardWidth = 0; // [HGM] pieces: kludge to ensure InitPosition() calls InitDrawingSizes() InitPosition(TRUE); - XtSetKeyboardFocus(shellWidget, formWidget); +// XtSetKeyboardFocus(shellWidget, formWidget); + XSetInputFocus(xDisplay, XtWindow(formWidget), RevertToPointerRoot, CurrentTime); XtAppMainLoop(appContext); if (appData.debugMode) fclose(debugFP); // [DM] debug return 0; } +static Boolean noEcho; + void ShutDownFrontEnd() { @@ -2638,6 +2712,7 @@ ShutDownFrontEnd() if (saveSettingsOnExit) SaveSettings(settingsFileName); unlink(gameCopyFilename); unlink(gamePasteFilename); + if(noEcho) EchoOn(); } RETSIGTYPE TermSizeSigHandler(int sig) @@ -2781,10 +2856,12 @@ Enables icsEnables[] = { { "menuOptions.Hide Thinking", False }, { "menuOptions.Ponder Next Move", False }, #endif - { "menuEngine.Engine #1 Settings", False }, #endif + { "menuEngine.Engine #1 Settings", False }, { "menuEngine.Engine #2 Settings", False }, + { "menuEngine.Load Engine", False }, { "menuEdit.Annotate", False }, + { "menuOptions.Match", False }, { NULL, False } }; @@ -2843,6 +2920,20 @@ Enables gnuEnables[] = { { "menuFile.Mail Move", False }, { "menuFile.Reload CMail Message", False }, + // [HGM] The following have been added to make a switch from ncp to GNU mode possible + { "menuMode.Machine White", True }, + { "menuMode.Machine Black", True }, + { "menuMode.Analysis Mode", True }, + { "menuMode.Analyze File", True }, + { "menuMode.Two Machines", True }, + { "menuMode.Machine Match", True }, + { "menuEngine.Engine #1 Settings", True }, + { "menuEngine.Engine #2 Settings", True }, + { "menuEngine.Hint", True }, + { "menuEngine.Book", True }, + { "menuEngine.Move Now", True }, + { "menuEngine.Retract Move", True }, + { "Action", True }, { NULL, False } }; @@ -2897,7 +2988,7 @@ Enables machineThinkingEnables[] = { { "menuMode.Machine White", False }, { "menuMode.Machine Black", False }, { "menuMode.Two Machines", False }, - { "menuMode.Machine Match", False }, +// { "menuMode.Machine Match", False }, { "menuEngine.Retract Move", False }, { NULL, False } }; @@ -2916,7 +3007,7 @@ Enables userThinkingEnables[] = { { "menuMode.Machine White", True }, { "menuMode.Machine Black", True }, { "menuMode.Two Machines", True }, - { "menuMode.Machine Match", True }, +// { "menuMode.Machine Match", True }, { "menuEngine.Retract Move", True }, { NULL, False } }; @@ -2926,8 +3017,10 @@ void SetICSMode() SetMenuEnables(icsEnables); #if ZIPPY - if (appData.zippyPlay && !appData.noChessProgram) /* [DM] icsEngineAnalyze */ + if (appData.zippyPlay && !appData.noChessProgram) { /* [DM] icsEngineAnalyze */ XtSetSensitive(XtNameToWidget(menuBarWidget, "menuMode.Analysis Mode"), True); + XtSetSensitive(XtNameToWidget(menuBarWidget, "menuEngine.Engine #1 Settings"), True); + } #endif } @@ -3039,6 +3132,96 @@ NextInHistory() #define Abs(n) ((n)<0 ? -(n) : (n)) +#ifdef ENABLE_NLS +char * +InsertPxlSize(pattern, targetPxlSize) + char *pattern; + int targetPxlSize; +{ + char *base_fnt_lst, strInt[12], *p, *q; + int alternatives, i, len, strIntLen; + + /* + * Replace the "*" (if present) in the pixel-size slot of each + * alternative with the targetPxlSize. + */ + p = pattern; + alternatives = 1; + while ((p = strchr(p, ',')) != NULL) { + alternatives++; + p++; + } + snprintf(strInt, sizeof(strInt), "%d", targetPxlSize); + strIntLen = strlen(strInt); + base_fnt_lst = calloc(1, strlen(pattern) + strIntLen * alternatives + 1); + + p = pattern; + q = base_fnt_lst; + while (alternatives--) { + char *comma = strchr(p, ','); + for (i=0; i<14; i++) { + char *hyphen = strchr(p, '-'); + if (!hyphen) break; + if (comma && hyphen > comma) break; + len = hyphen + 1 - p; + if (i == 7 && *p == '*' && len == 2) { + p += len; + memcpy(q, strInt, strIntLen); + q += strIntLen; + *q++ = '-'; + } else { + memcpy(q, p, len); + p += len; + q += len; + } + } + if (!comma) break; + len = comma + 1 - p; + memcpy(q, p, len); + p += len; + q += len; + } + strcpy(q, p); + + return base_fnt_lst; +} + +XFontSet +CreateFontSet(base_fnt_lst) + char *base_fnt_lst; +{ + XFontSet fntSet; + char **missing_list; + int missing_count; + char *def_string; + + fntSet = XCreateFontSet(xDisplay, base_fnt_lst, + &missing_list, &missing_count, &def_string); + if (appData.debugMode) { + int i, count; + XFontStruct **font_struct_list; + char **font_name_list; + fprintf(debugFP, "Requested font set for list %s\n", base_fnt_lst); + if (fntSet) { + fprintf(debugFP, " got list %s, locale %s\n", + XBaseFontNameListOfFontSet(fntSet), + XLocaleOfFontSet(fntSet)); + count = XFontsOfFontSet(fntSet, &font_struct_list, &font_name_list); + for (i = 0; i < count; i++) { + fprintf(debugFP, " got charset %s\n", font_name_list[i]); + } + } + for (i = 0; i < missing_count; i++) { + fprintf(debugFP, " missing charset %s\n", missing_list[i]); + } + } + if (fntSet == NULL) { + fprintf(stderr, _("Unable to create font set for %s.\n"), base_fnt_lst); + exit(2); + } + return fntSet; +} +#else // not ENABLE_NLS /* * Find a font that matches "pattern" that is as close as * possible to the targetPxlSize. Prefer fonts that are k @@ -3056,39 +3239,12 @@ FindFont(pattern, targetPxlSize) char **fonts, *p, *best, *scalable, *scalableTail; int i, j, nfonts, minerr, err, pxlSize; -#ifdef ENABLE_NLS - char **missing_list; - int missing_count; - char *def_string, *base_fnt_lst, strInt[3]; - XFontSet fntSet; - XFontStruct **fnt_list; - - base_fnt_lst = calloc(1, strlen(pattern) + 3); - snprintf(strInt, sizeof(strInt)/sizeof(strInt[0]), "%d", targetPxlSize); - p = strstr(pattern, "--"); - strncpy(base_fnt_lst, pattern, p - pattern + 2); - strcat(base_fnt_lst, strInt); - strcat(base_fnt_lst, strchr(p + 2, '-')); - - if ((fntSet = XCreateFontSet(xDisplay, - base_fnt_lst, - &missing_list, - &missing_count, - &def_string)) == NULL) { - - fprintf(stderr, _("Unable to create font set.\n")); - exit (2); - } - - nfonts = XFontsOfFontSet(fntSet, &fnt_list, &fonts); -#else fonts = XListFonts(xDisplay, pattern, 999999, &nfonts); if (nfonts < 1) { fprintf(stderr, _("%s: no fonts match pattern %s\n"), programName, pattern); exit(2); } -#endif best = fonts[0]; scalable = NULL; @@ -3130,15 +3286,10 @@ FindFont(pattern, targetPxlSize) fprintf(debugFP, _("resolved %s at pixel size %d\n to %s\n"), pattern, targetPxlSize, p); } -#ifdef ENABLE_NLS - if (missing_count > 0) - XFreeStringList(missing_list); - XFreeFontSet(xDisplay, fntSet); -#else - XFreeFontNames(fonts); -#endif + XFreeFontNames(fonts); return p; } +#endif void DeleteGCs() { // [HGM] deletes GCs that are to be remade, to prevent resource leak; @@ -3450,7 +3601,7 @@ void CreateXPMBoard(char *s, int kind) { XpmAttributes attr; attr.valuemask = 0; - if(s == NULL || *s == 0 || *s == '*') { useTexture &= ~(kind+1); return; } + if(!appData.useBitmaps || s == NULL || *s == 0 || *s == '*') { useTexture &= ~(kind+1); return; } if (XpmReadFileToPixmap(xDisplay, xBoardWindow, s, &(xpmBoardBitmap[kind]), NULL, &attr) == 0) { useTexture |= kind + 1; textureW[kind] = attr.width; textureH[kind] = attr.height; } @@ -3769,10 +3920,10 @@ void CreateMenuBarPopup(parent, name, mb) mi = mb->mi; while (mi->string != NULL) { if (strcmp(mi->string, "----") == 0) { - entry = XtCreateManagedWidget(mi->string, smeLineObjectClass, + entry = XtCreateManagedWidget(_(mi->string), smeLineObjectClass, menu, args, j); } else { - XtSetArg(args[j], XtNlabel, XtNewString(mi->string)); + XtSetArg(args[j], XtNlabel, XtNewString(_(mi->string))); entry = XtCreateManagedWidget(mi->ref, smeBSBObjectClass, menu, args, j+1); XtAddCallback(entry, XtNcallback, @@ -3810,7 +3961,7 @@ Widget CreateMenuBar(mb) XtSetArg(args[j], XtNlabel, XtNewString(shortName)); j++; } else { - XtSetArg(args[j], XtNlabel, XtNewString(mb->name)); j++; + XtSetArg(args[j], XtNlabel, XtNewString(_(mb->name))); j++; } XtSetArg(args[j], XtNborderWidth, 0); j++; @@ -3958,7 +4109,7 @@ void PieceMenuPopup(w, event, params, num_params) String *params; Cardinal *num_params; { - String whichMenu; int menuNr; + String whichMenu; int menuNr = -2; shiftKey = strcmp(params[0], "menuW"); // used to indicate black if (event->type == ButtonRelease) menuNr = RightClick(Release, event->xbutton.x, event->xbutton.y, &pmFromX, &pmFromY); @@ -3998,6 +4149,7 @@ void WhiteClock(w, event, prms, nprms) String *prms; Cardinal *nprms; { + shiftKey = prms[0][0] & 1; ClockClick(0); } @@ -4007,6 +4159,7 @@ void BlackClock(w, event, prms, nprms) String *prms; Cardinal *nprms; { + shiftKey = prms[0][0] & 1; ClockClick(1); } @@ -4850,6 +5003,14 @@ void CommentPopDown() PopDown(1); } +static char *openName; +FILE *openFP; + +void DelayedLoad() +{ + (void) (*fileProc)(openFP, 0, openName); +} + void FileNamePopUp(label, def, filter, proc, openMode) char *label; char *def; @@ -4860,12 +5021,11 @@ void FileNamePopUp(label, def, filter, proc, openMode) fileProc = proc; /* I can't see a way not */ fileOpenMode = openMode; /* to use globals here */ { // [HGM] use file-selector dialog stolen from Ghostview - char *name; int index; // this is not supported yet - FILE *f; - if(f = XsraSelFile(shellWidget, label, NULL, NULL, "could not open: ", - (def[0] ? def : NULL), filter, openMode, NULL, &name)) - (void) (*fileProc)(f, index=0, name); + if(openFP = XsraSelFile(shellWidget, label, NULL, NULL, "could not open: ", + (def[0] ? def : NULL), filter, openMode, NULL, &openName)) + // [HGM] delay to give expose event opportunity to redraw board after browser-dialog popdown before lengthy load starts + ScheduleDelayedEvent(&DelayedLoad, 50); } } @@ -4983,7 +5143,7 @@ void PromotionPopUp() (XtPointer) dialog); XawDialogAddButton(dialog, _("Captain"), PromotionCallback, (XtPointer) dialog); - } else { + } else { XawDialogAddButton(dialog, _("Queen"), PromotionCallback, (XtPointer) dialog); XawDialogAddButton(dialog, _("Rook"), PromotionCallback, @@ -4994,7 +5154,7 @@ void PromotionPopUp() (XtPointer) dialog); } if (!appData.testLegality || gameInfo.variant == VariantSuicide || - gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove) || + gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove) || gameInfo.variant == VariantGiveaway) { XawDialogAddButton(dialog, _("King"), PromotionCallback, (XtPointer) dialog); @@ -5279,6 +5439,8 @@ void ModeHighlight() XtSetValues(XtNameToWidget(menuBarWidget, wname), args, 1); } oldmode = gameMode; + XtSetArg(args[0], XtNleftBitmap, matchMode && matchGame < appData.matchGames ? xMarkPixmap : None); + XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Machine Match"), args, 1); /* Maybe all the enables should be handled here, not just this one */ XtSetSensitive(XtNameToWidget(menuBarWidget, "menuMode.Training"), @@ -5591,8 +5753,6 @@ SendGameSelection(Widget w, Atom *selection, Atom *target, void CopySomething() { - int ret; - /* * Set both PRIMARY (the selection) and CLIPBOARD, since we don't * have a notion of a game that is selected but not copied. @@ -5804,9 +5964,7 @@ void MatchProc(w, event, prms, nprms) String *prms; Cardinal *nprms; { - if(gameMode != BeginningOfGame) { DisplayError(_("You can only start a match from the initial position."), 0); return; } - appData.matchGames = appData.defaultMatchGames; - MatchEvent(2); + MatchEvent(2); } void IcsClientProc(w, event, prms, nprms) @@ -6735,6 +6893,8 @@ void DisplayMessage(message, extMessage) }; }; + safeStrCpy(lastMsg, message, MSG_SIZ); // [HGM] make available + /* need to test if messageWidget already exists, since this function can also be called during the startup, if for example a Xresource is not set up correctly */ @@ -6794,6 +6954,7 @@ void DisplayTitle(text) XtSetArg(args[i], XtNiconName, (XtArgVal) icon); i++; XtSetArg(args[i], XtNtitle, (XtArgVal) title); i++; XtSetValues(shellWidget, args, i); + XSync(xDisplay, False); } @@ -7082,15 +7243,23 @@ PlayAlarmSound() } void +PlayTellSound() +{ + PlaySound(appData.soundTell); +} + +void EchoOn() { system("stty echo"); + noEcho = False; } void EchoOff() { system("stty -echo"); + noEcho = True; } void @@ -7590,50 +7759,40 @@ int OpenTCP(host, port, pr) #if OMIT_SOCKETS DisplayFatalError(_("Socket support is not configured in"), 0, 2); #else /* !OMIT_SOCKETS */ - int s; - struct sockaddr_in sa; - struct hostent *hp; - unsigned short uport; + struct addrinfo hints; + struct addrinfo *ais, *ai; + int error; + int s=0; ChildProc *cp; - if ((s = socket(AF_INET, SOCK_STREAM, 6)) < 0) { - return errno; - } - - memset((char *) &sa, (int)0, sizeof(struct sockaddr_in)); - sa.sin_family = AF_INET; - sa.sin_addr.s_addr = INADDR_ANY; - uport = (unsigned short) 0; - sa.sin_port = htons(uport); - if (bind(s, (struct sockaddr *) &sa, sizeof(struct sockaddr_in)) < 0) { - return errno; - } - - memset((char *) &sa, (int)0, sizeof(struct sockaddr_in)); - if (!(hp = gethostbyname(host))) { - int b0, b1, b2, b3; - if (sscanf(host, "%d.%d.%d.%d", &b0, &b1, &b2, &b3) == 4) { - hp = (struct hostent *) calloc(1, sizeof(struct hostent)); - hp->h_addrtype = AF_INET; - hp->h_length = 4; - hp->h_addr_list = (char **) calloc(2, sizeof(char *)); - hp->h_addr_list[0] = (char *) malloc(4); - hp->h_addr_list[0][0] = b0; - hp->h_addr_list[0][1] = b1; - hp->h_addr_list[0][2] = b2; - hp->h_addr_list[0][3] = b3; - } else { - return ENOENT; - } + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + error = getaddrinfo(host, port, &hints, &ais); + if (error != 0) { + /* a getaddrinfo error is not an errno, so can't return it */ + fprintf(debugFP, "getaddrinfo(%s, %s): %s\n", + host, port, gai_strerror(error)); + return ENOENT; + } + + for (ai = ais; ai != NULL; ai = ai->ai_next) { + if ((s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) < 0) { + error = errno; + continue; + } + if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0) { + error = errno; + continue; + } + error = 0; + break; } - sa.sin_family = hp->h_addrtype; - uport = (unsigned short) atoi(port); - sa.sin_port = htons(uport); - memcpy((char *) &sa.sin_addr, hp->h_addr, hp->h_length); + freeaddrinfo(ais); - if (connect(s, (struct sockaddr *) &sa, - sizeof(struct sockaddr_in)) < 0) { - return errno; + if (error != 0) { + return error; } cp = (ChildProc *) calloc(1, sizeof(ChildProc)); @@ -7642,7 +7801,6 @@ int OpenTCP(host, port, pr) cp->fdFrom = s; cp->fdTo = s; *pr = (ProcRef) cp; - #endif /* !OMIT_SOCKETS */ return 0; @@ -8010,8 +8168,7 @@ CreateAnimVars () /* For XPM pieces, we need bitmaps to use as masks. */ if (useImages) - CreateAnimMasks(info.depth); - xpmDone = 1; + CreateAnimMasks(info.depth), xpmDone = 1; } #ifndef HAVE_USLEEP @@ -8503,8 +8660,8 @@ AnimateMove(board, fromX, fromY, toX, toY) } void -DragPieceBegin(x, y) - int x; int y; +DragPieceBegin(x, y, instantly) + int x; int y; Boolean instantly; { int boardX, boardY, color; XPoint corner; @@ -8868,3 +9025,9 @@ void DrawArrowHighlight(int fromX, int fromY, int toX,int toY) if( IsDrawArrowEnabled() && fromX >= 0 && fromY >= 0 && toX >= 0 && toY >= 0) DrawArrowBetweenSquares(fromX, fromY, toX, toY); } + +void UpdateLogos(int displ) +{ + return; // no logos in XBoard yet +} +