Status _XkbReadGetGeometryReply( Display * dpy, xkbGetGeometryReply * rep, XkbDescPtr xkb, int * nread_rtrn) { XkbGeometryPtr geom; geom= _XkbTypedCalloc(1,XkbGeometryRec); if (!geom) return BadAlloc; if (xkb->geom) XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True); xkb->geom= geom; geom->name= rep->name; geom->width_mm= rep->widthMM; geom->height_mm= rep->heightMM; if (rep->length) { XkbReadBufferRec buf; int left; if (_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) { Status status= Success; if (nread_rtrn) *nread_rtrn= (int)rep->length*4; if (!_XkbGetReadBufferCountedString(&buf,&geom->label_font)) status= BadLength; if (status==Success) status= _XkbReadGeomProperties(&buf,geom,rep); if (status==Success) status= _XkbReadGeomColors(&buf,geom,rep); if (status==Success) status= _XkbReadGeomShapes(&buf,geom,rep); if (status==Success) status= _XkbReadGeomSections(&buf,geom,rep); if (status==Success) status= _XkbReadGeomDoodads(&buf,geom,rep); if (status==Success) status= _XkbReadGeomKeyAliases(&buf,geom,rep); left= _XkbFreeReadBuffer(&buf); if ((status!=Success) || left || buf.error) { if (status==Success) status= BadLength; XkbFreeGeometry(geom,XkbGeomAllMask,True); xkb->geom= NULL; return status; } geom->base_color= &geom->colors[rep->baseColorNdx]; geom->label_color= &geom->colors[rep->labelColorNdx]; } else { XkbFreeGeometry(geom,XkbGeomAllMask,True); xkb->geom= NULL; return BadAlloc; } } return Success; }
XkbComponentListPtr XkbListComponents( Display * dpy, unsigned deviceSpec, XkbComponentNamesPtr ptrns, int * max_inout) { register xkbListComponentsReq* req; xkbListComponentsReply rep; XkbInfoPtr xkbi; XkbComponentListPtr list; XkbReadBufferRec buf; int left; char * str; int extraLen,len,mapLen,codesLen,typesLen,compatLen,symsLen,geomLen; if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) || (ptrns==NULL) || (max_inout==NULL)) return NULL; xkbi= dpy->xkb_info; LockDisplay(dpy); GetReq(kbListComponents, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbListComponents; req->deviceSpec = deviceSpec; req->maxNames = *max_inout; mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0; if (ptrns->keymap) mapLen= (int)strlen(ptrns->keymap); if (ptrns->keycodes) codesLen= (int)strlen(ptrns->keycodes); if (ptrns->types) typesLen= (int)strlen(ptrns->types); if (ptrns->compat) compatLen= (int)strlen(ptrns->compat); if (ptrns->symbols) symsLen= (int)strlen(ptrns->symbols); if (ptrns->geometry) geomLen= (int)strlen(ptrns->geometry); if (mapLen>255) mapLen= 255; if (codesLen>255) codesLen= 255; if (typesLen>255) typesLen= 255; if (compatLen>255) compatLen= 255; if (symsLen>255) symsLen= 255; if (geomLen>255) geomLen= 255; len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6; len= XkbPaddedSize(len); req->length+= len/4; BufAlloc(char *,str,len); *str++= mapLen; if (mapLen>0) { memcpy(str,ptrns->keymap,mapLen); str+= mapLen; } *str++= codesLen; if (codesLen>0) { memcpy(str,ptrns->keycodes,codesLen); str+= codesLen; } *str++= typesLen; if (typesLen>0) { memcpy(str,ptrns->types,typesLen); str+= typesLen; } *str++= compatLen; if (compatLen>0) { memcpy(str,ptrns->compat,compatLen); str+= compatLen; } *str++= symsLen; if (symsLen>0) { memcpy(str,ptrns->symbols,symsLen); str+= symsLen; } *str++= geomLen; if (geomLen>0) { memcpy(str,ptrns->geometry,geomLen); str+= geomLen; } if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) goto BAILOUT; extraLen= (int)rep.length*4; *max_inout= rep.extra; if (extraLen==0) { /* no matches, but we don't want to report a failure */ list= _XkbTypedCalloc(1,XkbComponentListRec); UnlockDisplay(dpy); SyncHandle(); return list; } if (_XkbInitReadBuffer(dpy,&buf,extraLen)) { Status status; status= Success; list= _XkbTypedCalloc(1,XkbComponentListRec); if (!list) { _XkbFreeReadBuffer(&buf); goto BAILOUT; } list->num_keymaps= rep.nKeymaps; list->num_keycodes= rep.nKeycodes; list->num_types= rep.nTypes; list->num_compat= rep.nCompatMaps; list->num_symbols= rep.nSymbols; list->num_geometry= rep.nGeometries; if ((status==Success)&&(list->num_keymaps>0)) list->keymaps= _ReadListing(&buf,list->num_keymaps,&status); if ((status==Success)&&(list->num_keycodes>0)) list->keycodes= _ReadListing(&buf,list->num_keycodes,&status); if ((status==Success)&&(list->num_types>0)) list->types= _ReadListing(&buf,list->num_types,&status); if ((status==Success)&&(list->num_compat>0)) list->compat= _ReadListing(&buf,list->num_compat,&status); if ((status==Success)&&(list->num_symbols>0)) list->symbols= _ReadListing(&buf,list->num_symbols,&status); if ((status==Success)&&(list->num_geometry>0)) list->geometry= _ReadListing(&buf,list->num_geometry,&status); left= _XkbFreeReadBuffer(&buf); if ((status!=Success)||(buf.error)||(left>2)) { XkbFreeComponentList(list); goto BAILOUT; } UnlockDisplay(dpy); SyncHandle(); return list; } BAILOUT: UnlockDisplay(dpy); SyncHandle(); return NULL; }
Status _XkbReadGetCompatMapReply( Display * dpy, xkbGetCompatMapReply * rep, XkbDescPtr xkb, int * nread_rtrn) { register int i; XkbReadBufferRec buf; if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) return BadAlloc; if (nread_rtrn) *nread_rtrn= (int)rep->length*4; i= rep->firstSI+rep->nSI; if ((!xkb->compat)&& (XkbAllocCompatMap(xkb,XkbAllCompatMask,i)!=Success)) return BadAlloc; if (rep->nSI!=0) { XkbSymInterpretRec *syms; xkbSymInterpretWireDesc *wire; wire= (xkbSymInterpretWireDesc *)_XkbGetReadBufferPtr(&buf, rep->nSI*SIZEOF(xkbSymInterpretWireDesc)); if (wire==NULL) goto BAILOUT; syms= &xkb->compat->sym_interpret[rep->firstSI]; for (i=0;i<rep->nSI;i++,syms++,wire++) { syms->sym= wire->sym; syms->mods= wire->mods; syms->match= wire->match; syms->virtual_mod= wire->virtualMod; syms->flags= wire->flags; syms->act= *((XkbAnyAction *)&wire->act); } xkb->compat->num_si+= rep->nSI; } if (rep->groups&XkbAllGroupsMask) { register unsigned bit,nGroups; xkbModsWireDesc * wire; for (i=0,nGroups=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) { if (rep->groups&bit) nGroups++; } wire= (xkbModsWireDesc *)_XkbGetReadBufferPtr(&buf, nGroups*SIZEOF(xkbModsWireDesc)); if (wire==NULL) goto BAILOUT; for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) { if ((rep->groups&bit)==0) continue; xkb->compat->groups[i].mask= wire->mask; xkb->compat->groups[i].real_mods= wire->realMods; xkb->compat->groups[i].vmods= wire->virtualMods; wire++; } } i= _XkbFreeReadBuffer(&buf); if (i) fprintf(stderr,"CompatMapReply! Bad length (%d extra bytes)\n",i); if (i || buf.error) return BadLength; return Success; BAILOUT: _XkbFreeReadBuffer(&buf); return BadLength; }