2 * (c) Copyright 1989, 1990, 1991, 1992, 1993, 1994 OPEN SOFTWARE FOUNDATION, INC.
10 static char rcsid[] = "$XConsortium: WmError.c /main/6 1996/10/07 14:27:34 drk $"
14 * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
23 #include <Dt/UserMsg.h>
28 * Function Declarations:
34 #define E_MAJOR_CODE 0
35 #define E_MINOR_CODE 1
36 #define E_RESOURCE_ID 2
37 #define E_ERROR_SERIAL 3
38 #define E_CURRENT_SERIAL 4
40 #define NUM_E_STRINGS 5
42 static char *pchErrorFormatNames [NUM_E_STRINGS] = {
50 static char *pchDefaultErrorFormat [NUM_E_STRINGS] = {
58 static char *pchErrorFormat [NUM_E_STRINGS];
65 /*************************************<->*************************************
67 * WmInitErrorHandler (display)
72 * This function initializes the window manager error handler.
77 * display = display we're talking about
80 *************************************<->***********************************/
83 WmInitErrorHandler (Display *display)
90 * Fetch the X error format strings from XErrorDB
92 for (i = 0; i< NUM_E_STRINGS; i++)
94 XGetErrorDatabaseText (display, "XlibMessage",
95 pchErrorFormatNames[i],
96 pchDefaultErrorFormat[i], buffer, BUFSIZ);
98 if ((pchErrorFormat[i] = (char *) XtMalloc (1+strlen(buffer))) == NULL)
100 Warning ("Insufficient memory for error message initialization.");
104 strcpy(pchErrorFormat[i], buffer);
109 XSetErrorHandler (WmXErrorHandler);
110 XSetIOErrorHandler (WmXIOErrorHandler);
112 XtSetWarningHandler (WmXtWarningHandler);
113 XtSetErrorHandler (WmXtErrorHandler);
115 } /* END OF FUNCTION WmInitErrorHandler */
118 /*************************************<->*************************************
120 * WmXErrorHandler (display, errorEvent)
125 * This function is the X error handler that is registered with X to
126 * handle X errors resulting from window management activities.
131 * display = display on which X error occurred
133 * errorEvent = pointer to a block of information describing the error
138 * wmGD.errorFlag = set to True
142 *************************************<->***********************************/
145 WmXErrorHandler (Display *display, XErrorEvent *errorEvent)
151 char message[BUFSIZ];
153 XGetErrorText (display, errorEvent->error_code, buffer, BUFSIZ);
154 Warning ("X error occurred during window management operation");
155 fprintf (stderr, "Description = '%s'\n ", buffer);
157 fprintf (stderr, pchErrorFormat[E_MAJOR_CODE], errorEvent->request_code);
158 sprintf(message, "%d", errorEvent->request_code);
159 XGetErrorDatabaseText (display, "XRequest", message,
160 " ", buffer, BUFSIZ);
161 fprintf (stderr, " (%s)\n ", buffer);
162 fprintf (stderr, pchErrorFormat[E_MINOR_CODE], errorEvent->minor_code);
163 fprintf (stderr, "\n ");
164 fprintf (stderr, pchErrorFormat[E_RESOURCE_ID], errorEvent->resourceid);
165 fprintf (stderr, "\n ");
166 fprintf (stderr, pchErrorFormat[E_ERROR_SERIAL], errorEvent->serial);
167 fprintf (stderr, "\n ");
168 fprintf (stderr, pchErrorFormat[E_CURRENT_SERIAL],
169 LastKnownRequestProcessed(display));
170 fprintf (stderr, "\n");
174 * Check for a BadWindow error for a managed window. If this error
175 * is detected indicate in the client data that the window no longer
179 if ((errorEvent->error_code == BadWindow) &&
180 !XFindContext (DISPLAY, errorEvent->resourceid, wmGD.windowContextType,
183 if (errorEvent->resourceid == pCD->client)
185 pCD->clientFlags |= CLIENT_DESTROYED;
189 wmGD.errorFlag = True;
190 wmGD.errorResource = errorEvent->resourceid;
191 wmGD.errorRequestCode = errorEvent->request_code;
195 } /* END OF FUNCTION WmXErrorHandler */
199 /*************************************<->*************************************
201 * WmXIOErrorHandler (display)
206 * This function is the X IO error handler that is registered with X to
207 * handle X IO errors. This function exits the window manager.
212 * display = X display on which the X IO error occurred
214 *************************************<->***********************************/
217 WmXIOErrorHandler (Display *display)
221 sprintf (err, "%s: %s\n", "I/O error on display:", XDisplayString(display));
224 ExitWM (WM_ERROR_EXIT_VALUE);
228 } /* END OF FUNCTIONS WmXIOErrorHandler */
232 /*************************************<->*************************************
234 * WmXtErrorHandler (message)
239 * This function is registered as the X Toolkit fatal error handler.
244 * message = pointer to an error message
246 *************************************<->***********************************/
249 WmXtErrorHandler (char *message)
253 ExitWM (WM_ERROR_EXIT_VALUE);
255 } /* END OF FUNCTION WmXtErrorHandler */
259 /*************************************<->*************************************
261 * WmXtWarningHandler (message)
266 * This function is registered as an X Toolkit warning handler.
271 * message = pointer to a warning message
273 *************************************<->***********************************/
276 WmXtWarningHandler (char *message)
283 } /* END OF FUNCTIONS WmXtWarningHandler */
286 /*************************************<->*************************************
293 * This function lists a message to stderr.
298 * message = pointer to a message string
300 *************************************<->***********************************/
303 Warning (char *message)
306 char pch[MAXWMPATH+1];
308 sprintf (pch, "%s: %s\n",
309 GETMESSAGE(20, 1, "Workspace Manager"), message);
311 _DtSimpleError (wmGD.mwmName, DtIgnore, NULL, pch, NULL);
313 fprintf (stderr, "%s: %s\n", wmGD.mwmName, message);
317 } /* END OF FUNCTION Warning */
322 /******************************<->*************************************
324 * PrintFormatted (format, message, message, ...)
329 * This function lists several messages to stderr using fprinf()
330 * formatting capabilities.
334 * s0-s9 = pointers to message strings
338 * Caller must provide his/her own argv[0] to this function.
339 ******************************<->***********************************/
343 PrintFormatted(char *f, char *s0, char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8, char *s9)
344 /* limit of ten args */
346 fprintf( stderr, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
348 } /* END OF FUNCTION PrintFormatted */
350 /************************ eof **************************/
351 #endif /* DEBUGGER */