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

  1. /* $XConsortium: pl_struct.c,v 1.7 92/08/26 13:06:23 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. #include "pl_oc_util.h"
  31.  
  32.  
  33. PEXStructure
  34. PEXCreateStructure (display)
  35.  
  36. INPUT Display        *display;
  37.  
  38. {
  39.     pexCreateStructureReq    *req;
  40.     pexStructure        s;
  41.  
  42.  
  43.     /*
  44.      * Get a structure resource id from X.
  45.      */
  46.  
  47.     s = XAllocID (display);
  48.  
  49.  
  50.     /*
  51.      * Lock around the critical section, for multithreading.
  52.      */
  53.  
  54.     LockDisplay (display);
  55.  
  56.  
  57.     /*
  58.      * Put the request in the X request buffer.
  59.      */
  60.  
  61.     PEXGetReq (CreateStructure, req);
  62.     req->id = s;
  63.  
  64.  
  65.     /*
  66.      * Done, so unlock and check for synchronous-ness.
  67.      */
  68.  
  69.     UnlockDisplay (display);
  70.     PEXSyncHandle (display);
  71.  
  72.     return (s);
  73. }
  74.  
  75.  
  76. void
  77. PEXDestroyStructures (display, numStructures, structures)
  78.  
  79. INPUT Display        *display;
  80. INPUT unsigned long    numStructures;
  81. INPUT PEXStructure    *structures;
  82.  
  83. {
  84.     pexDestroyStructuresReq    *req;
  85.     int             size;
  86.  
  87.  
  88.     /*
  89.      * Lock around the critical section, for multithreading.
  90.      */
  91.  
  92.     LockDisplay (display);
  93.  
  94.  
  95.     /*
  96.      * Put the request in the X request buffer.
  97.      */
  98.  
  99.     size = numStructures * sizeof (pexStructure);
  100.  
  101.     PEXGetReqExtra (DestroyStructures, size, req);
  102.     req->numStructures = numStructures;
  103.  
  104.     COPY_AREA ((char *) structures, ((char *) &req[1]), size);
  105.  
  106.  
  107.     /*
  108.      * Done, so unlock and check for synchronous-ness.
  109.      */
  110.  
  111.     UnlockDisplay (display);
  112.     PEXSyncHandle (display);
  113. }
  114.  
  115.  
  116. void
  117. PEXCopyStructure (display, srcStructure, destStructure)
  118.  
  119. INPUT Display        *display;
  120. INPUT PEXStructure    srcStructure;
  121. INPUT PEXStructure    destStructure;
  122.  
  123. {
  124.     pexCopyStructureReq    *req;
  125.  
  126.  
  127.     /*
  128.      * Lock around the critical section, for multithreading.
  129.      */
  130.  
  131.     LockDisplay (display);
  132.  
  133.  
  134.     /*
  135.      * Put the request in the X request buffer.
  136.      */
  137.  
  138.     PEXGetReq (CopyStructure, req);
  139.     req->src = srcStructure;
  140.     req->dst = destStructure;
  141.  
  142.  
  143.     /*
  144.      * Done, so unlock and check for synchronous-ness.
  145.      */
  146.  
  147.     UnlockDisplay (display);
  148.     PEXSyncHandle (display);
  149. }
  150.  
  151.  
  152. Status
  153. PEXGetStructureInfo (display, structure, float_format,
  154.     value_mask, info_return)
  155.  
  156. INPUT Display            *display;
  157. INPUT PEXStructure        structure;
  158. INPUT int            float_format;
  159. INPUT unsigned long        value_mask;
  160. OUTPUT PEXStructureInfo        *info_return;
  161.  
  162. {
  163.     pexGetStructureInfoReq    *req;
  164.     pexGetStructureInfoReply    rep;
  165.  
  166.  
  167.     /*
  168.      * Lock around the critical section, for multithreading.
  169.      */
  170.  
  171.     LockDisplay (display);
  172.  
  173.  
  174.     /*
  175.      * Put the request in the X request buffer and get a reply.
  176.      */
  177.  
  178.     PEXGetReq (GetStructureInfo, req);
  179.     req->fpFormat = float_format;
  180.     req->sid = structure;
  181.     req->itemMask = value_mask;
  182.  
  183.     if (_XReply (display, &rep, 0, xTrue) == 0)
  184.     {
  185.         UnlockDisplay (display);
  186.         PEXSyncHandle (display);
  187.     return (0);            /* return an error */
  188.     }
  189.  
  190.  
  191.     if (value_mask & PEXEditMode)
  192.     info_return->edit_mode = rep.editMode;
  193.     if (value_mask & PEXElementPtr)
  194.     info_return->element_pointer = rep.elementPtr;
  195.     if (value_mask & PEXNumElements)
  196.     info_return->element_count = rep.numElements;
  197.     if (value_mask & PEXLengthStructure)
  198.     info_return->size = rep.lengthStructure;
  199.     if (value_mask & PEXHasRefs)
  200.     info_return->has_refs = rep.hasRefs;
  201.  
  202.  
  203.     /*
  204.      * Done, so unlock and check for synchronous-ness.
  205.      */
  206.  
  207.     UnlockDisplay (display);
  208.     PEXSyncHandle (display);
  209.  
  210.     return (1);
  211. }
  212.  
  213.  
  214. Status
  215. PEXGetElementInfo (display, structure, whence1, offset1, whence2, offset2,
  216.     float_format, numElementInfoReturn, infoReturn)
  217.  
  218. INPUT Display        *display;
  219. INPUT PEXStructure    structure;
  220. INPUT int        whence1;
  221. INPUT long        offset1;
  222. INPUT int        whence2;
  223. INPUT long        offset2;
  224. INPUT int        float_format;
  225. OUTPUT unsigned long    *numElementInfoReturn;
  226. OUTPUT PEXElementInfo    **infoReturn;
  227.  
  228. {
  229.     pexGetElementInfoReq    *req;
  230.     pexGetElementInfoReply    rep;
  231.  
  232.  
  233.     /*
  234.      * Lock around the critical section, for multithreading.
  235.      */
  236.  
  237.     LockDisplay (display);
  238.  
  239.  
  240.     /*
  241.      * Put the request in the X request buffer and get a reply.
  242.      */
  243.  
  244.     PEXGetReq (GetElementInfo, req);
  245.     req->fpFormat = float_format;
  246.     req->sid = structure;
  247.     req->range.position1.whence = whence1;
  248.     req->range.position1.offset = offset1;
  249.     req->range.position2.whence = whence2;
  250.     req->range.position2.offset = offset2;
  251.  
  252.     if (_XReply (display, &rep, 0, xFalse) == 0)
  253.     {
  254.         UnlockDisplay (display);
  255.         PEXSyncHandle (display);
  256.     *numElementInfoReturn = 0;
  257.     *infoReturn = NULL;
  258.     return (0);        /* return an error */
  259.     }
  260.  
  261.     *numElementInfoReturn = rep.numInfo;
  262.  
  263.  
  264.     /*
  265.      * Allocate a buffer for the replies to pass back to the client.
  266.      */
  267.  
  268.     *infoReturn = (PEXElementInfo *) PEXAllocBuf (
  269.     (unsigned) (rep.length << 2));
  270.  
  271.     _XRead (display, (char *) *infoReturn, (long) (rep.length << 2));
  272.  
  273.  
  274.     /*
  275.      * Done, so unlock and check for synchronous-ness.
  276.      */
  277.  
  278.     UnlockDisplay (display);
  279.     PEXSyncHandle (display);
  280.  
  281.     return (1);
  282. }
  283.  
  284.  
  285. PEXStructure *
  286. PEXGetStructuresInNetwork (display, structure, which, numStructuresReturn)
  287.  
  288. INPUT Display        *display;
  289. INPUT PEXStructure    structure;
  290. INPUT int        which;
  291. OUTPUT unsigned long    *numStructuresReturn;
  292.  
  293. {
  294.     pexGetStructuresInNetworkReq    *req;
  295.     pexGetStructuresInNetworkReply    rep;
  296.     pexStructure            *ps;
  297.  
  298.  
  299.     /*
  300.      * Lock around the critical section, for multithreading.
  301.      */
  302.  
  303.     LockDisplay (display);
  304.  
  305.  
  306.     /*
  307.      * Put the request in the X request buffer and get a reply.
  308.      */
  309.  
  310.     PEXGetReq (GetStructuresInNetwork, req);
  311.     req->sid = structure;
  312.     req->which = which;
  313.  
  314.     if (_XReply (display, &rep, 0, xFalse) == 0)
  315.     {
  316.         UnlockDisplay (display);
  317.         PEXSyncHandle (display);
  318.     *numStructuresReturn = 0;
  319.     return (NULL);             /* return an error */
  320.     }
  321.  
  322.     *numStructuresReturn = rep.numStructures;
  323.  
  324.  
  325.     /*
  326.      * Allocate a buffer for the replies to pass back to the client.
  327.      */
  328.  
  329.     ps = (pexStructure *) PEXAllocBuf ((unsigned) (rep.length << 2));
  330.  
  331.     _XRead (display, (char *) ps, (long) (rep.length << 2));
  332.  
  333.  
  334.     /*
  335.      * Done, so unlock and check for synchronous-ness.
  336.      */
  337.  
  338.     UnlockDisplay (display);
  339.     PEXSyncHandle (display);
  340.  
  341.     return ((PEXStructure *) ps);
  342. }
  343.  
  344.  
  345. PEXStructurePath *
  346. PEXGetAncestors (display, structure, pathPart, pathDepth, numPathsReturn)
  347.  
  348. INPUT Display        *display;
  349. INPUT PEXStructure    structure;
  350. INPUT int        pathPart;
  351. INPUT unsigned long    pathDepth;
  352. OUTPUT unsigned long    *numPathsReturn;
  353.  
  354. {
  355.     pexGetAncestorsReq        *req;
  356.     pexGetAncestorsReply    rep;
  357.     PEXStructurePath        *psp, *pathsReturn;
  358.     pexElementRef        *per;
  359.     char            *prep;
  360.     int                numElements, size, i;
  361.  
  362.  
  363.     /*
  364.      * Lock around the critical section, for multithreading.
  365.      */
  366.  
  367.     LockDisplay (display);
  368.  
  369.  
  370.     /*
  371.      * Put the request in the X request buffer and get a reply.
  372.      */
  373.  
  374.     PEXGetReq (GetAncestors, req);
  375.     req->sid = structure;
  376.     req->pathOrder = pathPart;
  377.     req->pathDepth = pathDepth;
  378.  
  379.     if (_XReply (display, &rep, 0, xFalse) == 0)
  380.     {
  381.         UnlockDisplay (display);
  382.         PEXSyncHandle (display);
  383.     *numPathsReturn = 0;
  384.     return (NULL);           /* return an error */
  385.     }
  386.  
  387.     *numPathsReturn = rep.numPaths;
  388.  
  389.  
  390.     /*
  391.      * Allocate a scratch buffer and copy the reply data to the buffer.
  392.      */
  393.  
  394.     prep = _XAllocScratch (display, (unsigned long) (rep.length << 2));
  395.  
  396.     _XRead (display, (char *) prep, (long) (rep.length << 2));
  397.  
  398.  
  399.     /*
  400.      * Allocate a buffer for the replies to pass back to the client.
  401.      */
  402.  
  403.     pathsReturn = psp = (PEXStructurePath *) PEXAllocBuf
  404.     ((unsigned) (rep.numPaths * sizeof (PEXStructurePath)));
  405.  
  406.     for (i = 0; i < rep.numPaths; i++)
  407.     {
  408.     numElements = *((CARD32 *) prep);
  409.     prep += sizeof (CARD32);
  410.     size = numElements * sizeof (pexElementRef);
  411.     per = (pexElementRef *) PEXAllocBuf ((unsigned) size);
  412.     COPY_AREA ((char *) prep, (char *) per, size);
  413.     psp->count = numElements;
  414.     psp->elements = (PEXElementRef *) per;
  415.     psp++;
  416.     prep += size;
  417.     }
  418.  
  419.  
  420.     /*
  421.      * Done, so unlock and check for synchronous-ness.
  422.      */
  423.  
  424.     UnlockDisplay (display);
  425.     PEXSyncHandle (display);
  426.  
  427.     return (pathsReturn);
  428. }
  429.  
  430.  
  431.  
  432. PEXStructurePath *
  433. PEXGetDescendants (display, structure, pathPart, pathDepth, numPathsReturn)
  434.  
  435. INPUT Display        *display;
  436. INPUT PEXStructure    structure;
  437. INPUT int        pathPart;
  438. INPUT unsigned long    pathDepth;
  439. OUTPUT unsigned long    *numPathsReturn;
  440.  
  441. {
  442.     pexGetDescendantsReq    *req;
  443.     pexGetDescendantsReply    rep;
  444.     PEXStructurePath        *psp, *pathsReturn;
  445.     pexElementRef        *per;
  446.     char            *prep;
  447.     int                numElements, size, i;
  448.  
  449.  
  450.     /*
  451.      * Lock around the critical section, for multithreading.
  452.      */
  453.  
  454.     LockDisplay (display);
  455.  
  456.  
  457.     /*
  458.      * Put the request in the X request buffer and get a reply.
  459.      */
  460.  
  461.     PEXGetReq (GetDescendants, req);
  462.     req->sid = structure;
  463.     req->pathOrder = pathPart;
  464.     req->pathDepth = pathDepth;
  465.  
  466.     if (_XReply (display, &rep, 0, xFalse) == 0)
  467.     {
  468.         UnlockDisplay (display);
  469.         PEXSyncHandle (display);
  470.     *numPathsReturn = 0;
  471.     return (NULL);          /* return an error */
  472.     }
  473.  
  474.     *numPathsReturn = rep.numPaths;
  475.  
  476.  
  477.     /*
  478.      * Allocate a scratch buffer and copy the reply data to the buffer.
  479.      */
  480.  
  481.     prep = _XAllocScratch (display, (unsigned long) (rep.length << 2));
  482.  
  483.     _XRead (display, (char *) prep, (long)(rep.length << 2));
  484.  
  485.  
  486.     /*
  487.      * Allocate a buffer to pass the replies back to the client.
  488.      */
  489.  
  490.     pathsReturn = psp = (PEXStructurePath *) PEXAllocBuf
  491.     ((unsigned) (rep.numPaths * sizeof (PEXStructurePath)));
  492.  
  493.     for (i = 0; i < rep.numPaths; i++)
  494.     {
  495.     numElements = *((CARD32 *) prep);
  496.     prep += sizeof (CARD32);
  497.     size = numElements * sizeof (pexElementRef);
  498.     per = (pexElementRef *) PEXAllocBuf ((unsigned) size);
  499.     COPY_AREA ((char *) prep, (char *) per, size);
  500.     psp->count = numElements;
  501.     psp->elements = (PEXElementRef *) per;
  502.     psp++;
  503.     prep += size;
  504.     }
  505.  
  506.  
  507.     /*
  508.      * Done, so unlock and check for synchronous-ness.
  509.      */
  510.  
  511.     UnlockDisplay (display);
  512.     PEXSyncHandle (display);
  513.  
  514.     return (pathsReturn);
  515. }
  516.  
  517.  
  518. Status
  519. PEXFetchElements (display, structure, whence1, offset1, whence2, offset2,
  520.     float_format, numElementsReturn, sizeReturn, ocsReturn)
  521.  
  522. INPUT Display        *display;
  523. INPUT PEXStructure    structure;
  524. INPUT int        whence1;
  525. INPUT long        offset1;
  526. INPUT int        whence2;
  527. INPUT long        offset2;
  528. INPUT int        float_format;
  529. OUTPUT unsigned long    *numElementsReturn;
  530. OUTPUT unsigned long    *sizeReturn;
  531. OUTPUT char        **ocsReturn;
  532.  
  533. {
  534.     pexFetchElementsReq        *req;
  535.     pexFetchElementsReply    rep;
  536.     long            repSize;
  537.     int                server_float_format;
  538.  
  539.  
  540.     /*
  541.      * Lock around the critical section, for multithreading.
  542.      */
  543.  
  544.     LockDisplay (display);
  545.  
  546.  
  547.     /*
  548.      * Put the request in the X request buffer and get a reply.
  549.      */
  550.  
  551.     server_float_format = PEXGetProtocolFloatFormat (display);
  552.  
  553.     PEXGetReq (FetchElements, req);
  554.     req->fpFormat = server_float_format;
  555.     req->sid = structure;
  556.     req->range.position1.whence = whence1;
  557.     req->range.position1.offset = offset1;
  558.     req->range.position2.whence = whence2;
  559.     req->range.position2.offset = offset2;
  560.  
  561.     if (_XReply (display, &rep, 0, xFalse) == 0)
  562.     {
  563.         UnlockDisplay (display);
  564.         PEXSyncHandle (display);
  565.         *sizeReturn = *numElementsReturn = 0;
  566.     *ocsReturn = NULL;
  567.         return (0);        /* return an error */
  568.     }
  569.  
  570.     *numElementsReturn = rep.numElements;
  571.  
  572.     if (server_float_format != float_format)
  573.     {
  574.     /*
  575.      * Convert from server's float format to the float format
  576.      * specified by the application.
  577.      */
  578.  
  579.     *sizeReturn = 0;
  580.     *ocsReturn = NULL;
  581.     }
  582.     else
  583.     {
  584.     /*
  585.      * No float conversion necessary.
  586.      */
  587.  
  588.     *sizeReturn = repSize = rep.length << 2;
  589.     *ocsReturn = (char *) PEXAllocBuf (repSize);
  590.     if (*ocsReturn != NULL)
  591.         _XRead (display, *ocsReturn, (long) repSize);
  592.     }
  593.  
  594.  
  595.     /*
  596.      * Done, so unlock and check for synchronous-ness.
  597.      */
  598.  
  599.     UnlockDisplay (display);
  600.     PEXSyncHandle (display);
  601.  
  602.     return (1);
  603. }
  604.  
  605.  
  606. Status
  607. PEXFetchElementsAndSend (display, structure,
  608.     whence1, offset1, whence2, offset2, dstDisplay, resID, reqType)
  609.  
  610. INPUT Display        *display;
  611. INPUT PEXStructure    structure;
  612. INPUT int        whence1;
  613. INPUT long        offset1;
  614. INPUT int        whence2;
  615. INPUT long        offset2;
  616. INPUT Display        *dstDisplay;
  617. INPUT XID        resID;
  618. INPUT PEXOCRequestType    reqType;
  619.  
  620. {
  621.     PEXDisplayInfo         *srcDisplayInfo, *dstDisplayInfo;
  622.     pexFetchElementsReq        *req;
  623.     pexFetchElementsReply    rep;
  624.     char             *ocAddr;
  625.     PEXEnumTypeDesc        *srcFloats, *dstFloats;
  626.     long            bytesLeft;
  627.     int                getSize, size, i, j;
  628.     int                fp_match, float_format;
  629.  
  630.  
  631.     /*
  632.      * Lock around the critical section, for multithreading.
  633.      */
  634.  
  635.     LockDisplay (display);
  636.  
  637.  
  638.     /*
  639.      * Determine which floating point format to use.
  640.      */
  641.  
  642.     PEXGetDisplayInfo (display, srcDisplayInfo);
  643.     PEXGetDisplayInfo (dstDisplay, dstDisplayInfo);
  644.  
  645.     if (display == dstDisplay)
  646.     {
  647.     float_format = dstDisplayInfo->fpFormat;
  648.     fp_match = 1;
  649.     }
  650.     else
  651.     {
  652.     srcFloats = srcDisplayInfo->fpSupport;
  653.     dstFloats = dstDisplayInfo->fpSupport;
  654.  
  655.     fp_match = 0;
  656.     for (i = 0; i < dstDisplayInfo->fpCount && !fp_match; i++)
  657.         for (j = 0; j < srcDisplayInfo->fpCount; j++)
  658.         {
  659.         if (dstFloats[i].index == srcFloats[j].index)
  660.         {
  661.             float_format = dstFloats[i].index;
  662.             fp_match = 1;
  663.             break;
  664.         }
  665.         }
  666.  
  667.     if (!fp_match)
  668.     {
  669.         /*
  670.          * Will have to convert from source display float format to
  671.          * destination display float format.
  672.          */
  673.  
  674.         float_format = srcDisplayInfo->fpFormat;
  675.     }
  676.     }
  677.  
  678.  
  679.     /*
  680.      * Put the request in the X request buffer and get a reply.
  681.      */
  682.  
  683.     PEXGetReq (FetchElements, req)
  684.     req->fpFormat = float_format;
  685.     req->sid = structure;
  686.     req->range.position1.whence = whence1;
  687.     req->range.position1.offset = offset1;
  688.     req->range.position2.whence = whence2;
  689.     req->range.position2.offset = offset2;
  690.  
  691.     if (_XReply (display, &rep, 0, xFalse) == 0)
  692.     {
  693.         UnlockDisplay (display);
  694.         PEXSyncHandle (display);
  695.         return (0);        /* return an error */
  696.     }
  697.  
  698.  
  699.     /*
  700.      * If no floating point conversion has to take place, fetch the element
  701.      * info directly into the destination display connection.
  702.      */
  703.  
  704.     if (fp_match)
  705.     {
  706.     if (display == dstDisplay)
  707.         UnlockDisplay (display);
  708.  
  709.     if (PEXStartOCs (dstDisplay, resID, reqType, float_format,
  710.         rep.numElements, rep.length))
  711.     {
  712.         bytesLeft = rep.length << 2;
  713.         getSize = PEXGetOCAddrMaxSize (dstDisplay);
  714.  
  715.         while (bytesLeft > 0)
  716.         {
  717.         size = min (bytesLeft, getSize);
  718.  
  719.         if (ocAddr = PEXGetOCAddr (dstDisplay, size))
  720.             _XRead (display, ocAddr, (long) size);
  721.         else
  722.         {
  723.             PEXFinishOC (dstDisplay);
  724.             if (display != dstDisplay)
  725.             UnlockDisplay (display);
  726.             PEXSyncHandle (dstDisplay);
  727.             return (0);
  728.         }
  729.  
  730.         bytesLeft -= size;
  731.         }
  732.  
  733.         PEXFinishOC (dstDisplay);
  734.     }
  735.  
  736.     if (display != dstDisplay)
  737.         UnlockDisplay (display);
  738.     }
  739.     else
  740.     {
  741.     /*
  742.      * Floating point conversion necessary.
  743.      */
  744.  
  745.     }
  746.  
  747.     PEXSyncHandle (dstDisplay);
  748.  
  749.     return (1);
  750. }
  751.  
  752.  
  753. void
  754. PEXSetEditingMode (display, structure, mode)
  755.  
  756. INPUT Display        *display;
  757. INPUT PEXStructure    structure;
  758. INPUT int        mode;
  759.  
  760. {
  761.     pexSetEditingModeReq    *req;
  762.  
  763.  
  764.     /*
  765.      * Lock around the critical section, for multithreading.
  766.      */
  767.  
  768.     LockDisplay (display);
  769.  
  770.  
  771.     /*
  772.      * Put the request in the X request buffer.
  773.      */
  774.  
  775.     PEXGetReq (SetEditingMode, req);
  776.     req->sid = structure;
  777.     req->mode = mode;
  778.  
  779.  
  780.     /*
  781.      * Done, so unlock and check for synchronous-ness.
  782.      */
  783.  
  784.     UnlockDisplay (display);
  785.     PEXSyncHandle (display);
  786. }
  787.  
  788.  
  789. void
  790. PEXSetElementPtr (display, structure, whence, offset)
  791.  
  792. INPUT Display        *display;
  793. INPUT PEXStructure    structure;
  794. INPUT int        whence;
  795. INPUT long        offset;
  796.  
  797. {
  798.     pexSetElementPointerReq    *req;
  799.  
  800.  
  801.     /*
  802.      * Lock around the critical section, for multithreading.
  803.      */
  804.  
  805.     LockDisplay (display);
  806.  
  807.  
  808.     /*
  809.      * Put the request in the X request buffer.
  810.      */
  811.  
  812.     PEXGetReq (SetElementPointer, req);
  813.     req->sid = structure;
  814.     req->position.whence = whence;
  815.     req->position.offset = offset;
  816.  
  817.  
  818.     /*
  819.      * Done, so unlock and check for synchronous-ness.
  820.      */
  821.  
  822.     UnlockDisplay (display);
  823.     PEXSyncHandle (display);
  824. }
  825.  
  826.  
  827. void
  828. PEXSetElementPtrAtLabel (display, structure, label, offset)
  829.  
  830. INPUT Display        *display;
  831. INPUT PEXStructure    structure;
  832. INPUT long        label;
  833. INPUT long        offset;
  834.  
  835. {
  836.     pexSetElementPointerAtLabelReq    *req;
  837.  
  838.  
  839.     /*
  840.      * Lock around the critical section, for multithreading.
  841.      */
  842.  
  843.     LockDisplay (display);
  844.  
  845.  
  846.     /*
  847.      * Put the request in the X request buffer.
  848.      */
  849.  
  850.     PEXGetReq (SetElementPointerAtLabel, req);
  851.     req->sid = structure;
  852.     req->label = label;
  853.     req->offset = offset;
  854.  
  855.  
  856.     /*
  857.      * Done, so unlock and check for synchronous-ness.
  858.      */
  859.  
  860.     UnlockDisplay (display);
  861.     PEXSyncHandle (display);
  862. }
  863.  
  864.  
  865. Status
  866. PEXElementSearch (display, structure, whence, offset, direction,
  867.     numIncl, inclList, numExcl, exclList, offsetReturn)
  868.  
  869. INPUT Display        *display;
  870. INPUT PEXStructure    structure;
  871. INPUT int        whence;
  872. INPUT long        offset;
  873. INPUT int        direction;
  874. INPUT unsigned long    numIncl;
  875. INPUT unsigned short    *inclList;
  876. INPUT unsigned long    numExcl;
  877. INPUT unsigned short    *exclList;
  878. OUTPUT unsigned long    *offsetReturn;
  879.  
  880. {
  881.     pexElementSearchReq        *req;
  882.     pexElementSearchReply    rep;
  883.     char            *ptr;
  884.  
  885.  
  886.     /*
  887.      * Lock around the critical section, for multithreading.
  888.      */
  889.  
  890.     LockDisplay (display);
  891.  
  892.  
  893.     /*
  894.      * Put the request in the X request buffer and get a reply.
  895.      */
  896.  
  897.     PEXGetReqExtra (ElementSearch,  sizeof (CARD16) *
  898.     (numIncl + (numIncl & 1) + numExcl + (numExcl & 1)), req);
  899.     req->sid = structure;
  900.     req->position.whence = whence;
  901.     req->position.offset = offset;
  902.     req->direction = direction;
  903.     req->numIncls = numIncl;
  904.     req->numExcls = numExcl;
  905.  
  906.     ptr = (char *) &req[1];
  907.     COPY_AREA ((char *) inclList, ptr, numIncl * sizeof (CARD16));
  908.     ptr += ((numIncl + (numIncl & 1)) * sizeof (CARD16));
  909.     COPY_AREA ((char *) exclList, ptr, numExcl * sizeof (CARD16));
  910.  
  911.     if (_XReply (display, &rep, 0, xTrue) == 0)
  912.     {
  913.         UnlockDisplay (display);
  914.         PEXSyncHandle (display);
  915.     *offsetReturn = 0;
  916.     return (0);               /* return an error */
  917.     }
  918.  
  919.     *offsetReturn = rep.foundOffset;
  920.  
  921.  
  922.     /*
  923.      * Done, so unlock and check for synchronous-ness.
  924.      */
  925.  
  926.     UnlockDisplay (display);
  927.     PEXSyncHandle (display);
  928.  
  929.     return (rep.status);
  930. }
  931.  
  932.  
  933. void
  934. PEXDeleteElements (display, structure, whence1, offset1, whence2, offset2)
  935.  
  936. INPUT Display        *display;
  937. INPUT PEXStructure    structure;
  938. INPUT int        whence1;
  939. INPUT long        offset1;
  940. INPUT int        whence2;
  941. INPUT long        offset2;
  942.  
  943. {
  944.     pexDeleteElementsReq    *req;
  945.  
  946.  
  947.     /*
  948.      * Lock around the critical section, for multithreading.
  949.      */
  950.  
  951.     LockDisplay (display);
  952.  
  953.  
  954.     /*
  955.      * Put the request in the X request buffer.
  956.      */
  957.  
  958.     PEXGetReq (DeleteElements, req);
  959.     req->sid =  structure;
  960.     req->range.position1.whence = whence1;
  961.     req->range.position1.offset = offset1;
  962.     req->range.position2.whence = whence2;
  963.     req->range.position2.offset = offset2;
  964.  
  965.  
  966.     /*
  967.      * Done, so unlock and check for synchronous-ness.
  968.      */
  969.  
  970.     UnlockDisplay (display);
  971.     PEXSyncHandle (display);
  972. }
  973.  
  974.  
  975. void
  976. PEXDeleteToLabel (display, structure, whence, offset, label)
  977.  
  978. INPUT Display        *display;
  979. INPUT PEXStructure    structure;
  980. INPUT int        whence;
  981. INPUT long        offset;
  982. INPUT long        label;
  983.  
  984. {
  985.     pexDeleteElementsToLabelReq    *req;
  986.  
  987.  
  988.     /*
  989.      * Lock around the critical section, for multithreading.
  990.      */
  991.  
  992.     LockDisplay (display);
  993.  
  994.  
  995.     /*
  996.      * Put the request in the X request buffer.
  997.      */
  998.  
  999.     PEXGetReq (DeleteElementsToLabel, req);
  1000.     req->sid =  structure;
  1001.     req->position.whence = whence;
  1002.     req->position.offset = offset;
  1003.     req->label = label;
  1004.  
  1005.  
  1006.     /*
  1007.      * Done, so unlock and check for synchronous-ness.
  1008.      */
  1009.  
  1010.     UnlockDisplay (display);
  1011.     PEXSyncHandle (display);
  1012. }
  1013.  
  1014.  
  1015. void
  1016. PEXDeleteBetweenLabels (display, structure, label1, label2)
  1017.  
  1018. INPUT Display        *display;
  1019. INPUT PEXStructure    structure;
  1020. INPUT long        label1;
  1021. INPUT long        label2;
  1022.  
  1023. {
  1024.     pexDeleteBetweenLabelsReq    *req;
  1025.  
  1026.  
  1027.     /*
  1028.      * Lock around the critical section, for multithreading.
  1029.      */
  1030.  
  1031.     LockDisplay (display);
  1032.  
  1033.  
  1034.     /*
  1035.      * Put the request in the X request buffer.
  1036.      */
  1037.  
  1038.     PEXGetReq (DeleteBetweenLabels, req);
  1039.     req->sid =  structure;
  1040.     req->label1 = label1;
  1041.     req->label2 = label2;
  1042.  
  1043.  
  1044.     /*
  1045.      * Done, so unlock and check for synchronous-ness.
  1046.      */
  1047.  
  1048.     UnlockDisplay (display);
  1049.     PEXSyncHandle (display);
  1050. }
  1051.  
  1052.  
  1053. void
  1054. PEXCopyElements (display, srcStructure, srcWhence1, srcOffset1, srcWhence2,
  1055.     srcOffset2, destStructure, destWhence, destOffset)
  1056.  
  1057. INPUT Display        *display;
  1058. INPUT PEXStructure    srcStructure;
  1059. INPUT int        srcWhence1;
  1060. INPUT long        srcOffset1;
  1061. INPUT int        srcWhence2;
  1062. INPUT long        srcOffset2;
  1063. INPUT PEXStructure    destStructure;
  1064. INPUT int        destWhence;
  1065. INPUT long        destOffset;
  1066.  
  1067. {
  1068.     pexCopyElementsReq    *req;
  1069.  
  1070.  
  1071.     /*
  1072.      * Lock around the critical section, for multithreading.
  1073.      */
  1074.  
  1075.     LockDisplay (display);
  1076.  
  1077.  
  1078.     /*
  1079.      * Put the request in the X request buffer.
  1080.      */
  1081.  
  1082.     PEXGetReq (CopyElements, req);
  1083.     req->src = srcStructure;
  1084.     req->srcRange.position1.whence = srcWhence1;
  1085.     req->srcRange.position1.offset = srcOffset1;
  1086.     req->srcRange.position2.whence = srcWhence2;
  1087.     req->srcRange.position2.offset = srcOffset2;
  1088.     req->dst = destStructure;
  1089.     req->dstPosition.whence = destWhence;
  1090.     req->dstPosition.offset = destOffset;
  1091.  
  1092.  
  1093.     /*
  1094.      * Done, so unlock and check for synchronous-ness.
  1095.      */
  1096.  
  1097.     UnlockDisplay (display);
  1098.     PEXSyncHandle (display);
  1099. }
  1100.  
  1101.  
  1102. void
  1103. PEXChangeStructureRefs (display, oldStructure, newStructure)
  1104.  
  1105. INPUT Display        *display;
  1106. INPUT PEXStructure    oldStructure;
  1107. INPUT PEXStructure    newStructure;
  1108.  
  1109. {
  1110.     pexChangeStructureRefsReq    *req;
  1111.  
  1112.  
  1113.     /*
  1114.      * Lock around the critical section, for multithreading.
  1115.      */
  1116.  
  1117.     LockDisplay (display);
  1118.  
  1119.  
  1120.     /*
  1121.      * Put the request in the X request buffer.
  1122.      */
  1123.  
  1124.     PEXGetReq (ChangeStructureRefs, req);
  1125.     req->old_id = oldStructure;
  1126.     req->new_id = newStructure;
  1127.  
  1128.  
  1129.     /*
  1130.      * Done, so unlock and check for synchronous-ness.
  1131.      */
  1132.  
  1133.     UnlockDisplay (display);
  1134.     PEXSyncHandle (display);
  1135. }
  1136.