2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
25 * (c) Copyright 1993, 1994 International Business Machines Corp. *
26 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
27 * (c) Copyright 1993, 1994 Novell, Inc. *
30 /* Copyright Massachusetts Institute of Technology 1985, 1986, 1987 */
33 * $TOG: PrintXErr.c /main/7 1998/04/10 07:46:38 mgreess $
36 /* ** (c) Copyright Hewlett-Packard Company, 1990.*/
38 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
39 /*Lifted from xlib code. How to print a reasonably complete message */
41 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
42 /*$TOG: PrintXErr.c /main/7 1998/04/10 07:46:38 mgreess $*/
46 #include <X11/Xlibint.h>
54 _DtPrintDefaultErrorSafe(dpy, event, msg, BUFSIZ);
57 #define _DTP_STRNCAT(s1, s2, nb, ec) \
59 strncat((s1),(s2),(nb)); \
61 if (0>=(nb)) return (ec); \
65 _DtPrintDefaultErrorSafe(
76 char *mtype = "XlibMessage";
78 register _XExtension *ext = (_XExtension *)NULL;
80 memset(msg, 0, bytes);
84 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
85 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
87 _DTP_STRNCAT(msg, mesg, nbytes, event->error_code);
88 _DTP_STRNCAT(msg, ": ", nbytes, event->error_code);
89 _DTP_STRNCAT(msg, buffer, nbytes, event->error_code);
90 _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
94 XGetErrorDatabaseText(
95 dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ);
97 if (strlen(mesg) < BUFSIZ-10)
100 fp = malloc(strlen(mesg) + 10);
102 (void) sprintf(fp, mesg, event->request_code);
104 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
106 if (fp != fpBuf) free(fp);
110 if (event->request_code < 128)
112 sprintf(number, "%d", event->request_code);
113 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
117 for (ext = dpy->ext_procs;
118 ext && (ext->codes.major_opcode != event->request_code);
123 strncpy(buffer, ext->name, BUFSIZ-1);
124 buffer[BUFSIZ-1] = '\0';
130 _DTP_STRNCAT(msg, " (", nbytes, event->error_code);
131 _DTP_STRNCAT(msg, buffer, nbytes, event->error_code);
132 _DTP_STRNCAT(msg, ")\n ", nbytes, event->error_code);
136 if (event->request_code >= 128)
138 XGetErrorDatabaseText(
139 dpy, mtype, "MinorCode", "Request Minor code %d", mesg, BUFSIZ);
140 if (strlen(mesg) < BUFSIZ-10)
143 fp = malloc(strlen(mesg) + 10);
145 (void) sprintf(fp, mesg, event->minor_code);
147 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
149 if (fp != fpBuf) free(fp);
153 if (strlen(ext->name) < BUFSIZ-10)
156 fp = malloc(strlen(ext->name) + 10);
158 sprintf(fp, "%s.%d", ext->name, event->minor_code);
160 XGetErrorDatabaseText(dpy, "XRequest", fp, "", buffer, BUFSIZ);
162 if (fp != fpBuf) free(fp);
165 _DTP_STRNCAT(msg, "\n (", nbytes, event->error_code);
166 _DTP_STRNCAT(msg, buffer, nbytes, event->error_code);
167 _DTP_STRNCAT(msg, ")", nbytes, event->error_code);
171 if (event->error_code >= 128)
173 /* kludge, try to find the extension that caused it */
175 for (ext = dpy->ext_procs; ext; ext = ext->next)
177 if (ext->error_string)
178 (*ext->error_string)(dpy, event->error_code, &ext->codes,
185 if (strlen(buffer) < BUFSIZ-10)
189 event->error_code - ext->codes.first_error);
192 strcpy(buffer, "Value");
193 XGetErrorDatabaseText(dpy, mtype, buffer, "Value 0x%x", mesg, BUFSIZ);
196 if (strlen(mesg) < BUFSIZ-10)
199 fp = malloc(strlen(mesg) + 10);
201 (void) sprintf(fp, mesg, event->resourceid);
203 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
204 _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
206 if (fp != fpBuf) free(fp);
209 else if ((event->error_code == BadWindow) ||
210 (event->error_code == BadPixmap) ||
211 (event->error_code == BadCursor) ||
212 (event->error_code == BadFont) ||
213 (event->error_code == BadDrawable) ||
214 (event->error_code == BadColor) ||
215 (event->error_code == BadGC) ||
216 (event->error_code == BadIDChoice) ||
217 (event->error_code == BadValue) ||
218 (event->error_code == BadAtom))
220 if (event->error_code == BadValue)
221 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
223 else if (event->error_code == BadAtom)
224 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
227 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
230 if (strlen(mesg) < BUFSIZ-10)
233 fp = malloc(strlen(mesg) + 10);
235 (void) sprintf(fp, mesg, event->resourceid);
237 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
238 _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
240 if (fp != fpBuf) free(fp);
244 XGetErrorDatabaseText(
245 dpy, mtype, "ErrorSerial", "Error Serial #%d", mesg, BUFSIZ);
247 if (strlen(mesg) < BUFSIZ-10)
250 fp = malloc(strlen(mesg) + 10);
252 (void) sprintf(fp, mesg, event->serial);
254 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
255 _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
257 if (fp != fpBuf) free(fp);
261 XGetErrorDatabaseText(
262 dpy, mtype, "CurrentSerial", "Current Serial #%d", mesg, BUFSIZ);
264 if (strlen(mesg) < BUFSIZ-10)
267 fp = malloc(strlen(mesg) + 10);
269 (void) sprintf(fp, mesg, dpy->request);
271 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
272 _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
274 if (fp != fpBuf) free(fp);
277 if (event->error_code == BadImplementation) return 0;