X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xboard.c;h=911f005558c96bad11ffc98e4e4844d6320e4b33;hb=e1edcbabb63e65d5d47c07a0836dd51d7e01de0e;hp=e8b561d1610da0ecd91bd58492bd4a60e73cac88;hpb=f9fe58c6ea5c0938364cd9bd0b434ee66e0f7272;p=xboard.git diff --git a/xboard.c b/xboard.c index e8b561d..911f005 100644 --- a/xboard.c +++ b/xboard.c @@ -232,6 +232,7 @@ typedef struct { int main P((int argc, char **argv)); RETSIGTYPE CmailSigHandler P((int sig)); RETSIGTYPE IntSigHandler P((int sig)); +RETSIGTYPE TermSizeSigHandler P((int sig)); void CreateGCs P((void)); void CreateXIMPieces P((void)); void CreateXPMPieces P((void)); @@ -280,7 +281,6 @@ void AskQuestionReplyAction P((Widget w, XEvent *event, void AskQuestionProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void AskQuestionPopDown P((void)); -void PromotionPopUp P((void)); void PromotionPopDown P((void)); void PromotionCallback P((Widget w, XtPointer client_data, XtPointer call_data)); @@ -427,9 +427,7 @@ void ErrorPopUp P((char *title, char *text, int modal)); void ErrorPopDown P((void)); static char *ExpandPathName P((char *path)); static void CreateAnimVars P((void)); -static void DragPieceBegin P((int x, int y)); static void DragPieceMove P((int x, int y)); -static void DragPieceEnd P((int x, int y)); static void DrawDragPiece P((void)); char *ModeToWidgetName P((GameMode mode)); void EngineOutputUpdate( FrontEndProgramStats * stats ); @@ -446,6 +444,8 @@ void UciPopDown P(()); void TimeControlPopDown P(()); void NewVariantPopDown P(()); void SettingsPopDown P(()); +void update_ics_width P(()); +int get_term_width P(()); /* * XBoard depends on Xt R4 or higher */ @@ -1404,6 +1404,18 @@ XtResource clientResources[] = { { "keepAlive", "keepAlive", XtRInt, sizeof(int), XtOffset(AppDataPtr, keepAlive), XtRImmediate, (XtPointer) 0}, + { "forceIllegalMoves", "forceIllegalMoves", XtRBoolean, + sizeof(Boolean), XtOffset(AppDataPtr, forceIllegal), + XtRImmediate, (XtPointer) False}, + { "keepLineBreaksICS", "keepLineBreaksICS", XtRBoolean, + sizeof(Boolean), XtOffset(AppDataPtr, noJoin), + XtRImmediate, (XtPointer) False}, + { "wrapContinuationSequence", "wrapContinuationSequence", XtRString, + sizeof(String), XtOffset(AppDataPtr, wrapContSeq), + XtRString, ""}, + { "useInternalWrap", "useInternalWrap", XtRBoolean, + sizeof(Boolean), XtOffset(AppDataPtr, useInternalWrap), + XtRImmediate, (XtPointer) True}, }; XrmOptionDescRec shellOptions[] = { @@ -1772,9 +1784,12 @@ XrmOptionDescRec shellOptions[] = { { "-firstNeedsNoncompliantFEN", "firstNeedsNoncompliantFEN", XrmoptionSepArg, NULL }, { "-secondNeedsNoncompliantFEN", "secondNeedsNoncompliantFEN", XrmoptionSepArg, NULL }, { "-keepAlive", "keepAlive", XrmoptionSepArg, NULL }, + { "-forceIllegalMoves", "forceIllegalMoves", XrmoptionNoArg, "True" }, + { "-keepLineBreaksICS", "keepLineBreaksICS", XrmoptionSepArg, NULL }, + { "-wrapContinuationSequence", "wrapContinuationSequence", XrmoptionSepArg, NULL }, + { "-useInternalWrap", "useInternalWrap", XrmoptionSepArg, NULL }, }; - XtActionsRec boardActions[] = { { "DrawPosition", DrawPositionProc }, { "HandleUserMove", HandleUserMove }, @@ -1886,7 +1901,6 @@ XtActionsRec boardActions[] = { { "TagsPopDown", (XtActionProc) TagsPopDown }, { "ErrorPopDown", (XtActionProc) ErrorPopDown }, { "ICSInputBoxPopDown", (XtActionProc) ICSInputBoxPopDown }, - { "AnalysisPopDown", (XtActionProc) AnalysisPopDown }, { "FileNamePopDown", (XtActionProc) FileNamePopDown }, { "AskQuestionPopDown", (XtActionProc) AskQuestionPopDown }, { "GameListPopDown", (XtActionProc) GameListPopDown }, @@ -2388,11 +2402,6 @@ main(argc, argv) argvCopy[j] = NULL; argv = argvCopy; argc = j; -#if 0 - if(appData.debugMode,1) { // OK, appData is not initialized here yet... - for(i=0; i 1) { + if (argc > 1) + { /* left over command line arguments, print out help and exit. + * Use two columns to print help + */ fprintf(stderr, _("%s: unrecognized argument %s\n"), programName, argv[1]); + fprintf(stderr, "Recognized options:\n"); - for(i = 0; i < XtNumber(shellOptions); i++) { + for(i = 0; i < XtNumber(shellOptions); i++) + { + /* print first column */ j = fprintf(stderr, " %s%s", shellOptions[i].option, (shellOptions[i].argKind == XrmoptionSepArg ? " ARG" : "")); - if (i++ < XtNumber(shellOptions)) { + /* print second column and end line */ + if (++i < XtNumber(shellOptions)) + { fprintf(stderr, "%*c%s%s\n", 40 - j, ' ', shellOptions[i].option, (shellOptions[i].argKind == XrmoptionSepArg ? " ARG" : "")); - } else { + } + else + { fprintf(stderr, "\n"); - } - } + }; + }; exit(2); - } + }; p = getenv("HOME"); if (p == NULL) p = "/tmp"; @@ -2495,19 +2514,6 @@ main(argc, argv) gameInfo.variant = StringToVariant(appData.variant); InitPosition(FALSE); -#if 0 - /* - * Determine boardSize - */ - gameInfo.boardWidth = gameInfo.boardHeight = 8; // [HGM] boardsize: make sure we start as 8x8 - -//#ifndef IDSIZE - // [HGM] as long as we have not created the possibility to change size while running, start with requested size - gameInfo.boardWidth = appData.NrFiles > 0 ? appData.NrFiles : 8; - gameInfo.boardHeight = appData.NrRanks > 0 ? appData.NrRanks : 8; - gameInfo.holdingsWidth = appData.holdingsSize > 0 ? 2 : 0; -#endif - #ifdef IDSIZE InitDrawingSizes(-1, 0); // [HGM] initsize: make this into a subroutine @@ -3211,6 +3217,11 @@ ShutDownFrontEnd() unlink(gamePasteFilename); } +RETSIGTYPE TermSizeSigHandler(int sig) +{ + update_ics_width(); +} + RETSIGTYPE IntSigHandler(sig) int sig; @@ -3904,14 +3915,6 @@ void CreateXPMPieces() static char *xpmkind[] = { "ll", "ld", "dl", "dd" }; XpmColorSymbol symbols[4]; -#if 0 - /* Apparently some versions of Xpm don't define XpmFormat at all --tpm */ - if (appData.debugMode) { - fprintf(stderr, "XPM Library Version: %d.%d%c\n", - XpmFormat, XpmVersion, (char)('a' + XpmRevision - 1)); - } -#endif - /* The XSynchronize calls were copied from CreatePieces. Not sure if needed, but can't hurt */ XSynchronize(xDisplay, True); /* Work-around for xlib/xt buffering bug */ @@ -4141,14 +4144,7 @@ void ReadBitmap(pm, name, bits, wreq, hreq) return; } } - if (bits == NULL) { -#if 0 - fprintf(stderr, _("%s: No built-in bitmap for %s; giving up\n"), - programName, name); - exit(1); -#endif - ; // [HGM] bitmaps: make it non-fatal if we have no bitmap; - } else { + if (bits != NULL) { *pm = XCreateBitmapFromData(xDisplay, xBoardWindow, (char *) bits, wreq, hreq); } @@ -5129,14 +5125,8 @@ void HandleUserMove(w, event, prms, nprms) String *prms; Cardinal *nprms; { - int x, y; - Boolean saveAnimate; - static int second = 0; - if (w != boardWidget || errorExitStatus != -1) return; - if (event->type == ButtonPress) ErrorPopDown(); - if (promotionUp) { if (event->type == ButtonPress) { XtPopdown(promotionShell); @@ -5149,134 +5139,9 @@ void HandleUserMove(w, event, prms, nprms) } } - x = EventToSquare(event->xbutton.x, BOARD_WIDTH); - y = EventToSquare(event->xbutton.y, BOARD_HEIGHT); - if (!flipView && y >= 0) { - y = BOARD_HEIGHT - 1 - y; - } - if (flipView && x >= 0) { - x = BOARD_WIDTH - 1 - x; - } - - /* [HGM] holdings: next 5 lines: ignore all clicks between board and holdings */ - if(event->type == ButtonPress - && ( x == BOARD_LEFT-1 || x == BOARD_RGHT - || x == BOARD_LEFT-2 && y < BOARD_HEIGHT-gameInfo.holdingsSize - || x == BOARD_RGHT+1 && y >= gameInfo.holdingsSize) ) - return; - - if (fromX == -1) { - if (event->type == ButtonPress) { - /* First square */ - if (OKToStartUserMove(x, y)) { - fromX = x; - fromY = y; - second = 0; - DragPieceBegin(event->xbutton.x, event->xbutton.y); - if (appData.highlightDragging) { - SetHighlights(x, y, -1, -1); - } - } - } - return; - } - - /* fromX != -1 */ - if (event->type == ButtonPress && gameMode != EditPosition && - x >= 0 && y >= 0) { - ChessSquare fromP; - ChessSquare toP; - int frc; - - /* Check if clicking again on the same color piece */ - fromP = boards[currentMove][fromY][fromX]; - toP = boards[currentMove][y][x]; - frc = gameInfo.variant == VariantFischeRandom || gameInfo.variant == VariantCapaRandom; - if ((WhitePawn <= fromP && fromP <= WhiteKing && // [HGM] this test should go, as UserMoveTest now does it. - WhitePawn <= toP && toP <= WhiteKing && - !(fromP == WhiteKing && toP == WhiteRook && frc)) || - (BlackPawn <= fromP && fromP <= BlackKing && - BlackPawn <= toP && toP <= BlackKing && - !(fromP == BlackKing && toP == BlackRook && frc))) { - /* Clicked again on same color piece -- changed his mind */ - second = (x == fromX && y == fromY); - if (appData.highlightDragging) { - SetHighlights(x, y, -1, -1); - } else { - ClearHighlights(); - } - if (OKToStartUserMove(x, y)) { - fromX = x; - fromY = y; - DragPieceBegin(event->xbutton.x, event->xbutton.y); - } - return; - } - } - - if (event->type == ButtonRelease && x == fromX && y == fromY) { - DragPieceEnd(event->xbutton.x, event->xbutton.y); - if (appData.animateDragging) { - /* Undo animation damage if any */ - DrawPosition(FALSE, NULL); - } - if (second) { - /* Second up/down in same square; just abort move */ - second = 0; - fromX = fromY = -1; - ClearHighlights(); - gotPremove = 0; - ClearPremoveHighlights(); - } else { - /* First upclick in same square; start click-click mode */ - SetHighlights(x, y, -1, -1); - } - return; - } - - /* Completed move */ - toX = x; - toY = y; - saveAnimate = appData.animate; - if (event->type == ButtonPress) { - /* Finish clickclick move */ - if (appData.animate || appData.highlightLastMove) { - SetHighlights(fromX, fromY, toX, toY); - } else { - ClearHighlights(); - } - } else { - /* Finish drag move */ - if (appData.highlightLastMove) { - SetHighlights(fromX, fromY, toX, toY); - } else { - ClearHighlights(); - } - DragPieceEnd(event->xbutton.x, event->xbutton.y); - /* Don't animate move and drag both */ - appData.animate = FALSE; - } - if (IsPromotion(fromX, fromY, toX, toY)) { - if (appData.alwaysPromoteToQueen) { - UserMoveEvent(fromX, fromY, toX, toY, 'q'); - if (!appData.highlightLastMove || gotPremove) ClearHighlights(); - if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY); - fromX = fromY = -1; - } else { - SetHighlights(fromX, fromY, toX, toY); - PromotionPopUp(); - } - } else { - UserMoveEvent(fromX, fromY, toX, toY, NULLCHAR); - if (!appData.highlightLastMove || gotPremove) ClearHighlights(); - if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY); - fromX = fromY = -1; - } - appData.animate = saveAnimate; - if (appData.animate || appData.animateDragging) { - /* Undo animation damage if needed */ - DrawPosition(FALSE, NULL); - } + // [HGM] mouse: the rest of the mouse handler is moved to the backend, and called here + if(event->type == ButtonPress) LeftClick(Press, event->xbutton.x, event->xbutton.y); + if(event->type == ButtonRelease) LeftClick(Release, event->xbutton.x, event->xbutton.y); } void AnimateUserMove (Widget w, XEvent * event, @@ -5330,12 +5195,8 @@ Widget CommentCreate(name, text, mutable, callback, lines) XtSetArg(args[j], XtNright, XtChainRight); j++; XtSetArg(args[j], XtNresizable, True); j++; XtSetArg(args[j], XtNwidth, bw_width); j++; /*force wider than buttons*/ -#if 0 - XtSetArg(args[j], XtNscrollVertical, XawtextScrollWhenNeeded); j++; -#else /* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */ XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++; -#endif XtSetArg(args[j], XtNautoFill, True); j++; XtSetArg(args[j], XtNwrap, XawtextWrapWord); j++; edit = @@ -5488,12 +5349,8 @@ Widget MiscCreate(name, text, mutable, callback, lines) XtSetArg(args[j], XtNleft, XtChainLeft); j++; XtSetArg(args[j], XtNright, XtChainRight); j++; XtSetArg(args[j], XtNresizable, True); j++; -#if 0 - XtSetArg(args[j], XtNscrollVertical, XawtextScrollWhenNeeded); j++; -#else /* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */ XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++; -#endif XtSetArg(args[j], XtNautoFill, True); j++; XtSetArg(args[j], XtNwrap, XawtextWrapWord); j++; edit = @@ -5726,37 +5583,6 @@ void CommentPopUp(title, text) commentUp = True; } -void AnalysisPopUp(title, text) - char *title, *text; -{ - Arg args[16]; - int j; - Widget edit; - - if (analysisShell == NULL) { - analysisShell = MiscCreate(title, text, False, NULL, 4); - XtRealizeWidget(analysisShell); - CatchDeleteWindow(analysisShell, "AnalysisPopDown"); - - } else { - edit = XtNameToWidget(analysisShell, "*form.text"); - j = 0; - XtSetArg(args[j], XtNstring, text); j++; - XtSetValues(edit, args, j); - j = 0; - XtSetArg(args[j], XtNiconName, (XtArgVal) title); j++; - XtSetArg(args[j], XtNtitle, (XtArgVal) title); j++; - XtSetValues(analysisShell, args, j); - } - - if (!analysisUp) { - XtPopup(analysisShell, XtGrabNone); - } - XSync(xDisplay, False); - - analysisUp = True; -} - void CommentCallback(w, client_data, call_data) Widget w; XtPointer client_data, call_data; @@ -5795,16 +5621,6 @@ void CommentPopDown() commentUp = False; } -void AnalysisPopDown() -{ - if (!analysisUp) return; - XtPopdown(analysisShell); - XSync(xDisplay, False); - analysisUp = False; - if (appData.icsEngineAnalyze) ExitAnalyzeMode(); /* [DM] icsEngineAnalyze */ -} - - void FileNamePopUp(label, def, proc, openMode) char *label; char *def; @@ -6232,15 +6048,6 @@ void ModeHighlight() args, 1); if (appData.showButtonBar) { -#if 0 - if (pausing) { - XtSetArg(args[0], XtNbackground, buttonForegroundPixel); - XtSetArg(args[1], XtNforeground, buttonBackgroundPixel); - } else { - XtSetArg(args[0], XtNbackground, buttonBackgroundPixel); - XtSetArg(args[1], XtNforeground, buttonForegroundPixel); - } -#else /* Always toggle, don't set. Previous code messes up when invoked while the button is pressed, as releasing it toggles the state again. */ @@ -6253,7 +6060,6 @@ void ModeHighlight() XtSetArg(args[0], XtNbackground, oldfg); XtSetArg(args[1], XtNforeground, oldbg); } -#endif XtSetValues(XtNameToWidget(buttonBarWidget, PAUSE_BUTTON), args, 2); } } @@ -6286,7 +6092,6 @@ void ResetProc(w, event, prms, nprms) Cardinal *nprms; { ResetGameEvent(); - AnalysisPopDown(); } int LoadGamePopUp(f, gameNumber, title) @@ -7498,16 +7303,6 @@ void ShowThinkingProc(w, event, prms, nprms) appData.showThinking = !appData.showThinking; // [HGM] thinking: tken out of ShowThinkingEvent ShowThinkingEvent(); -#if 0 - // [HGM] thinking: currently no suc menu item; replaced by Hide Thinking (From Human) - if (appData.showThinking) { - XtSetArg(args[0], XtNleftBitmap, xMarkPixmap); - } else { - XtSetArg(args[0], XtNleftBitmap, None); - } - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Show Thinking"), - args, 1); -#endif } void HideThinkingProc(w, event, prms, nprms) @@ -8400,6 +8195,10 @@ int StartChildProcess(cmdLine, dir, pr) SetUpChildIO(to_prog, from_prog); + #ifdef SIGWINCH + signal(SIGWINCH, TermSizeSigHandler); + #endif + if ((pid = fork()) == 0) { /* Child process */ // [HGM] PSWBTM: made order resistant against case where fd of created pipe was 0 or 1 @@ -8714,11 +8513,33 @@ int OutputToProcess(pr, message, count, outError) int count; int *outError; { + static int line = 0; ChildProc *cp = (ChildProc *) pr; int outCount; if (pr == NoProc) - outCount = fwrite(message, 1, count, stdout); + { + if (appData.noJoin || !appData.useInternalWrap) + outCount = fwrite(message, 1, count, stdout); + else + { + int width = get_term_width(); + int len = wrap(NULL, message, count, width, &line); + char *msg = malloc(len); + int dbgchk; + + if (!msg) + outCount = fwrite(message, 1, count, stdout); + else + { + dbgchk = wrap(msg, message, count, width, &line); + if (dbgchk != len && appData.debugMode) + fprintf(debugFP, "wrap(): dbgchk(%d) != len(%d)\n", dbgchk, len); + outCount = fwrite(msg, 1, dbgchk, stdout); + free(msg); + } + } + } else outCount = write(cp->fdTo, message, count); @@ -8938,12 +8759,7 @@ FrameDelay (time) delay.it_interval.tv_usec = delay.it_value.tv_usec = (time % 1000) * 1000; setitimer(ITIMER_REAL, &delay, NULL); -#if 0 - /* Ugh -- busy-wait! --tpm */ - while (frameWaiting); -#else while (frameWaiting) pause(); -#endif delay.it_interval.tv_sec = delay.it_value.tv_sec = 0; delay.it_interval.tv_usec = delay.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &delay, NULL); @@ -9373,7 +9189,7 @@ AnimateMove(board, fromX, fromY, toX, toY) damage[toY][toX] = True; } -static void +void DragPieceBegin(x, y) int x; int y; { @@ -9392,19 +9208,10 @@ DragPieceBegin(x, y) ScreenSquare(boardX, boardY, &corner, &color); player.startSquare = corner; player.startColor = color; -#if 0 - /* Start from exactly where the piece is. This can be confusing - if you start dragging far from the center of the square; most - or all of the piece can be over a different square from the one - the mouse pointer is in. */ - player.mouseDelta.x = x - corner.x; - player.mouseDelta.y = y - corner.y; -#else /* As soon as we start dragging, the piece will jump slightly to be centered over the mouse pointer. */ player.mouseDelta.x = squareSize/2; player.mouseDelta.y = squareSize/2; -#endif /* Initialise animation */ player.dragPiece = PieceForSquare(boardX, boardY); /* Sanity check */ @@ -9452,7 +9259,7 @@ DragPieceMove(x, y) #endif } -static void +void DragPieceEnd(x, y) int x; int y; { @@ -9506,3 +9313,38 @@ SetProgramStats( FrontEndProgramStats * stats ) // [HGM] done, but perhaps backend should call this directly? EngineOutputUpdate( stats ); } + +#include +int get_term_width() +{ + int fd, default_width; + + fd = STDIN_FILENO; + default_width = 79; // this is FICS default anyway... + +#if !defined(TIOCGWINSZ) && defined(TIOCGSIZE) + struct ttysize win; + if (!ioctl(fd, TIOCGSIZE, &win)) + default_width = win.ts_cols; +#elif defined(TIOCGWINSZ) + struct winsize win; + if (!ioctl(fd, TIOCGWINSZ, &win)) + default_width = win.ws_col; +#endif + return default_width; +} + +void update_ics_width() +{ + static int old_width = 0; + int new_width = get_term_width(); + + if (old_width != new_width) + ics_printf("set width %d\n", new_width); + old_width = new_width; +} + +void NotifyFrontendLogin() +{ + update_ics_width(); +}