1 /************************************************************
2 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
32 #include "XKBlibint.h"
33 #include <X11/extensions/XKBproto.h>
35 /***====================================================================***/
38 _XkbInitReadBuffer(Display *dpy,XkbReadBufferPtr buf,int size)
40 if ((dpy!=NULL) && (buf!=NULL) && (size>0)) {
43 buf->start= buf->data= _XkbAlloc(size);
45 _XRead(dpy, buf->start, size);
52 #define _XkbReadBufferDataLeft(b) (((b)->size)-((b)->data-(b)->start))
55 _XkbSkipReadBufferData(XkbReadBufferPtr from,int size)
59 if ((from==NULL)||(from->error)||(size<1)||
60 (_XkbReadBufferDataLeft(from)<size))
67 _XkbCopyFromReadBuffer(XkbReadBufferPtr from,char *to,int size)
71 if ((from==NULL)||(from->error)||(to==NULL)||(size<1)||
72 (_XkbReadBufferDataLeft(from)<size))
74 memcpy(to,from->data,size);
79 #ifdef XKB_FORCE_INT_KEYSYM
81 _XkbReadCopyKeySyms(int *wire,KeySym *to,int num_words)
83 while (num_words-->0) {
90 _XkbReadBufferCopyKeySyms(XkbReadBufferPtr from,KeySym *to,int num_words)
92 if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from))
94 _XkbReadCopyKeySyms((int *)from->data,to,num_words);
95 from->data+= (4*num_words);
100 _XkbWriteCopyKeySyms (register KeySym *from,CARD32 *to,int len)
104 *to++= (CARD32)*from++;
112 _XkbReadCopyData32(int *wire,long *to,int num_words)
114 while (num_words-->0) {
122 _XkbReadCopyData32(int *from,long *lp,int num_words)
125 long mask32 = 0x00000000ffffffff;
128 lpack = (long *)from;
131 for (i=0;i<num_words;i++) {
132 maskw = mask32 << bits;
133 *lp++ = (*lpack & maskw) >> bits;
142 #if defined(LONG64) || defined(WORD64)
144 _XkbReadBufferCopy32(XkbReadBufferPtr from,long *to,int num_words)
146 if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from))
148 _XkbReadCopyData32((int *)from->data,to,num_words);
149 from->data+= (4*num_words);
156 _XkbWriteCopyData32 (register unsigned long *from,CARD32 *to,int len)
160 *to++= (CARD32)*from++;
167 _XkbWriteCopyData32 Not Implemented Yet for sizeof(int)==8
171 _XkbPeekAtReadBuffer(XkbReadBufferPtr from,int size)
173 if ((from==NULL)||(from->error)||(size<1)||
174 (_XkbReadBufferDataLeft(from)<size))
180 _XkbGetReadBufferPtr(XkbReadBufferPtr from,int size)
183 if ((from==NULL)||(from->error)||(size<1)||
184 (_XkbReadBufferDataLeft(from)<size))
193 _XkbFreeReadBuffer(XkbReadBufferPtr buf)
195 if ((buf!=NULL) && (buf->start!=NULL)) {
197 left= (int)_XkbReadBufferDataLeft(buf);
198 if (buf->start!=NULL)
201 buf->start= buf->data= NULL;
208 _XkbGetReadBufferCountedString(XkbReadBufferPtr buf,char **rtrn)
214 if ((buf==NULL)||(buf->error)||((left=(int)_XkbReadBufferDataLeft(buf))<4))
216 pLen= (CARD16 *)buf->data;
219 if (XkbPaddedSize(len+2)>left)
221 str= _XkbAlloc(len+1);
223 memcpy(str,&buf->data[2],len);
227 buf->data+= XkbPaddedSize(len+2);