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

  1. /* $XConsortium: XKBRdBuf.c /main/7 1996/01/14 16:43:48 kaleb $ */
  2. /************************************************************
  3. Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
  4.  
  5. Permission to use, copy, modify, and distribute this
  6. software and its documentation for any purpose and without
  7. fee is hereby granted, provided that the above copyright
  8. notice appear in all copies and that both that copyright
  9. notice and this permission notice appear in supporting
  10. documentation, and that the name of Silicon Graphics not be 
  11. used in advertising or publicity pertaining to distribution 
  12. of the software without specific prior written permission.
  13. Silicon Graphics makes no representation about the suitability 
  14. of this software for any purpose. It is provided "as is"
  15. without any express or implied warranty.
  16.  
  17. SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
  18. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
  19. AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  20. GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  21. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
  22. DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
  23. OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  24. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  25.  
  26. ********************************************************/
  27.  
  28. #include <stdio.h>
  29. #define NEED_REPLIES
  30. #define NEED_EVENTS
  31. #include "Xlib_private.h"
  32. #include "XKBlibint.h"
  33. #include <X11/extensions/XKBproto.h>
  34.  
  35. /***====================================================================***/
  36.  
  37. #if 0
  38. int 
  39. #if NeedFunctionPrototypes
  40. _XkbInitReadBuffer(Display *dpy,XkbReadBufferPtr buf,int size)
  41. #else
  42. _XkbInitReadBuffer(dpy,buf,size)
  43.     Display        *dpy;
  44.     XkbReadBufferPtr     buf;
  45.     int             size;
  46. #endif
  47. {
  48.     DBUG_ENTER("_XkbInitReadBuffer")
  49.     if ((dpy!=NULL) && (buf!=NULL) && (size>0)) {
  50.     buf->error=  0;
  51.     buf->size=   size;
  52.     buf->start= buf->data= _XkbAlloc(size);
  53.     if (buf->start) {
  54.         _XRead(dpy, buf->start, size);
  55.         DBUG_RETURN(1);
  56.     }
  57.     }
  58.     DBUG_RETURN(0);
  59. }
  60. #endif
  61.  
  62. #define    _XkbReadBufferDataLeft(b)    (((b)->size)-((b)->data-(b)->start))
  63.  
  64. int
  65. #if NeedFunctionPrototypes
  66. _XkbSkipReadBufferData(XkbReadBufferPtr    from,int size)
  67. #else
  68. _XkbSkipReadBufferData(from,size)
  69.     XkbReadBufferPtr     from;
  70.     int             size;
  71. #endif
  72. {
  73.     DBUG_ENTER("_XkbSkipReadBufferData")
  74.     if (size==0)
  75.     DBUG_RETURN(1);
  76.     if ((from==NULL)||(from->error)||(size<1)||
  77.                     (_XkbReadBufferDataLeft(from)<size))
  78.     DBUG_RETURN(0);
  79.     from->data+= size;
  80.     DBUG_RETURN(1);
  81. }
  82.  
  83. int
  84. #if NeedFunctionPrototypes
  85. _XkbCopyFromReadBuffer(XkbReadBufferPtr    from,char *to,int size)
  86. #else
  87. _XkbCopyFromReadBuffer(from,to,size)
  88.     XkbReadBufferPtr     from;
  89.     char        *to;
  90.     int             size;
  91. #endif
  92. {
  93.     DBUG_ENTER("_XkbCopyFromReadBuffer")
  94.     if (size==0)
  95.     DBUG_RETURN(1);
  96.     if ((from==NULL)||(from->error)||(to==NULL)||(size<1)||
  97.                     (_XkbReadBufferDataLeft(from)<size))
  98.     DBUG_RETURN(0);
  99.     memcpy(to,from->data,size);
  100.     from->data+= size;
  101.     DBUG_RETURN(1);
  102. }
  103.  
  104. #ifdef XKB_FORCE_INT_KEYSYM
  105. int
  106. #if NeedFunctionPrototypes
  107. _XkbReadCopyKeySyms(int *wire,KeySym *to,int num_words)
  108. #else
  109. _XkbReadCopyKeySyms(wire,to,num_words)
  110.     int *               wire;
  111.     KeySym *            to;
  112.     int                 num_words;
  113. #endif
  114. {
  115.     DBUG_ENTER("_XkbReadCopyKeySyms")
  116.     while (num_words-->0) {
  117.     *to++= *wire++;
  118.     }
  119.     DBUG_RETURN(1);
  120. }
  121.  
  122. int
  123. #if NeedFunctionPrototypes
  124. _XkbReadBufferCopyKeySyms(XkbReadBufferPtr from,KeySym *to,int num_words)
  125. #else
  126. _XkbReadBufferCopyKeySyms(from,to,num_words)
  127.     XkbReadBufferPtr    from;
  128.     KeySym *            to;
  129.     int                 num_words;
  130. #endif
  131. {
  132.     DBUG_ENTER("_XkbReadBufferCopyKeySyms")
  133.     if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from))
  134.         DBUG_RETURN(0);
  135.     _XkbReadCopyKeySyms((int *)from->data,to,num_words);
  136.     from->data+= (4*num_words);
  137.     DBUG_RETURN(True);
  138. }
  139.  
  140. int
  141. #if NeedFunctionPrototypes
  142. _XkbWriteCopyKeySyms (register KeySym *from,CARD32 *to,int len)
  143. #else
  144. _XkbWriteCopyKeySyms (from,to,len)
  145.     register KeySym *           from;
  146.     CARD32 *                    to;
  147.     int                         len;
  148. #endif
  149. {
  150.     DBUG_ENTER("_XkbWriteCopyKeySyms")
  151.     while (len-->0) {
  152.         *to++= (CARD32)*from++;
  153.     }
  154.     DBUG_RETURN(True);
  155. }
  156. #endif
  157.  
  158. #ifdef LONG64
  159. int
  160. #if NeedFunctionPrototypes
  161. _XkbReadCopyData32(int *wire,long *to,int num_words)
  162. #else
  163. _XkbReadCopyData32(wire,to,num_words)
  164.     int *        wire;
  165.     long *        to;
  166.     int            num_words;
  167. #endif
  168. {
  169.     DBUG_ENTER("_XkbReadCopyData32")
  170.     while (num_words-->0) {
  171.     *to++= *wire++;
  172.     }
  173.     DBUG_RETURN(1);
  174. }
  175. #endif
  176. #ifdef WORD64
  177. int
  178. #if NeedFunctionPrototypes
  179. _XkbReadCopyData32(int *from,long *lp,int num_words)
  180. #else
  181. _XkbReadCopyData32(from,lp,num_words)
  182.     int *        from;
  183.     long *        lp;
  184.     int            num_words;
  185. #endif
  186. {
  187.     DBUG_ENTER("_XkbReadCopyData32")
  188.     long *lpack;
  189.     long mask32 = 0x00000000ffffffff;
  190.     long maskw, i, bits;
  191.  
  192.     lpack = (long *)from;
  193.     bits = 32;
  194.  
  195.     for (i=0;i<num_words;i++) {
  196.     maskw = mask32 << bits;
  197.     *lp++ = (*lpack & maskw) >> bits;
  198.     bits = bits ^ 32;
  199.     if (bits)
  200.         lpack++;
  201.     }
  202.     DBUG_RETURN(1);
  203. }
  204. #endif
  205.  
  206. #if defined(LONG64) || defined(WORD64)
  207. int
  208. #if NeedFunctionPrototypes
  209. _XkbReadBufferCopy32(XkbReadBufferPtr from,long *to,int num_words)
  210. #else
  211. _XkbReadBufferCopy32(from,to,num_words)
  212.     XkbReadBufferPtr    from;
  213.     long *        to;
  214.     int            num_words;
  215. #endif
  216. {
  217.     DBUG_ENTER("_XkbReadBufferCopy32")
  218.     if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from))
  219.     DBUG_RETURN(0);
  220.     _XkbReadCopyData32((int *)from->data,to,num_words);
  221.     from->data+= (4*num_words);
  222.     DBUG_RETURN(True);
  223. }
  224. #endif
  225.  
  226. #ifdef LONG64
  227. int
  228. #if NeedFunctionPrototypes
  229. _XkbWriteCopyData32 (register unsigned long *from,CARD32 *to,int len)
  230. #else
  231. _XkbWriteCopyData32 (from,to,len)
  232.     register unsigned long *    from;
  233.     CARD32 *            to;
  234.     int             len;
  235. #endif
  236. {
  237.     DBUG_ENTER("_XkbWriteCopyData32")
  238.     while (len-->0) {
  239.     *to++= (CARD32)*from++;
  240.     }
  241.     DBUG_RETURN(True);
  242. }
  243. #endif /* LONG64 */
  244.  
  245. #ifdef WORD64
  246. _XkbWriteCopyData32 Not Implemented Yet for sizeof(int)==8
  247. #endif
  248.  
  249. char *
  250. #if NeedFunctionPrototypes
  251. _XkbPeekAtReadBuffer(XkbReadBufferPtr from,int size)
  252. #else
  253. _XkbPeekAtReadBuffer(from,size)
  254.     XkbReadBufferPtr     from;
  255.     int             size;
  256. #endif
  257. {
  258.     DBUG_ENTER("_XkbPeekAtReadBuffer")
  259.     char * result;
  260.     if ((from==NULL)||(from->error)||(size<1)||
  261.                     (_XkbReadBufferDataLeft(from)<size))
  262.     DBUG_RETURN(0);
  263.     result = from->data;
  264.     DBUG_RETURN(result);
  265. }
  266.  
  267. char *
  268. #if NeedFunctionPrototypes
  269. _XkbGetReadBufferPtr(XkbReadBufferPtr from,int size)
  270. #else
  271. _XkbGetReadBufferPtr(from,size)
  272.     XkbReadBufferPtr     from;
  273.     int             size;
  274. #endif
  275. {
  276.     DBUG_ENTER("_XkbGetReadBufferPtr")
  277.     char    *ptr;
  278.     if ((from==NULL)||(from->error)||(size<1)||
  279.                     (_XkbReadBufferDataLeft(from)<size))
  280.     DBUG_RETURN(0);
  281.     ptr= from->data;
  282.     from->data+= size;
  283.     DBUG_RETURN(ptr);
  284. }
  285.  
  286.  
  287. int
  288. #if NeedFunctionPrototypes
  289. _XkbFreeReadBuffer(XkbReadBufferPtr buf)
  290. #else
  291. _XkbFreeReadBuffer(buf)
  292.     XkbReadBufferPtr    buf;
  293. #endif
  294. {
  295.     DBUG_ENTER("_XkbFreeReadBuffer")
  296.     if ((buf!=NULL) && (buf->start!=NULL)) {
  297.     int left;
  298.     left= (int)_XkbReadBufferDataLeft(buf);
  299.     if (buf->start!=NULL)
  300.         Xfree(buf->start);
  301.     buf->size= 0;
  302.     buf->start= buf->data= NULL;
  303.     DBUG_RETURN(left);
  304.     }
  305.     DBUG_RETURN(0);
  306. }
  307.  
  308. Bool
  309. #if NeedFunctionPrototypes
  310. _XkbGetReadBufferCountedString(XkbReadBufferPtr buf,char **rtrn)
  311. #else
  312. _XkbGetReadBufferCountedString(buf,rtrn)
  313.     XkbReadBufferPtr    buf;
  314.     char **        rtrn;
  315. #endif
  316. {
  317.     DBUG_ENTER("_XkbGetReadBufferCountedString")
  318.     CARD16    len,*pLen;
  319.     int    left;
  320.     char *    str;
  321.  
  322.     if ((buf==NULL)||(buf->error)||((left=(int)_XkbReadBufferDataLeft(buf))<4))
  323.     DBUG_RETURN(False);
  324.     pLen= (CARD16 *)buf->data;
  325.     len= *pLen;
  326.     if (len>0) {
  327.     if (XkbPaddedSize(len+2)>left)
  328.         DBUG_RETURN(False);
  329.     str= _XkbAlloc(len+1);
  330.     if (str) {
  331.         memcpy(str,&buf->data[2],len);
  332.         str[len]= '\0';
  333.     }
  334.     }
  335.     buf->data+= XkbPaddedSize(len+2);
  336.     *rtrn= str;
  337.     DBUG_RETURN(True);
  338. }
  339.