Blame src/DefErrMsg.c

Packit Service 2b1f13
/*
Packit Service 2b1f13
Packit Service 2b1f13
Copyright 1988, 1998  The Open Group
Packit Service 2b1f13
Packit Service 2b1f13
Permission to use, copy, modify, distribute, and sell this software and its
Packit Service 2b1f13
documentation for any purpose is hereby granted without fee, provided that
Packit Service 2b1f13
the above copyright notice appear in all copies and that both that
Packit Service 2b1f13
copyright notice and this permission notice appear in supporting
Packit Service 2b1f13
documentation.
Packit Service 2b1f13
Packit Service 2b1f13
The above copyright notice and this permission notice shall be included in
Packit Service 2b1f13
all copies or substantial portions of the Software.
Packit Service 2b1f13
Packit Service 2b1f13
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service 2b1f13
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service 2b1f13
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
Packit Service 2b1f13
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
Packit Service 2b1f13
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit Service 2b1f13
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit Service 2b1f13
Packit Service 2b1f13
Except as contained in this notice, the name of The Open Group shall not be
Packit Service 2b1f13
used in advertising or otherwise to promote the sale, use or other dealings
Packit Service 2b1f13
in this Software without prior written authorization from The Open Group.
Packit Service 2b1f13
Packit Service 2b1f13
*/
Packit Service 2b1f13
Packit Service 2b1f13
#ifdef HAVE_CONFIG_H
Packit Service 2b1f13
#include <config.h>
Packit Service 2b1f13
#endif
Packit Service 2b1f13
#include <stdio.h>
Packit Service 2b1f13
#include <X11/Xlibint.h>
Packit Service 2b1f13
#include <X11/Xproto.h>
Packit Service 2b1f13
#include <X11/Xmu/Error.h>
Packit Service 2b1f13
#include <X11/Xmu/SysUtil.h>
Packit Service 2b1f13
Packit Service 2b1f13
/*
Packit Service 2b1f13
 * XmuPrintDefaultErrorMessage - print a nice error that looks like the usual
Packit Service 2b1f13
 * message.  Returns 1 if the caller should consider exitting else 0.
Packit Service 2b1f13
 */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuPrintDefaultErrorMessage(Display *dpy, XErrorEvent *event, FILE *fp)
Packit Service 2b1f13
{
Packit Service 2b1f13
    char buffer[BUFSIZ];
Packit Service 2b1f13
    char mesg[BUFSIZ];
Packit Service 2b1f13
    char number[32];
Packit Service 2b1f13
    _Xconst char *mtype = "XlibMessage";
Packit Service 2b1f13
    register _XExtension *ext = (_XExtension *)NULL;
Packit Service 2b1f13
    _XExtension *bext = (_XExtension *)NULL;
Packit Service 2b1f13
    XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
Packit Service 2b1f13
    XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
Packit Service 2b1f13
    (void) fprintf(fp, "%s:  %s\n  ", mesg, buffer);
Packit Service 2b1f13
    XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
Packit Service 2b1f13
	mesg, BUFSIZ);
Packit Service 2b1f13
    (void) fprintf(fp, mesg, event->request_code);
Packit Service 2b1f13
    if (event->request_code < 128) {
Packit Service 2b1f13
	XmuSnprintf(number, sizeof(number), "%d", event->request_code);
Packit Service 2b1f13
	XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
Packit Service 2b1f13
    } else {
Packit Service 2b1f13
	/* XXX this is non-portable */
Packit Service 2b1f13
	for (ext = dpy->ext_procs;
Packit Service 2b1f13
	     ext && (ext->codes.major_opcode != event->request_code);
Packit Service 2b1f13
	     ext = ext->next)
Packit Service 2b1f13
	  ;
Packit Service 2b1f13
	if (ext)
Packit Service 2b1f13
	  XmuSnprintf(buffer, sizeof(buffer), "%s", ext->name);
Packit Service 2b1f13
	else
Packit Service 2b1f13
	    buffer[0] = '\0';
Packit Service 2b1f13
    }
Packit Service 2b1f13
    (void) fprintf(fp, " (%s)", buffer);
Packit Service 2b1f13
    fputs("\n  ", fp);
Packit Service 2b1f13
    if (event->request_code >= 128) {
Packit Service 2b1f13
	XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
Packit Service 2b1f13
			      mesg, BUFSIZ);
Packit Service 2b1f13
	(void) fprintf(fp, mesg, event->minor_code);
Packit Service 2b1f13
	if (ext) {
Packit Service 2b1f13
	    XmuSnprintf(mesg, sizeof(mesg),
Packit Service 2b1f13
			"%s.%d", ext->name, event->minor_code);
Packit Service 2b1f13
	    XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
Packit Service 2b1f13
	    (void) fprintf(fp, " (%s)", buffer);
Packit Service 2b1f13
	}
Packit Service 2b1f13
	fputs("\n  ", fp);
Packit Service 2b1f13
    }
