home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / x / xhearts.zip / XAWCLIEN.C < prev    next >
C/C++ Source or Header  |  1992-01-07  |  51KB  |  1,682 lines

  1. /*****************************************************************
  2. Copyright 1992 by Silicon Graphics Incorporated, Mountain View, CA,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of SGI or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. SGI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. SGI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. /*
  26.  * xawclient.c - X11/Xaw client interface to hearts
  27.  * 
  28.  * Author:    Mike Yang (mikey@sgi.com)
  29.  *        Silicon Graphics, Inc.
  30.  * Date:    Fri Jan 3 1992
  31.  * Copyright (c) 1992 Mike Yang
  32.  */
  33.  
  34. #include <stdlib.h>
  35. #include <malloc.h>
  36. #include <sys/errno.h>
  37. #include <sys/types.h>
  38. #include <sys/stat.h>
  39. #include <fcntl.h>
  40. #include "misc.h"
  41. #include "defs.h"
  42. #include "local.h"
  43. #include "client.h"
  44. #include "gfx.h"
  45. #ifdef SYSV
  46. #include <sys/termio.h>
  47. #endif
  48. #include <X11/cursorfont.h>
  49. #include <X11/Intrinsic.h>
  50. #include <X11/StringDefs.h>
  51. #include <X11/Shell.h>
  52. #include <X11/Xaw/Form.h>
  53. #include <X11/Xaw/Command.h>
  54. #include <X11/Xaw/Label.h>
  55. #include <X11/Xaw/AsciiText.h>
  56. #include <X11/Xaw/Text.h>
  57. #include <X11/Xaw/Simple.h>
  58.  
  59. #ifdef X11R4
  60. #define XawChainTop XtChainTop
  61. #define XawChainBottom XtChainBottom
  62. #define XawChainLeft XtChainLeft
  63. #define XawChainRight XtChainRight
  64. #endif
  65.  
  66. #define NUM_TABLES_ROWS    2
  67. #define NUM_TABLES_COLS    4
  68. #define NUM_TABLES    (NUM_TABLES_ROWS*NUM_TABLES_COLS)
  69.  
  70. static int count;
  71. static Arg args[20];
  72.  
  73. typedef struct _CardInfo {
  74.   int rank;
  75.   int suit;
  76.   struct _CardInfo *next;
  77. } CardInfo;
  78.  
  79. typedef struct {
  80.   CardInfo *head;
  81. } SuitInfo;
  82.  
  83. SuitInfo my_hand[MAX_SUIT+1];
  84.  
  85. XtAppContext appContext;
  86. Widget toplevel, form, displayFrame, displayArea, playArea, scoreArea;
  87. Widget messageLabel, messageArea, messageEntry;
  88. Widget commandArea, showButton = NULL, autoButton = NULL;
  89. Widget quitButton, helpButton;
  90. Widget displayLabels, roundLabel, leadLabel, textArea, playLabelArea;
  91. Widget scorePlayer, scoreScore, scoreTotal;
  92. Widget playerLabels[5], scoreLabels[5], totalLabels[5];
  93. Widget playLabels[4];
  94. Widget optionForm, helpDialog = NULL, playForm, optionHeader;
  95. Widget gameBox, anotherGame, newGame, moreGames, quitGame, helpGame;
  96. Widget gamesHeader, gamesFrame, gamesRC, gamesMessage;
  97. Boolean showOld, *anotherPtr;
  98. CardInfo playCards[4], lastCards[4];
  99. char playNames[4][256], lastNames[4][256];
  100. XtInputId distId = None, dealerId = None;
  101. Boolean readingCard;
  102. Cursor cardCursor = None;
  103. Dimension globalTableHeight;
  104.  
  105. resizeWidget(w, width, height)
  106. Widget w;
  107. Dimension width, height;
  108. {
  109.   Dimension bw;
  110.   Position x, y;
  111.  
  112.   count = 0;
  113.   if (!width) {
  114.     XtSetArg(args[count], XtNwidth, &width);  count++;
  115.   }
  116.   if (!height) {
  117.     XtSetArg(args[count], XtNheight, &height);  count++;
  118.   }
  119.   XtSetArg(args[count], XtNborderWidth, &bw);  count++;
  120.   XtSetArg(args[count], XtNx, &x);  count++;
  121.   XtSetArg(args[count], XtNy, &y);  count++;
  122.   XtGetValues(w, args, count);
  123.   count = 0;
  124.   XtSetArg(args[count], XtNwidth, width);  count++;
  125.   XtSetArg(args[count], XtNheight, height);  count++;
  126.   XtSetValues(w, args, count);
  127.   XtConfigureWidget(w, x, y, width, height, bw);
  128. }
  129.  
  130. updateLabel(w)
  131. Widget w;
  132. {
  133.   XEvent event;
  134.  
  135.   while (XCheckTypedWindowEvent(XtDisplay(w), XtWindow(w), Expose, &event)) {
  136.     XtDispatchEvent(&event);
  137.   }
  138. }
  139.  
  140. updateDisplay()
  141. {
  142.   int i;
  143.  
  144.   for (i=0; i<4; i++) {
  145.     updateLabel(playLabels[i]);
  146.   }
  147.   updateLabel(roundLabel);
  148.   updateLabel(leadLabel);
  149. }
  150.  
  151. Rank
  152. convertRank(rank)
  153. int rank;
  154. {
  155.   if (rank == 13) {
  156.     return Ace;
  157.   } else {
  158.     return rank;
  159.   }
  160. }
  161.  
  162. Suit
  163. convertSuit(suit)
  164. int suit;
  165. {
  166.   Suit s;
  167.  
  168.   switch (suit) {
  169.   case SPADES:
  170.     s = Spade;
  171.     break;
  172.   case HEARTS:
  173.     s = Heart;
  174.     break;
  175.   case DIAMONDS:
  176.     s = Diamond;
  177.     break;
  178.   case CLUBS:
  179.     s = Club;
  180.     break;
  181.   }
  182.   return s;
  183. }
  184.  
  185. void
  186. showPlayArea(cards, names)
  187. CardInfo *cards;
  188. char names[4][256];
  189. {
  190.   int i;
  191.  
  192.   for (i=0; i<4; i++) {
  193.     if (cards[i].rank) {
  194.       paint_card(XtWindow(playArea), i*STACK_WIDTH, 0,
  195.          convertRank(cards[i].rank), convertSuit(cards[i].suit), 0);
  196.     } else {
  197.       XClearArea(XtDisplay(playArea), XtWindow(playArea), i*STACK_WIDTH, 0,
  198.          STACK_WIDTH, 0, False);
  199.     }
  200.     count = 0;
  201.     if (cards[i].rank) {
  202.       XtSetArg(args[count], XtNlabel, names[i]);  count++;
  203.     } else {
  204.       XtSetArg(args[count], XtNlabel, " ");  count++;
  205.     }
  206.     XtSetValues(playLabels[i], args, count);
  207.   }
  208. }
  209.  
  210. void
  211. setShowOld(v)
  212. Boolean v;
  213. {
  214.   if (showOld != v) {
  215.     showOld = v;
  216.     if (showOld) {
  217.       showPlayArea(lastCards, lastNames);
  218.     } else {
  219.       showPlayArea(playCards, playNames);
  220.     }
  221.   }
  222. }
  223.  
  224. void
  225. setReadingCard(v)
  226. Boolean v;
  227. {
  228.   if (readingCard != v) {
  229.     readingCard = v;
  230.     if (cardCursor == None) {
  231.       cardCursor = XCreateFontCursor(XtDisplay(toplevel), XC_hand1);
  232.     }
  233.     if (XtIsRealized(displayArea)) {
  234.       if (readingCard) {
  235.     XDefineCursor(XtDisplay(displayArea), XtWindow(displayArea),
  236.               cardCursor);
  237.       } else {
  238.     XUndefineCursor(XtDisplay(displayArea), XtWindow(displayArea));
  239.       }
  240.       XFlush(XtDisplay(displayArea));
  241.     }
  242.     if (!readingCard && showOld) {
  243.       setShowOld(False);
  244.     }
  245.   }
  246. }
  247.  
  248. /**********************************************************************/
  249.  
  250. void
  251. exposeDisplayArea(w, client_data, call_data)
  252. Widget w;
  253. XtPointer client_data;
  254. XtPointer call_data;
  255. {
  256.   Suit suit;
  257.  
  258.   for (suit=CLUBS; suit<=SPADES; suit++) {
  259.     print_cards(suit);
  260.   }
  261. }
  262.  
  263. void
  264. displaySelect(w, client_data, event)
  265. Widget w;
  266. XtPointer client_data;
  267. XEvent *event;
  268. {
  269.   int suit, card, count;
  270.   CardInfo *ptr, *cardSelected;
  271.   char rch, sch;
  272.   static char rnames[] = " 23456789TJQKA";
  273.  
  274.   cardSelected = NULL;
  275.   if (readingCard &&
  276.       event->type == ButtonPress && event->xbutton.button == Button1) {
  277.     suit = (event->xbutton.x/STACK_WIDTH)+1;
  278.     card = (event->xbutton.y/CARD_DELTA)+1;
  279.     if (event->xbutton.x % STACK_WIDTH > CARD_WIDTH) {
  280.       /* clicked on space between stacks */
  281.     } else if (suit > 4) {
  282.       /* clicked outside stacks */
  283.     } else {
  284.       ptr = my_hand[suit].head;
  285.       count = 0;
  286.       while (count < card && ptr->next) {
  287.     count++;
  288.     ptr = ptr->next;
  289.       }
  290.       if (count == card) {
  291.     cardSelected = ptr;
  292.       } else if (count < card &&
  293.          event->xbutton.y-(count-1)*CARD_DELTA < CARD_HEIGHT) {
  294.     /* clicked on last card */
  295.     cardSelected = ptr;
  296.       } else {
  297.     /* clicked below stack */
  298.       }
  299.       if (!ptr->rank) {
  300.     cardSelected = NULL;
  301.       }
  302.     }
  303.   }
  304.   if (cardSelected) {
  305.     rch = rnames[cardSelected->rank];
  306.     switch (cardSelected->suit) {
  307.     case SPADES:
  308.       sch = 's';
  309.       break;
  310.     case HEARTS:
  311.       sch = 'h';
  312.       break;
  313.     case DIAMONDS:
  314.       sch = 'd';
  315.       break;
  316.     case CLUBS:
  317.       sch = 'c';
  318.       break;
  319.     }
  320.     send_card(rch, sch);
  321.     setReadingCard(False);
  322.     erase_window(TEXT_WINDOW);
  323.   } else {
  324.     XBell(XtDisplay(toplevel), 0);
  325.   }
  326. }
  327.  
  328. void
  329. show_button(w, client_data, call_data)
  330. Widget w;
  331. XtPointer client_data;
  332. XtPointer call_data;
  333. {
  334.   if (readingCard) {
  335.     setShowOld(!showOld);
  336.   }
  337. }
  338.  
  339. void
  340. auto_play(w, client_data, call_data)
  341. Widget w;
  342. XtPointer client_data;
  343. XtPointer call_data;
  344. {
  345.   if (readingCard) {
  346.     send_auto();
  347.     setReadingCard(False);
  348.     erase_window(TEXT_WINDOW);
  349.   }
  350. }
  351.  
  352. void
  353. quit_game(w, client_data, call_data)
  354. Widget w;
  355. XtPointer client_data;
  356. XtPointer call_data;
  357. {
  358.   wimp_out();
  359. }
  360.  
  361. void
  362. help_away(w, client_data, call_data)
  363. Widget w;
  364. XtPointer client_data;
  365. XtPointer call_data;
  366. {
  367.   XtPopdown(helpDialog);
  368. }
  369.  
  370. void
  371. help_me(w, client_data, call_data)
  372. Widget w;
  373. XtPointer client_data;
  374. XtPointer call_data;
  375. {
  376.   Widget form, text, okButton, label;
  377.   char filename[256];
  378.   int fildes;
  379.   struct stat buf;
  380.   char *data;
  381.  
  382.   if (!helpDialog) {
  383.     count = 0;
  384.     helpDialog = XtCreatePopupShell("xawhearts help", topLevelShellWidgetClass,
  385.                     toplevel, args, count);
  386.     count = 0;
  387.     XtSetArg(args[count], XtNborderWidth, 0);  count++;
  388.     form = XtCreateManagedWidget("helpForm", formWidgetClass, helpDialog,
  389.                  args, count);
  390.  
  391.     count = 0;
  392.     XtSetArg(args[count], XtNscrollVertical, True);  count++;
  393.     XtSetArg(args[count], XtNheight, 200);  count++;
  394.     XtSetArg(args[count], XtNwidth, 700);  count++;
  395.     text = XtCreateManagedWidget("helpText", asciiTextWidgetClass, form,
  396.                  args, count);
  397.  
  398.     count = 0;
  399.     XtSetArg(args[count], XtNborderWidth, 0);  count++;
  400.     XtSetArg(args[count], XtNfromVert, text);  count++;
  401.     XtSetArg(args[count], XtNvertDistance, 10);  count++;
  402.     XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  403.     XtSetArg(args[count], XtNlabel, "Xawhearts, an Xaw interface to hearts.  Mike Yang, Silicon Graphics, mikey@sgi.com");  count++;
  404.     label = XtCreateManagedWidget("label", labelWidgetClass, form,
  405.                   args, count);
  406.  
  407.     count = 0;
  408.     XtSetArg(args[count], XtNfromVert, text);  count++;
  409.     XtSetArg(args[count], XtNvertDistance, 10);  count++;
  410.     XtSetArg(args[count], XtNfromHoriz, label);  count++;
  411.     XtSetArg(args[count], XtNhorizDistance, 10);  count++;
  412.     XtSetArg(args[count], XtNleft, XawChainRight);  count++;
  413.     XtSetArg(args[count], XtNright, XawChainRight);  count++;
  414.     XtSetArg(args[count], XtNtop, XawChainBottom);  count++;
  415.     XtSetArg(args[count], XtNbottom, XawChainBottom);  count++;
  416.     XtSetArg(args[count], XtNlabel, "OK");  count++;
  417.     okButton = XtCreateManagedWidget("helpOK", commandWidgetClass, form,
  418.                      args, count);
  419.     XtAddCallback(okButton, XtNcallback, help_away, NULL);
  420.  
  421.     sprintf(filename, "%s/%s", HEARTSLIB, INSTRUCT);
  422.     if ((fildes = open(filename, O_RDONLY)) != -1) {
  423.       fstat(fildes, &buf);
  424.       data = (char *) malloc((size_t) buf.st_size+1);
  425.       read(fildes, data, (unsigned) buf.st_size);
  426.       data[buf.st_size] = '\0';
  427.       close(fildes);
  428.       count = 0;
  429.       XtSetArg(args[count], XtNstring, data);  count++;
  430.       XtSetValues(text, args, count);
  431.       free(data);
  432.     } else {
  433.       count = 0;
  434.       XtSetArg(args[count], XtNstring, "Help file missing.\n");  count++;
  435.       XtSetValues(text, args, count);
  436.     }
  437.   }
  438.   XtPopup(helpDialog, XtGrabNone);
  439. }
  440.  
  441. void
  442. exposePlayArea(w, client_data, call_data)
  443. Widget w;
  444. XtPointer client_data;
  445. XtPointer call_data;
  446. {
  447.   if (showOld) {
  448.     showPlayArea(lastCards, lastNames);
  449.   } else {
  450.     showPlayArea(playCards, playNames);
  451.   }
  452. }
  453.  
  454. void
  455. another_game(w, client_data, call_data)
  456. Widget w;
  457. XtPointer client_data;
  458. XtPointer call_data;
  459. {
  460.   *anotherPtr = TRUE;
  461.   if (!first_game) {
  462.     joined = TRUE;
  463.   }
  464. }
  465.  
  466. void
  467. new_game(w, client_data, call_data)
  468. Widget w;
  469. XtPointer client_data;
  470. XtPointer call_data;
  471. {
  472.   start_new_game();
  473.   joined = TRUE;
  474. }
  475.  
  476. void
  477. more_games(w, client_data, call_data)
  478. Widget w;
  479. XtPointer client_data;
  480. XtPointer call_data;
  481. {
  482.   if (table_count > NUM_TABLES) {
  483.     if ((cur_screen_table += NUM_TABLES) > table_count) {
  484.       cur_screen_table = 1;
  485.     }
  486.     show_tables(cur_screen_table);
  487.   }
  488. }
  489.  
  490. void
  491. tableSelect(w, client_data, event)
  492. Widget w;
  493. XtPointer client_data;
  494. XEvent *event;
  495. {
  496.   int i;
  497.   Widget *widgets;
  498.   table_ptr cur_ptr;
  499.  
  500.   if (table_count && first_game &&
  501.       event->type == ButtonPress && event->xbutton.button == Button1) {
  502.     cur_ptr = first_table;
  503.     for (i=0; i<table_count; i++) {
  504.       if (cur_ptr->data && !cur_ptr->closed) {
  505.     widgets = (Widget *) cur_ptr->data;
  506.     if (w == widgets[1]) {
  507.       join_game(cur_ptr->table_id);
  508.       joined = TRUE;
  509.       return;
  510.     }
  511.       }
  512.       cur_ptr = cur_ptr->next_table;
  513.     }
  514.   } else if (XtIsSensitive(anotherGame)) {
  515.     another_game(w, NULL, NULL);
  516.   }
  517. }
  518.  
  519. void
  520. send_msg(w, event, params, num_params)
  521. Widget w;
  522. XEvent *event;
  523. String *params;
  524. Cardinal *num_params;
  525. {
  526.   char *msg;
  527.  
  528.   count = 0;
  529.   XtSetArg(args[count], XtNstring, &msg);  count++;
  530.   XtGetValues(messageEntry, args, count);
  531.   send_message(msg);
  532.   count = 0;
  533.   XtSetArg(args[count], XtNstring, "");  count++;
  534.   XtSetValues(messageEntry, args, count);
  535. }
  536.  
  537. /**********************************************************************/
  538.  
  539. void
  540. dealerInput(client_data, source, id)
  541. XtPointer client_data;
  542. int *source;
  543. XtInputId *id;
  544. {
  545.   fd_type read_fd;
  546.   int nready;
  547.   struct timeval timeout;
  548.  
  549.   timeout.tv_sec = 0;
  550.   timeout.tv_usec = 0;
  551.   fd_init(dealer_socket, &read_fd);
  552.   while (dealerId &&
  553.      (nready = select(WIDTH, &read_fd, (fd_type *) 0, (fd_type *) 0,
  554.               &timeout)) && nready > 0) {
  555.     do_socket();
  556.   }
  557. }
  558.  
  559. void
  560. distInput(client_data, source, id)
  561. XtPointer client_data;
  562. int *source;
  563. XtInputId *id;
  564. {
  565.   fd_type read_fd;
  566.   int nready;
  567.   struct timeval timeout;
  568.  
  569.   timeout.tv_sec = 0;
  570.   timeout.tv_usec = 0;
  571.   fd_init(dist_socket, &read_fd);
  572.   while (distId &&
  573.      (nready = select(WIDTH, &read_fd, (fd_type *) 0, (fd_type *) 0,
  574.               &timeout)) && nready > 0) {
  575.     do_dist();
  576.   }
  577. }
  578.  
  579. Widget
  580. buildScoreLabels(parent, header, array)
  581. Widget parent;
  582. char *header;
  583. Widget *array;
  584. {
  585.   Widget rc, last;
  586.   Dimension width;
  587.   int each;
  588.  
  589.   count = 0;
  590.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  591.   rc = XtCreateManagedWidget("scoresColumn", formWidgetClass, parent,
  592.                  args, count);
  593.   count = 0;
  594.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  595.   if (array == playerLabels) {
  596.     XtSetArg(args[count], XtNjustify, XtJustifyLeft);  count++;
  597.   } else {
  598.     XtSetArg(args[count], XtNjustify, XtJustifyRight);  count++;
  599.   }
  600.   XtSetArg(args[count], XtNlabel, header);  count++;
  601.   array[0] = XtCreateManagedWidget("header", labelWidgetClass, rc,
  602.                    args, count);
  603.   count = 0;
  604.   XtSetArg(args[count], XtNwidth, &width);  count++;
  605.   XtGetValues(array[0], args, count);
  606.   last = array[0];
  607.   for (each=1; each<=4; each++) {
  608.     count = 0;
  609.     XtSetArg(args[count], XtNborderWidth, 0);  count++;
  610.     if (array == playerLabels) {
  611.       XtSetArg(args[count], XtNjustify, XtJustifyLeft);  count++;
  612.     } else {
  613.       XtSetArg(args[count], XtNjustify, XtJustifyRight);  count++;
  614.     }
  615.     XtSetArg(args[count], XtNlabel, " ");  count++; 
  616.     XtSetArg(args[count], XtNfromVert, last);  count++;
  617.     XtSetArg(args[count], XtNwidth, width);  count++;
  618.     array[each] = XtCreateManagedWidget("label", labelWidgetClass, rc,
  619.                     args, count);
  620.     last = array[each];
  621.   }
  622.   return rc;
  623. }
  624.  
  625. void
  626. buildScoreArea(parent)
  627. Widget parent;
  628. {
  629.   Widget rc, p, s, t;
  630.  
  631.   count = 0;
  632.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  633.   rc = XtCreateManagedWidget("scoreArea", formWidgetClass, parent,
  634.                  args, count);
  635.   p = buildScoreLabels(rc, "Player:      ", playerLabels);
  636.   s = buildScoreLabels(rc, "Score:", scoreLabels);
  637.   count = 0;
  638.   XtSetArg(args[count], XtNfromHoriz, p);  count++;
  639.   XtSetValues(s, args, count);
  640.   t = buildScoreLabels(rc, "Total:", totalLabels);
  641.   count = 0;
  642.   XtSetArg(args[count], XtNfromHoriz, s);  count++;
  643.   XtSetValues(t, args, count);
  644. }
  645.  
  646. void
  647. buildCommandArea(parent)
  648. Widget parent;
  649. {
  650.   Widget rc;
  651.  
  652.   count = 0;
  653.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  654.   rc = XtCreateManagedWidget("commandArea", formWidgetClass, parent,
  655.                  args, count);
  656.   count = 0;
  657.   XtSetArg(args[count], XtNlabel, "Toggle Last");  count++;
  658.   showButton = XtCreateManagedWidget("showButton", commandWidgetClass, rc,
  659.                      args, count);
  660.   XtAddCallback(showButton, XtNcallback, show_button, NULL);
  661.   count = 0;
  662.   XtSetArg(args[count], XtNlabel, "Auto Play");  count++;
  663.   XtSetArg(args[count], XtNfromHoriz, showButton);  count++;
  664.   autoButton = XtCreateManagedWidget("autoButton", commandWidgetClass, rc,
  665.                      args, count);
  666.   XtAddCallback(autoButton, XtNcallback, auto_play, NULL);
  667.   count = 0;
  668.   XtSetArg(args[count], XtNlabel, "Quit");  count++;
  669.   XtSetArg(args[count], XtNfromHoriz, autoButton);  count++;
  670.   quitButton = XtCreateManagedWidget("quitButton", commandWidgetClass, rc,
  671.                      args, count);
  672.   XtAddCallback(quitButton, XtNcallback, quit_game, NULL);
  673.   count = 0;
  674.   XtSetArg(args[count], XtNlabel, "Help");  count++;
  675.   XtSetArg(args[count], XtNfromHoriz, quitButton);  count++;
  676.   helpButton = XtCreateManagedWidget("helpButton", commandWidgetClass, rc,
  677.                      args, count);
  678.   XtAddCallback(helpButton, XtNcallback, help_me, NULL);
  679. }
  680.  
  681. void
  682. buildInterface(parent)
  683. Widget parent;
  684. {
  685.   Widget form;
  686.  
  687.   static String textTranslations = "<Key>Return:doreturn()";
  688.   static XtActionsRec actionTable[] = {
  689.     {"doreturn", send_msg},
  690.     {NULL, NULL},
  691.   };
  692.  
  693.   count = 0;
  694.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  695.   form = XtCreateManagedWidget("form", formWidgetClass, parent, args, count);
  696.  
  697.   count = 0;
  698.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  699.   XtSetArg(args[count], XtNright, XawChainLeft);  count++;
  700.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  701.   XtSetArg(args[count], XtNbottom, XawChainTop);  count++;
  702.   XtSetArg(args[count], XtNdefaultDistance, STACK_SPACING);  count++;
  703.   displayFrame = XtCreateManagedWidget("displayFrame", formWidgetClass, form,
  704.                        args, count);
  705.  
  706.   count = 0;
  707.   XtSetArg(args[count], XtNvertDistance, 10);  count++;
  708.   XtSetArg(args[count], XtNhorizDistance, 10);  count++;
  709.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  710.   XtSetArg(args[count], XtNwidth, 4*STACK_WIDTH-STACK_SPACING+2);  count++;
  711.   XtSetArg(args[count], XtNheight, 12*CARD_DELTA+CARD_HEIGHT+2);  count++;
  712.   displayArea = XtCreateManagedWidget("displayArea", simpleWidgetClass,
  713.                       displayFrame, args, count);
  714.   XtAddEventHandler(displayArea, ExposureMask, False, exposeDisplayArea, NULL);
  715.   XtAddEventHandler(displayArea, ButtonPressMask, False, displaySelect, NULL);
  716.  
  717.   count = 0;
  718.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  719.   XtSetArg(args[count], XtNright, XawChainLeft);  count++;
  720.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  721.   XtSetArg(args[count], XtNbottom, XawChainTop);  count++;
  722.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  723.   XtSetArg(args[count], XtNfromVert, displayFrame);  count++;
  724.   XtSetArg(args[count], XtNvertDistance, 10);  count++;
  725. /* adjust for display frame margin */
  726.   XtSetArg(args[count], XtNhorizDistance, 10);  count++;
  727.   XtSetArg(args[count], XtNwidth, 4*STACK_WIDTH-STACK_SPACING+2);  count++;
  728.   XtSetArg(args[count], XtNheight, CARD_HEIGHT+2);  count++;
  729.   playArea = XtCreateManagedWidget("playArea", formWidgetClass,
  730.                    form, args, count);
  731.   XtAddEventHandler(playArea, ExposureMask, False, exposePlayArea, NULL);
  732.  
  733.   count = 0;
  734.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  735.   XtSetArg(args[count], XtNright, XawChainLeft);  count++;
  736.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  737.   XtSetArg(args[count], XtNbottom, XawChainTop);  count++;
  738.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  739.   XtSetArg(args[count], XtNfromVert, playArea);  count++;
  740.   XtSetArg(args[count], XtNvertDistance, 10);  count++;
  741. /* adjust for display frame margin */
  742.   XtSetArg(args[count], XtNhorizDistance, 10);  count++;
  743.   playLabelArea = XtCreateManagedWidget("playLabelArea", formWidgetClass,
  744.                     form, args, count);
  745.  
  746.   count = 0;
  747.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  748.   XtSetArg(args[count], XtNlabel, " ");  count++;
  749.   XtSetArg(args[count], XtNwidth, CARD_WIDTH);  count++;
  750.   XtSetArg(args[count], XtNresize, False);  count++;
  751.   playLabels[0] = XtCreateManagedWidget("playLabel", labelWidgetClass,
  752.                     playLabelArea, args, count);
  753.   count = 0;
  754.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  755.   XtSetArg(args[count], XtNlabel, " ");  count++;
  756.   XtSetArg(args[count], XtNwidth, CARD_WIDTH);  count++;
  757.   XtSetArg(args[count], XtNfromHoriz, playLabels[0]);  count++;
  758.   XtSetArg(args[count], XtNhorizDistance, STACK_SPACING);  count++;
  759.   XtSetArg(args[count], XtNresize, False);  count++;
  760.   playLabels[1] = XtCreateManagedWidget("playLabel", labelWidgetClass,
  761.                     playLabelArea, args, count);
  762.   count = 0;
  763.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  764.   XtSetArg(args[count], XtNlabel, " ");  count++;
  765.   XtSetArg(args[count], XtNwidth, CARD_WIDTH);  count++;
  766.   XtSetArg(args[count], XtNfromHoriz, playLabels[1]);  count++;
  767.   XtSetArg(args[count], XtNhorizDistance, STACK_SPACING);  count++;
  768.   XtSetArg(args[count], XtNresize, False);  count++;
  769.   playLabels[2] = XtCreateManagedWidget("playLabel", labelWidgetClass,
  770.                     playLabelArea, args, count);
  771.   count = 0;
  772.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  773.   XtSetArg(args[count], XtNlabel, " ");  count++;
  774.   XtSetArg(args[count], XtNwidth, CARD_WIDTH);  count++;
  775.   XtSetArg(args[count], XtNfromHoriz, playLabels[2]);  count++;
  776.   XtSetArg(args[count], XtNhorizDistance, STACK_SPACING);  count++;
  777.   XtSetArg(args[count], XtNresize, False);  count++;
  778.   playLabels[3] = XtCreateManagedWidget("playLabel", labelWidgetClass,
  779.                     playLabelArea, args, count);
  780.  
  781.   count = 0;
  782.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  783.   XtSetArg(args[count], XtNright, XawChainRight);  count++;
  784.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  785.   XtSetArg(args[count], XtNfromHoriz, displayFrame);  count++;
  786.   XtSetArg(args[count], XtNhorizDistance, 10);  count++;
  787.   displayLabels = XtCreateManagedWidget("displayLabels", formWidgetClass,
  788.                     form, args, count);
  789.  
  790.   count = 0;
  791.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  792.   XtSetArg(args[count], XtNright, XawChainRight);  count++;
  793.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  794.   XtSetArg(args[count], XtNlabel, "New hand...");  count++;
  795.   XtSetArg(args[count], XtNjustify, XtJustifyLeft);  count++;
  796.   XtSetArg(args[count], XtNwidth, 10);  count++;
  797.   roundLabel = XtCreateManagedWidget("roundLabel", labelWidgetClass,
  798.                      displayLabels, args, count);
  799.  
  800.   count = 0;
  801.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  802.   XtSetArg(args[count], XtNright, XawChainRight);  count++;
  803.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  804.   XtSetArg(args[count], XtNlabel, "Round: 1");  count++;
  805.   XtSetArg(args[count], XtNjustify, XtJustifyLeft);  count++;
  806.   XtSetArg(args[count], XtNfromVert, roundLabel);  count++;
  807.   XtSetArg(args[count], XtNwidth, 10);  count++;
  808.   leadLabel = XtCreateManagedWidget("roundLabel", labelWidgetClass,
  809.                     displayLabels, args, count);
  810.  
  811.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  812.   XtSetArg(args[count], XtNright, XawChainRight);  count++;
  813.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  814.   XtSetArg(args[count], XtNbottom, XawChainTop);  count++;
  815.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  816.   XtSetArg(args[count], XtNlabel, " ");  count++;
  817.   XtSetArg(args[count], XtNjustify, XtJustifyLeft);  count++;
  818.   XtSetArg(args[count], XtNfromVert, leadLabel);  count++;
  819.   XtSetArg(args[count], XtNwidth, 10);  count++;
  820.   textArea = XtCreateManagedWidget("textArea", labelWidgetClass,
  821.                     displayLabels, args, count);
  822.   count = 0;
  823.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  824.   XtSetArg(args[count], XtNright, XawChainLeft);  count++;
  825.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  826.   XtSetArg(args[count], XtNbottom, XawChainTop);  count++;
  827.   scoreArea = XtCreateManagedWidget("scoreArea", formWidgetClass,
  828.                     form, args, count);
  829.   XtManageChild(scoreArea);
  830.   buildScoreArea(scoreArea);
  831.  
  832.   count = 0;
  833.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  834.   XtSetArg(args[count], XtNright, XawChainLeft);  count++;
  835.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  836.   XtSetArg(args[count], XtNbottom, XawChainTop);  count++;
  837.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  838.   XtSetArg(args[count], XtNlabel, "Messages:");  count++;
  839.   XtSetArg(args[count], XtNfromVert, scoreArea);  count++;
  840.   XtSetArg(args[count], XtNvertDistance, 10);  count++;
  841.   XtSetArg(args[count], XtNfromHoriz, displayFrame);  count++;
  842.   XtSetArg(args[count], XtNhorizDistance, 10);  count++;
  843.   XtSetArg(args[count], XtNjustify, XtJustifyLeft);  count++;
  844.   messageLabel = XtCreateManagedWidget("messageLabel", labelWidgetClass,
  845.                        form, args, count);
  846.  
  847.   count = 0;
  848.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  849.   XtSetArg(args[count], XtNright, XawChainRight);  count++; 
  850.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  851.   XtSetArg(args[count], XtNbottom, XawChainBottom);  count++;
  852.   XtSetArg(args[count], XtNscrollVertical, True);  count++;
  853. /* The height is important, so that the buttons line up with the bottom
  854.    of the screen.  Unfortunately, I can't figure out how to do the
  855.    form constraints to make this happen cleanly. */
  856.   XtSetArg(args[count], XtNheight, 430);  count++;
  857.   XtSetArg(args[count], XtNwidth, 500);  count++;
  858.   XtSetArg(args[count], XtNfromVert, messageLabel);  count++;
  859.   XtSetArg(args[count], XtNfromHoriz, displayFrame);  count++;
  860.   XtSetArg(args[count], XtNhorizDistance, 10);  count++;
  861.   messageArea = XtCreateManagedWidget("messageArea", asciiTextWidgetClass,
  862.                       form, args, count);
  863.  
  864.   count = 0;
  865.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  866.   XtSetArg(args[count], XtNright, XawChainRight);  count++;
  867.   XtSetArg(args[count], XtNtop, XawChainBottom);  count++;
  868.   XtSetArg(args[count], XtNbottom, XawChainBottom);  count++;
  869.   XtSetArg(args[count], XtNwidth, 500);  count++;
  870.   XtSetArg(args[count], XtNfromVert, messageArea);  count++;
  871.   XtSetArg(args[count], XtNfromHoriz, displayFrame);  count++;
  872.   XtSetArg(args[count], XtNhorizDistance, 10);  count++;
  873.   XtSetArg(args[count], XtNeditType, XawtextEdit);  count++;
  874.   messageEntry = XtCreateManagedWidget("messageEntry", asciiTextWidgetClass,
  875.                       form, args, count);
  876.   XtOverrideTranslations(messageEntry,
  877.              XtParseTranslationTable(textTranslations));
  878.   XtAppAddActions(XtWidgetToApplicationContext(messageEntry),
  879.           actionTable, XtNumber(actionTable));
  880.  
  881.   count = 0;
  882.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  883.   XtSetArg(args[count], XtNright, XawChainLeft);  count++;
  884.   XtSetArg(args[count], XtNtop, XawChainBottom);  count++;
  885.   XtSetArg(args[count], XtNbottom, XawChainBottom);  count++;
  886.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  887.   XtSetArg(args[count], XtNfromVert, messageEntry);  count++;
  888.   XtSetArg(args[count], XtNvertDistance, 10);  count++;
  889.   XtSetArg(args[count], XtNfromHoriz, displayFrame);  count++;
  890.   XtSetArg(args[count], XtNhorizDistance, 10);  count++;
  891.   commandArea = XtCreateManagedWidget("commandArea", formWidgetClass,
  892.                       form, args, count);
  893.   buildCommandArea(commandArea);
  894. }
  895.  
  896. void
  897. buildOptionInterface(parent)
  898. Widget parent;
  899. {
  900.   count = 0;
  901.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  902.   optionForm = XtCreateManagedWidget("optionForm", formWidgetClass,
  903.                      parent, args, count);
  904.  
  905.   count = 0;
  906.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  907.   XtSetArg(args[count], XtNright, XawChainLeft);  count++;
  908.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  909.   XtSetArg(args[count], XtNbottom, XawChainTop);  count++;
  910.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  911.   XtSetArg(args[count], XtNlabel, "Welcome to the Game of Hearts");  count++;
  912.   XtSetArg(args[count], XtNjustify, XtJustifyCenter);  count++;
  913.   XtSetArg(args[count], XtNresize, False);  count++;
  914.   optionHeader = XtCreateManagedWidget("optionHeader", labelWidgetClass,
  915.                        optionForm, args, count);
  916.  
  917.   count = 0;
  918.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  919.   XtSetArg(args[count], XtNright, XawChainLeft);  count++;
  920.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  921.   XtSetArg(args[count], XtNbottom, XawChainTop);  count++;
  922.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  923.   XtSetArg(args[count], XtNfromVert, optionHeader);  count++;
  924.   XtSetArg(args[count], XtNvertDistance, 20);  count++;
  925.   XtSetArg(args[count], XtNjustify, XtJustifyCenter);  count++;
  926.   if (MIKEYJ) {
  927.     XtSetArg(args[count], XtNlabel,
  928.          "(the Jack of Diamonds scores -10)");  count++;
  929.   } else {
  930.     XtSetArg(args[count], XtNlabel, " ");  count++;
  931.   }
  932.   gamesMessage= XtCreateManagedWidget("gamesMessage", labelWidgetClass,
  933.                       optionForm, args, count);
  934.  
  935.   count = 0;
  936.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  937.   XtSetArg(args[count], XtNright, XawChainLeft);  count++;
  938.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  939.   XtSetArg(args[count], XtNbottom, XawChainTop);  count++;
  940.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  941.   XtSetArg(args[count], XtNfromVert, gamesMessage);  count++;
  942.   XtSetArg(args[count], XtNvertDistance, 20);  count++;
  943.   XtSetArg(args[count], XtNjustify, XtJustifyLeft);  count++;
  944.   XtSetArg(args[count], XtNlabel, "Current Games:");  count++;
  945.   gamesHeader = XtCreateManagedWidget("gamesHeader", labelWidgetClass,
  946.                       optionForm, args, count);
  947.  
  948.   count = 0;
  949.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  950.   XtSetArg(args[count], XtNright, XawChainLeft);  count++;
  951.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  952.   XtSetArg(args[count], XtNbottom, XawChainBottom);  count++;
  953.   XtSetArg(args[count], XtNfromVert, gamesHeader);  count++;
  954.   XtSetArg(args[count], XtNdefaultDistance, 0);  count++;
  955.   gamesFrame = XtCreateManagedWidget("gamesFrame", formWidgetClass,
  956.                      optionForm, args, count);
  957.  
  958.   count = 0;
  959.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  960.   XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  961.   XtSetArg(args[count], XtNright, XawChainRight);  count++;
  962.   XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  963.   XtSetArg(args[count], XtNbottom, XawChainBottom);  count++;
  964.   XtSetArg(args[count], XtNdefaultDistance, 0);  count++;
  965.   XtSetArg(args[count], XtNwidth, 10);  count++;
  966.   XtSetArg(args[count], XtNheight, 10);  count++;
  967.   gamesRC = XtCreateManagedWidget("gamesRC", formWidgetClass,
  968.                   gamesFrame, args, count);
  969.  
  970.   count = 0;
  971.   XtSetArg(args[count], XtNleft, XawChainRight);  count++;
  972.   XtSetArg(args[count], XtNright, XawChainRight);  count++;
  973.   XtSetArg(args[count], XtNtop, XawChainBottom);  count++;
  974.   XtSetArg(args[count], XtNbottom, XawChainBottom);  count++;
  975.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  976.   XtSetArg(args[count], XtNfromVert, gamesFrame);  count++;
  977.   XtSetArg(args[count], XtNvertDistance, 10);  count++;
  978.   gameBox = XtCreateManagedWidget("gameBox", formWidgetClass,
  979.                   optionForm, args, count);
  980.  
  981.   count = 0;
  982.   XtSetArg(args[count], XtNlabel, "Another Game");  count++;
  983.   anotherGame = XtCreateManagedWidget("anotherGame", commandWidgetClass,
  984.                       gameBox, args, count);
  985.   XtAddCallback(anotherGame, XtNcallback, another_game, NULL);
  986.  
  987.   count = 0;
  988.   XtSetArg(args[count], XtNlabel, "New Game");  count++;
  989.   XtSetArg(args[count], XtNfromHoriz, anotherGame);  count++;
  990.   newGame = XtCreateManagedWidget("newGame", commandWidgetClass,
  991.                   gameBox, args, count);
  992.   XtAddCallback(newGame, XtNcallback, new_game, NULL);
  993.  
  994.   count = 0;
  995.   XtSetArg(args[count], XtNlabel, "More Games");  count++;
  996.   XtSetArg(args[count], XtNfromHoriz, newGame);  count++;
  997.   moreGames = XtCreateManagedWidget("moreGames", commandWidgetClass,
  998.                     gameBox, args, count);
  999.   XtAddCallback(moreGames, XtNcallback, more_games, NULL);
  1000.  
  1001.   count = 0;
  1002.   XtSetArg(args[count], XtNlabel, "Quit");  count++;
  1003.   XtSetArg(args[count], XtNfromHoriz, moreGames);  count++;
  1004.   quitGame = XtCreateManagedWidget("quitGame", commandWidgetClass,
  1005.                    gameBox, args, count);
  1006.   XtAddCallback(quitGame, XtNcallback, quit_game, NULL);
  1007.  
  1008.   count = 0;
  1009.   XtSetArg(args[count], XtNlabel, "Help");  count++;
  1010.   XtSetArg(args[count], XtNfromHoriz, quitGame);  count++;
  1011.   helpGame = XtCreateManagedWidget("helpGame", commandWidgetClass,
  1012.                    gameBox, args, count);
  1013.   XtAddCallback(helpGame, XtNcallback, help_me, NULL);
  1014.  
  1015.   playForm = form;
  1016. }
  1017.  
  1018. init(argc_p, argv)
  1019. int *argc_p;
  1020. char **argv;
  1021. {
  1022.   char ch, *pager, buffer[128];
  1023.   int suit;
  1024.   CardInfo *card;
  1025.  
  1026.   toplevel = XtInitialize(argv[0], "Xawhearts", NULL, 0, argc_p, argv);
  1027.   appContext = XtWidgetToApplicationContext(toplevel);
  1028.  
  1029.   count = 0;
  1030.   XtSetArg(args[count], XtNborderWidth, 0);  count++;
  1031.   form = XtCreateManagedWidget("form", formWidgetClass,
  1032.                    toplevel, args, count);
  1033.  
  1034.   buildInterface(form);
  1035.   buildOptionInterface(form);
  1036.   gfx_init(XtDisplay(toplevel), XScreenNumberOfScreen(XtScreen(toplevel)));
  1037.  
  1038.   XtRealizeWidget(toplevel);
  1039.   fixupLayout();
  1040.   XtAddEventHandler(form, StructureNotifyMask, False,
  1041.             (XtEventHandler) fixupLayout, NULL);
  1042.  
  1043.   for (suit=CLUBS; suit<=SPADES; suit++) {
  1044.     card = (CardInfo *) malloc(sizeof(CardInfo));
  1045.     card->rank = card->suit = 0;
  1046.     card->next = NULL;
  1047.     my_hand[suit].head = card;
  1048.   }
  1049.   playCards[0].rank = 0;
  1050.   playCards[1].rank = 0;
  1051.   playCards[2].rank = 0;
  1052.   playCards[3].rank = 0;
  1053.   playNames[0][0] = '\0';
  1054.   playNames[1][0] = '\0';
  1055.   playNames[2][0] = '\0';
  1056.   playNames[3][0] = '\0';
  1057.   lastCards[0].rank = 0;
  1058.   lastCards[1].rank = 0;
  1059.   lastCards[2].rank = 0;
  1060.   lastCards[3].rank = 0;
  1061.   lastNames[0][0] = '\0';
  1062.   lastNames[1][0] = '\0';
  1063.   lastNames[2][0] = '\0';
  1064.   lastNames[3][0] = '\0';
  1065.   setReadingCard(False);
  1066. }
  1067.  
  1068. print_cards(suit)
  1069. int suit;
  1070. {
  1071.   CardInfo *ptr;
  1072.   int y;
  1073.   Rank r;
  1074.   Suit s;
  1075.  
  1076.   s = convertSuit(suit);
  1077.   ptr = my_hand[suit].head;
  1078.   y = 0;
  1079.   while (ptr->next) {
  1080.     ptr = ptr->next;
  1081.     r = convertRank(ptr->rank);
  1082.     paint_card(XtWindow(displayArea), (suit-1)*STACK_WIDTH, y, r, s,
  1083.            ptr->next ? CARD_DELTA : 0);
  1084.     y += CARD_DELTA;
  1085.   }
  1086.   if (y) {
  1087.     XClearArea(XtDisplay(displayArea), XtWindow(displayArea),
  1088.            (suit-1)*STACK_WIDTH, y+CARD_HEIGHT-CARD_DELTA+1 /* bw */,
  1089.            STACK_WIDTH, 0, False);
  1090.   } else {
  1091.     XClearArea(XtDisplay(displayArea), XtWindow(displayArea),
  1092.            (suit-1)*STACK_WIDTH, 0,
  1093.            STACK_WIDTH, 0, False);
  1094.   }
  1095. }
  1096.  
  1097. void
  1098. displayMessage(msg)
  1099. char *msg;
  1100. {
  1101.   count = 0;
  1102.   XtSetArg(args[count], XtNlabel, msg);  count++;
  1103.   XtSetValues(textArea, args, count);
  1104. }
  1105.  
  1106.  
  1107. void
  1108. positionTables()
  1109. {
  1110.   int i, ct;
  1111.   table_ptr cur_ptr;
  1112.   Widget *widgets;
  1113.   Dimension width, height, tableHeight, tableWidth, spacing;
  1114.   Dimension marginWidth, marginHeight, bw;
  1115.   Position x, y;
  1116.  
  1117.   ct = 0;
  1118.   cur_ptr = first_table;
  1119.   /* make the gamesRC as large as the gamesFrame */
  1120.   count = 0;
  1121.   XtSetArg(args[count], XtNwidth, &width);  count++;
  1122.   XtSetArg(args[count], XtNheight, &height);  count++;
  1123.   XtGetValues(gamesFrame, args, count);
  1124.   resizeWidget(gamesRC, width, height);
  1125.   marginWidth = 10;
  1126.   marginHeight = 10;
  1127.   spacing = 10;
  1128.   for (i=0; i<table_count; i++) {
  1129.     if (cur_ptr->data) {
  1130.       widgets = (Widget *) cur_ptr->data;
  1131.       if (XtIsManaged(widgets[0])) {
  1132.     count = 0;
  1133.     XtSetArg(args[count], XtNheight, &tableHeight);  count++;
  1134.     XtSetArg(args[count], XtNborderWidth, &bw);  count++;
  1135.     XtGetValues(widgets[0], args, count);
  1136.     tableHeight = globalTableHeight;
  1137.     if (width >
  1138.         2*marginWidth+NUM_TABLES_COLS*4+(NUM_TABLES_COLS-1)*spacing) {
  1139.       tableWidth = (width-2*marginWidth-NUM_TABLES_COLS*4-
  1140.             (NUM_TABLES_COLS-1)*spacing)/NUM_TABLES_COLS;
  1141.       y = marginHeight+tableHeight*(ct/NUM_TABLES_COLS);
  1142.       x = marginWidth+(ct % NUM_TABLES_COLS)*(tableWidth+spacing);
  1143.       XtConfigureWidget(widgets[0], x, y, tableWidth, tableHeight, bw);
  1144.       XtConfigureWidget(widgets[1], 0, 0, tableWidth, tableHeight, 0);
  1145.       ct++;
  1146.     }
  1147.       }
  1148.     }
  1149.     cur_ptr = cur_ptr->next_table;
  1150.   }
  1151.  
  1152. }
  1153.  
  1154. fixupLayout()
  1155. {
  1156.   Dimension formWidth, formHeight, width, height, bw;
  1157.   Position x, y;
  1158.   int hd, dd;
  1159.  
  1160.   /*****************************************************************/
  1161.   /* Grrr.  I hate Xaw.  The form widget is not expressive enough. */
  1162.   /* Or, I just can't figure it out.
  1163.   /*****************************************************************/
  1164.  
  1165.   /* make option form as big as play form */
  1166.   count = 0;
  1167.   XtSetArg(args[count], XtNwidth, &formWidth);  count++;
  1168.   XtSetArg(args[count], XtNheight, &formHeight);  count++;
  1169.   XtGetValues(playForm, args, count);
  1170.   resizeWidget(optionForm, formWidth-2, formHeight-2);
  1171.  
  1172.   /* make the labels and table container as wide as the option form */
  1173.   count = 0;
  1174.   XtSetArg(args[count], XtNwidth, &formWidth);  count++;
  1175.   XtSetArg(args[count], XtNdefaultDistance, &dd);  count++;
  1176.   XtGetValues(optionForm, args, count);
  1177.   count = 0;
  1178.   XtSetArg(args[count], XtNhorizDistance, &hd);  count++;
  1179.   XtGetValues(optionHeader, args, count);
  1180.   resizeWidget(optionHeader, formWidth-2*hd-2*dd, 0);
  1181.   resizeWidget(gamesMessage, formWidth-2*hd-2*dd, 0);
  1182.   resizeWidget(gamesHeader, formWidth-2*hd-2*dd, 0);
  1183.   count = 0;
  1184.   XtSetArg(args[count], XtNborderWidth, &bw);  count++;
  1185.   XtGetValues(gamesFrame, args, count);
  1186.   resizeWidget(gamesFrame, formWidth-2*hd-2*dd-2*bw, 0);
  1187.  
  1188.   /* Expand labels area, move score area to the right of the play form */
  1189.   count = 0;
  1190.   XtSetArg(args[count], XtNwidth, &formWidth);  count++;
  1191.   XtSetArg(args[count], XtNdefaultDistance, &dd);  count++;
  1192.   XtGetValues(playForm, args, count);
  1193.   count = 0;
  1194.   XtSetArg(args[count], XtNwidth, &width);  count++;
  1195.   XtSetArg(args[count], XtNheight, &height);  count++;
  1196.   XtSetArg(args[count], XtNx, &x);  count++;
  1197.   XtSetArg(args[count], XtNy, &y);  count++;
  1198.   XtSetArg(args[count], XtNborderWidth, &bw);  count++;
  1199.   XtGetValues(scoreArea, args, count);
  1200. /* I have no idea why I need this fudge factor to line things up... */
  1201. #define FUDGE_FACTOR 8
  1202.   count = 0;
  1203.   XtSetArg(args[count], XtNx, formWidth-width-dd-2*bw-FUDGE_FACTOR);  count++;
  1204.   XtSetValues(scoreArea, args, count);
  1205.   XtConfigureWidget(scoreArea, formWidth-width-dd-2*bw-FUDGE_FACTOR, y,
  1206.             width, height, bw);
  1207.   count = 0;
  1208.   XtSetArg(args[count], XtNwidth, &width);  count++;
  1209.   XtGetValues(scoreArea, args, count);
  1210.   count = 0;
  1211.   XtSetArg(args[count], XtNx, &x);  count++;
  1212.   XtGetValues(displayLabels, args, count);
  1213.   if (x > formWidth-width-dd-2*bw-FUDGE_FACTOR) {
  1214.     resizeWidget(displayLabels, 1, 0);
  1215.   } else {
  1216.     resizeWidget(displayLabels, formWidth-width-dd-2*bw-x-FUDGE_FACTOR, 0);
  1217.   }
  1218.  
  1219.   /* move the play buttons to the lower right of the play form */
  1220.   count = 0;
  1221.   XtSetArg(args[count], XtNwidth, &formWidth);  count++;
  1222.   XtSetArg(args[count], XtNdefaultDistance, &dd);  count++;
  1223.   XtGetValues(playForm, args, count);
  1224.   count = 0;
  1225.   XtSetArg(args[count], XtNwidth, &width);  count++;
  1226.   XtSetArg(args[count], XtNheight, &height);  count++;
  1227.   XtSetArg(args[count], XtNx, &x);  count++;
  1228.   XtSetArg(args[count], XtNy, &y);  count++;
  1229.   XtSetArg(args[count], XtNborderWidth, &bw);  count++;
  1230.   XtGetValues(commandArea, args, count);
  1231.   count = 0;
  1232.   XtSetArg(args[count], XtNx, formWidth-width-dd-2*bw);  count++;
  1233.   XtSetValues(commandArea, args, count);
  1234.   XtConfigureWidget(commandArea, formWidth-width-dd-2*bw, y,
  1235.             width, height, bw);
  1236.  
  1237.   positionTables();
  1238. }
  1239.  
  1240. /**********************************************************************/
  1241.  
  1242. enter_card(rank, suit)
  1243. int rank, suit;
  1244. {
  1245.   CardInfo *card, *ptr;
  1246.  
  1247.   card = (CardInfo *) malloc(sizeof(CardInfo));
  1248.   card->rank = rank;
  1249.   card->suit = suit;
  1250.   ptr = my_hand[suit].head;
  1251.   while (ptr->next && ptr->next->rank > rank) {
  1252.     ptr = ptr->next;
  1253.   }
  1254.   card->next = ptr->next;
  1255.   ptr->next = card;
  1256.   print_cards(suit);
  1257. }
  1258.  
  1259. remove_card(rank, suit)
  1260. int rank, suit;
  1261. {
  1262.   CardInfo *card, *ptr;
  1263.  
  1264.   ptr = my_hand[suit].head;
  1265.   while (ptr->next) {
  1266.     if (ptr->next->rank == rank) {
  1267.       card = ptr->next;
  1268.       ptr->next = card->next;
  1269.       free((char *) card);
  1270.       break;
  1271.     } else {
  1272.       ptr = ptr->next;
  1273.     }
  1274.   }
  1275.   print_cards(suit);
  1276. }
  1277.  
  1278. erase_window(window_num)
  1279. int window_num;
  1280. {
  1281.   if (window_num == PLAY_WINDOW) {
  1282. /* if PLAY_WINDOW then save it for showing last */
  1283.     lastCards[0] = playCards[0];
  1284.     lastCards[1] = playCards[1];
  1285.     lastCards[2] = playCards[2];
  1286.     lastCards[3] = playCards[3];
  1287.     strcpy(lastNames[0], playNames[0]);
  1288.     strcpy(lastNames[1], playNames[1]);
  1289.     strcpy(lastNames[2], playNames[2]);
  1290.     strcpy(lastNames[3], playNames[3]);
  1291.     playCards[0].rank = 0;
  1292.     playCards[1].rank = 0;
  1293.     playCards[2].rank = 0;
  1294.     playCards[3].rank = 0;
  1295.     playNames[0][0] = '\0';
  1296.     playNames[1][0] = '\0';
  1297.     playNames[2][0] = '\0';
  1298.     playNames[3][0] = '\0';
  1299.     XClearArea(XtDisplay(playArea), XtWindow(playArea), 0, 0,
  1300.            0, 0, False);
  1301.     count = 0;
  1302.     XtSetArg(args[count], XtNlabel, " ");  count++;
  1303.     XtSetValues(playLabels[0], args, count);
  1304.     XtSetValues(playLabels[1], args, count);
  1305.     XtSetValues(playLabels[2], args, count);
  1306.     XtSetValues(playLabels[3], args, count);
  1307.   } else if (window_num == TEXT_WINDOW) {
  1308.     displayMessage("");
  1309.   }
  1310. }
  1311.  
  1312. read_card()
  1313. {
  1314.   setReadingCard(True);
  1315. }
  1316.  
  1317. play_card(player, rch, sch, msg)
  1318. int player, rch, sch;
  1319. char *msg;
  1320. {
  1321.   playCards[player-1].rank = get_rank(rch);
  1322.   playCards[player-1].suit = get_suit(sch);
  1323.   if (!showOld) {
  1324.     paint_card(XtWindow(playArea), (player-1)*STACK_WIDTH, 0,
  1325.            convertRank(playCards[player-1].rank),
  1326.            convertSuit(playCards[player-1].suit),
  1327.            0);
  1328.   }
  1329.   if (*msg != '\0') {
  1330.     strcpy(playNames[player-1], msg);
  1331.     if (!showOld) {
  1332.       count = 0;
  1333.       XtSetArg(args[count], XtNlabel, msg);  count++;
  1334.       XtSetValues(playLabels[player-1], args, count);
  1335.     }
  1336.   }
  1337.   XSync(XtDisplay(playArea), False);
  1338.   updateDisplay();
  1339.   sleep(1);
  1340. }
  1341.  
  1342. score_points(player, pts, total_pts, msg)
  1343. int player, pts, total_pts;
  1344. char *msg;
  1345. {
  1346.   char str[256];
  1347.  
  1348.   count = 0;
  1349.   XtSetArg(args[count], XtNlabel, msg);  count++;
  1350.   XtSetValues(playerLabels[player], args, count);
  1351.   sprintf(str, "%d  ", pts);
  1352.   count = 0;
  1353.   XtSetArg(args[count], XtNlabel, str);  count++;
  1354.   XtSetValues(scoreLabels[player], args, count);
  1355.   sprintf(str, "%d  ", total_pts);
  1356.   count = 0;
  1357.   XtSetArg(args[count], XtNlabel, str);  count++;
  1358.   XtSetValues(totalLabels[player], args, count);
  1359. }
  1360.  
  1361. display_message(window_num, msg)
  1362. int window_num;
  1363. char *msg;
  1364. {
  1365.   char *str, *str2;
  1366.  
  1367.   if (window_num == MESG_WINDOW || window_num == PLAY_WINDOW) {
  1368.     count = 0;
  1369.     XtSetArg(args[count], XtNstring, &str);  count++;
  1370.     XtGetValues(messageArea, args, count);
  1371.     str2 = malloc(strlen(str)+strlen(msg)+2);
  1372.     strcpy(str2, str);
  1373.     strcat(str2, msg);
  1374.     strcat(str2, "\n");
  1375.     count = 0;
  1376.     XtSetArg(args[count], XtNstring, str2);  count++;
  1377.     XtSetValues(messageArea, args, count);
  1378.     free(str2);
  1379.   } else {
  1380.     count = 0;
  1381.     XtSetArg(args[count], XtNlabel, msg);  count++;
  1382.     if (window_num == TEXT_WINDOW) {
  1383.       XtSetValues(textArea, args, count);
  1384.     } else if (window_num == ROUND_WINDOW) {
  1385.       XtSetValues(roundLabel, args, count);
  1386.     } else if (window_num == LEAD_WINDOW) {
  1387.       XtSetValues(leadLabel, args, count);
  1388.     }
  1389.   }
  1390. }
  1391.  
  1392. game_is_over()
  1393. {
  1394.   Boolean buttonPressed;
  1395.   XEvent event;
  1396.  
  1397.   display_message(MESG_WINDOW,
  1398.           "--------------------------------------------------------");
  1399.   display_message(MESG_WINDOW, "");
  1400.   display_message(MESG_WINDOW, "Click the left mouse button to continue...");
  1401.  
  1402.   buttonPressed = False;
  1403.   XGrabPointer(XtDisplay(messageArea), XtWindow(messageArea), True,
  1404.            ButtonPressMask, GrabModeAsync, GrabModeAsync,
  1405.            XtWindow(messageArea), None, CurrentTime);
  1406.   while (!buttonPressed) {
  1407.     if (XCheckTypedWindowEvent(XtDisplay(messageArea),
  1408.                    XtWindow(messageArea),
  1409.                    ButtonPress, &event)) {
  1410.       XtDispatchEvent(&event);
  1411.       XUngrabPointer(XtDisplay(messageArea), event.xbutton.time);
  1412.       XSync(XtDisplay(messageArea), False);
  1413.       buttonPressed = True;
  1414.     }
  1415.   }
  1416. }
  1417.  
  1418. start_game()
  1419. {
  1420.   XLowerWindow(XtDisplay(optionForm), XtWindow(optionForm));
  1421.   XSync(XtDisplay(optionForm), False);
  1422.   showOld = False;
  1423.  
  1424.   playCards[0].rank = 0;
  1425.   playCards[1].rank = 0;
  1426.   playCards[2].rank = 0;
  1427.   playCards[3].rank = 0;
  1428.   playNames[0][0] = '\0';
  1429.   playNames[1][0] = '\0';
  1430.   playNames[2][0] = '\0';
  1431.   playNames[3][0] = '\0';
  1432.   lastCards[0].rank = 0;
  1433.   lastCards[1].rank = 0;
  1434.   lastCards[2].rank = 0;
  1435.   lastCards[3].rank = 0;
  1436.   lastNames[0][0] = '\0';
  1437.   lastNames[1][0] = '\0';
  1438.   lastNames[2][0] = '\0';
  1439.   lastNames[3][0] = '\0';
  1440.  
  1441.   count = 0;
  1442.   XtSetArg(args[count], XtNstring, "");  count++;
  1443.   XtSetValues(messageArea, args, count);
  1444. }
  1445.  
  1446. /*
  1447.  * Scan input for redraw screen requests or ':' messages.
  1448.  * Also scan socket for incoming commands.
  1449.  */
  1450. scan()
  1451. {
  1452.   static XEvent event;
  1453.  
  1454.   XtAppNextEvent(appContext, &event);
  1455.   XtDispatchEvent(&event);
  1456. }
  1457.  
  1458. terminate()
  1459. {
  1460.   XtDestroyWidget(toplevel);
  1461. }
  1462.  
  1463. /*
  1464.  * show_table - display table which is position table_pos on screen.
  1465.  */
  1466. show_table(cur_ptr, table_pos)
  1467. table_ptr    cur_ptr;
  1468. int        table_pos;
  1469. {
  1470.   Dimension width, height, marginWidth, marginHeight, spacing;
  1471.   Widget *widgets;
  1472.   char str[256];
  1473.   int each;
  1474.  
  1475.   count = 0;
  1476.   XtSetArg(args[count], XtNwidth, &width);  count++;
  1477.   XtSetArg(args[count], XtNheight, &height);  count++;
  1478.   marginWidth = 10;
  1479.   marginHeight = 10;
  1480.   spacing = 10;
  1481.   XtGetValues(gamesRC, args, count);
  1482.  
  1483.   if (!cur_ptr->data) {
  1484.     widgets = (Widget *) malloc(8*sizeof(Widget));
  1485.     count = 0;
  1486.     XtSetArg(args[count], XtNresize, False);  count++;
  1487.     XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  1488.     XtSetArg(args[count], XtNright, XawChainLeft);  count++;
  1489.     XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  1490.     XtSetArg(args[count], XtNbottom, XawChainTop);  count++;
  1491.     XtSetArg(args[count], XtNdefaultDistance, 0);  count++;
  1492.     XtSetArg(args[count], XtNwidth, 10);  count++;
  1493.     XtSetArg(args[count], XtNheight, 10);  count++;
  1494.     widgets[0] = XtCreateManagedWidget("tableFrame", formWidgetClass,
  1495.                        gamesRC, args, count);
  1496.     count = 0;
  1497.     XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  1498.     XtSetArg(args[count], XtNright, XawChainRight);  count++;
  1499.     XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  1500.     XtSetArg(args[count], XtNbottom, XawChainBottom);  count++;
  1501.     XtSetArg(args[count], XtNborderWidth, 0);  count++;
  1502.     XtSetArg(args[count], XtNresize, False);  count++;
  1503.     XtSetArg(args[count], XtNdefaultDistance, 0);  count++;
  1504.     XtSetArg(args[count], XtNwidth, 10);  count++;
  1505.     XtSetArg(args[count], XtNheight, 10);  count++;
  1506.     widgets[1] = XtCreateManagedWidget("tableW", formWidgetClass,
  1507.                        widgets[0], args, count);
  1508.     XtAddEventHandler(widgets[1], ButtonPressMask, False, tableSelect, NULL);
  1509.     globalTableHeight = 0;
  1510.     for (each=0; each<6; each++) {
  1511.       count = 0;
  1512.       XtSetArg(args[count], XtNlabel, " ");  count++;
  1513.       XtSetArg(args[count], XtNborderWidth, 0);  count++;
  1514.       XtSetArg(args[count], XtNresize, False);  count++;
  1515.       XtSetArg(args[count], XtNleft, XawChainLeft);  count++;
  1516.       XtSetArg(args[count], XtNright, XawChainRight);  count++;
  1517.       XtSetArg(args[count], XtNtop, XawChainTop);  count++;
  1518.       XtSetArg(args[count], XtNbottom, XawChainTop);  count++;
  1519.       XtSetArg(args[count], XtNwidth, 10);  count++;
  1520.       if (each) {
  1521.     XtSetArg(args[count], XtNfromVert, widgets[each+1]);  count++;
  1522.       }
  1523.       widgets[each+2] = XtCreateManagedWidget("tableLabel", labelWidgetClass,
  1524.                           widgets[1], args, count);
  1525.       count = 0;
  1526.       XtSetArg(args[count], XtNheight, &height);  count++;
  1527.       XtGetValues(widgets[each+2], args, count);
  1528.       globalTableHeight += height;
  1529.     }
  1530.     cur_ptr->data = (char *) widgets;
  1531.   } else {
  1532.     widgets = (Widget *) cur_ptr->data;
  1533.     XtManageChild(widgets[0]);
  1534.   }
  1535.  
  1536.   sprintf(str, "Table %d", table_pos+1);
  1537.   count = 0;
  1538.   XtSetArg(args[count], XtNlabel, str);  count++;
  1539.   XtSetValues(widgets[2], args, count);
  1540.  
  1541.   if (cur_ptr->closed) {
  1542.     count = 0;
  1543.     XtSetArg(args[count], XtNlabel, "<game over>");  count++;
  1544.     XtSetValues(widgets[3], args, count);
  1545.     count = 0;
  1546.     XtSetArg(args[count], XtNlabel, " ");  count++;
  1547.     XtSetValues(widgets[4], args, count);
  1548.     XtSetValues(widgets[5], args, count);
  1549.     XtSetValues(widgets[6], args, count);
  1550.     XtSetValues(widgets[7], args, count);
  1551.   } else {
  1552.     if (!cur_ptr->hand) {
  1553.       sprintf(str, "<starting>");
  1554.     } else {
  1555.       sprintf(str, "Hand: %d  Round: %d", cur_ptr->hand, cur_ptr->round);
  1556.     }
  1557.     count = 0;
  1558.     XtSetArg(args[count], XtNlabel, str);  count++;
  1559.     XtSetValues(widgets[3], args, count);
  1560.  
  1561.     for (each=0; each<4; each++) {
  1562.       count = 0;
  1563.       XtSetArg(args[count], XtNlabel, cur_ptr->player_name[each]);  count++;
  1564.       XtSetValues(widgets[4+each], args, count);
  1565.     }
  1566.   }
  1567.  
  1568.   /* Make the row column the right width */
  1569.   count = 0;
  1570.   XtSetArg(args[count], XtNwidth,
  1571.        (width-2*marginWidth-NUM_TABLES_COLS*4-
  1572.         (NUM_TABLES_COLS-1)*spacing)/NUM_TABLES_COLS);  count++;
  1573.   for (each=2; each<8; each++) {
  1574.     XtSetValues(widgets[each], args, count);
  1575.   }
  1576. }
  1577.  
  1578. /*
  1579.  * show_tables - display up to NUM_TABLES tables starting with table # start_id.
  1580.  */
  1581. show_tables(start_id)
  1582. int    start_id;
  1583. {
  1584.   table_ptr cur_ptr;
  1585.   int cur_id, i;
  1586.   char str[256];
  1587.   Widget *widgets;
  1588.   
  1589.   XtSetSensitive(moreGames, (table_count > 8));
  1590.   cur_ptr = first_table;
  1591.   for (i=0; i<table_count; i++) {
  1592.     if (cur_ptr->data) {
  1593.       widgets = (Widget *) cur_ptr->data;
  1594.       XtUnmanageChild(widgets[0]);
  1595.     }
  1596.     cur_ptr = cur_ptr->next_table;
  1597.   }
  1598.   count = 0;
  1599.   if (table_count) {
  1600.     sprintf(str, "Current Games (page %d of %d):",
  1601.         (start_id + NUM_TABLES-1) / NUM_TABLES,
  1602.         (table_count + NUM_TABLES-1) / NUM_TABLES);
  1603.     XtSetArg(args[count], XtNlabel, str);  count++;
  1604.   } else {
  1605.     XtSetArg(args[count], XtNlabel, "Current Games:");  count++;
  1606.   }
  1607.   XtSetValues(gamesHeader, args, count);
  1608.   cur_ptr = first_table;
  1609.   for (cur_id = 1; cur_id < start_id; cur_id++) {
  1610.     cur_ptr = cur_ptr->next_table;
  1611.   }
  1612.   XtUnmanageChild(gamesRC);
  1613.   for (cur_id = 0; (cur_id < NUM_TABLES) && cur_ptr;
  1614.        cur_ptr = cur_ptr->next_table) {
  1615.     show_table(cur_ptr, cur_id++);
  1616.   }
  1617.   positionTables();
  1618.   XtManageChild(gamesRC);
  1619. }
  1620.  
  1621. option_scan(another)
  1622. char *another;
  1623. {
  1624.   XEvent event;
  1625.  
  1626.   anotherPtr = another;
  1627.   *anotherPtr = FALSE;
  1628.   XtAppNextEvent(appContext, &event);
  1629.   XtDispatchEvent(&event);
  1630. }
  1631.  
  1632. option_init()
  1633. {
  1634.   if (distId) {
  1635.     XtRemoveInput(distId);
  1636.   }
  1637.   distId = XtAppAddInput(appContext, dist_socket,
  1638.              (XtPointer) XtInputReadMask, distInput, NULL);
  1639.   XtSetSensitive(anotherGame, !first_game);
  1640.   XtSetSensitive(newGame, first_game);
  1641.   XRaiseWindow(XtDisplay(optionForm), XtWindow(optionForm));
  1642.   XSync(XtDisplay(optionForm), False);
  1643. }
  1644.  
  1645. init_socket()
  1646. {
  1647.   if (dealerId) {
  1648.     XtRemoveInput(dealerId);
  1649.   }
  1650.   dealerId = XtAppAddInput(appContext, dealer_socket,
  1651.                (XtPointer) XtInputReadMask, dealerInput, NULL);
  1652. }
  1653.  
  1654. close_socket(s)
  1655. int s;
  1656. {
  1657.   if (s == dealer_socket && dealerId) {
  1658.     XtRemoveInput(dealerId);
  1659.     dealerId = None;
  1660.   } else if (s == dist_socket && distId) {
  1661.     XtRemoveInput(distId);
  1662.     distId = None;
  1663.   }
  1664. }
  1665.  
  1666. option_clear()
  1667. {
  1668.   table_ptr cur_ptr;
  1669.   int i;
  1670.   Widget *widgets;
  1671.  
  1672.   cur_ptr = first_table;
  1673.   for (i=0; i<table_count; i++) {
  1674.     if (cur_ptr->data) {
  1675.       widgets = (Widget *) cur_ptr->data;
  1676.       XtDestroyWidget(widgets[0]);
  1677.       cur_ptr->data = NULL;
  1678.     }
  1679.     cur_ptr = cur_ptr->next_table;
  1680.   }
  1681. }
  1682.