123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /*
- * (c) Copyright 1993, 1994 Hewlett-Packard Company *
- * (c) Copyright 1993, 1994 International Business Machines Corp. *
- * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
- * (c) Copyright 1993, 1994 Novell, Inc. *
- */
- /* Copyright Massachusetts Institute of Technology 1985, 1986, 1987 */
- /*
- * $TOG: PrintXErr.c /main/7 1998/04/10 07:46:38 mgreess $
- */
- /* ** (c) Copyright Hewlett-Packard Company, 1990.*/
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- /*Lifted from xlib code. How to print a reasonably complete message */
- /*and NOT exit.*/
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- /*$TOG: PrintXErr.c /main/7 1998/04/10 07:46:38 mgreess $*/
- #include <stdio.h>
- #include <X11/Xlib.h>
- #include <X11/Xlibint.h>
- #include <Dt/UserMsg.h>
- int
- _DtPrintDefaultError(
- Display *dpy,
- XErrorEvent *event,
- char *msg )
- {
- _DtPrintDefaultErrorSafe(dpy, event, msg, BUFSIZ);
- /* XXX retval? */
-
- /* COV: 87468 nothing actually checks this return value */
- return(1);
- }
- #define _DTP_STRNCAT(s1, s2, nb, ec) \
- { \
- strncat((s1),(s2),(nb)); \
- (nb)-=strlen(s2); \
- if (0>=(nb)) return (ec); \
- }
- int
- _DtPrintDefaultErrorSafe(
- Display *dpy,
- XErrorEvent *event,
- char *msg,
- int bytes)
- {
- char buffer[BUFSIZ];
- char fpBuf[BUFSIZ];
- char *fp;
- char mesg[BUFSIZ];
- char number[32];
- char *mtype = "XlibMessage";
- int nbytes = bytes-1;
- _XExtension *ext = (_XExtension *)NULL;
- memset(msg, 0, bytes);
- {
- XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
- XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
- _DTP_STRNCAT(msg, mesg, nbytes, event->error_code);
- _DTP_STRNCAT(msg, ": ", nbytes, event->error_code);
- _DTP_STRNCAT(msg, buffer, nbytes, event->error_code);
- _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
- }
- {
- XGetErrorDatabaseText(
- dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ);
- if (strlen(mesg) < BUFSIZ-10)
- fp = fpBuf;
- else
- fp = malloc(strlen(mesg) + 10);
- (void) sprintf(fp, mesg, event->request_code);
- _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
- if (fp != fpBuf) free(fp);
- }
- {
- if (event->request_code < 128)
- {
- sprintf(number, "%d", event->request_code);
- XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
- }
- else
- {
- for (ext = dpy->ext_procs;
- ext && (ext->codes.major_opcode != event->request_code);
- ext = ext->next)
- ;
- if (ext)
- {
- strncpy(buffer, ext->name, BUFSIZ-1);
- buffer[BUFSIZ-1] = '\0';
- }
- else
- buffer[0] = '\0';
- }
- _DTP_STRNCAT(msg, " (", nbytes, event->error_code);
- _DTP_STRNCAT(msg, buffer, nbytes, event->error_code);
- _DTP_STRNCAT(msg, ")\n ", nbytes, event->error_code);
- }
- {
- if (event->request_code >= 128)
- {
- XGetErrorDatabaseText(
- dpy, mtype, "MinorCode", "Request Minor code %d", mesg, BUFSIZ);
- if (strlen(mesg) < BUFSIZ-10)
- fp = fpBuf;
- else
- fp = malloc(strlen(mesg) + 10);
- (void) sprintf(fp, mesg, event->minor_code);
-
- _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
- if (fp != fpBuf) free(fp);
- if (ext)
- {
- if (strlen(ext->name) < BUFSIZ-10)
- fp = fpBuf;
- else
- fp = malloc(strlen(ext->name) + 10);
- sprintf(fp, "%s.%d", ext->name, event->minor_code);
- XGetErrorDatabaseText(dpy, "XRequest", fp, "", buffer, BUFSIZ);
- if (fp != fpBuf) free(fp);
- }
- _DTP_STRNCAT(msg, "\n (", nbytes, event->error_code);
- _DTP_STRNCAT(msg, buffer, nbytes, event->error_code);
- _DTP_STRNCAT(msg, ")", nbytes, event->error_code);
- }
- }
- if (event->error_code >= 128)
- {
- /* kludge, try to find the extension that caused it */
- buffer[0] = '\0';
- for (ext = dpy->ext_procs; ext; ext = ext->next)
- {
- if (ext->error_string)
- (*ext->error_string)(dpy, event->error_code, &ext->codes,
- buffer, BUFSIZ);
- if (buffer[0])
- break;
- }
- if (buffer[0])
- {
- if (strlen(buffer) < BUFSIZ-10)
- sprintf(buffer,
- "%s.%d",
- ext->name,
- event->error_code - ext->codes.first_error);
- }
- else
- strcpy(buffer, "Value");
- XGetErrorDatabaseText(dpy, mtype, buffer, "Value 0x%x", mesg, BUFSIZ);
- if (*mesg)
- {
- if (strlen(mesg) < BUFSIZ-10)
- fp = fpBuf;
- else
- fp = malloc(strlen(mesg) + 10);
- (void) sprintf(fp, mesg, event->resourceid);
- _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
- _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
- if (fp != fpBuf) free(fp);
- }
- }
- else if ((event->error_code == BadWindow) ||
- (event->error_code == BadPixmap) ||
- (event->error_code == BadCursor) ||
- (event->error_code == BadFont) ||
- (event->error_code == BadDrawable) ||
- (event->error_code == BadColor) ||
- (event->error_code == BadGC) ||
- (event->error_code == BadIDChoice) ||
- (event->error_code == BadValue) ||
- (event->error_code == BadAtom))
- {
- if (event->error_code == BadValue)
- XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
- mesg, BUFSIZ);
- else if (event->error_code == BadAtom)
- XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
- mesg, BUFSIZ);
- else
- XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
- mesg, BUFSIZ);
- if (strlen(mesg) < BUFSIZ-10)
- fp = fpBuf;
- else
- fp = malloc(strlen(mesg) + 10);
- (void) sprintf(fp, mesg, event->resourceid);
- _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
- _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
- if (fp != fpBuf) free(fp);
- }
- {
- XGetErrorDatabaseText(
- dpy, mtype, "ErrorSerial", "Error Serial #%d", mesg, BUFSIZ);
- if (strlen(mesg) < BUFSIZ-10)
- fp = fpBuf;
- else
- fp = malloc(strlen(mesg) + 10);
- (void) sprintf(fp, mesg, event->serial);
- _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
- _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
- if (fp != fpBuf) free(fp);
- }
- {
- XGetErrorDatabaseText(
- dpy, mtype, "CurrentSerial", "Current Serial #%d", mesg, BUFSIZ);
- if (strlen(mesg) < BUFSIZ-10)
- fp = fpBuf;
- else
- fp = malloc(strlen(mesg) + 10);
- (void) sprintf(fp, mesg, dpy->request);
- _DTP_STRNCAT(msg, fp, nbytes, event->error_code);
- _DTP_STRNCAT(msg, "\n ", nbytes, event->error_code);
- if (fp != fpBuf) free(fp);
- }
- if (event->error_code == BadImplementation) return 0;
- return 1;
- }
|