Packit Service 2b1f13
    if (event->error_code >= 128) {
Packit Service 2b1f13
	/* kludge, try to find the extension that caused it */
Packit Service 2b1f13
	buffer[0] = '\0';
Packit Service 2b1f13
	for (ext = dpy->ext_procs; ext; ext = ext->next) {
Packit Service 2b1f13
	    if (ext->error_string)
Packit Service 2b1f13
		(*ext->error_string)(dpy, event->error_code, &ext->codes,
Packit Service 2b1f13
				     buffer, BUFSIZ);
Packit Service 2b1f13
	    if (buffer[0]) {
Packit Service 2b1f13
		bext = ext;
Packit Service 2b1f13
		break;
Packit Service 2b1f13
	    }
Packit Service 2b1f13
	    if (ext->codes.first_error &&
Packit Service 2b1f13
		ext->codes.first_error < event->error_code &&
Packit Service 2b1f13
		(!bext || ext->codes.first_error > bext->codes.first_error))
Packit Service 2b1f13
		bext = ext;
Packit Service 2b1f13
	}
Packit Service 2b1f13
	if (bext)
Packit Service 2b1f13
	    XmuSnprintf(buffer, sizeof(buffer), "%s.%d", bext->name,
Packit Service 2b1f13
			event->error_code - bext->codes.first_error);
Packit Service 2b1f13
	else
Packit Service 2b1f13
	    strcpy(buffer, "Value");
Packit Service 2b1f13
	XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ);
Packit Service 2b1f13
	if (mesg[0]) {
Packit Service 2b1f13
	    fputs("  ", fp);
Packit Service 2b1f13
	    (void) fprintf(fp, mesg, event->resourceid);
Packit Service 2b1f13
	    fputs("\n", fp);
Packit Service 2b1f13
	}
Packit Service 2b1f13
	/* let extensions try to print the values */
Packit Service 2b1f13
	for (ext = dpy->ext_procs; ext; ext = ext->next) {
Packit Service 2b1f13
	    if (ext->error_values)
Packit Service 2b1f13
		(*ext->error_values)(dpy, event, fp);
Packit Service 2b1f13
	}
Packit Service 2b1f13
    } else if ((event->error_code == BadWindow) ||
Packit Service 2b1f13
	       (event->error_code == BadPixmap) ||
Packit Service 2b1f13
	       (event->error_code == BadCursor) ||
Packit Service 2b1f13
	       (event->error_code == BadFont) ||
Packit Service 2b1f13
	       (event->error_code == BadDrawable) ||
Packit Service 2b1f13
	       (event->error_code == BadColor) ||
Packit Service 2b1f13
	       (event->error_code == BadGC) ||
Packit Service 2b1f13
	       (event->error_code == BadIDChoice) ||
Packit Service 2b1f13
	       (event->error_code == BadValue) ||
Packit Service 2b1f13
	       (event->error_code == BadAtom)) {
Packit Service 2b1f13
	if (event->error_code == BadValue)
Packit Service 2b1f13
	    XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
Packit Service 2b1f13
				  mesg, BUFSIZ);
Packit Service 2b1f13
	else if (event->error_code == BadAtom)
Packit Service 2b1f13
	    XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
Packit Service 2b1f13
				  mesg, BUFSIZ);
Packit Service 2b1f13
	else
Packit Service 2b1f13
	    XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
Packit Service 2b1f13
				  mesg, BUFSIZ);
Packit Service 2b1f13
	(void) fprintf(fp, mesg, event->resourceid);
Packit Service 2b1f13
	fputs("\n  ", fp);
Packit Service 2b1f13
    }
Packit Service 2b1f13
    XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
Packit Service 2b1f13
	mesg, BUFSIZ);
Packit Service 2b1f13
    (void) fprintf(fp, mesg, event->serial);
Packit Service 2b1f13
    fputs("\n  ", fp);
Packit Service 2b1f13
    XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
Packit Service 2b1f13
	mesg, BUFSIZ);
Packit Service 2b1f13
    (void) fprintf(fp, mesg, NextRequest(dpy)-1);
Packit Service 2b1f13
    fputs("\n", fp);
Packit Service 2b1f13
    if (event->error_code == BadImplementation) return 0;
Packit Service 2b1f13
    return 1;
Packit Service 2b1f13
}
Packit Service 2b1f13
Packit Service 2b1f13
Packit Service 2b1f13
/*
Packit Service 2b1f13
 * XmuSimpleErrorHandler - ignore errors for XQueryTree, XGetWindowAttributes,
Packit Service 2b1f13
 * and XGetGeometry; print a message for everything else.  In all case, do
Packit Service 2b1f13
 * not exit.
Packit Service 2b1f13
 */
Packit Service 2b1f13
int
Packit Service 2b1f13
XmuSimpleErrorHandler(Display *dpy, XErrorEvent *errorp)
Packit Service 2b1f13
{
Packit Service 2b1f13
    switch (errorp->request_code) {
Packit Service 2b1f13
      case X_QueryTree:
Packit Service 2b1f13
      case X_GetWindowAttributes:
Packit Service 2b1f13
        if (errorp->error_code == BadWindow) return 0;
Packit Service 2b1f13
	break;
Packit Service 2b1f13
      case X_GetGeometry:
Packit Service 2b1f13
	if (errorp->error_code == BadDrawable) return 0;
Packit Service 2b1f13
	break;
Packit Service 2b1f13
    }
Packit Service 2b1f13
    /* got a "real" X error */
Packit Service 2b1f13
    return XmuPrintDefaultErrorMessage (dpy, errorp, stderr);
Packit Service 2b1f13
}