home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / X / XErrDes.c.orig < prev    next >
Encoding:
Text File  |  1991-05-04  |  3.9 KB  |  141 lines

  1. /*
  2.  * $XConsortium: XErrDes.c,v 11.45 91/05/04 14:02:29 rws Exp $
  3.  */
  4.  
  5. /***********************************************************
  6. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  7. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  8.  
  9.                         All Rights Reserved
  10.  
  11. Permission to use, copy, modify, and distribute this software and its 
  12. documentation for any purpose and without fee is hereby granted, 
  13. provided that the above copyright notice appear in all copies and that
  14. both that copyright notice and this permission notice appear in 
  15. supporting documentation, and that the names of Digital or MIT not be
  16. used in advertising or publicity pertaining to distribution of the
  17. software without specific, written prior permission.  
  18.  
  19. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  21. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  22. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  23. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  24. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  25. SOFTWARE.
  26.  
  27. ******************************************************************/
  28.  
  29. #include "Xlibint.h"
  30. #include <X11/Xos.h>
  31. #include "Xresource.h"
  32. #include <stdio.h>
  33.  
  34. #ifndef ERRORDB
  35. #define ERRORDB "/usr/lib/X11/XErrorDB"
  36. #endif
  37.  
  38. #if __STDC__
  39. #define Const const
  40. #else
  41. #define Const /**/
  42. #endif
  43.  
  44. /*
  45.  * descriptions of errors in Section 4 of Protocol doc (pp. 350-351); more
  46.  * verbose descriptions are given in the error database
  47.  */
  48. static Const char * Const _XErrorList[] = {
  49.     /* No error    */        "no error",
  50.     /* BadRequest */        "BadRequest",
  51.     /* BadValue    */        "BadValue",
  52.     /* BadWindow */        "BadWindow",
  53.     /* BadPixmap */        "BadPixmap",
  54.     /* BadAtom */        "BadAtom",
  55.     /* BadCursor */        "BadCursor",
  56.     /* BadFont */        "BadFont",
  57.     /* BadMatch    */        "BadMatch",
  58.     /* BadDrawable */        "BadDrawable",
  59.     /* BadAccess */        "BadAccess",
  60.     /* BadAlloc    */        "BadAlloc",
  61.     /* BadColor */          "BadColor",
  62.     /* BadGC */          "BadGC",
  63.     /* BadIDChoice */        "BadIDChoice",
  64.     /* BadName */        "BadName",
  65.     /* BadLength */        "BadLength",
  66.     /* BadImplementation */    "BadImplementation",
  67. };
  68.  
  69.  
  70. XGetErrorText(dpy, code, buffer, nbytes)
  71.     register int code;
  72.     register Display *dpy;
  73.     char *buffer;
  74.     int nbytes;
  75. {
  76.     char buf[32];
  77.     register _XExtension *ext;
  78.  
  79.     if (nbytes == 0) return;
  80.     if (code <= BadImplementation && code > 0) {
  81.     sprintf(buf, "%d", code);
  82.     XGetErrorDatabaseText(dpy, "XProtoError", buf, _XErrorList[code],
  83.                   buffer, nbytes);
  84.     } else
  85.     sprintf(buffer, "%d", code);
  86.     ext = dpy->ext_procs;
  87.     while (ext) {        /* call out to any extensions interested */
  88.      if (ext->error_string != NULL) 
  89.          (*ext->error_string)(dpy, code, &ext->codes, buffer, nbytes);
  90.      ext = ext->next;
  91.     }    
  92.     return;
  93. }
  94.  
  95. #if NeedFunctionPrototypes
  96. /*ARGSUSED*/
  97. XGetErrorDatabaseText(
  98.     Display *dpy,
  99.     register _Xconst char *name,
  100.     register _Xconst char *type,
  101.     _Xconst char *defaultp,
  102.     char *buffer,
  103.     int nbytes)
  104. #else
  105. /*ARGSUSED*/
  106. XGetErrorDatabaseText(dpy, name, type, defaultp, buffer, nbytes)
  107.     Display *dpy;
  108.     register char *name, *type;
  109.     char *defaultp;
  110.     char *buffer;
  111.     int nbytes;
  112. #endif
  113. {
  114.  
  115.     static XrmDatabase db;
  116.     static int initialized = False;
  117.     XrmString type_str;
  118.     XrmValue result;
  119.     char temp[BUFSIZ];
  120.  
  121.     if (nbytes == 0) return;
  122.     if (!initialized) {
  123.     XrmInitialize();
  124.     db = XrmGetFileDatabase(ERRORDB);
  125.     initialized = True;
  126.     }
  127.     if (db)
  128.     {
  129.     sprintf(temp, "%s.%s", name, type);
  130.     XrmGetResource(db, temp, "ErrorType.ErrorNumber", &type_str, &result);
  131.     }
  132.     else
  133.     result.addr = (XPointer)NULL;
  134.     if (!result.addr) {
  135.     result.addr = (XPointer) defaultp;
  136.     result.size = strlen(defaultp) + 1;
  137.     }
  138.     (void) strncpy (buffer, (char *) result.addr, nbytes);
  139.     if (result.size > nbytes) buffer[nbytes-1] = '\0';
  140. }
  141.