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 libraries 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>
48 #include <Dt/UserMsg.h>
56 _DtPrintDefaultErrorSafe(dpy, event, msg, BUFSIZ);
59 /* COV: 87468 nothing actually checks this return value */
63 #define _DTP_STRNCAT(s1, s2, nb, ec) \
65 strncat((s1),(s2),(nb)); \
67 if (0>=(nb)) return (ec); \
71 _DtPrintDefaultErrorSafe(
82 char *mtype = "XlibMessage";
84 register _XExtension *ext = (_XExtension *)NULL;
86 memset(msg, 0, bytes);
90 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
91 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
93 _DTP_STRNCAT(msg, mesg, nbytes, event->error_code);
94 _DTP_STRNCAT(msg, ": ", nbytes, event->error_code);
95 _DTP_STRNCAT(msg, buffer, nbytes, event->error_code);
96 _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
100 XGetErrorDatabaseText(
101 dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ);
103 if (strlen(mesg) < BUFSIZ-10)
106 fp = malloc(strlen(mesg) + 10);
108 (void) sprintf(fp, mesg, event->request_code);
110 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
112 if (fp != fpBuf) free(fp);
116 if (event->request_code < 128)
118 sprintf(number, "%d", event->request_code);
119 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
123 for (ext = dpy->ext_procs;
124 ext && (ext->codes.major_opcode != event->request_code);
129 strncpy(buffer, ext->name, BUFSIZ-1);
130 buffer[BUFSIZ-1] = '\0';
136 _DTP_STRNCAT(msg, " (", nbytes, event->error_code);
137 _DTP_STRNCAT(msg, buffer, nbytes, event->error_code);
138 _DTP_STRNCAT(msg, ")\n ", nbytes, event->error_code);
142 if (event->request_code >= 128)
144 XGetErrorDatabaseText(
145 dpy, mtype, "MinorCode", "Request Minor code %d", mesg, BUFSIZ);
146 if (strlen(mesg) < BUFSIZ-10)
149 fp = malloc(strlen(mesg) + 10);
151 (void) sprintf(fp, mesg, event->minor_code);
153 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
155 if (fp != fpBuf) free(fp);
159 if (strlen(ext->name) < BUFSIZ-10)
162 fp = malloc(strlen(ext->name) + 10);
164 sprintf(fp, "%s.%d", ext->name, event->minor_code);
166 XGetErrorDatabaseText(dpy, "XRequest", fp, "", buffer, BUFSIZ);
168 if (fp != fpBuf) free(fp);
171 _DTP_STRNCAT(msg, "\n (", nbytes, event->error_code);
172 _DTP_STRNCAT(msg, buffer, nbytes, event->error_code);
173 _DTP_STRNCAT(msg, ")", nbytes, event->error_code);
177 if (event->error_code >= 128)
179 /* kludge, try to find the extension that caused it */
181 for (ext = dpy->ext_procs; ext; ext = ext->next)
183 if (ext->error_string)
184 (*ext->error_string)(dpy, event->error_code, &ext->codes,
191 if (strlen(buffer) < BUFSIZ-10)
195 event->error_code - ext->codes.first_error);
198 strcpy(buffer, "Value");
199 XGetErrorDatabaseText(dpy, mtype, buffer, "Value 0x%x", mesg, BUFSIZ);
202 if (strlen(mesg) < BUFSIZ-10)
205 fp = malloc(strlen(mesg) + 10);
207 (void) sprintf(fp, mesg, event->resourceid);
209 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
210 _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
212 if (fp != fpBuf) free(fp);
215 else if ((event->error_code == BadWindow) ||
216 (event->error_code == BadPixmap) ||
217 (event->error_code == BadCursor) ||
218 (event->error_code == BadFont) ||
219 (event->error_code == BadDrawable) ||
220 (event->error_code == BadColor) ||
221 (event->error_code == BadGC) ||
222 (event->error_code == BadIDChoice) ||
223 (event->error_code == BadValue) ||
224 (event->error_code == BadAtom))
226 if (event->error_code == BadValue)
227 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
229 else if (event->error_code == BadAtom)
230 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
233 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
236 if (strlen(mesg) < BUFSIZ-10)
239 fp = malloc(strlen(mesg) + 10);
241 (void) sprintf(fp, mesg, event->resourceid);
243 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
244 _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
246 if (fp != fpBuf) free(fp);
250 XGetErrorDatabaseText(
251 dpy, mtype, "ErrorSerial", "Error Serial #%d", mesg, BUFSIZ);
253 if (strlen(mesg) < BUFSIZ-10)
256 fp = malloc(strlen(mesg) + 10);
258 (void) sprintf(fp, mesg, event->serial);
260 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
261 _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
263 if (fp != fpBuf) free(fp);
267 XGetErrorDatabaseText(
268 dpy, mtype, "CurrentSerial", "Current Serial #%d", mesg, BUFSIZ);
270 if (strlen(mesg) < BUFSIZ-10)
273 fp = malloc(strlen(mesg) + 10);
275 (void) sprintf(fp, mesg, dpy->request);
277 _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
278 _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
280 if (fp != fpBuf) free(fp);
283 if (event->error_code == BadImplementation) return 0;