home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlib_StBytes.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  4KB  |  118 lines

  1. /* $XConsortium: StBytes.c /main/12 1996/10/22 14:23:01 kaleb $ */
  2. /*
  3.  
  4. Copyright (c) 1986  X Consortium
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  19. X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22.  
  23. Except as contained in this notice, the name of the X Consortium shall not be
  24. used in advertising or otherwise to promote the sale, use or other dealings
  25. in this Software without prior written authorization from the X Consortium.
  26.  
  27. */
  28.  
  29. #undef XLIB_ILLEGAL_ACCESS
  30.  
  31. #include <X11/Xlibint.h>
  32. #include <X11/Xatom.h>
  33.  
  34. /* insulate predefined atom numbers from cut routines */
  35. static Atom n_to_atom[8] = { 
  36.     XA_CUT_BUFFER0,
  37.     XA_CUT_BUFFER1,
  38.     XA_CUT_BUFFER2,
  39.     XA_CUT_BUFFER3,
  40.     XA_CUT_BUFFER4,
  41.     XA_CUT_BUFFER5,
  42.     XA_CUT_BUFFER6,
  43.     XA_CUT_BUFFER7};
  44.  
  45. XRotateBuffers (dpy, rotate)
  46.     register Display *dpy;
  47.     int rotate;
  48. {
  49.     return XRotateWindowProperties(dpy, RootWindow(dpy, 0), n_to_atom, 8, rotate);
  50. }
  51.     
  52. char *XFetchBuffer (dpy, nbytes, buffer)
  53.     register Display *dpy;
  54.     int *nbytes;
  55.     register int buffer;
  56. {
  57.     Atom actual_type;
  58.     int actual_format;
  59.     unsigned long nitems;
  60.     unsigned long leftover;
  61.     unsigned char *data;
  62.     *nbytes = 0;
  63.     if ((buffer < 0) || (buffer > 7)) return (NULL);
  64. /* XXX should be (sizeof (maxint) - 1)/4 */
  65.     if (XGetWindowProperty(dpy, RootWindow(dpy, 0), n_to_atom[buffer], 
  66.     0L, 10000000L, False, XA_STRING, 
  67.     &actual_type, &actual_format, &nitems, &leftover, &data) != Success) {
  68.     return (NULL);
  69.     }
  70.     if ( (actual_type == XA_STRING) &&  (actual_format != 32) ) {
  71.     *nbytes = nitems;
  72.     return((char *)data);
  73.     }
  74.     if ((char *) data != NULL) Xfree ((char *)data);
  75.     return(NULL);
  76. }
  77.  
  78. char *XFetchBytes (dpy, nbytes)
  79.     register Display *dpy;
  80.     int *nbytes;
  81. {
  82.     return (XFetchBuffer (dpy, nbytes, 0));
  83. }
  84.  
  85. #if NeedFunctionPrototypes
  86. XStoreBuffer (
  87.     register Display *dpy,
  88.     _Xconst char *bytes,
  89.     int nbytes,
  90.     register int buffer)
  91. #else
  92. XStoreBuffer (dpy, bytes, nbytes, buffer)
  93.     register Display *dpy;
  94.     char *bytes;
  95.     int nbytes;
  96.     register int buffer;
  97. #endif
  98. {
  99.     if ((buffer < 0) || (buffer > 7)) return 0;
  100.     return XChangeProperty(dpy, RootWindow(dpy, 0), n_to_atom[buffer], 
  101.     XA_STRING, 8, PropModeReplace, (unsigned char *) bytes, nbytes);
  102. }
  103.  
  104. #if NeedFunctionPrototypes
  105. XStoreBytes (
  106.     register Display *dpy,
  107.     _Xconst char *bytes,
  108.     int nbytes)
  109. #else
  110. XStoreBytes (dpy, bytes, nbytes)
  111.     register Display *dpy;
  112.     char *bytes;
  113.     int nbytes;
  114. #endif
  115. {
  116.     return XStoreBuffer (dpy, bytes, nbytes, 0);
  117. }
  118.