X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xboard.c;h=ada34c2f35fde5964f763394f9e0f8c38ba6afd7;hb=24f7a493a2d030011b0a4f883eaeeb6cbf991414;hp=ea64f44be10b9274792627bffdeef89de75d3c22;hpb=36c1871d84e1132cee5c4c7fe4363c442fa34af2;p=xboard.git diff --git a/xboard.c b/xboard.c index ea64f44..ada34c2 100644 --- a/xboard.c +++ b/xboard.c @@ -206,6 +206,7 @@ extern char *getenv(); #include "menus.h" #include "board.h" #include "dialogs.h" +#include "usystem.h" #include "gettext.h" @@ -225,8 +226,6 @@ extern char *getenv(); #endif int main P((int argc, char **argv)); -FILE * XsraSelFile P((Widget w, char *prompt, char *ok, char *cancel, char *failed, - char *init_path, char *filter, char *mode, int (*show_entry)(), char **name_return)); RETSIGTYPE CmailSigHandler P((int sig)); RETSIGTYPE IntSigHandler P((int sig)); RETSIGTYPE TermSizeSigHandler P((int sig)); @@ -252,7 +251,6 @@ static void DropMenuSelect P((Widget w, ChessSquare piece, caddr_t junk)); void ReadBitmap P((Pixmap *pm, String name, unsigned char bits[], u_int wreq, u_int hreq)); void CreateGrid P((void)); -int EventToSquare P((int x, int limit)); void EventProc P((Widget widget, caddr_t unused, XEvent *event)); void DelayedDrag P((void)); static void MoveTypeInProc P((Widget widget, caddr_t unused, XEvent *event)); @@ -272,54 +270,27 @@ void BlackClock P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void DrawPositionProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void XDrawPosition P((Widget w, /*Boolean*/int repaint, - Board board)); void CommentClick P((Widget w, XEvent * event, String * params, Cardinal * nParams)); -void CommentPopUp P((char *title, char *label)); -void CommentPopDown P((void)); void ICSInputBoxPopUp P((void)); -void ICSInputBoxPopDown P((void)); void FileNamePopUp P((char *label, char *def, char *filter, FileProc proc, char *openMode)); -void FileNamePopDown P((void)); -void FileNameCallback P((Widget w, XtPointer client_data, - XtPointer call_data)); -void FileNameAction P((Widget w, XEvent *event, - String *prms, Cardinal *nprms)); -void AskQuestionReplyAction P((Widget w, XEvent *event, - String *prms, Cardinal *nprms)); -void AskQuestionProc P((Widget w, XEvent *event, - String *prms, Cardinal *nprms)); -void AskQuestionPopDown P((void)); -void PromotionPopDown P((void)); -void PromotionCallback P((Widget w, XtPointer client_data, - XtPointer call_data)); void SelectCommand P((Widget w, XtPointer client_data, XtPointer call_data)); void KeyBindingProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void QuitWrapper P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void TypeInProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void EnterKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void UpKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void DownKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +static void EnterKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +static void UpKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +static void DownKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void TempBackwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void TempForwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); Boolean TempBackwardActive = False; void ManInner P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void DisplayMove P((int moveNumber)); -void DisplayTitle P((char *title)); void ICSInitScript P((void)); -void ErrorPopUp P((char *title, char *text, int modal)); -void ErrorPopDown P((void)); -static char *ExpandPathName P((char *path)); void SelectMove P((Widget w, XEvent * event, String * params, Cardinal * nParams)); -void GameListOptionsPopDown P(()); -void GenericPopDown P(()); void update_ics_width P(()); int get_term_width P(()); int CopyMemoProc P(()); -void DrawArrowHighlight P((int fromX, int fromY, int toX,int toY)); -Boolean IsDrawArrowEnabled P(()); /* * XBoard depends on Xt R4 or higher @@ -330,21 +301,20 @@ int xScreen; Display *xDisplay; Window xBoardWindow; Pixel lightSquareColor, darkSquareColor, whitePieceColor, blackPieceColor, - jailSquareColor, highlightSquareColor, premoveHighlightColor; + highlightSquareColor, premoveHighlightColor, dialogColor, buttonColor; Pixel lowTimeWarningColor; -GC lightSquareGC, darkSquareGC, jailSquareGC, lineGC, wdPieceGC, wlPieceGC, +GC lightSquareGC, darkSquareGC, lineGC, wdPieceGC, wlPieceGC, bdPieceGC, blPieceGC, wbPieceGC, bwPieceGC, coordGC, highlineGC, - wjPieceGC, bjPieceGC, prelineGC, countGC; + prelineGC, countGC; Pixmap iconPixmap, wIconPixmap, bIconPixmap, xMarkPixmap; Widget shellWidget, layoutWidget, formWidget, boardWidget, messageWidget, whiteTimerWidget, blackTimerWidget, titleWidget, widgetList[16], - commentShell, promotionShell, whitePieceMenu, blackPieceMenu, dropMenu, + commentShell, whitePieceMenu, blackPieceMenu, dropMenu, menuBarWidget, buttonBarWidget, editShell, errorShell, analysisShell, - ICSInputShell, fileNameShell, askQuestionShell; + ICSInputShell, fileNameShell; Widget historyShell, evalGraphShell, gameListShell; XSegment secondSegments[BOARD_RANKS + BOARD_FILES + 2]; XSegment gridSegments[BOARD_RANKS + BOARD_FILES + 2]; -XSegment jailGridSegments[BOARD_RANKS + BOARD_FILES + 6]; #if ENABLE_NLS XFontSet fontSet, clockFontSet; #else @@ -355,7 +325,6 @@ Font coordFontID, countFontID; XFontStruct *coordFontStruct, *countFontStruct; XtAppContext appContext; char *layoutName; -char *oldICSInteractionTitle; FileProc fileProc; char *fileOpenMode; @@ -371,9 +340,9 @@ int minX, minY; // [HGM] placement: volatile limits on upper-left corner int smallLayout = 0, tinyLayout = 0, marginW, marginH, // [HGM] for run-time resizing fromX = -1, fromY = -1, toX, toY, commentUp = False, analysisUp = False, - ICSInputBoxUp = False, askQuestionUp = False, - filenameUp = False, promotionUp = False, pmFromX = -1, pmFromY = -1, - errorUp = False, errorExitStatus = -1, defaultLineGap; + ICSInputBoxUp = False, + filenameUp = False, pmFromX = -1, pmFromY = -1, + errorExitStatus = -1, defaultLineGap; Dimension textHeight; Pixel timerForegroundPixel, timerBackgroundPixel; Pixel buttonForegroundPixel, buttonBackgroundPixel; @@ -544,9 +513,6 @@ XtActionsRec boardActions[] = { { "HandlePV", HandlePV }, { "SelectPV", SelectPV }, { "StopPV", StopPV }, - { "FileNameAction", FileNameAction }, - { "AskQuestionProc", AskQuestionProc }, - { "AskQuestionReplyAction", AskQuestionReplyAction }, { "PieceMenuPopup", PieceMenuPopup }, { "WhiteClock", WhiteClock }, { "BlackClock", BlackClock }, @@ -556,18 +522,12 @@ XtActionsRec boardActions[] = { { "TempBackwardProc", TempBackwardProc }, { "TempForwardProc", TempForwardProc }, { "CommentClick", (XtActionProc) CommentClick }, - { "CommentPopDown", (XtActionProc) CommentPopDown }, - { "TagsPopDown", (XtActionProc) TagsPopDown }, - { "ErrorPopDown", (XtActionProc) ErrorPopDown }, - { "ICSInputBoxPopDown", (XtActionProc) ICSInputBoxPopDown }, - { "FileNamePopDown", (XtActionProc) FileNamePopDown }, - { "AskQuestionPopDown", (XtActionProc) AskQuestionPopDown }, { "GameListPopDown", (XtActionProc) GameListPopDown }, { "GameListOptionsPopDown", (XtActionProc) GameListOptionsPopDown }, - { "PromotionPopDown", (XtActionProc) PromotionPopDown }, { "EngineOutputPopDown", (XtActionProc) EngineOutputPopDown }, { "EvalGraphPopDown", (XtActionProc) EvalGraphPopDown }, { "GenericPopDown", (XtActionProc) GenericPopDown }, + { "ErrorPopDown", (XtActionProc) ErrorPopDown }, { "CopyMemoProc", (XtActionProc) CopyMemoProc }, { "SelectMove", (XtActionProc) SelectMove }, { "LoadSelectedProc", LoadSelectedProc }, @@ -576,6 +536,8 @@ XtActionsRec boardActions[] = { { "EnterKeyProc", EnterKeyProc }, { "UpKeyProc", UpKeyProc }, { "DownKeyProc", DownKeyProc }, + { "WheelProc", WheelProc }, + { "TabProc", TabProc }, }; char globalTranslations[] = @@ -683,9 +645,7 @@ char ICSInputTranslations[] = char commentTranslations[] = ": extend-end() select-start() CommentClick() \n"; String xboardResources[] = { - "*fileName*value.translations: #override\\n Return: FileNameAction()", - "*question*value.translations: #override\\n Return: AskQuestionReplyAction()", - "*errorpopup*translations: #override\\n Return: ErrorPopDown()", + "*Error*translations: #override\\n Return: ErrorPopDown()", NULL }; @@ -814,77 +774,6 @@ Warning: No DIR structure found on this system --\n\ } #endif /* HAVE_DIR_STRUCT */ -static char *cnames[9] = { "black", "red", "green", "yellow", "blue", - "magenta", "cyan", "white" }; -typedef struct { - int attr, bg, fg; -} TextColors; -TextColors textColors[(int)NColorClasses]; - -/* String is: "fg, bg, attr". Which is 0, 1, 2 */ -static int -parse_color (char *str, int which) -{ - char *p, buf[100], *d; - int i; - - if (strlen(str) > 99) /* watch bounds on buf */ - return -1; - - p = str; - d = buf; - for (i=0; itype == ButtonPress) { - XtPopdown(promotionShell); - XtDestroyWidget(promotionShell); - promotionUp = False; + PopDown(PromoDlg); ClearHighlights(); fromX = fromY = -1; } else { @@ -3838,38 +3560,6 @@ EditCommentPopUp (int index, char *title, char *text) } void -ICSInputBoxPopUp () -{ - InputBoxPopup(); -} - -extern Option boxOptions[]; - -void -ICSInputSendText () -{ - Widget edit; - int j; - Arg args[16]; - String val; - - edit = boxOptions[0].handle; - j = 0; - XtSetArg(args[j], XtNstring, &val); j++; - XtGetValues(edit, args, j); - SaveInHistory(val); - SendMultiLineToICS(val); - XtCallActionProc(edit, "select-all", NULL, NULL, 0); - XtCallActionProc(edit, "kill-selection", NULL, NULL, 0); -} - -void -ICSInputBoxPopDown () -{ - PopDown(InputBoxDlg); -} - -void CommentPopUp (char *title, char *text) { savedIndex = currentMove; // [HGM] vari @@ -3905,278 +3595,6 @@ FileNamePopUp (char *label, char *def, char *filter, FileProc proc, char *openMo } } -void -FileNamePopDown () -{ - if (!filenameUp) return; - XtPopdown(fileNameShell); - XtDestroyWidget(fileNameShell); - filenameUp = False; - ModeHighlight(); -} - -void -FileNameCallback (Widget w, XtPointer client_data, XtPointer call_data) -{ - String name; - Arg args[16]; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, _("cancel")) == 0) { - FileNamePopDown(); - return; - } - - FileNameAction(w, NULL, NULL, NULL); -} - -void -FileNameAction (Widget w, XEvent *event, String *prms, Cardinal *nprms) -{ - char buf[MSG_SIZ]; - String name; - FILE *f; - char *p, *fullname; - int index; - - name = XawDialogGetValueString(w = XtParent(w)); - - if ((name != NULL) && (*name != NULLCHAR)) { - safeStrCpy(buf, name, sizeof(buf)/sizeof(buf[0]) ); - XtPopdown(w = XtParent(XtParent(w))); - XtDestroyWidget(w); - filenameUp = False; - - p = strrchr(buf, ' '); - if (p == NULL) { - index = 0; - } else { - *p++ = NULLCHAR; - index = atoi(p); - } - fullname = ExpandPathName(buf); - if (!fullname) { - ErrorPopUp(_("Error"), _("Can't open file"), FALSE); - } - else { - f = fopen(fullname, fileOpenMode); - if (f == NULL) { - DisplayError(_("Failed to open file"), errno); - } else { - (void) (*fileProc)(f, index, buf); - } - } - ModeHighlight(); - return; - } - - XtPopdown(w = XtParent(XtParent(w))); - XtDestroyWidget(w); - filenameUp = False; - ModeHighlight(); -} - -void -PromotionPopUp () -{ - Arg args[16]; - Widget dialog, layout; - Position x, y; - Dimension bw_width, pw_width; - int j; - char *PromoChars = "wglcqrbnkac+=\0"; - - j = 0; - XtSetArg(args[j], XtNwidth, &bw_width); j++; - XtGetValues(boardWidget, args, j); - - j = 0; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNtitle, XtNewString(_("Promotion"))); j++; - promotionShell = - XtCreatePopupShell("Promotion", transientShellWidgetClass, - shellWidget, args, j); - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, promotionShell, - layoutArgs, XtNumber(layoutArgs)); - - j = 0; - XtSetArg(args[j], XtNlabel, _("Promote to what?")); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - dialog = XtCreateManagedWidget("promotion", dialogWidgetClass, - layout, args, j); - - if(gameInfo.variant != VariantShogi) { - if(gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove)) { - XawDialogAddButton(dialog, _("Warlord"), PromotionCallback, PromoChars + 0); - XawDialogAddButton(dialog, _("General"), PromotionCallback, PromoChars + 1); - XawDialogAddButton(dialog, _("Lieutenant"), PromotionCallback, PromoChars + 2); - XawDialogAddButton(dialog, _("Captain"), PromotionCallback, PromoChars + 3); - } else { - XawDialogAddButton(dialog, _("Queen"), PromotionCallback, PromoChars + 4); - XawDialogAddButton(dialog, _("Rook"), PromotionCallback, PromoChars + 5); - XawDialogAddButton(dialog, _("Bishop"), PromotionCallback, PromoChars + 6); - XawDialogAddButton(dialog, _("Knight"), PromotionCallback, PromoChars + 7); - } - if (!appData.testLegality || gameInfo.variant == VariantSuicide || - gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove) || - gameInfo.variant == VariantGiveaway) { - XawDialogAddButton(dialog, _("King"), PromotionCallback, PromoChars + 8); - } - if(gameInfo.variant == VariantCapablanca || - gameInfo.variant == VariantGothic || - gameInfo.variant == VariantCapaRandom) { - XawDialogAddButton(dialog, _("Archbishop"), PromotionCallback, PromoChars + 9); - XawDialogAddButton(dialog, _("Chancellor"), PromotionCallback, PromoChars + 10); - } - } else // [HGM] shogi - { - XawDialogAddButton(dialog, _("Promote"), PromotionCallback, PromoChars + 11); - XawDialogAddButton(dialog, _("Defer"), PromotionCallback, PromoChars + 12); - } - XawDialogAddButton(dialog, _("cancel"), PromotionCallback, PromoChars + 13); - - XtRealizeWidget(promotionShell); - CatchDeleteWindow(promotionShell, "PromotionPopDown"); - - j = 0; - XtSetArg(args[j], XtNwidth, &pw_width); j++; - XtGetValues(promotionShell, args, j); - - XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2, - lineGap + squareSize/3 + - ((toY == BOARD_HEIGHT-1) ^ (flipView) ? - 0 : 6*(squareSize + lineGap)), &x, &y); - - j = 0; - XtSetArg(args[j], XtNx, x); j++; - XtSetArg(args[j], XtNy, y); j++; - XtSetValues(promotionShell, args, j); - - XtPopup(promotionShell, XtGrabNone); - - promotionUp = True; -} - -void -PromotionPopDown () -{ - if (!promotionUp) return; - XtPopdown(promotionShell); - XtDestroyWidget(promotionShell); - promotionUp = False; -} - -void -PromotionCallback (Widget w, XtPointer client_data, XtPointer call_data) -{ - int promoChar = * (const char *) client_data; - - PromotionPopDown(); - - if (fromX == -1) return; - - if (! promoChar) { - fromX = fromY = -1; - ClearHighlights(); - return; - } - UserMoveEvent(fromX, fromY, toX, toY, promoChar); - - if (!appData.highlightLastMove || gotPremove) ClearHighlights(); - if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY); - fromX = fromY = -1; -} - - -void -ErrorCallback (Widget w, XtPointer client_data, XtPointer call_data) -{ - dialogError = errorUp = False; - XtPopdown(w = XtParent(XtParent(XtParent(w)))); - XtDestroyWidget(w); - if (errorExitStatus != -1) ExitEvent(errorExitStatus); -} - - -void -ErrorPopDown () -{ - if (!errorUp) return; - dialogError = errorUp = False; - XtPopdown(errorShell); - XtDestroyWidget(errorShell); - if (errorExitStatus != -1) ExitEvent(errorExitStatus); -} - -void -ErrorPopUp (char *title, char *label, int modal) -{ - Arg args[16]; - Widget dialog, layout; - Position x, y; - int xx, yy; - Window junk; - Dimension bw_width, pw_width; - Dimension pw_height; - int i; - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; - XtSetArg(args[i], XtNtitle, title); i++; - errorShell = - XtCreatePopupShell("errorpopup", transientShellWidgetClass, - shellUp[TransientDlg] ? (dialogError = modal = TRUE, shells[TransientDlg]) : shellWidget, args, i); - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, errorShell, - layoutArgs, XtNumber(layoutArgs)); - - i = 0; - XtSetArg(args[i], XtNlabel, label); i++; - XtSetArg(args[i], XtNborderWidth, 0); i++; - dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, - layout, args, i); - - XawDialogAddButton(dialog, _("ok"), ErrorCallback, (XtPointer) dialog); - - XtRealizeWidget(errorShell); - CatchDeleteWindow(errorShell, "ErrorPopDown"); - - i = 0; - XtSetArg(args[i], XtNwidth, &bw_width); i++; - XtGetValues(boardWidget, args, i); - i = 0; - XtSetArg(args[i], XtNwidth, &pw_width); i++; - XtSetArg(args[i], XtNheight, &pw_height); i++; - XtGetValues(errorShell, args, i); - -#ifdef NOTDEF - /* This code seems to tickle an X bug if it is executed too soon - after xboard starts up. The coordinates get transformed as if - the main window was positioned at (0, 0). - */ - XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2, - 0 - pw_height + squareSize / 3, &x, &y); -#else - XTranslateCoordinates(xDisplay, XtWindow(boardWidget), - RootWindowOfScreen(XtScreen(boardWidget)), - (bw_width - pw_width) / 2, - 0 - pw_height + squareSize / 3, &xx, &yy, &junk); - x = xx; - y = yy; -#endif - if (y < 0) y = 0; /*avoid positioning top offscreen*/ - - i = 0; - XtSetArg(args[i], XtNx, x); i++; - XtSetArg(args[i], XtNy, y); i++; - XtSetValues(errorShell, args, i); - - errorUp = True; - XtPopup(errorShell, modal ? XtGrabExclusive : XtGrabNone); -} /* Disable all user input other than deleting the window */ static int frozen = 0; @@ -4278,13 +3696,31 @@ SendPositionSelection (Widget w, Atom *selection, Atom *target, { char *selection_tmp; - if (!selected_fen_position) return False; /* should never happen */ +// if (!selected_fen_position) return False; /* should never happen */ if (*target == XA_STRING || *target == XA_UTF8_STRING(xDisplay)){ + if (!selected_fen_position) { // since it never happens, we use it for indicating a game is being sent + FILE* f = fopen(gameCopyFilename, "r"); // This code, taken from SendGameSelection, now merges the two + long len; + size_t count; + if (f == NULL) return False; + fseek(f, 0, 2); + len = ftell(f); + rewind(f); + selection_tmp = XtMalloc(len + 1); + count = fread(selection_tmp, 1, len, f); + fclose(f); + if (len != count) { + XtFree(selection_tmp); + return False; + } + selection_tmp[len] = NULLCHAR; + } else { /* note: since no XtSelectionDoneProc was registered, Xt will * automatically call XtFree on the value returned. So have to * make a copy of it allocated with XtMalloc */ selection_tmp= XtMalloc(strlen(selected_fen_position)+16); safeStrCpy(selection_tmp, selected_fen_position, strlen(selected_fen_position)+16 ); + } *value_return=selection_tmp; *length_return=strlen(selection_tmp); @@ -4321,17 +3757,14 @@ SendPositionSelection (Widget w, Atom *selection, Atom *target, * Widget which was clicked on was, or what the click event was */ void -CopyPositionProc () +CopySomething (char *src) { + selected_fen_position = src; /* * Set both PRIMARY (the selection) and CLIPBOARD, since we don't * have a notion of a position that is selected but not copied. * See http://www.freedesktop.org/wiki/Specifications/ClipboardsWiki */ - if(gameMode == EditPosition) EditPositionDone(TRUE); - if (selected_fen_position) free(selected_fen_position); - selected_fen_position = (char *)PositionToFEN(currentMove, NULL); - if (!selected_fen_position) return; XtOwnSelection(menuBarWidget, XA_PRIMARY, CurrentTime, SendPositionSelection, @@ -4374,80 +3807,6 @@ PastePositionProc () return; } -static Boolean -SendGameSelection (Widget w, Atom *selection, Atom *target, - Atom *type_return, XtPointer *value_return, - unsigned long *length_return, int *format_return) -{ - char *selection_tmp; - - if (*target == XA_STRING || *target == XA_UTF8_STRING(xDisplay)){ - FILE* f = fopen(gameCopyFilename, "r"); - long len; - size_t count; - if (f == NULL) return False; - fseek(f, 0, 2); - len = ftell(f); - rewind(f); - selection_tmp = XtMalloc(len + 1); - count = fread(selection_tmp, 1, len, f); - fclose(f); - if (len != count) { - XtFree(selection_tmp); - return False; - } - selection_tmp[len] = NULLCHAR; - *value_return = selection_tmp; - *length_return = len; - *type_return = *target; - *format_return = 8; /* bits per byte */ - return True; - } else if (*target == XA_TARGETS(xDisplay)) { - Atom *targets_tmp = (Atom *) XtMalloc(2 * sizeof(Atom)); - targets_tmp[0] = XA_UTF8_STRING(xDisplay); - targets_tmp[1] = XA_STRING; - *value_return = targets_tmp; - *type_return = XA_ATOM; - *length_return = 2; -#if 0 - // This code leads to a read of value_return out of bounds on 64-bit systems. - // Other code which I have seen always sets *format_return to 32 independent of - // sizeof(Atom) without adjusting *length_return. For instance see TextConvertSelection() - // at http://cgit.freedesktop.org/xorg/lib/libXaw/tree/src/Text.c -- BJ - *format_return = 8 * sizeof(Atom); - if (*format_return > 32) { - *length_return *= *format_return / 32; - *format_return = 32; - } -#else - *format_return = 32; -#endif - return True; - } else { - return False; - } -} - -void -CopySomething () -{ - /* - * Set both PRIMARY (the selection) and CLIPBOARD, since we don't - * have a notion of a game that is selected but not copied. - * See http://www.freedesktop.org/wiki/Specifications/ClipboardsWiki - */ - XtOwnSelection(menuBarWidget, XA_PRIMARY, - CurrentTime, - SendGameSelection, - NULL/* lose_ownership_proc */ , - NULL/* transfer_done_proc */); - XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay), - CurrentTime, - SendGameSelection, - NULL/* lose_ownership_proc */ , - NULL/* transfer_done_proc */); -} - /* note: when called from menu all parameters are NULL, so no clue what the * Widget which was clicked on was, or what the click event was */ @@ -4496,72 +3855,48 @@ QuitWrapper (Widget w, XEvent *event, String *prms, Cardinal *nprms) QuitProc(); } +int +ShiftKeys () +{ // bassic primitive for determining if modifier keys are pressed + long int codes[] = { XK_Meta_L, XK_Meta_R, XK_Control_L, XK_Control_R, XK_Shift_L, XK_Shift_R }; + char keys[32]; + int i,j, k=0; + XQueryKeymap(xDisplay,keys); + for(i=0; i<6; i++) { + k <<= 1; + j = XKeysymToKeycode(xDisplay, codes[i]); + k += ( (keys[j>>3]&1<<(j&7)) != 0 ); + } + return k; +} + static void MoveTypeInProc (Widget widget, caddr_t unused, XEvent *event) { - char buf[10], keys[32]; + char buf[10]; KeySym sym; - KeyCode metaL, metaR; //, ctrlL, ctrlR; int n = XLookupString(&(event->xkey), buf, 10, &sym, NULL); - XQueryKeymap(xDisplay,keys); - metaL = XKeysymToKeycode(xDisplay, XK_Meta_L); - metaR = XKeysymToKeycode(xDisplay, XK_Meta_R); -// ctrlL = XKeysymToKeycode(xDisplay, XK_Control_L); -// ctrlR = XKeysymToKeycode(xDisplay, XK_Control_R); if ( n == 1 && *buf >= 32 // printable - && !(keys[metaL>>3]&1<<(metaL&7)) && !(keys[metaR>>3]&1<<(metaR&7)) // no alt key pressed -// && !(keys[ctrlL>>3]&1<<(ctrlL&7)) && !(keys[ctrlR>>3]&1<<(ctrlR&7)) // no ctrl key pressed - ) BoxAutoPopUp (buf); + && !(ShiftKeys() & 0x3C) // no Alt, Ctrl + ) BoxAutoPopUp (buf); } -void +static void UpKeyProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) { // [HGM] input: let up-arrow recall previous line from history - Widget edit; - int j; - Arg args[16]; - String val; - XawTextBlock t; - - if (!shellUp[InputBoxDlg]) return; - edit = boxOptions[0].handle; - j = 0; - XtSetArg(args[j], XtNstring, &val); j++; - XtGetValues(edit, args, j); - val = PrevInHistory(val); - XtCallActionProc(edit, "select-all", NULL, NULL, 0); - XtCallActionProc(edit, "kill-selection", NULL, NULL, 0); - if(val) { - t.ptr = val; t.firstPos = 0; t.length = strlen(val); t.format = XawFmt8Bit; - XawTextReplace(edit, 0, 0, &t); - XawTextSetInsertionPoint(edit, 9999); - } + IcsKey(1); } -void +static void DownKeyProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) { // [HGM] input: let down-arrow recall next line from history - Widget edit; - String val; - XawTextBlock t; - - if (!shellUp[InputBoxDlg]) return; - edit = boxOptions[0].handle; - val = NextInHistory(); - XtCallActionProc(edit, "select-all", NULL, NULL, 0); - XtCallActionProc(edit, "kill-selection", NULL, NULL, 0); - if(val) { - t.ptr = val; t.firstPos = 0; t.length = strlen(val); t.format = XawFmt8Bit; - XawTextReplace(edit, 0, 0, &t); - XawTextSetInsertionPoint(edit, 9999); - } + IcsKey(-1); } -void +static void EnterKeyProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) { - if (shellUp[InputBoxDlg] == True) - ICSInputSendText(); + IcsKey(0); } void @@ -4638,48 +3973,15 @@ DisplayMessage (char *message, char *extMessage) } void -DisplayTitle (char *text) +SetWindowTitle (char *text, char *title, char *icon) { Arg args[16]; int i; - char title[MSG_SIZ]; - char icon[MSG_SIZ]; - - if (text == NULL) text = ""; - if (appData.titleInWindow) { i = 0; XtSetArg(args[i], XtNlabel, text); i++; XtSetValues(titleWidget, args, i); } - - if (*text != NULLCHAR) { - safeStrCpy(icon, text, sizeof(icon)/sizeof(icon[0]) ); - safeStrCpy(title, text, sizeof(title)/sizeof(title[0]) ); - } else if (appData.icsActive) { - snprintf(icon, sizeof(icon), "%s", appData.icsHost); - snprintf(title, sizeof(title), "%s: %s", programName, appData.icsHost); - } else if (appData.cmailGameName[0] != NULLCHAR) { - snprintf(icon, sizeof(icon), "%s", "CMail"); - snprintf(title,sizeof(title), "%s: %s", programName, "CMail"); -#ifdef GOTHIC - // [HGM] license: This stuff should really be done in back-end, but WinBoard already had a pop-up for it - } else if (gameInfo.variant == VariantGothic) { - safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) ); - safeStrCpy(title, GOTHIC, sizeof(title)/sizeof(title[0]) ); -#endif -#ifdef FALCON - } else if (gameInfo.variant == VariantFalcon) { - safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) ); - safeStrCpy(title, FALCON, sizeof(title)/sizeof(title[0]) ); -#endif - } else if (appData.noChessProgram) { - safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) ); - safeStrCpy(title, programName, sizeof(title)/sizeof(title[0]) ); - } else { - safeStrCpy(icon, first.tidy, sizeof(icon)/sizeof(icon[0]) ); - snprintf(title,sizeof(title), "%s: %s", programName, first.tidy); - } i = 0; XtSetArg(args[i], XtNiconName, (XtArgVal) icon); i++; XtSetArg(args[i], XtNtitle, (XtArgVal) title); i++; @@ -4688,79 +3990,6 @@ DisplayTitle (char *text) } -void -DisplayError (String message, int error) -{ - char buf[MSG_SIZ]; - - if (error == 0) { - if (appData.debugMode || appData.matchMode) { - fprintf(stderr, "%s: %s\n", programName, message); - } - } else { - if (appData.debugMode || appData.matchMode) { - fprintf(stderr, "%s: %s: %s\n", - programName, message, strerror(error)); - } - snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error)); - message = buf; - } - ErrorPopUp(_("Error"), message, FALSE); -} - - -void -DisplayMoveError (String message) -{ - fromX = fromY = -1; - ClearHighlights(); - DrawPosition(FALSE, NULL); - if (appData.debugMode || appData.matchMode) { - fprintf(stderr, "%s: %s\n", programName, message); - } - if (appData.popupMoveErrors) { - ErrorPopUp(_("Error"), message, FALSE); - } else { - DisplayMessage(message, ""); - } -} - - -void -DisplayFatalError (String message, int error, int status) -{ - char buf[MSG_SIZ]; - - errorExitStatus = status; - if (error == 0) { - fprintf(stderr, "%s: %s\n", programName, message); - } else { - fprintf(stderr, "%s: %s: %s\n", - programName, message, strerror(error)); - snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error)); - message = buf; - } - if (appData.popupExitMessage && boardWidget && XtIsRealized(boardWidget)) { - ErrorPopUp(status ? _("Fatal Error") : _("Exiting"), message, TRUE); - } else { - ExitEvent(status); - } -} - -void -DisplayInformation (String message) -{ - ErrorPopDown(); - ErrorPopUp(_("Information"), message, TRUE); -} - -void -DisplayNote (String message) -{ - ErrorPopDown(); - ErrorPopUp(_("Note"), message, FALSE); -} - static int NullXErrorCheck (Display *dpy, XErrorEvent *error_event) { @@ -4796,326 +4025,6 @@ DisplayIcsInteractionTitle (String message) fflush(stdout); } -char pendingReplyPrefix[MSG_SIZ]; -ProcRef pendingReplyPR; - -void -AskQuestionProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) -{ - if (*nprms != 4) { - fprintf(stderr, _("AskQuestionProc needed 4 parameters, got %d\n"), - *nprms); - return; - } - AskQuestionEvent(prms[0], prms[1], prms[2], prms[3]); -} - -void -AskQuestionPopDown () -{ - if (!askQuestionUp) return; - XtPopdown(askQuestionShell); - XtDestroyWidget(askQuestionShell); - askQuestionUp = False; -} - -void -AskQuestionReplyAction (Widget w, XEvent *event, String *prms, Cardinal *nprms) -{ - char buf[MSG_SIZ]; - int err; - String reply; - - reply = XawDialogGetValueString(w = XtParent(w)); - safeStrCpy(buf, pendingReplyPrefix, sizeof(buf)/sizeof(buf[0]) ); - if (*buf) strncat(buf, " ", MSG_SIZ - strlen(buf) - 1); - strncat(buf, reply, MSG_SIZ - strlen(buf) - 1); - strncat(buf, "\n", MSG_SIZ - strlen(buf) - 1); - OutputToProcess(pendingReplyPR, buf, strlen(buf), &err); - AskQuestionPopDown(); - - if (err) DisplayFatalError(_("Error writing to chess program"), err, 0); -} - -void -AskQuestionCallback (Widget w, XtPointer client_data, XtPointer call_data) -{ - String name; - Arg args[16]; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, _("cancel")) == 0) { - AskQuestionPopDown(); - } else { - AskQuestionReplyAction(w, NULL, NULL, NULL); - } -} - -void -AskQuestion (char *title, char *question, char *replyPrefix, ProcRef pr) -{ - Arg args[16]; - Widget popup, layout, dialog, edit; - Window root, child; - int x, y, i; - int win_x, win_y; - unsigned int mask; - - safeStrCpy(pendingReplyPrefix, replyPrefix, sizeof(pendingReplyPrefix)/sizeof(pendingReplyPrefix[0]) ); - pendingReplyPR = pr; - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; - XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; - askQuestionShell = popup = - XtCreatePopupShell(title, transientShellWidgetClass, - shellWidget, args, i); - - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, popup, - layoutArgs, XtNumber(layoutArgs)); - - i = 0; - XtSetArg(args[i], XtNlabel, question); i++; - XtSetArg(args[i], XtNvalue, ""); i++; - XtSetArg(args[i], XtNborderWidth, 0); i++; - dialog = XtCreateManagedWidget("question", dialogWidgetClass, - layout, args, i); - - XawDialogAddButton(dialog, _("enter"), AskQuestionCallback, - (XtPointer) dialog); - XawDialogAddButton(dialog, _("cancel"), AskQuestionCallback, - (XtPointer) dialog); - - XtRealizeWidget(popup); - CatchDeleteWindow(popup, "AskQuestionPopDown"); - - XQueryPointer(xDisplay, xBoardWindow, &root, &child, - &x, &y, &win_x, &win_y, &mask); - - XtSetArg(args[0], XtNx, x - 10); - XtSetArg(args[1], XtNy, y - 30); - XtSetValues(popup, args, 2); - - XtPopup(popup, XtGrabExclusive); - askQuestionUp = True; - - edit = XtNameToWidget(dialog, "*value"); - XtSetKeyboardFocus(popup, edit); -} - - -void -PlaySound (char *name) -{ - if (*name == NULLCHAR) { - return; - } else if (strcmp(name, "$") == 0) { - putc(BELLCHAR, stderr); - } else { - char buf[2048]; - char *prefix = "", *sep = ""; - if(appData.soundProgram[0] == NULLCHAR) return; - if(!strchr(name, '/')) { prefix = appData.soundDirectory; sep = "/"; } - snprintf(buf, sizeof(buf), "%s '%s%s%s' &", appData.soundProgram, prefix, sep, name); - system(buf); - } -} - -void -RingBell () -{ - PlaySound(appData.soundMove); -} - -void -PlayIcsWinSound () -{ - PlaySound(appData.soundIcsWin); -} - -void -PlayIcsLossSound () -{ - PlaySound(appData.soundIcsLoss); -} - -void -PlayIcsDrawSound () -{ - PlaySound(appData.soundIcsDraw); -} - -void -PlayIcsUnfinishedSound () -{ - PlaySound(appData.soundIcsUnfinished); -} - -void -PlayAlarmSound () -{ - PlaySound(appData.soundIcsAlarm); -} - -void -PlayTellSound () -{ - PlaySound(appData.soundTell); -} - -void -EchoOn () -{ - system("stty echo"); - noEcho = False; -} - -void -EchoOff () -{ - system("stty -echo"); - noEcho = True; -} - -void -RunCommand (char *buf) -{ - system(buf); -} - -void -Colorize (ColorClass cc, int continuation) -{ - char buf[MSG_SIZ]; - int count, outCount, error; - - if (textColors[(int)cc].bg > 0) { - if (textColors[(int)cc].fg > 0) { - snprintf(buf, MSG_SIZ, "\033[0;%d;%d;%dm", textColors[(int)cc].attr, - textColors[(int)cc].fg, textColors[(int)cc].bg); - } else { - snprintf(buf, MSG_SIZ, "\033[0;%d;%dm", textColors[(int)cc].attr, - textColors[(int)cc].bg); - } - } else { - if (textColors[(int)cc].fg > 0) { - snprintf(buf, MSG_SIZ, "\033[0;%d;%dm", textColors[(int)cc].attr, - textColors[(int)cc].fg); - } else { - snprintf(buf, MSG_SIZ, "\033[0;%dm", textColors[(int)cc].attr); - } - } - count = strlen(buf); - outCount = OutputToProcess(NoProc, buf, count, &error); - if (outCount < count) { - DisplayFatalError(_("Error writing to display"), error, 1); - } - - if (continuation) return; - switch (cc) { - case ColorShout: - PlaySound(appData.soundShout); - break; - case ColorSShout: - PlaySound(appData.soundSShout); - break; - case ColorChannel1: - PlaySound(appData.soundChannel1); - break; - case ColorChannel: - PlaySound(appData.soundChannel); - break; - case ColorKibitz: - PlaySound(appData.soundKibitz); - break; - case ColorTell: - PlaySound(appData.soundTell); - break; - case ColorChallenge: - PlaySound(appData.soundChallenge); - break; - case ColorRequest: - PlaySound(appData.soundRequest); - break; - case ColorSeek: - PlaySound(appData.soundSeek); - break; - case ColorNormal: - case ColorNone: - default: - break; - } -} - -char * -UserName () -{ - return getpwuid(getuid())->pw_name; -} - -static char * -ExpandPathName (char *path) -{ - static char static_buf[4*MSG_SIZ]; - char *d, *s, buf[4*MSG_SIZ]; - struct passwd *pwd; - - s = path; - d = static_buf; - - while (*s && isspace(*s)) - ++s; - - if (!*s) { - *d = 0; - return static_buf; - } - - if (*s == '~') { - if (*(s+1) == '/') { - safeStrCpy(d, getpwuid(getuid())->pw_dir, 4*MSG_SIZ ); - strcat(d, s+1); - } - else { - safeStrCpy(buf, s+1, sizeof(buf)/sizeof(buf[0]) ); - { char *p; if(p = strchr(buf, '/')) *p = 0; } - pwd = getpwnam(buf); - if (!pwd) - { - fprintf(stderr, _("ERROR: Unknown user %s (in path %s)\n"), - buf, path); - return NULL; - } - safeStrCpy(d, pwd->pw_dir, 4*MSG_SIZ ); - strcat(d, strchr(s+1, '/')); - } - } - else - safeStrCpy(d, s, 4*MSG_SIZ ); - - return static_buf; -} - -char * -HostName () -{ - static char host_name[MSG_SIZ]; - -#if HAVE_GETHOSTNAME - gethostname(host_name, MSG_SIZ); - return host_name; -#else /* not HAVE_GETHOSTNAME */ -# if HAVE_SYSINFO && HAVE_SYS_SYSTEMINFO_H - sysinfo(SI_HOSTNAME, host_name, MSG_SIZ); - return host_name; -# else /* not (HAVE_SYSINFO && HAVE_SYS_SYSTEMINFO_H) */ - return "localhost"; -# endif/* not (HAVE_SYSINFO && HAVE_SYS_SYSTEMINFO_H) */ -#endif /* not HAVE_GETHOSTNAME */ -} XtIntervalId delayedEventTimerXID = 0; DelayedEventCallback delayedEventCallback = 0; @@ -5313,258 +4222,6 @@ DisplayBlackClock (long timeRemaining, int highlight) } } -#define CPNone 0 -#define CPReal 1 -#define CPComm 2 -#define CPSock 3 -#define CPLoop 4 -typedef int CPKind; - -typedef struct { - CPKind kind; - int pid; - int fdTo, fdFrom; -} ChildProc; - - -int -StartChildProcess (char *cmdLine, char *dir, ProcRef *pr) -{ - char *argv[64], *p; - int i, pid; - int to_prog[2], from_prog[2]; - ChildProc *cp; - char buf[MSG_SIZ]; - - if (appData.debugMode) { - fprintf(debugFP, "StartChildProcess (dir=\"%s\") %s\n",dir, cmdLine); - } - - /* We do NOT feed the cmdLine to the shell; we just - parse it into blank-separated arguments in the - most simple-minded way possible. - */ - i = 0; - safeStrCpy(buf, cmdLine, sizeof(buf)/sizeof(buf[0]) ); - p = buf; - for (;;) { - while(*p == ' ') p++; - argv[i++] = p; - if(*p == '"' || *p == '\'') - p = strchr(++argv[i-1], *p); - else p = strchr(p, ' '); - if (p == NULL) break; - *p++ = NULLCHAR; - } - argv[i] = NULL; - - SetUpChildIO(to_prog, from_prog); - - if ((pid = fork()) == 0) { - /* Child process */ - // [HGM] PSWBTM: made order resistant against case where fd of created pipe was 0 or 1 - close(to_prog[1]); // first close the unused pipe ends - close(from_prog[0]); - dup2(to_prog[0], 0); // to_prog was created first, nd is the only one to use 0 or 1 - dup2(from_prog[1], 1); - if(to_prog[0] >= 2) close(to_prog[0]); // if 0 or 1, the dup2 already cosed the original - close(from_prog[1]); // and closing again loses one of the pipes! - if(fileno(stderr) >= 2) // better safe than sorry... - dup2(1, fileno(stderr)); /* force stderr to the pipe */ - - if (dir[0] != NULLCHAR && chdir(dir) != 0) { - perror(dir); - exit(1); - } - - nice(appData.niceEngines); // [HGM] nice: adjust priority of engine proc - - execvp(argv[0], argv); - - /* If we get here, exec failed */ - perror(argv[0]); - exit(1); - } - - /* Parent process */ - close(to_prog[0]); - close(from_prog[1]); - - cp = (ChildProc *) calloc(1, sizeof(ChildProc)); - cp->kind = CPReal; - cp->pid = pid; - cp->fdFrom = from_prog[0]; - cp->fdTo = to_prog[1]; - *pr = (ProcRef) cp; - return 0; -} - -// [HGM] kill: implement the 'hard killing' of AS's Winboard_x -static RETSIGTYPE -AlarmCallBack (int n) -{ - return; -} - -void -DestroyChildProcess (ProcRef pr, int signalType) -{ - ChildProc *cp = (ChildProc *) pr; - - if (cp->kind != CPReal) return; - cp->kind = CPNone; - if (signalType == 10) { // [HGM] kill: if it does not terminate in 3 sec, kill - signal(SIGALRM, AlarmCallBack); - alarm(3); - if(wait((int *) 0) == -1) { // process does not terminate on its own accord - kill(cp->pid, SIGKILL); // kill it forcefully - wait((int *) 0); // and wait again - } - } else { - if (signalType) { - kill(cp->pid, signalType == 9 ? SIGKILL : SIGTERM); // [HGM] kill: use hard kill if so requested - } - /* Process is exiting either because of the kill or because of - a quit command sent by the backend; either way, wait for it to die. - */ - wait((int *) 0); - } - close(cp->fdFrom); - close(cp->fdTo); -} - -void -InterruptChildProcess (ProcRef pr) -{ - ChildProc *cp = (ChildProc *) pr; - - if (cp->kind != CPReal) return; - (void) kill(cp->pid, SIGINT); /* stop it thinking */ -} - -int -OpenTelnet (char *host, char *port, ProcRef *pr) -{ - char cmdLine[MSG_SIZ]; - - if (port[0] == NULLCHAR) { - snprintf(cmdLine, sizeof(cmdLine), "%s %s", appData.telnetProgram, host); - } else { - snprintf(cmdLine, sizeof(cmdLine), "%s %s %s", appData.telnetProgram, host, port); - } - return StartChildProcess(cmdLine, "", pr); -} - -int -OpenTCP (char *host, char *port, ProcRef *pr) -{ -#if OMIT_SOCKETS - DisplayFatalError(_("Socket support is not configured in"), 0, 2); -#else /* !OMIT_SOCKETS */ - struct addrinfo hints; - struct addrinfo *ais, *ai; - int error; - int s=0; - ChildProc *cp; - - 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; - } - freeaddrinfo(ais); - - if (error != 0) { - return error; - } - - cp = (ChildProc *) calloc(1, sizeof(ChildProc)); - cp->kind = CPSock; - cp->pid = 0; - cp->fdFrom = s; - cp->fdTo = s; - *pr = (ProcRef) cp; -#endif /* !OMIT_SOCKETS */ - - return 0; -} - -int -OpenCommPort (char *name, ProcRef *pr) -{ - int fd; - ChildProc *cp; - - fd = open(name, 2, 0); - if (fd < 0) return errno; - - cp = (ChildProc *) calloc(1, sizeof(ChildProc)); - cp->kind = CPComm; - cp->pid = 0; - cp->fdFrom = fd; - cp->fdTo = fd; - *pr = (ProcRef) cp; - - return 0; -} - -int -OpenLoopback (ProcRef *pr) -{ - ChildProc *cp; - int to[2], from[2]; - - SetUpChildIO(to, from); - - cp = (ChildProc *) calloc(1, sizeof(ChildProc)); - cp->kind = CPLoop; - cp->pid = 0; - cp->fdFrom = to[0]; /* note not from[0]; we are doing a loopback */ - cp->fdTo = to[1]; - *pr = (ProcRef) cp; - - return 0; -} - -int -OpenRcmd (char *host, char *user, char *cmd, ProcRef *pr) -{ - DisplayFatalError(_("internal rcmd not implemented for Unix"), 0, 1); - return -1; -} - -#define INPUT_SOURCE_BUF_SIZE 8192 - -typedef struct { - CPKind kind; - int fd; - int lineByLine; - char *unused; - InputCallback func; - XtInputId xid; - char buf[INPUT_SOURCE_BUF_SIZE]; - VOIDSTAR closure; -} InputSource; - void DoInputCallback (caddr_t closure, int *source, XtInputId *xid) { @@ -5642,72 +4299,6 @@ RemoveInputSource (InputSourceRef isr) is->xid = 0; } -int -OutputToProcess (ProcRef pr, char *message, int count, int *outError) -{ - static int line = 0; - ChildProc *cp = (ChildProc *) pr; - int outCount; - - if (pr == NoProc) - { - 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); - - if (outCount == -1) - *outError = errno; - else - *outError = 0; - - return outCount; -} - -/* Output message to process, with "ms" milliseconds of delay - between each character. This is needed when sending the logon - script to ICC, which for some reason doesn't like the - instantaneous send. */ -int -OutputToProcessDelayed (ProcRef pr, char *message, int count, int *outError, long msdelay) -{ - ChildProc *cp = (ChildProc *) pr; - int outCount = 0; - int r; - - while (count--) { - r = write(cp->fdTo, message++, 1); - if (r == -1) { - *outError = errno; - return outCount; - } - ++outCount; - if (msdelay >= 0) - TimeDelay(msdelay); - } - - return outCount; -} - /**** Animation code by Hugh Fisher, DCS, ANU. ****/ /* Masks for XPM pieces. Black and white pieces can have @@ -5988,44 +4579,6 @@ SetDragPiece (AnimNr anr, ChessSquare piece) XSetClipMask(xDisplay, animGCs[anr+2], mask); } -#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(); -} - /* [AS] Arrow highlighting support */ void