1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#include <stdio.h>
#include "constant.h"
/**** x include files ****/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/keysymdef.h>
#if USE_LONGJMP
#include <setjmp.h>
#endif
#include "extern.h"
/******************************************************************************
my_error_handler (my_display, my_error)
Handle those pesky errors which used to completely destroy the game. Now
they cause the game to dump the current board state, then exit gracefully.
******************************************************************************/
my_error_handler (my_display, my_error)
Display *my_display;
XErrorEvent *my_error;
{
char message[MAX_LINE];
/** Grab the system error message and print it **/
XGetErrorText (my_display, my_error->error_code, message, MAX_LINE);
throw_message ("ERROR: ", "Unrecoverable, code %s", message);
/** Dump the board and exit **/
fprintf (stderr, " dumping board to %s\n", Config->file_store_map);
dump_board (Config->file_store_map, FALSE);
exit (0);
}
/******************************************************************************
my_io_error_handler (my_display)
Attempt to recover from an error caused by someone remotely executing one
of the xwindows. Tries to find the window that has been eliminated, and
removes that player from the game. Failing that, dumps the board.
******************************************************************************/
my_io_error_handler (my_display)
Display *my_display;
{
int player,
bad_player;
static int iteration=0;
/** If this routine gets called many times, something is seriously wrong **/
if (iteration < 20)
iteration++;
else
{
/**
fprintf (stderr, "EXTRA FATAL ERROR: display %s\n",
XDisplayName (my_display));
**/
throw_error ("Lost X-Window connection", NULL);
}
/** Match the error window with a particular player **/
bad_player = -1;
for (player=0; player<Config->player_count; player++)
if (XWindow[player]->display == my_display)
bad_player = player;
/** Print error message and dump board **/
fprintf (stderr, "FATAL ERROR: player %d\n", bad_player);
fprintf (stderr, " dumping board to %s\n", Config->file_store_map);
dump_board (Config->file_store_map, FALSE);
/** Continue only if error window found, disabling that player **/
if (bad_player < 0)
throw_error ("Cannot find resolve display death", NULL);
else
XWindow[bad_player]->open = FALSE;
/** Return, in whatever manner is selected, to the main program **/
#if USE_LONGJMP
longjmp (Config->saved_environment, 1);
return (0);
#endif
#if USE_PROCEDURE
#if USE_UNIX
run_unix_loop ();
#else
run_generic_loop ();
#endif
#endif
#if !USE_FATAL_RECOVER
exit (0);
#endif
}
/******************************************************************************
throw_error (control_string, parameter_string)
Print error message defined by <control_string> with argument
<parameter_string> and exit the program.
******************************************************************************/
throw_error (control_string, parameter_string)
char *control_string,
*parameter_string;
{
throw_message ("ERROR: ", control_string, parameter_string);
exit (0);
}
/******************************************************************************
throw_warning (control_string, parameter_string)
Print warning message defined by <control_string> with argument
<parameter_string>.
******************************************************************************/
throw_warning (control_string, parameter_string)
char *control_string,
*parameter_string;
{
throw_message ("WARNING: ", control_string, parameter_string);
}
/******************************************************************************
throw_message (type_string, control_string, parameter_string)
Print generic message with prefix <type_string>, as defined by
<control_string> with argument <parameter_string>.
******************************************************************************/
throw_message (type_string, control_string, parameter_string)
char *type_string,
*control_string,
*parameter_string;
{
char full_string[200],
temp_string[200];
if (parameter_string == NULL)
sprintf (full_string, "%s%s\n", type_string, control_string);
else
{
sprintf (temp_string, "%s%s\n", type_string, control_string);
sprintf (full_string, temp_string, parameter_string);
}
fprintf (stderr, full_string);
fflush (stderr);
}
|