home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / lib / PEXlib / pl_nameset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  4.9 KB  |  246 lines

  1. /* $XConsortium: pl_nameset.c,v 1.4 92/08/26 13:06:10 mor Exp $ */
  2.  
  3. /******************************************************************************
  4. Copyright 1987,1991 by Digital Equipment Corporation, Maynard, Massachusetts
  5. Copyright 1992 by the Massachusetts Institute of Technology
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, distribute, and sell this software and its
  10. documentation for any purpose is hereby granted without fee, provided that
  11. the above copyright notice appear in all copies and that both that copyright
  12. notice and this permission notice appear in supporting documentation, and that
  13. the name of Digital or M.I.T. not be used in advertising or publicity
  14. pertaining to distribution of the software without specific, written prior
  15. permission.  Digital and M.I.T. make no representations about the suitability
  16. of this software for any purpose.  It is provided "as is" without express or
  17. implied warranty.
  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. #include "PEXlib.h"
  29. #include "PEXlibint.h"
  30.  
  31.  
  32. PEXNameSet
  33. PEXCreateNameSet (display)
  34.  
  35. INPUT Display        *display;
  36.  
  37. {
  38.     pexCreateNameSetReq    *req;
  39.     PEXNameSet        ns;
  40.  
  41.  
  42.     /*
  43.      * Get a nameset resource id from X.
  44.      */
  45.  
  46.     ns = XAllocID (display);
  47.  
  48.  
  49.     /*
  50.      * Lock around the critical section, for multithreading.
  51.      */
  52.  
  53.     LockDisplay (display);
  54.  
  55.  
  56.     /*
  57.      * Put the request in the X request buffer.
  58.      */
  59.  
  60.     PEXGetReq (CreateNameSet, req);
  61.     req->id = ns;
  62.  
  63.  
  64.     /*
  65.      * Done, so unlock and check for synchronous-ness.
  66.      */
  67.  
  68.     UnlockDisplay (display);
  69.     PEXSyncHandle (display);
  70.  
  71.     return (ns);
  72. }
  73.  
  74.  
  75. void
  76. PEXFreeNameSet (display, ns)
  77.  
  78. INPUT Display        *display;
  79. INPUT PEXNameSet    ns;
  80.  
  81. {
  82.     pexFreeNameSetReq    *req;
  83.  
  84.  
  85.     /*
  86.      * Lock around the critical section, for multithreading.
  87.      */
  88.  
  89.     LockDisplay (display);
  90.  
  91.  
  92.     /*
  93.      * Put the request in the X request buffer.
  94.      */
  95.  
  96.     PEXGetReq (FreeNameSet, req);
  97.     req->id = ns;
  98.  
  99.  
  100.     /*
  101.      * Done, so unlock and check for synchronous-ness.
  102.      */
  103.  
  104.     UnlockDisplay (display);
  105.     PEXSyncHandle (display);
  106. }
  107.  
  108.  
  109. void
  110. PEXCopyNameSet (display, srcNs, destNs)
  111.  
  112. INPUT Display        *display;
  113. INPUT PEXNameSet    srcNs;
  114. INPUT PEXNameSet    destNs;
  115.  
  116. {
  117.     pexCopyNameSetReq    *req;
  118.  
  119.  
  120.     /*
  121.      * Lock around the critical section, for multithreading.
  122.      */
  123.  
  124.     LockDisplay (display);
  125.  
  126.  
  127.     /*
  128.      * Put the request in the X request buffer.
  129.      */
  130.  
  131.     PEXGetReq (CopyNameSet, req);
  132.     req->src = srcNs;
  133.     req->dst = destNs;
  134.  
  135.  
  136.     /*
  137.      * Done, so unlock and check for synchronous-ness.
  138.      */
  139.  
  140.     UnlockDisplay (display);
  141.     PEXSyncHandle (display);
  142. }
  143.  
  144.  
  145. Status
  146. PEXGetNameSet (display, ns, numNamesReturn, namesReturn)
  147.  
  148. INPUT Display        *display;
  149. INPUT PEXNameSet    ns;
  150. OUTPUT unsigned long    *numNamesReturn;
  151. OUTPUT PEXName        **namesReturn;
  152.  
  153. {
  154.     pexGetNameSetReq    *req;
  155.     pexGetNameSetReply    rep;
  156.  
  157.  
  158.     /*
  159.      * Lock around the critical section, for multithreading.
  160.      */
  161.  
  162.     LockDisplay (display);
  163.  
  164.  
  165.     /*
  166.      * Put the request in the X request buffer and get a reply.
  167.      */
  168.  
  169.     PEXGetReq (GetNameSet, req);
  170.     req->id = ns;
  171.  
  172.     if (_XReply (display,  &rep, 0, xFalse) == 0)
  173.     {
  174.         UnlockDisplay (display);
  175.         PEXSyncHandle (display);
  176.     *numNamesReturn = 0;
  177.     *namesReturn = NULL;
  178.     return (0);         /* return an error */
  179.     }
  180.  
  181.     *numNamesReturn = rep.numNames;
  182.  
  183.  
  184.     /*
  185.      * Allocate a buffer for the replies to pass back to the user.
  186.      */
  187.  
  188.     *namesReturn = (PEXName *) PEXAllocBuf ((unsigned) (rep.length << 2));
  189.  
  190.     if (rep.numNames)
  191.         _XRead (display, (char *) *namesReturn, (long) (rep.length << 2));
  192.  
  193.  
  194.    /*
  195.     * Done, so unlock and check for synchronous-ness.
  196.     */
  197.  
  198.     UnlockDisplay (display);
  199.     PEXSyncHandle (display);
  200.  
  201.     return (1);
  202. }
  203.  
  204.  
  205. void
  206. PEXChangeNameSet (display, ns, action, numValues, values)
  207.  
  208. INPUT Display        *display;
  209. INPUT PEXNameSet    ns;
  210. INPUT int        action;
  211. INPUT unsigned long    numValues;
  212. INPUT PEXName        *values;
  213.  
  214. {
  215.     pexChangeNameSetReq    *req;
  216.     int            size;
  217.  
  218.  
  219.     /*
  220.      * Lock around the critical section, for multithreading.
  221.      */
  222.  
  223.     LockDisplay (display);
  224.  
  225.  
  226.     /*
  227.      * Put the request in the X request buffer.
  228.      */
  229.  
  230.     size = numValues * sizeof (PEXName);
  231.  
  232.     PEXGetReqExtra (ChangeNameSet, size, req);
  233.     req->ns = ns;
  234.     req->action = action;
  235.  
  236.     COPY_AREA ((char *) values, ((char *) &req[1]), size);
  237.  
  238.  
  239.     /*
  240.      * Done, so unlock and check for synchronous-ness.
  241.      */
  242.  
  243.     UnlockDisplay (display);
  244.     PEXSyncHandle (display);
  245. }
  246.