/* $Xorg: xkbtext.c,v 1.3 2000/08/17 19:46:44 cpqbld Exp $ */ /************************************************************ Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Silicon Graphics not be used in advertising or publicity pertaining to distribution of the software without specific prior written permission. Silicon Graphics makes no representation about the suitability of this software for any purpose. It is provided "as is" without any express or implied warranty. SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ /* $XFree86: xc/lib/xkbfile/xkbtext.c,v 3.11 2002/12/21 18:49:02 paulo Exp $ */ #include #include #include #include #ifndef XKB_IN_SERVER #include #include #include #include "XKMformat.h" #include "XKBfileInt.h" #else #include "X.h" #define NEED_EVENTS #include "Xproto.h" #include "misc.h" #include "inputstr.h" #include "dix.h" #include "XKBstr.h" #define XKBSRV_NEED_FILE_FUNCS 1 #include "XKBsrv.h" #include "XKBgeom.h" #endif /***====================================================================***/ #define BUFFER_SIZE 512 static char textBuffer[BUFFER_SIZE]; static int tbNext= 0; static char * #if NeedFunctionPrototypes tbGetBuffer(unsigned size) #else tbGetBuffer(size) unsigned size; #endif { char *rtrn; if (size>=BUFFER_SIZE) return NULL; if ((BUFFER_SIZE-tbNext)<=size) tbNext= 0; rtrn= &textBuffer[tbNext]; tbNext+= size; return rtrn; } /***====================================================================***/ char * #if NeedFunctionPrototypes XkbAtomText(Display *dpy,Atom atm,unsigned format) #else XkbAtomText(dpy,atm,format) Display * dpy; Atom atm; unsigned format; #endif { char *rtrn,*tmp; tmp= XkbAtomGetString(dpy,atm); if (tmp!=NULL) { int len; len= strlen(tmp)+1; if (len>BUFFER_SIZE) len= BUFFER_SIZE-2; rtrn= tbGetBuffer(len); strncpy(rtrn,tmp,len); rtrn[len]= '\0'; } else { rtrn= tbGetBuffer(1); rtrn[0]= '\0'; } if (format==XkbCFile) { for (tmp=rtrn;*tmp!='\0';tmp++) { if ((tmp==rtrn)&&(!isalpha(*tmp))) *tmp= '_'; else if (!isalnum(*tmp)) *tmp= '_'; } } return XkbStringText(rtrn,format); } /***====================================================================***/ char * #if NeedFunctionPrototypes XkbVModIndexText(Display *dpy,XkbDescPtr xkb,unsigned ndx,unsigned format) #else XkbVModIndexText(dpy,xkb,ndx,format) Display * dpy; XkbDescPtr xkb; unsigned ndx; unsigned format; #endif { register int len; register Atom *vmodNames; char *rtrn,*tmp; char numBuf[20]; if (xkb && xkb->names) vmodNames= xkb->names->vmods; else vmodNames= NULL; tmp= NULL; if (ndx>=XkbNumVirtualMods) tmp= "illegal"; else if (vmodNames&&(vmodNames[ndx]!=None)) tmp= XkbAtomGetString(dpy,vmodNames[ndx]); if (tmp==NULL) sprintf(tmp=numBuf,"%d",ndx); len= strlen(tmp)+1; if (format==XkbCFile) len+= 4; if (len>=BUFFER_SIZE) len= BUFFER_SIZE-1; rtrn= tbGetBuffer(len); if (format==XkbCFile) { strcpy(rtrn,"vmod_"); strncpy(&rtrn[5],tmp,len-4); } else strncpy(rtrn,tmp,len); return rtrn; } char * #if NeedFunctionPrototypes XkbVModMaskText( Display * dpy, XkbDescPtr xkb, unsigned modMask, unsigned mask, unsigned format) #else XkbVModMaskText(dpy,xkb,modMask,mask,format) Display * dpy; XkbDescPtr xkb; unsigned modMask; unsigned mask; unsigned format; #endif { register int i,bit; int len; char *mm,*rtrn; char *str,buf[BUFFER_SIZE]; if ((modMask==0)&&(mask==0)) { rtrn= tbGetBuffer(5); if (format==XkbCFile) sprintf(rtrn,"0"); else sprintf(rtrn,"none"); return rtrn; } if (modMask!=0) mm= XkbModMaskText(modMask,format); else mm= NULL; str= buf; buf[0]= '\0'; if (mask) { char *tmp; for (i=0,bit=1;i=BUFFER_SIZE) len= BUFFER_SIZE-1; rtrn= tbGetBuffer(len+1); rtrn[0]= '\0'; if (mm!=NULL) { i= strlen(mm); if (i>len) i= len; strcpy(rtrn,mm); } else { i=0; } if (str!=NULL) { if (mm!=NULL) { if (format==XkbCFile) strcat(rtrn,"|"); else strcat(rtrn,"+"); } strncat(rtrn,str,len-i); } rtrn[len]= '\0'; return rtrn; } static char *modNames[XkbNumModifiers] = { "Shift", "Lock", "Control", "Mod1", "Mod2", "Mod3", "Mod4", "Mod5" }; char * #if NeedFunctionPrototypes XkbModIndexText(unsigned ndx,unsigned format) #else XkbModIndexText(ndx,format) unsigned ndx; unsigned format; #endif { char * rtrn; char buf[100]; if (format==XkbCFile) { if (ndx0) { len= strlen(from); if (len<((*pLeft)-3)) { strcat(to,from); *pLeft-= len; return True; } } *pLeft= -1; return False; } /*ARGSUSED*/ static Bool #if NeedFunctionPrototypes CopyNoActionArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf,int*sz) #else CopyNoActionArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { return True; } static Bool #if NeedFunctionPrototypes CopyModActionArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf, int* sz) #else CopyModActionArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbModAction * act; unsigned tmp; act= &action->mods; tmp= XkbModActionVMods(act); TryCopyStr(buf,"modifiers=",sz); if (act->flags&XkbSA_UseModMapMods) TryCopyStr(buf,"modMapMods",sz); else if (act->real_mods || tmp) { TryCopyStr(buf, XkbVModMaskText(dpy,xkb,act->real_mods,tmp,XkbXKBFile), sz); } else TryCopyStr(buf,"none",sz); if (act->type==XkbSA_LockMods) return True; if (act->flags&XkbSA_ClearLocks) TryCopyStr(buf,",clearLocks",sz); if (act->flags&XkbSA_LatchToLock) TryCopyStr(buf,",latchToLock",sz); return True; } /*ARGSUSED*/ static Bool #if NeedFunctionPrototypes CopyGroupActionArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf, int *sz) #else CopyGroupActionArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbGroupAction * act; char tbuf[32]; act= &action->group; TryCopyStr(buf,"group=",sz); if (act->flags&XkbSA_GroupAbsolute) sprintf(tbuf,"%d",XkbSAGroup(act)+1); else if (XkbSAGroup(act)<0) sprintf(tbuf,"%d",XkbSAGroup(act)); else sprintf(tbuf,"+%d",XkbSAGroup(act)); TryCopyStr(buf,tbuf,sz); if (act->type==XkbSA_LockGroup) return True; if (act->flags&XkbSA_ClearLocks) TryCopyStr(buf,",clearLocks",sz); if (act->flags&XkbSA_LatchToLock) TryCopyStr(buf,",latchToLock",sz); return True; } /*ARGSUSED*/ static Bool #if NeedFunctionPrototypes CopyMovePtrArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf,int *sz) #else CopyMovePtrArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbPtrAction * act; int x,y; char tbuf[32]; act= &action->ptr; x= XkbPtrActionX(act); y= XkbPtrActionY(act); if ((act->flags&XkbSA_MoveAbsoluteX)||(x<0)) sprintf(tbuf,"x=%d",x); else sprintf(tbuf,"x=+%d",x); TryCopyStr(buf,tbuf,sz); if ((act->flags&XkbSA_MoveAbsoluteY)||(y<0)) sprintf(tbuf,",y=%d",y); else sprintf(tbuf,",y=+%d",y); TryCopyStr(buf,tbuf,sz); if (act->flags&XkbSA_NoAcceleration) TryCopyStr(buf,",!accel",sz); return True; } /*ARGSUSED*/ static Bool #if NeedFunctionPrototypes CopyPtrBtnArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf,int *sz) #else CopyPtrBtnArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbPtrBtnAction * act; char tbuf[32]; act= &action->btn; TryCopyStr(buf,"button=",sz); if ((act->button>0)&&(act->button<6)) { sprintf(tbuf,"%d",act->button); TryCopyStr(buf,tbuf,sz); } else TryCopyStr(buf,"default",sz); if (act->count>0) { sprintf(tbuf,",count=%d",act->count); TryCopyStr(buf,tbuf,sz); } if (action->type==XkbSA_LockPtrBtn) { switch (act->flags&(XkbSA_LockNoUnlock|XkbSA_LockNoLock)) { case XkbSA_LockNoLock: sprintf(tbuf,",affect=unlock"); break; case XkbSA_LockNoUnlock: sprintf(tbuf,",affect=lock"); break; case XkbSA_LockNoUnlock|XkbSA_LockNoLock: sprintf(tbuf,",affect=neither"); break; default: sprintf(tbuf,",affect=both"); break; } TryCopyStr(buf,tbuf,sz); } return True; } /*ARGSUSED*/ static Bool #if NeedFunctionPrototypes CopySetPtrDfltArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf, int *sz) #else CopySetPtrDfltArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbPtrDfltAction * act; char tbuf[32]; act= &action->dflt; if (act->affect==XkbSA_AffectDfltBtn) { TryCopyStr(buf,"affect=button,button=",sz); if ((act->flags&XkbSA_DfltBtnAbsolute)||(XkbSAPtrDfltValue(act)<0)) sprintf(tbuf,"%d",XkbSAPtrDfltValue(act)); else sprintf(tbuf,"+%d",XkbSAPtrDfltValue(act)); TryCopyStr(buf,tbuf,sz); } return True; } static Bool #if NeedFunctionPrototypes CopyISOLockArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf,int *sz) #else CopyISOLockArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbISOAction * act; char tbuf[64]; act= &action->iso; if (act->flags&XkbSA_ISODfltIsGroup) { TryCopyStr(tbuf,"group=",sz); if (act->flags&XkbSA_GroupAbsolute) sprintf(tbuf,"%d",XkbSAGroup(act)+1); else if (XkbSAGroup(act)<0) sprintf(tbuf,"%d",XkbSAGroup(act)); else sprintf(tbuf,"+%d",XkbSAGroup(act)); TryCopyStr(buf,tbuf,sz); } else { unsigned tmp; tmp= XkbModActionVMods(act); TryCopyStr(buf,"modifiers=",sz); if (act->flags&XkbSA_UseModMapMods) TryCopyStr(buf,"modMapMods",sz); else if (act->real_mods || tmp) { if (act->real_mods) { TryCopyStr(buf,XkbModMaskText(act->real_mods,XkbXKBFile),sz); if (tmp) TryCopyStr(buf,"+",sz); } if (tmp) TryCopyStr(buf,XkbVModMaskText(dpy,xkb,0,tmp,XkbXKBFile),sz); } else TryCopyStr(buf,"none",sz); } TryCopyStr(buf,",affect=",sz); if ((act->affect&XkbSA_ISOAffectMask)==0) TryCopyStr(buf,"all",sz); else { int nOut= 0; if ((act->affect&XkbSA_ISONoAffectMods)==0) { TryCopyStr(buf,"mods",sz); nOut++; } if ((act->affect&XkbSA_ISONoAffectGroup)==0) { sprintf(tbuf,"%sgroups",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if ((act->affect&XkbSA_ISONoAffectPtr)==0) { sprintf(tbuf,"%spointer",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if ((act->affect&XkbSA_ISONoAffectCtrls)==0) { sprintf(tbuf,"%scontrols",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } } return True; } /*ARGSUSED*/ static Bool #if NeedFunctionPrototypes CopySwitchScreenArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf, int *sz) #else CopySwitchScreenArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbSwitchScreenAction * act; char tbuf[32]; act= &action->screen; if ((act->flags&XkbSA_SwitchAbsolute)||(XkbSAScreen(act)<0)) sprintf(tbuf,"screen=%d",XkbSAScreen(act)); else sprintf(tbuf,"screen=+%d",XkbSAScreen(act)); TryCopyStr(buf,tbuf,sz); if (act->flags&XkbSA_SwitchApplication) TryCopyStr(buf,",!same",sz); else TryCopyStr(buf,",same",sz); return True; } /*ARGSUSED*/ static Bool #if NeedFunctionPrototypes CopySetLockControlsArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action, char *buf,int *sz) #else CopySetLockControlsArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbCtrlsAction * act; unsigned tmp; char tbuf[32]; act= &action->ctrls; tmp= XkbActionCtrls(act); TryCopyStr(buf,"controls=",sz); if (tmp==0) TryCopyStr(buf,"none",sz); else if ((tmp&XkbAllBooleanCtrlsMask)==XkbAllBooleanCtrlsMask) TryCopyStr(buf,"all",sz); else { int nOut= 0; if (tmp&XkbRepeatKeysMask) { sprintf(tbuf,"%sRepeatKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbSlowKeysMask) { sprintf(tbuf,"%sSlowKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbBounceKeysMask) { sprintf(tbuf,"%sBounceKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbStickyKeysMask) { sprintf(tbuf,"%sStickyKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbMouseKeysMask) { sprintf(tbuf,"%sMouseKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbMouseKeysAccelMask) { sprintf(tbuf,"%sMouseKeysAccel",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAccessXKeysMask) { sprintf(tbuf,"%sAccessXKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAccessXTimeoutMask) { sprintf(tbuf,"%sAccessXTimeout",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAccessXFeedbackMask) { sprintf(tbuf,"%sAccessXFeedback",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAudibleBellMask) { sprintf(tbuf,"%sAudibleBell",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbOverlay1Mask) { sprintf(tbuf,"%sOverlay1",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbOverlay2Mask) { sprintf(tbuf,"%sOverlay2",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbIgnoreGroupLockMask) { sprintf(tbuf,"%sIgnoreGroupLock",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } } return True; } /*ARGSUSED*/ static Bool #if NeedFunctionPrototypes CopyActionMessageArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf, int *sz) #else CopyActionMessageArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbMessageAction * act; unsigned all; char tbuf[32]; act= &action->msg; all= XkbSA_MessageOnPress|XkbSA_MessageOnRelease; TryCopyStr(buf,"report=",sz); if ((act->flags&all)==0) TryCopyStr(buf,"none",sz); else if ((act->flags&all)==all) TryCopyStr(buf,"all",sz); else if (act->flags&XkbSA_MessageOnPress) TryCopyStr(buf,"KeyPress",sz); else TryCopyStr(buf,"KeyRelease",sz); sprintf(tbuf,",data[0]=0x%02x",act->message[0]); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[1]=0x%02x",act->message[1]); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[2]=0x%02x",act->message[2]); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[3]=0x%02x",act->message[3]); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[4]=0x%02x",act->message[4]); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[5]=0x%02x",act->message[5]); TryCopyStr(buf,tbuf,sz); return True; } static Bool #if NeedFunctionPrototypes CopyRedirectKeyArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf, int *sz) #else CopyRedirectKeyArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbRedirectKeyAction * act; char tbuf[32],*tmp; unsigned kc; unsigned vmods,vmods_mask; act= &action->redirect; kc= act->new_key; vmods= XkbSARedirectVMods(act); vmods_mask= XkbSARedirectVModsMask(act); if (xkb && xkb->names && xkb->names->keys && (kc<=xkb->max_key_code) && (xkb->names->keys[kc].name[0]!='\0')) { char *kn; kn= XkbKeyNameText(xkb->names->keys[kc].name,XkbXKBFile); sprintf(tbuf,"key=%s",kn); } else sprintf(tbuf,"key=%d",kc); TryCopyStr(buf,tbuf,sz); if ((act->mods_mask==0)&&(vmods_mask==0)) return True; if ((act->mods_mask==XkbAllModifiersMask)&& (vmods_mask==XkbAllVirtualModsMask)) { tmp= XkbVModMaskText(dpy,xkb,act->mods,vmods,XkbXKBFile); TryCopyStr(buf,",mods=",sz); TryCopyStr(buf,tmp,sz); } else { if ((act->mods_mask&act->mods)||(vmods_mask&vmods)) { tmp= XkbVModMaskText(dpy,xkb,act->mods_mask&act->mods, vmods_mask&vmods,XkbXKBFile); TryCopyStr(buf,",mods= ",sz); TryCopyStr(buf,tmp,sz); } if ((act->mods_mask&(~act->mods))||(vmods_mask&(~vmods))) { tmp= XkbVModMaskText(dpy,xkb,act->mods_mask&(~act->mods), vmods_mask&(~vmods),XkbXKBFile); TryCopyStr(buf,",clearMods= ",sz); TryCopyStr(buf,tmp,sz); } } return True; } /*ARGSUSED*/ static Bool #if NeedFunctionPrototypes CopyDeviceBtnArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf, int *sz) #else CopyDeviceBtnArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbDeviceBtnAction * act; char tbuf[32]; act= &action->devbtn; sprintf(tbuf,"device= %d",act->device); TryCopyStr(buf,tbuf,sz); TryCopyStr(buf,",button=",sz); sprintf(tbuf,"%d",act->button); TryCopyStr(buf,tbuf,sz); if (act->count>0) { sprintf(tbuf,",count=%d",act->count); TryCopyStr(buf,tbuf,sz); } if (action->type==XkbSA_LockDeviceBtn) { switch (act->flags&(XkbSA_LockNoUnlock|XkbSA_LockNoLock)) { case XkbSA_LockNoLock: sprintf(tbuf,",affect=unlock"); break; case XkbSA_LockNoUnlock: sprintf(tbuf,",affect=lock"); break; case XkbSA_LockNoUnlock|XkbSA_LockNoLock: sprintf(tbuf,",affect=neither"); break; default: sprintf(tbuf,",affect=both"); break; } TryCopyStr(buf,tbuf,sz); } return True; } /*ARGSUSED*/ static Bool #if NeedFunctionPrototypes CopyOtherArgs(Display *dpy,XkbDescPtr xkb,XkbAction *action,char *buf,int *sz) #else CopyOtherArgs(dpy,xkb,action,buf,sz) Display * dpy; XkbDescPtr xkb; XkbAction * action; char * buf; int * sz; #endif { XkbAnyAction * act; char tbuf[32]; act= &action->any; sprintf(tbuf,"type=0x%02x",act->type); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[0]=0x%02x",act->data[0]); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[1]=0x%02x",act->data[1]); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[2]=0x%02x",act->data[2]); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[3]=0x%02x",act->data[3]); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[4]=0x%02x",act->data[4]); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[5]=0x%02x",act->data[5]); TryCopyStr(buf,tbuf,sz); sprintf(tbuf,",data[6]=0x%02x",act->data[6]); TryCopyStr(buf,tbuf,sz); return True; } typedef Bool (*actionCopy)( #if NeedFunctionPrototypes Display * /* dpy */, XkbDescPtr /* xkb */, XkbAction * /* action */, char * /* buf */, int* /* sz */ #endif ); static actionCopy copyActionArgs[XkbSA_NumActions] = { CopyNoActionArgs /* NoAction */, CopyModActionArgs /* SetMods */, CopyModActionArgs /* LatchMods */, CopyModActionArgs /* LockMods */, CopyGroupActionArgs /* SetGroup */, CopyGroupActionArgs /* LatchGroup */, CopyGroupActionArgs /* LockGroup */, CopyMovePtrArgs /* MovePtr */, CopyPtrBtnArgs /* PtrBtn */, CopyPtrBtnArgs /* LockPtrBtn */, CopySetPtrDfltArgs /* SetPtrDflt */, CopyISOLockArgs /* ISOLock */, CopyNoActionArgs /* Terminate */, CopySwitchScreenArgs /* SwitchScreen */, CopySetLockControlsArgs /* SetControls */, CopySetLockControlsArgs /* LockControls */, CopyActionMessageArgs /* ActionMessage*/, CopyRedirectKeyArgs /* RedirectKey */, CopyDeviceBtnArgs /* DeviceBtn */, CopyDeviceBtnArgs /* LockDeviceBtn*/ }; #define ACTION_SZ 256 char * #if NeedFunctionPrototypes XkbActionText(Display *dpy,XkbDescPtr xkb,XkbAction *action,unsigned format) #else XkbActionText(dpy,xkb,action,format) Display * dpy; XkbDescPtr xkb; XkbAction * action; unsigned format; #endif { char buf[ACTION_SZ],*tmp; int sz; if (format==XkbCFile) { sprintf(buf, "{ %20s, { 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x } }", XkbActionTypeText(action->type,XkbCFile), action->any.data[0],action->any.data[1],action->any.data[2], action->any.data[3],action->any.data[4],action->any.data[5], action->any.data[6]); } else { sprintf(buf,"%s(",XkbActionTypeText(action->type,XkbXKBFile)); sz= ACTION_SZ-strlen(buf)+2; /* room for close paren and NULL */ if (action->type<(unsigned)XkbSA_NumActions) (*copyActionArgs[action->type])(dpy,xkb,action,buf,&sz); else CopyOtherArgs(dpy,xkb,action,buf,&sz); TryCopyStr(buf,")",&sz); } tmp= tbGetBuffer(strlen(buf)+1); if (tmp!=NULL) strcpy(tmp,buf); return tmp; } char * #if NeedFunctionPrototypes XkbBehaviorText(XkbDescPtr xkb,XkbBehavior *behavior,unsigned format) #else XkbBehaviorText(xkb,behavior,format) XkbDescPtr xkb; XkbBehavior * behavior; unsigned format; #endif { char buf[256],*tmp; if (format==XkbCFile) { if (behavior->type==XkbKB_Default) sprintf(buf,"{ 0, 0 }"); else sprintf(buf,"{ %3d, 0x%02x }",behavior->type,behavior->data); } else { unsigned type,permanent; type= behavior->type&XkbKB_OpMask; permanent=((behavior->type&XkbKB_Permanent)!=0); if (type==XkbKB_Lock) { sprintf(buf,"lock= %s",(permanent?"Permanent":"True")); } else if (type==XkbKB_RadioGroup) { int g; char *tmp; g= ((behavior->data)&(~XkbKB_RGAllowNone))+1; if (XkbKB_RGAllowNone&behavior->data) { sprintf(buf,"allowNone,"); tmp= &buf[strlen(buf)]; } else tmp= buf; if (permanent) sprintf(tmp,"permanentRadioGroup= %d",g); else sprintf(tmp,"radioGroup= %d",g); } else if ((type==XkbKB_Overlay1)||(type==XkbKB_Overlay2)) { int ndx,kc; char *kn; ndx= ((type==XkbKB_Overlay1)?1:2); kc= behavior->data; if ((xkb)&&(xkb->names)&&(xkb->names->keys)) kn= XkbKeyNameText(xkb->names->keys[kc].name,XkbXKBFile); else { static char tbuf[8]; sprintf(tbuf,"%d",kc); kn= tbuf; } if (permanent) sprintf(buf,"permanentOverlay%d= %s",ndx,kn); else sprintf(buf,"overlay%d= %s",ndx,kn); } } tmp= tbGetBuffer(strlen(buf)+1); if (tmp!=NULL) strcpy(tmp,buf); return tmp; } /***====================================================================***/ char * #if NeedFunctionPrototypes XkbIndentText(unsigned size) #else XkbIndentText(size) unsigned size; #endif { static char buf[32]; register int i; if (size>31) size= 31; for (i=0;ired= color->green= color->blue= 0; return True; } else if (_XkbStrCaseEqual(def,"white")) { color->red= color->green= color->blue= PIXEL_MAX; return True; } else if ((sscanf(def,"grey%d",&tmp)==1)|| (sscanf(def,"gray%d",&tmp)==1)|| (sscanf(def,"Grey%d",&tmp)==1)|| (sscanf(def,"Gray%d",&tmp)==1)) { if ((tmp>0)&&(tmp<=100)) { tmp= (PIXEL_MAX*tmp)/100; color->red= color->green= color->blue= tmp; return True; } } else if ((tmp=(_XkbStrCaseEqual(def,"red")*100))|| (sscanf(def,"red%d",&tmp)==1)) { if ((tmp>0)&&(tmp<=100)) { tmp= (PIXEL_MAX*tmp)/100; color->red= tmp; color->green= color->blue= 0; return True; } } else if ((tmp=(_XkbStrCaseEqual(def,"green")*100))|| (sscanf(def,"green%d",&tmp)==1)) { if ((tmp>0)&&(tmp<=100)) { tmp= (PIXEL_MAX*tmp)/100; color->green= tmp; color->red= color->blue= 0; return True; } } else if ((tmp=(_XkbStrCaseEqual(def,"blue")*100))|| (sscanf(def,"blue%d",&tmp)==1)) { if ((tmp>0)&&(tmp<=100)) { tmp= (PIXEL_MAX*tmp)/100; color->blue= tmp; color->red= color->green= 0; return True; } } else if ((tmp=(_XkbStrCaseEqual(def,"magenta")*100))|| (sscanf(def,"magenta%d",&tmp)==1)) { if ((tmp>0)&&(tmp<=100)) { tmp= (PIXEL_MAX*tmp)/100; color->green= 0; color->red= color->blue= tmp; return True; } } else if ((tmp=(_XkbStrCaseEqual(def,"cyan")*100))|| (sscanf(def,"cyan%d",&tmp)==1)) { if ((tmp>0)&&(tmp<=100)) { tmp= (PIXEL_MAX*tmp)/100; color->red= 0; color->green= color->blue= tmp; return True; } } else if ((tmp=(_XkbStrCaseEqual(def,"yellow")*100))|| (sscanf(def,"yellow%d",&tmp)==1)) { if ((tmp>0)&&(tmp<=100)) { tmp= (PIXEL_MAX*tmp)/100; color->blue= 0; color->red= color->green= tmp; return True; } } return False; } #endif