cleaned up an old #ifdef in zippy
[xboard.git] / xboard.c
index 79b61a2..86fda44 100644 (file)
--- 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));
@@ -446,6 +447,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
 */
@@ -1407,6 +1410,9 @@ XtResource clientResources[] = {
     { "forceIllegalMoves", "forceIllegalMoves", XtRBoolean,
        sizeof(Boolean), XtOffset(AppDataPtr, forceIllegal),
        XtRImmediate, (XtPointer) False},
+    { "keepLineBreaksICS", "keepLineBreaksICS", XtRBoolean,
+       sizeof(Boolean), XtOffset(AppDataPtr, noJoin),
+       XtRImmediate, (XtPointer) True},
 };
 
 XrmOptionDescRec shellOptions[] = {
@@ -1776,6 +1782,7 @@ XrmOptionDescRec shellOptions[] = {
     { "-secondNeedsNoncompliantFEN", "secondNeedsNoncompliantFEN", XrmoptionSepArg, NULL },
     { "-keepAlive", "keepAlive", XrmoptionSepArg, NULL },
     { "-forceIllegalMoves", "forceIllegalMoves", XrmoptionNoArg, "True" },
+    { "-keepLineBreaksICS", "keepLineBreaksICS", XrmoptionSepArg, NULL },
 };
 
 
@@ -2392,11 +2399,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<argc; i++) fprintf(stderr, "argv[%2d] = '%s'\n", i, argv[i]);
-    }
-#endif
 #endif
 
     setbuf(stdout, NULL);
@@ -2509,19 +2511,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
@@ -3225,6 +3214,11 @@ ShutDownFrontEnd()
     unlink(gamePasteFilename);
 }
 
+RETSIGTYPE TermSizeSigHandler(int sig)
+{
+    update_ics_width();
+}
+
 RETSIGTYPE
 IntSigHandler(sig)
      int sig;
@@ -3918,14 +3912,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 */
@@ -4155,14 +4141,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);
     }
@@ -5377,12 +5356,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 =
@@ -5535,12 +5510,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 =
@@ -6279,15 +6250,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. */
@@ -6300,7 +6262,6 @@ void ModeHighlight()
            XtSetArg(args[0], XtNbackground, oldfg);
            XtSetArg(args[1], XtNforeground, oldbg);
          }
-#endif
          XtSetValues(XtNameToWidget(buttonBarWidget, PAUSE_BUTTON), args, 2);
        }
     }
@@ -7545,16 +7506,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)
@@ -8447,6 +8398,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
@@ -8985,12 +8940,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);
@@ -9439,19 +9389,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 */
@@ -9553,3 +9494,38 @@ SetProgramStats( FrontEndProgramStats * stats )
   // [HGM] done, but perhaps backend should call this directly?
     EngineOutputUpdate( stats );
 }
+
+#include <sys/ioctl.h>
+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();
+}