home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xcu16.zip / clients / xhearts / init_x.c < prev    next >
C/C++ Source or Header  |  1991-10-03  |  20KB  |  717 lines

  1. /*
  2.  * Copyright 1991 Cornell University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and its
  5.  * documentation for any purpose and without fee is hereby granted, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Cornell U. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Cornell U. makes no representations about the
  11.  * suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * CORNELL UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16.  * EVENT SHALL CORNELL UNIVERSITY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  18.  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20.  * PERFORMANCE OF THIS SOFTWARE.
  21.  *
  22.  * Author:  Gene W. Dykes, Program of Computer Graphics
  23.  *          580 Theory Center, Cornell University, Ithaca, NY 14853
  24.  *          (607) 255-6713   gwd@graphics.cornell.edu
  25.  */
  26.  
  27.  
  28. #include <stdio.h>
  29. #include <sys/ioctl.h>
  30. #include <X11/Intrinsic.h>
  31. #include <X11/StringDefs.h>
  32. #include <X11/Shell.h>
  33. #include <X11/Xfuncs.h>
  34. #include <X11/Xcu/Wlm.h>
  35. #include "hearts.h"
  36.  
  37. FILE *logerr ;
  38.  
  39. extern void moon_decision () ;
  40. extern void hand_decision () ;
  41. extern void card_picked () ;
  42. extern void discard_picked () ;
  43. extern void confirm_discard () ;
  44. extern void confirm_receipt () ;
  45. static void display_names () ;
  46. static void install_callbacks () ;
  47. static void get_widget_ids () ;
  48. static void get_suit_colors () ;
  49. static void find_program () ;
  50. static void input_error () ;
  51. static void syntax_error () ;
  52. static void AddStringToPassingStyleConverter () ;
  53. XtErrorHandler handler () ;
  54. int Xhandler () ;
  55.  
  56. static XrmOptionDescRec options[] =
  57.  {
  58.   {"-goal",    "*goal",         XrmoptionSepArg, NULL }
  59.  ,{"-jack",    "*jackCounts",        XrmoptionNoArg, "True" }
  60.  ,{"-pass",    "*passingStyle",    XrmoptionSepArg, NULL }
  61.  ,{"-drop",    "*dropOnFirst",        XrmoptionNoArg, "True" }
  62.  ,{"-players",    "*playerFile",        XrmoptionSepArg, NULL }
  63.  ,{"-wlm",    "*wlm",            XrmoptionSepArg, NULL }
  64.  ,{"-seed",    "*seed",        XrmoptionSepArg, NULL }
  65.  ,{"-sleep",    "*sleep",        XrmoptionSepArg, NULL }
  66.  ,{"-log",    "*logFile",        XrmoptionSepArg, NULL }
  67.  } ;
  68.  
  69. static int    def_goal = 100 ;
  70. static Boolean    def_false = False ;
  71.  
  72. #define XtNgoal    "goal"
  73. #define XtCGoal    "Goal"
  74.  
  75. #define XtNpassingStyle    "passingStyle"
  76. #define XtCPassingStyle    "PassingStyle"
  77. #define XtRPassingStyle    "PassingStyle"
  78.  
  79. #define XtNdropOnFirst    "dropOnFirst"
  80. #define XtCDropOnFirst    "dropOnFirst"
  81.  
  82. #define XtNjackCounts    "jackCounts"
  83. #define XtCJackCounts    "JackCounts"
  84.  
  85. #define XtNseed        "seed"
  86. #define XtCNrandSeed    "NrandSeed"
  87.  
  88. #define XtNsleep    "sleep"
  89. #define XtCSleep    "Sleep"
  90.  
  91. #define XtNplayerFile    "playerFile"
  92. #define XtCPlayerFile    "PlayerFile"
  93.  
  94. #define XtNwlm        "wlm"
  95. #define XtCWlmFile    "WlmFile"
  96.  
  97. #define XtNlogFile    "logFile"
  98. #define XtCLogFile    "LogFile"
  99.  
  100. #define offset(name,field) XtOffset(name *,field)
  101.  
  102. static XtResource history_resources[] =
  103.     {
  104.      {XtNgoal, XtCGoal, XtRInt, sizeof(int),
  105.     offset(History, goal), XtRInt, (XPointer)&def_goal}
  106.     ,{XtNpassingStyle, XtCPassingStyle, XtRPassingStyle, sizeof(PassingStyle),
  107.     offset(History, passing_style), XtRString, (XPointer)"LeftRightAcross"}
  108.     ,{XtNdropOnFirst, XtCDropOnFirst, XtRBoolean, sizeof(Boolean),
  109.     offset(History, points_on_first_trick), XtRBoolean, (XPointer)&def_false}
  110.     ,{XtNjackCounts, XtCJackCounts, XtRBoolean, sizeof(Boolean),
  111.     offset(History, jack_counts), XtRBoolean, (XPointer)&def_false}
  112.     } ;
  113.  
  114. static XtResource game_resources[] =
  115.     {
  116.      {XtNplayerFile, XtCPlayerFile, XtRString, sizeof(String),
  117.     offset(Game, player_file), XtRString, (XPointer)"players"}
  118.     ,{XtNlogFile, XtCLogFile, XtRString, sizeof(String),
  119.     offset(Game, log_file), XtRString, (XPointer)NULL}
  120.     ,{XtNwlm, XtCWlmFile, XtRString, sizeof(String),
  121.     offset(Game, wlm_file), XtRString, (XPointer)"hearts"}
  122.     ,{XtNseed, XtCNrandSeed, XtRString, sizeof(String),
  123.     offset(Game, seed), XtRString, (XPointer)NULL}
  124.     ,{XtNsleep, XtCSleep, XtRInt, sizeof(int),
  125.     offset(Game, sleep_seconds), XtRString, (XPointer)"2"}
  126.     } ;
  127.  
  128. void
  129. init_x_phase_1 (argc, argv)
  130.     int argc ;
  131.     char **argv ;
  132. {
  133. unsigned int saved_argc ;
  134. char **saved_argv ;
  135. Arg wlm_arg ;
  136. int i, j, n ;
  137. Arg args[2] ;
  138. FILE *fd = (FILE *) NULL ;
  139. XStruct *x = &game->x ;
  140. int noblock = 1 ;
  141.  
  142. XtToolkitInitialize() ;
  143. x->app = XtCreateApplicationContext () ;
  144. XtSetErrorHandler (handler) ;
  145. XSetIOErrorHandler (handler) ;
  146. XSetErrorHandler (Xhandler) ;
  147.  
  148. saved_argc = argc ;
  149. saved_argv = (char **)XtMalloc (argc * sizeof(char *)) ;
  150. bcopy (argv, saved_argv, argc * sizeof(char *)) ;
  151.  
  152. /*
  153.  * I have to search for the -players flag myself!
  154.  * The options list can only be specified in calls that open a display,
  155.  * and the players file contains the display info :-(
  156.  */
  157.  
  158. for (i=1;  i < argc-1; i++)
  159.     {
  160.     if (strcmp ("-players", argv[i]) == 0)
  161.     {
  162.     fd = fopen (argv[i+1], "r") ; 
  163.     if (!fd)
  164.         input_error (argv[i+1], argv) ;
  165.     break ;
  166.     }
  167.     }
  168.  
  169. if (fd == (FILE *) NULL)
  170.     {
  171.     fd = fopen ("players", "r") ;
  172.     if (!fd)
  173.     input_error ("players", argv) ;
  174.     }
  175.  
  176. logerr = stderr ;
  177.  
  178. for (i=0;  i < N_PLAYERS;  i++)
  179.     {
  180.     char name_string[40] ;
  181.     char display_string[40] ;
  182.     for (j=0;j<40;j++)name_string[j]=0 ;
  183.     fscanf (fd, "%s", name_string) ;
  184.     game->player[i].name_string = XtNewString(name_string) ;
  185.     if (game->player[i].name_string[0] == ':')
  186.     {
  187.     game->player[i].physiology = ComputerPhysiology ;
  188.     find_program (i) ;
  189.     }
  190.     else
  191.     game->player[i].physiology = HumanPhysiology ;
  192.     fscanf (fd, "%s", display_string) ;
  193.     if (game->player[i].physiology == HumanPhysiology)
  194.     {
  195.     fprintf (logerr, "Opening a connection to (%s)\n", display_string) ;
  196.     x->dpy[i] = XtOpenDisplay (x->app, display_string, "xhearts", "XHearts",
  197.                     options, XtNumber(options), &argc, argv ) ;
  198.     if (!x->dpy[i])
  199.         {
  200.         fprintf (logerr, "Couldn't open display (%s)\n", display_string) ;
  201.         exit (1) ;
  202.         }
  203.     n=0;
  204.     XtSetArg(args[n], XtNargc, saved_argc) ; n++ ;
  205.     XtSetArg(args[n], XtNargv, saved_argv) ; n++ ;
  206.     x->top[i] = XtAppCreateShell ("xhearts", "XHearts",
  207.                     applicationShellWidgetClass,
  208.                     x->dpy[i], args, n) ;
  209.     if (i == 0)
  210.         {
  211.         if (argc != 1)
  212.         syntax_error (argv) ;
  213.         AddStringToPassingStyleConverter () ;
  214.         XtGetApplicationResources (game->x.top[0], game,
  215.                 game_resources, XtNumber(game_resources),
  216.                 NULL, 0) ;
  217.         XtGetApplicationResources (game->x.top[0], history,
  218.                 history_resources, XtNumber(history_resources),
  219.                 NULL, 0) ;
  220.         }
  221.     XtSetArg (wlm_arg, XtNfile, game->wlm_file) ;
  222. fprintf (stderr, "Using (%s) as the compiled layout file\n", game->wlm_file) ;
  223.     sprintf (name_string, "wlm%d", i) ;
  224.     x->wlm_id[i] = XtCreateManagedWidget ( name_string, xcuWlmWidgetClass,
  225.                         x->top[i], &wlm_arg, 1 ) ;
  226.     XtRealizeWidget (x->top[i]) ;
  227.     }
  228.     }
  229.  
  230. if (game->log_file)
  231.     logerr = fopen (game->log_file, "w") ;
  232. else
  233.     logerr = NULL ;
  234.  
  235. return ;
  236. }
  237.  
  238. void
  239. init_x_phase_2 ()
  240. {
  241. display_names () ;
  242. install_callbacks () ;
  243. get_widget_ids () ;
  244. get_suit_colors () ;
  245.  
  246. return ;
  247. }
  248.  
  249. static void
  250. get_suit_colors ()
  251. {
  252. int i, j ;
  253. for (i=0;  i < N_PLAYERS;  i++)
  254.     {
  255.     static String suit_colors[] = { "Black", "Red", "Red", "Black" } ;
  256.     XrmValue string_value ;
  257.     XrmValue pixel_value ;
  258.     game->suit[i].color_string = XtNewString (suit_colors[i]) ;
  259.     if (game->player[i].physiology == ComputerPhysiology)
  260.     continue ;
  261.     for (j=0;  j < N_SUITS;  j++)
  262.     {
  263.     string_value.addr = suit_colors[j] ;
  264.     string_value.size = strlen(suit_colors[j]) ;
  265.     XtConvert ((Widget)game->x.top[i], XtRString, &string_value,
  266.                        XtRPixel, &pixel_value) ;
  267.     game->suit[j].color[i] = *((Pixel *)pixel_value.addr) ; 
  268.     }
  269.     }
  270. return ;
  271. }
  272.  
  273. static void
  274. get_widget_ids ()
  275. {
  276. int i,j,k ;
  277.  
  278. for (i=0;  i < N_PLAYERS;  i++)
  279.     {
  280.     if (game->player[i].physiology == ComputerPhysiology)
  281.     continue ;
  282.     game->x.table_deck[i] = XcuWlmInquireWidget
  283.               (game->x.wlm_id[i], "XcuDeck", "table") ;
  284.     game->x.play_tbl[i] = XcuWlmInquireWidget
  285.               (game->x.wlm_id[i], "XcuTbl", "play") ;
  286.     game->x.exchange_tbl[i] = XcuWlmInquireWidget
  287.               (game->x.wlm_id[i], "XcuTbl", "exchange") ;
  288.     game->x.exchange_deck[i] = XcuWlmInquireWidget
  289.               (game->x.wlm_id[i], "XcuDeck", "exchange") ;
  290.     game->x.exchange_discard[i] = XcuWlmInquireWidget
  291.               (game->x.wlm_id[i], "XcuLabel", "discard") ;
  292.     game->x.exchange_waiting[i] = XcuWlmInquireWidget
  293.               (game->x.wlm_id[i], "XcuLabel", "waiting") ;
  294.     game->x.exchange_confirm_d[i] = XcuWlmInquireWidget
  295.               (game->x.wlm_id[i], "XcuCommand", "confirm_discard") ;
  296.     game->x.exchange_confirm_r[i] = XcuWlmInquireWidget
  297.               (game->x.wlm_id[i], "XcuCommand", "confirm_receipt") ;
  298.     game->x.moon_decision[i] = XcuWlmInquireWidget
  299.               (game->x.wlm_id[i], "XcuTbl", "moon_decision") ;
  300.     game->x.hand_decision[i] = XcuWlmInquireWidget
  301.               (game->x.wlm_id[i], "XcuTbl", "hand_decision") ;
  302.     game->x.south_bitmap[i] = XcuWlmInquireWidget
  303.               (game->x.wlm_id[i], "XcuDeck", "south") ;
  304.     game->x.north_bitmap[i] = XcuWlmInquireWidget
  305.               (game->x.wlm_id[i], "XcuDeck", "north") ;
  306.     game->x.west_bitmap[i] = XcuWlmInquireWidget
  307.               (game->x.wlm_id[i], "XcuDeck", "west") ;
  308.     game->x.east_bitmap[i] = XcuWlmInquireWidget
  309.               (game->x.wlm_id[i], "XcuDeck", "east") ;
  310.     for (j=0;  j < N_SUITS;  j++)
  311.     {
  312.     char bitmap_string[20] ;
  313.     sprintf (bitmap_string, "south_%s", game->suit[j].name) ;
  314.     game->x.south_suit[i][j] = XcuWlmInquireWidget
  315.                   (game->x.wlm_id[i], "Label", bitmap_string) ;
  316.     sprintf (bitmap_string, "north_%s", game->suit[j].name) ;
  317.     game->x.north_suit[i][j] = XcuWlmInquireWidget
  318.                   (game->x.wlm_id[i], "Label", bitmap_string) ;
  319.     sprintf (bitmap_string, "west_%s", game->suit[j].name) ;
  320.     game->x.west_suit[i][j] = XcuWlmInquireWidget
  321.                   (game->x.wlm_id[i], "Label", bitmap_string) ;
  322.     sprintf (bitmap_string, "east_%s", game->suit[j].name) ;
  323.     game->x.east_suit[i][j] = XcuWlmInquireWidget
  324.                   (game->x.wlm_id[i], "Label", bitmap_string) ;
  325.     }
  326.     game->x.south_suit[i][j] = XcuWlmInquireWidget
  327.               (game->x.wlm_id[i], "XcuLabel", "south_Blank") ;
  328.     game->x.north_suit[i][j] = XcuWlmInquireWidget
  329.               (game->x.wlm_id[i], "XcuLabel", "north_Blank") ;
  330.     game->x.west_suit[i][j] = XcuWlmInquireWidget
  331.               (game->x.wlm_id[i], "XcuLabel", "west_Blank") ;
  332.     game->x.east_suit[i][j] = XcuWlmInquireWidget
  333.               (game->x.wlm_id[i], "XcuLabel", "east_Blank") ;
  334.     }
  335.  
  336. for (i=0;  i < N_PLAYERS;  i++)
  337.     {
  338.     if (game->player[i].physiology == ComputerPhysiology)
  339.     continue ;
  340.     for (j=0;  j < N_SUITS;  j++)
  341.     {
  342.     game->x.hands[i][j] = (Widget *) XtMalloc (info->cards_per_suit[j] *
  343.                            sizeof (Widget)) ;
  344.     for (k=0;  k < info->cards_per_suit[j];  k++)
  345.         {
  346.         char name_string[40] ;
  347.         int card_number = game->suit[j].rank[k].card ;
  348.         int card_rank = info->deck[card_number].rank ;
  349.         sprintf (name_string, "%s%d", game->suit[j].character, k) ;
  350.         game->x.hands[i][j][k] =
  351.         XcuWlmInquireWidget
  352.         (game->x.wlm_id[i], "XcuCommand", name_string) ;
  353.         }
  354.     }
  355.     }
  356.  
  357. for (i=0;  i < N_PLAYERS;  i++)
  358.     {
  359.     if (game->player[i].physiology == ComputerPhysiology)
  360.     continue ;
  361.     for (j=0;  j < N_PLAYERS;  j++)
  362.     {
  363.     char points_string[20] ;
  364.     char tricks_string[20] ;
  365.     char score_string[20] ;
  366.     char plays_string[20] ;
  367.  
  368.     sprintf (points_string, "%s_points", game->seat[j]) ;
  369.     sprintf (tricks_string, "%s_tricks", game->seat[j]) ;
  370.     sprintf (score_string, "%s_score", game->seat[j]) ;
  371.     sprintf (plays_string, "%s_card", game->seat[j]) ;
  372.  
  373.     game->x.points[i][j] =
  374.         XcuWlmInquireWidget (game->x.wlm_id[i], "XcuLabel", points_string) ;
  375.     game->x.tricks[i][j] =
  376.         XcuWlmInquireWidget (game->x.wlm_id[i], "XcuLabel", tricks_string) ;
  377.     game->x.score[i][j] =
  378.         XcuWlmInquireWidget (game->x.wlm_id[i], "XcuLabel", score_string) ;
  379.     game->x.plays[i][j] =
  380.         XcuWlmInquireWidget (game->x.wlm_id[i], "XcuLabel", plays_string) ;
  381.     }
  382.     }
  383.  
  384. for (i=0;  i < N_PLAYERS;  i++)
  385.     {
  386.     if (game->player[i].physiology == ComputerPhysiology)
  387.     continue ;
  388.     for (j=0;  j < N_DISCARDS;  j++)
  389.     {
  390.     char discard_string[20] ;
  391.     sprintf (discard_string, "discard%d", j) ;
  392.     game->x.discards[i][j] =
  393.         XcuWlmInquireWidget(game->x.wlm_id[i], "XcuCommand",discard_string);
  394.     sprintf (discard_string, "discard%d", j) ;
  395.     game->x.discard_bitmap[i][j] =
  396.         XcuWlmInquireWidget(game->x.wlm_id[i], "XcuDeck",discard_string);
  397.     for (k=0;  k < N_SUITS; k++)
  398.         {
  399.         sprintf (discard_string, "%s%d", game->suit[k].name, j) ;
  400.         game->x.discard_suit[i][j][k] =
  401.         XcuWlmInquireWidget(game->x.wlm_id[i], "Label",
  402.                     discard_string);
  403.         }
  404.     sprintf (discard_string, "Blank%d", j) ;
  405.     game->x.discard_suit[i][j][k] =
  406.         XcuWlmInquireWidget(game->x.wlm_id[i], "XcuLabel",
  407.                 discard_string);
  408.     }
  409.     }
  410.  
  411. return ;
  412. }
  413.  
  414. static void
  415. install_callbacks ()
  416. {
  417. int i,j,k ;
  418. long *data ;
  419. for (k=0;  k < N_PLAYERS;  k++)
  420.     {
  421.     if (game->player[k].physiology == ComputerPhysiology)
  422.     continue ;
  423.     /*
  424.      * A callback for each of the possible cards in the hand
  425.      */
  426.     for (i=0;  i < N_SUITS;  i++)
  427.     {
  428.     for (j=0;  j < info->cards_per_suit[i];  j++)
  429.         {
  430.         char name_string[40] ;
  431.         sprintf (name_string, "%s%d", game->suit[i].character, j) ;
  432.         data = (long *) XtMalloc (3 * sizeof(long)) ;
  433.         data[0] = k ;
  434.         data[1] = i ;
  435.         data[2] = j ;
  436.         XcuWlmAddCallback ( game->x.wlm_id[k], NULL,
  437.                    "XcuCommand", name_string, "callback",
  438.                    card_picked, data ) ;
  439.         }
  440.     }
  441.     /*
  442.      * A callback for each of the discard positions
  443.      */
  444.     for (i=0;  i < N_DISCARDS;  i++)
  445.     {
  446.     char name_string[40] ;
  447.     sprintf (name_string, "discard%d", i) ;
  448.     data = (long *) XtMalloc (2 * sizeof(long)) ;
  449.     data[0] = k ;
  450.     data[1] = i ;
  451.     XcuWlmAddCallback (game->x.wlm_id[k], NULL, "XcuCommand", name_string,
  452.                 "callback", discard_picked, data ) ;
  453.     }
  454.     /*
  455.      * A callback for each of the 2 exchange commands
  456.      */
  457.     data = (long *) XtMalloc (1 * sizeof(long)) ;
  458.     data[0] = k ;
  459.     XcuWlmAddCallback (game->x.wlm_id[k], NULL, "XcuCommand", "confirm_discard",
  460.             "callback", confirm_discard, data ) ;
  461.     XcuWlmAddCallback (game->x.wlm_id[k], NULL, "XcuCommand", "confirm_receipt",
  462.             "callback", confirm_receipt, data ) ;
  463.  
  464.     /*
  465.      * A callback for each of the 2 shoot the moon decision commands
  466.      */
  467.     data = (long *) XtMalloc (1 * sizeof(long)) ;
  468.     data[0] = LowerMe ;
  469.     XcuWlmAddCallback (game->x.wlm_id[k], NULL, "XcuCommand", "lower_me",
  470.             "callback", moon_decision, data ) ;
  471.     data = (long *) XtMalloc (1 * sizeof(long)) ;
  472.     data[0] = RaiseOthers ;
  473.     XcuWlmAddCallback (game->x.wlm_id[k], NULL, "XcuCommand", "raise_others",
  474.             "callback", moon_decision, data ) ;
  475.  
  476.     /*
  477.      * A callback for each of the 2 hand decision commands
  478.      */
  479.     data = (long *) XtMalloc (2 * sizeof(long)) ;
  480.     data[0] = k ;
  481.     data[1] = AnotherHand ;
  482.     XcuWlmAddCallback (game->x.wlm_id[k], NULL, "XcuCommand", "another_hand",
  483.             "callback", hand_decision, data ) ;
  484.     data = (long *) XtMalloc (2 * sizeof(long)) ;
  485.     data[0] = k ;
  486.     data[1] = NoMore ;
  487.     XcuWlmAddCallback (game->x.wlm_id[k], NULL, "XcuCommand", "no_more",
  488.             "callback", hand_decision, data ) ;
  489.     }
  490. return ;
  491. }
  492.  
  493. #include <X11/Xcu/WlmP.h>
  494. #include <X11/Xcu/Tbl.h>
  495. #include <X11/Xcu/Deck.h>
  496. #include <X11/Xcu/Command.h>
  497. #include <X11/Xcu/Label.h>
  498. #include <X11/Xaw/Label.h>
  499.  
  500. void
  501. make_tag_class_list (ww)
  502.     XcuWlmWidget ww ;
  503. {
  504. TAG_CLASS_ENTRY(ww, "XcuWlm", xcuWlmWidgetClass) ;
  505. TAG_CLASS_ENTRY(ww, "XcuCommand", xcuCommandWidgetClass) ;
  506. TAG_CLASS_ENTRY(ww, "XcuTbl", xcuTblWidgetClass) ;
  507. TAG_CLASS_ENTRY(ww, "XcuDeck", xcuDeckWidgetClass) ;
  508. TAG_CLASS_ENTRY(ww, "XcuLabel", xcuLabelWidgetClass) ;
  509. TAG_CLASS_ENTRY(ww, "Label", labelWidgetClass) ;
  510. return ;
  511. }
  512.  
  513. void 
  514. refresh_screens ()
  515. {
  516. int i, j ;
  517. XEvent event ;
  518.  
  519. for (i=0;  i < N_PLAYERS;  i++)
  520.     {
  521.     if (game->player[i].physiology == HumanPhysiology)
  522.     {
  523. #define N_REFRESHES 200
  524.     for (j=0;  j < N_REFRESHES;  j++)
  525.         XcuWlmEvent (game->x.wlm_id[i]) ;
  526.     }
  527.     }
  528. return ;
  529. }
  530.  
  531. void 
  532. wait_for_player_events ()
  533. {
  534. int i ;
  535. XEvent event ;
  536.  
  537. XtAppPeekEvent (game->x.app, &event) ;
  538. for (i=0;  i < N_PLAYERS;  i++)
  539.     {
  540.     if (game->player[i].physiology == HumanPhysiology)
  541.     {
  542.     if (event.xany.display == game->x.dpy[i])
  543.         {
  544.         XcuWlmEvent (game->x.wlm_id[i]) ;
  545.         break ;
  546.         }
  547.     }
  548.     }
  549. return ;
  550. }
  551.  
  552. static void
  553. display_names ()
  554. {
  555. int i ;
  556. XStruct *x = &game->x ;
  557.  
  558. /*
  559.  * Every player sees himself as South
  560.  */
  561.  
  562. for (i=0;  i < N_PLAYERS;  i++)
  563.     {
  564.     int j = i ;
  565.     if (game->player[i].physiology == ComputerPhysiology)
  566.     continue ;
  567.     XcuWlmSetValue (game->x.wlm_id[i], "XcuLabel", "Splayer",
  568.             XtNlabel, game->player[j].name_string) ;
  569.  
  570.     if (++j == N_PLAYERS)
  571.     j = 0 ;
  572.     XcuWlmSetValue (game->x.wlm_id[i], "XcuLabel", "Wplayer",
  573.             XtNlabel, game->player[j].name_string) ;
  574.  
  575.     if (++j == N_PLAYERS)
  576.     j = 0 ;
  577.     XcuWlmSetValue (game->x.wlm_id[i], "XcuLabel", "Nplayer",
  578.             XtNlabel, game->player[j].name_string) ;
  579.  
  580.     if (++j == N_PLAYERS)
  581.     j = 0 ;
  582.     XcuWlmSetValue (game->x.wlm_id[i], "XcuLabel", "Eplayer",
  583.             XtNlabel, game->player[j].name_string) ;
  584.     }
  585. return ;
  586. }
  587.  
  588. void
  589. proc_message (msg, player)
  590.     String msg ;
  591.     int player ;
  592. {
  593. if (game->player[player].physiology == HumanPhysiology)
  594.     {
  595.     XcuWlmSetValue (game->x.wlm_id[player], "XcuLabel", "proc_msg",
  596.             XtNlabel, msg) ;
  597.     }
  598. return ;
  599. }
  600.  
  601. void
  602. err_message (msg, player)
  603.     String msg ;
  604.     int player ;
  605. {
  606. if (game->player[player].physiology == HumanPhysiology)
  607.     {
  608.     XcuWlmSetValue (game->x.wlm_id[player], "XcuLabel", "err_msg",
  609.             XtNlabel, msg) ;
  610.     }
  611. return ;
  612. }
  613.  
  614. static void
  615. find_program (player_index)
  616.     int player_index ;
  617. {
  618. extern void discard_program() ;
  619. extern void play_program() ;
  620. /* String description is in &game->player[player_index].name_string[1] */
  621. game->player[player_index].discard_program = discard_program ;
  622. game->player[player_index].play_program = play_program ;
  623. }
  624.  
  625. static void
  626. input_error (text, argv)
  627.     String text ;
  628.     char **argv ;
  629. {
  630. fprintf (stderr, "%s : Couldn't open file (%s)\n", argv[0], text) ;
  631. exit (1) ;
  632. }
  633.  
  634. static void
  635. syntax_error (argv)
  636.     char **argv ;
  637. {
  638. fprintf (stderr, "Usage: %s\n", argv[0]) ;
  639. fprintf (stderr, "      -goal %%d\n") ;
  640. fprintf (stderr, "      -jack\n") ;
  641. fprintf (stderr, "      -pass LeftRight     | LeftRightAcross     |\n") ;
  642. fprintf (stderr, "            LeftRightKeep | LeftRightAcrossKeep\n") ;
  643. fprintf (stderr, "      -drop\n") ;
  644. fprintf (stderr, "      -players filename\n") ;
  645. fprintf (stderr, "      -wlm filename\n") ;
  646. #ifdef NRAND48
  647. fprintf (stderr, "      -seed \"%%d %%d %%d\"\n") ;
  648. #else
  649. fprintf (stderr, "      -seed \"%%d\"\n") ;
  650. #endif
  651. fprintf (stderr, "      -sleep \"%%d\"\n") ;
  652. exit (1) ;
  653. }
  654.  
  655. static void CvtStringToPassingStyle() ;    /* Resource Converter */
  656. static XrmQuark    XrmQElr, XrmQElra, XrmQElrak, XrmQElrk ;/* Passing styles */
  657.  
  658. static void
  659. AddStringToPassingStyleConverter ()
  660. {
  661. XrmQElr   = XrmStringToQuark("leftright") ;
  662. XrmQElra = XrmStringToQuark("leftrightacross") ;
  663. XrmQElrak  = XrmStringToQuark("leftrightacrosskeep") ;
  664. XrmQElrk  = XrmStringToQuark("leftrightkeep") ;
  665. XtAddConverter (XtRString, XtRPassingStyle, CvtStringToPassingStyle, NULL, 0) ;
  666. return ;
  667. }
  668.  
  669. #include <ctype.h>
  670.  
  671. static void CvtStringToPassingStyle (args, num_args, fromVal, toVal)
  672.     XrmValuePtr *args ;        /* unused */
  673.     Cardinal    *num_args ;    /* unused */
  674.     XrmValuePtr fromVal ;
  675.     XrmValuePtr toVal ;
  676. {
  677. static PassingStyle    e ; /* must be static! */
  678. XrmQuark    q ;
  679. char    *s = (char *) fromVal->addr ;
  680.  
  681. if (s == NULL) return ;
  682.  
  683. q = XcuSimplifyArg (s, "xcu") ;
  684.  
  685. toVal->size = sizeof(PassingStyle) ;
  686. toVal->addr = (XPointer) &e ;
  687.  
  688. if (q == XrmQElr)  { e = LeftRight;        return; }
  689. if (q == XrmQElra) { e = LeftRightAcross;    return; }
  690. if (q == XrmQElrak){ e = LeftRightAcrossKeep;    return; }
  691. if (q == XrmQElrk) { e = LeftRightKeep;        return; }
  692.  
  693. toVal->size = 0 ;
  694. toVal->addr = NULL ;
  695. return ;
  696. }
  697.  
  698. XtErrorHandler
  699. handler (message)
  700.     char *message ;
  701. {
  702. fprintf (stderr, "\nHANDLER\n%s\n", message) ;
  703. abort () ;
  704. }
  705.  
  706. int
  707. Xhandler (dpy, s)
  708.     Display *dpy ;
  709.     XErrorEvent *s ;
  710. {
  711. char buf[200] ;
  712. XGetErrorText (dpy, s->error_code, buf, 200) ;
  713. fprintf (stderr, "\nHANDLER\n%s\n", buf) ;
  714. abort () ;
  715. }
  716.  
  717.