1966bf024Smrg/* $XFree86: xc/lib/XTrap/XEStrMap.c,v 1.1 2001/11/02 23:29:27 dawes Exp $ */ 2966bf024Smrg/***************************************************************************** 3966bf024SmrgCopyright 1987, 1988, 1989, 1990, 1991, 1992, 1994 by Digital Equipment Corp., 4966bf024SmrgMaynard, MA 5966bf024Smrg 6966bf024SmrgPermission to use, copy, modify, and distribute this software and its 7966bf024Smrgdocumentation for any purpose and without fee is hereby granted, 8966bf024Smrgprovided that the above copyright notice appear in all copies and that 9966bf024Smrgboth that copyright notice and this permission notice appear in 10966bf024Smrgsupporting documentation, and that the name of Digital not be 11966bf024Smrgused in advertising or publicity pertaining to distribution of the 12966bf024Smrgsoftware without specific, written prior permission. 13966bf024Smrg 14966bf024SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 15966bf024SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 16966bf024SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 17966bf024SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 18966bf024SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 19966bf024SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 20966bf024SmrgSOFTWARE. 21966bf024Smrg 22966bf024Smrg*****************************************************************************/ 23966bf024Smrg#include <stdio.h> 24966bf024Smrg#include <X11/Xlib.h> 25966bf024Smrg#include <X11/extensions/xtraplib.h> 26966bf024Smrg#include <X11/extensions/xtraplibp.h> 27966bf024Smrg 28966bf024Smrgstatic char *eventName[] = { 29966bf024Smrg "", "", 30966bf024Smrg "KeyPress", "KeyRelease", "ButtonPress", 31966bf024Smrg "ButtonRelease", "MotionNotify", "EnterNotify", 32966bf024Smrg "LeaveNotify", "FocusIn", "FocusOut", 33966bf024Smrg "KeymapNotify", "Expose", "GraphicsExpose", 34966bf024Smrg "NoExpose", "VisibilityNotify", "CreateNotify", 35966bf024Smrg "DestroyNotify", "UnmapNotify", "MapNotify", 36966bf024Smrg "MapRequest", "ReparentNotify", "ConfigureNotify", 37966bf024Smrg "ConfigureRequest", "GravityNotify", "ResizeRequest", 38966bf024Smrg "CirculateNotify", "CirculateRequest", "PropertyNotify", 39966bf024Smrg "SelectionClear", "SelectionRequest", "SelectionNotify", 40966bf024Smrg "ColormapNotify", "ClientMessage", "MappingNotify", 41966bf024Smrg "LASTEvent", 42966bf024Smrg}; 43966bf024Smrg 44966bf024Smrgstatic char *requestName[] = { 45966bf024Smrg "Invalid", 46966bf024Smrg "X_CreateWindow", "X_ChangeWindowAttributes", 47966bf024Smrg "X_GetWindowAttributes", "X_DestroyWindow", 48966bf024Smrg "X_DestroySubwindows", "X_ChangeSaveSet", 49966bf024Smrg "X_ReparentWindow", "X_MapWindow", 50966bf024Smrg "X_MapSubwindows", "X_UnmapWindow", 51966bf024Smrg "X_UnmapSubwindows", "X_ConfigureWindow", 52966bf024Smrg "X_CirculateWindow", "X_GetGeometry", 53966bf024Smrg "X_QueryTree", "X_InternAtom", 54966bf024Smrg "X_GetAtomName", "X_ChangeProperty", 55966bf024Smrg "X_DeleteProperty", "X_GetProperty", 56966bf024Smrg "X_ListProperties", "X_SetSelectionOwner", 57966bf024Smrg "X_GetSelectionOwner", "X_ConvertSelection", 58966bf024Smrg "X_SendEvent", "X_GrabPointer", 59966bf024Smrg "X_UngrabPointer", "X_GrabButton", 60966bf024Smrg "X_UngrabButton", "X_ChangeActivePointerGrab", 61966bf024Smrg "X_GrabKeyboard", "X_UngrabKeyboard", 62966bf024Smrg "X_GrabKey", "X_UngrabKey", 63966bf024Smrg "X_AllowEvents", "X_GrabServer", 64966bf024Smrg "X_UngrabServer", "X_QueryPointer", 65966bf024Smrg "X_GetMotionEvents", "X_TranslateCoords", 66966bf024Smrg "X_WarpPointer", "X_SetInputFocus", 67966bf024Smrg "X_GetInputFocus", "X_QueryKeymap", 68966bf024Smrg "X_OpenFont", "X_CloseFont", 69966bf024Smrg "X_QueryFont", "X_QueryTextExtents", 70966bf024Smrg "X_ListFonts", "X_ListFontsWithInfo", 71966bf024Smrg "X_SetFontPath", "X_GetFontPath", 72966bf024Smrg "X_CreatePixmap", "X_FreePixmap", 73966bf024Smrg "X_CreateGC", "X_ChangeGC", 74966bf024Smrg "X_CopyGC", "X_SetDashes", 75966bf024Smrg "X_SetClipRectangles", "X_FreeGC", 76966bf024Smrg "X_ClearArea", "X_CopyArea", 77966bf024Smrg "X_CopyPlane", "X_PolyPoint", 78966bf024Smrg "X_PolyLine", "X_PolySegment", 79966bf024Smrg "X_PolyRectangle", "X_PolyArc", 80966bf024Smrg "X_FillPoly", "X_PolyFillRectangle", 81966bf024Smrg "X_PolyFillArc", "X_PutImage", 82966bf024Smrg "X_GetImage", "X_PolyText8", 83966bf024Smrg "X_PolyText16", "X_ImageText8", 84966bf024Smrg "X_ImageText16", "X_CreateColormap", 85966bf024Smrg "X_FreeColormap", "X_CopyColormapAndFree", 86966bf024Smrg "X_InstallColormap", "X_UninstallColormap", 87966bf024Smrg "X_ListInstalledColormaps", "X_AllocColor", 88966bf024Smrg "X_AllocNamedColor", "X_AllocColorCells", 89966bf024Smrg "X_AllocColorPlanes", "X_FreeColors", 90966bf024Smrg "X_StoreColors", "X_StoreNamedColor", 91966bf024Smrg "X_QueryColors", "X_LookupColor", 92966bf024Smrg "X_CreateCursor", "X_CreateGlyphCursor", 93966bf024Smrg "X_FreeCursor", "X_RecolorCursorSize", 94966bf024Smrg "X_QueryBestSize", "X_QueryExtension", 95966bf024Smrg "X_ListExtensions", "X_ChangeKeyboardMapping", 96966bf024Smrg "X_GetKeyboardMapping", "X_ChangeKeyboardControl", 97966bf024Smrg "X_GetKeyboardControl", "X_Bell", 98966bf024Smrg "X_ChangePointerControl", "X_GetPointerControl", 99966bf024Smrg "X_SetScreenSaver", "X_GetScreenSaver", 100966bf024Smrg "X_ChangeHosts", "X_ListHosts", 101966bf024Smrg "X_SetAccessControl", "X_SetCloseDownMode", 102966bf024Smrg "X_KillClient", "X_RotateProperties", 103966bf024Smrg "X_ForceScreenSaver", "X_SetPointerMapping", 104966bf024Smrg "X_GetPointerMapping", "X_SetModifierMapping", 105966bf024Smrg "X_GetModifierMapping", "Invalid", 106966bf024Smrg "Invalid", "Invalid", 107966bf024Smrg "Invalid", "Invalid", 108966bf024Smrg "Invalid", "Invalid", 109966bf024Smrg "X_NoOperation", 110966bf024Smrg}; 111966bf024Smrg 112966bf024Smrgtypedef struct 113966bf024Smrg{ 114966bf024Smrg char *extName; 115966bf024Smrg int extEvent; 116966bf024Smrg} _extensionData; 1179384b2f3Smrgstatic _extensionData *extensionData; 1189384b2f3Smrgstatic int numExtension = -1; 119966bf024Smrg 120966bf024Smrgstatic struct _pf_tbl {CARD32 id; char *str;} pf_tbl[] = 121966bf024Smrg{ 122966bf024Smrg {PF_Apollo, "Apollo"}, 123966bf024Smrg {PF_ATT, "ATT"}, 124966bf024Smrg {PF_Cray1, "Cray1"}, 125966bf024Smrg {PF_Cray2, "Cray2"}, 126966bf024Smrg {PF_DECUltrix, "DECUltrix"}, 127966bf024Smrg {PF_DECVMS, "DECVMS"}, 128966bf024Smrg {PF_DECELN, "DECELN"}, 129966bf024Smrg {PF_DECOSF1, "DECOSF1"}, 130966bf024Smrg {PF_DECVT1000, "DECVT1000"}, 131966bf024Smrg {PF_DECXTerm, "DECXTerm"}, 132966bf024Smrg {PF_HP9000s800, "HP9000s800"}, 133966bf024Smrg {PF_HP9000s300, "HP9000s300"}, 134966bf024Smrg {PF_IBMAT, "IBMAT"}, 135966bf024Smrg {PF_IBMRT, "IBMRT"}, 136966bf024Smrg {PF_IBMPS2, "IBMPS2"}, 137966bf024Smrg {PF_IBMRS, "IBMRS"}, 138966bf024Smrg {PF_MacII, "MacII"}, 139966bf024Smrg {PF_Pegasus, "Pegasus"}, 140966bf024Smrg {PF_SGI, "SGI"}, 141966bf024Smrg {PF_Sony, "Sony"}, 142966bf024Smrg {PF_Sun3, "Sun3"}, 143966bf024Smrg {PF_Sun386i, "Sun386i"}, 144966bf024Smrg {PF_SunSparc, "SunSparc"}, 145966bf024Smrg {PF_Other, "Other"} /* always the last one! */ 146966bf024Smrg}; 147966bf024Smrg 148966bf024Smrgstatic char unknown[] = "unknown"; 149966bf024Smrg 150966bf024Smrg#define ASize(array) (sizeof(array)/sizeof((array)[0])) 151966bf024Smrg 152966bf024Smrgstatic INT16 _StringToID(register char *match, register char **strings, 153966bf024Smrg INT16 nstrings) 154966bf024Smrg{ 155966bf024Smrg register INT16 id = nstrings; 156966bf024Smrg 157966bf024Smrg if (match && *match) 158966bf024Smrg { while ((--id >= 0L) && (strcmp(match,strings[id]) != 0L)); } 159966bf024Smrg else 160966bf024Smrg { id = -1L; } 161966bf024Smrg 162966bf024Smrg return(id); 163966bf024Smrg} 164966bf024Smrgstatic void loadExtStrings(XETC *tc) 165966bf024Smrg{ 166966bf024Smrg char **extensionName=XListExtensions(tc->dpy,&numExtension); 167966bf024Smrg if (numExtension) 168966bf024Smrg { 169966bf024Smrg int i; 170966bf024Smrg extensionData = (_extensionData *)XtCalloc(numExtension, 171966bf024Smrg sizeof(_extensionData)); 172966bf024Smrg for (i = 0; i < numExtension; i++) 173966bf024Smrg { /* Arrange extensions in opcode order */ 174966bf024Smrg int opcode,event,error; 175966bf024Smrg if (XQueryExtension(tc->dpy,extensionName[i],&opcode,&event, 176966bf024Smrg &error)) 177966bf024Smrg { 178966bf024Smrg extensionData[opcode-128].extName = extensionName[i]; 179966bf024Smrg extensionData[opcode-128].extEvent = event; 180966bf024Smrg } 181966bf024Smrg else 182966bf024Smrg { /* This extension didn't load! Error! */ 183966bf024Smrg extensionData[opcode-128].extName = "Invalid_Extension"; 184966bf024Smrg } 185966bf024Smrg } 186966bf024Smrg XFreeExtensionList(extensionName); 187966bf024Smrg } 188966bf024Smrg} 189966bf024Smrg 190966bf024SmrgINT16 XEEventStringToID(register char *string) 191966bf024Smrg{ 192966bf024Smrg return(_StringToID(string,eventName,ASize(eventName))); 193966bf024Smrg} 194966bf024Smrg 195966bf024SmrgINT16 XERequestStringToID(register char *string) 196966bf024Smrg{ 197966bf024Smrg return(_StringToID(string,requestName,ASize(requestName))); 198966bf024Smrg} 199966bf024Smrg 200966bf024SmrgCARD32 XEPlatformStringToID(register char *string) 201966bf024Smrg{ 202966bf024Smrg struct _pf_tbl *ptr = &(pf_tbl[0]); 203966bf024Smrg while(ptr->id != PF_Other) 204966bf024Smrg { 205966bf024Smrg if (!strncmp(ptr->str, string, strlen(ptr->str))) 206966bf024Smrg { 207966bf024Smrg return(ptr->id); 208966bf024Smrg } 209966bf024Smrg ptr++; 210966bf024Smrg } 211966bf024Smrg return((!strncmp(ptr->str,string,strlen(ptr->str))) ? ptr->id : -1L); 212966bf024Smrg} 213966bf024Smrg 214966bf024Smrgchar *XEEventIDToString(register CARD8 id, XETC *tc) 215966bf024Smrg{ 216966bf024Smrg int i; 217966bf024Smrg if (id < ASize(eventName)) 218966bf024Smrg return(eventName[id]); 219966bf024Smrg /* either erroneous or an extension event */ 220966bf024Smrg if (numExtension < 0) 221966bf024Smrg { /* 222966bf024Smrg * This is unfortunate, but necessary. The client 223966bf024Smrg * program has requested the string identifier for 224966bf024Smrg * an extension request/event. Since there's no Xlib 225966bf024Smrg * equivalent for this, we have to query *all* the 226966bf024Smrg * extensions looking for a match. Chances are 227966bf024Smrg * if a client wants one, it'll want them all, 228966bf024Smrg * so just go through and initialize the extension 229966bf024Smrg * list once. 230966bf024Smrg */ 231966bf024Smrg loadExtStrings(tc); 232966bf024Smrg } 233966bf024Smrg /* Find id within extensionData */ 234966bf024Smrg for (i=0; i<numExtension; i++) 235966bf024Smrg { 236966bf024Smrg if (extensionData[i].extEvent == id) 237966bf024Smrg return(extensionData[i].extName); 238966bf024Smrg } 239966bf024Smrg return(unknown); 240966bf024Smrg} 241966bf024Smrg 242966bf024Smrgchar *XERequestIDToExtString(register CARD8 id, XETC *tc) 243966bf024Smrg{ 244966bf024Smrg int extid; 245966bf024Smrg 246966bf024Smrg extid = id - ASize(requestName); 247966bf024Smrg 248966bf024Smrg if (numExtension < 0) 249966bf024Smrg { /* 250966bf024Smrg * This is unfortunate, but necessary. The client 251966bf024Smrg * program has requested the string identifier for 252966bf024Smrg * an extension request/event. Since there's no Xlib 253966bf024Smrg * equivalent for this, we have to query *all* the 254966bf024Smrg * extensions looking for a match. Chances are 255966bf024Smrg * if a client wants one, it'll want them all, 256966bf024Smrg * so just go through and initialize the extension 257966bf024Smrg * list once. 258966bf024Smrg */ 259966bf024Smrg loadExtStrings(tc); 260966bf024Smrg } 261966bf024Smrg return((extid >=0 && extid < numExtension) ? 262966bf024Smrg extensionData[extid].extName : unknown); 263966bf024Smrg} 264966bf024Smrg 265966bf024Smrg 266966bf024Smrgchar *XERequestIDToString(register CARD8 id, XETC *tc) 267966bf024Smrg{ 268966bf024Smrg return((id < ASize(requestName)) ? requestName[id] : 269966bf024Smrg XERequestIDToExtString(id,tc)); 270966bf024Smrg} 271966bf024Smrg 272966bf024Smrgchar *XEPlatformIDToString(register CARD32 id) 273966bf024Smrg{ 274966bf024Smrg struct _pf_tbl *ptr = &(pf_tbl[0]); 275966bf024Smrg while((ptr->id != PF_Other) || (id == ptr->id)) 276966bf024Smrg { 277966bf024Smrg if (id == ptr->id) 278966bf024Smrg { 279966bf024Smrg return(ptr->str); 280966bf024Smrg } 281966bf024Smrg ptr++; 282966bf024Smrg } 283966bf024Smrg return(unknown); 284966bf024Smrg} 285