1 /************************************************************
2 Copyright (c) 1994 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 ********************************************************/
31 #include "xkbcommon/xkbcommon.h"
32 #include "XKBcommonint.h"
37 #define BUFFER_SIZE 1024
38 static char textBuffer[BUFFER_SIZE];
39 static int tbNext = 0;
42 tbGetBuffer(unsigned int size)
46 if (size >= BUFFER_SIZE)
49 if ((BUFFER_SIZE - tbNext) <= size)
52 rtrn = &textBuffer[tbNext];
59 XkbcVModIndexText(struct xkb_desc * xkb, unsigned ndx)
63 const char *tmp = NULL;
66 if (ndx >= XkbNumVirtualMods)
68 else if (xkb && xkb->names)
69 tmp = xkb->names->vmods[ndx];
72 snprintf(buf, sizeof(buf) - 1, "%d", ndx);
76 len = strlen(tmp) + 1;
77 if (len >= BUFFER_SIZE)
78 len = BUFFER_SIZE - 1;
80 rtrn = tbGetBuffer(len);
81 strncpy(rtrn, tmp, len);
87 XkbcVModMaskText(struct xkb_desc * xkb, unsigned modMask, unsigned mask)
90 const char *mm = NULL;
92 char buf[BUFFER_SIZE];
94 if ((modMask == 0) && (mask == 0))
98 mm = XkbcModMaskText(modMask, False);
105 for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<= 1)
110 len = snprintf(str, rem, "%s%s",
111 (str != buf) ? "+" : "",
112 XkbcVModIndexText(xkb, i));
122 len = ((str) ? strlen(str) : 0) + ((mm) ? strlen(mm) : 0) +
123 ((str && mm) ? 1 : 0);
124 if (len >= BUFFER_SIZE)
125 len = BUFFER_SIZE - 1;
127 rtrn = tbGetBuffer(len + 1);
130 snprintf(rtrn, len + 1, "%s%s%s", (mm) ? mm : "",
131 (mm && str) ? "+" : "", (str) ? str : "");
136 static const char *modNames[XkbNumModifiers] = {
148 XkbcModIndexText(unsigned ndx)
152 if (ndx < XkbNumModifiers)
153 return modNames[ndx];
154 else if (ndx == XkbNoModifier)
157 buf = tbGetBuffer(32);
158 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
164 XkbcModMaskText(unsigned mask, Bool cFormat)
169 if ((mask & 0xff) == 0xff)
170 return (cFormat ? "0xff" : "all");
172 if ((mask & 0xff) == 0)
173 return (cFormat ? "0" : "none");
176 buf = tbGetBuffer(rem);
179 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
185 len = snprintf(str, rem, "%s%s%s",
186 (str != buf) ? (cFormat ? "|" : "+") : "",
188 cFormat ? "Mask" : "");
197 XkbcConfigText(unsigned config)
200 case XkmSemanticsFile:
208 case XkmCompatMapIndex:
210 case XkmSymbolsIndex:
212 case XkmIndicatorsIndex:
214 case XkmKeyNamesIndex:
216 case XkmVirtualModsIndex:
217 return "VirtualMods";
223 static const char *actionTypeNames[XkbSA_NumActions]= {
224 "NoAction", /* XkbSA_NoAction */
225 "SetMods", /* XkbSA_SetMods */
226 "LatchMods", /* XkbSA_LatchMods */
227 "LockMods", /* XkbSA_LockMods */
228 "SetGroup", /* XkbSA_SetGroup */
229 "LatchGroup", /* XkbSA_LatchGroup */
230 "LockGroup", /* XkbSA_LockGroup */
231 "MovePtr", /* XkbSA_MovePtr */
232 "PtrBtn", /* XkbSA_PtrBtn */
233 "LockPtrBtn", /* XkbSA_LockPtrBtn */
234 "SetPtrDflt", /* XkbSA_SetPtrDflt */
235 "ISOLock", /* XkbSA_ISOLock */
236 "Terminate", /* XkbSA_Terminate */
237 "SwitchScreen", /* XkbSA_SwitchScreen */
238 "SetControls", /* XkbSA_SetControls */
239 "LockControls", /* XkbSA_LockControls */
240 "ActionMessage", /* XkbSA_ActionMessage */
241 "RedirectKey", /* XkbSA_RedirectKey */
242 "DeviceBtn", /* XkbSA_DeviceBtn */
243 "LockDeviceBtn", /* XkbSA_LockDeviceBtn */
244 "DeviceValuator" /* XkbSA_DeviceValuator */
248 XkbcActionTypeText(unsigned type)
250 if (type <= XkbSA_LastAction)
251 return actionTypeNames[type];
256 XkbcKeysymText(uint32_t sym)
258 static char buffer[16];
260 xkb_keysym_to_string(sym, buffer, sizeof buffer);
266 XkbcKeyNameText(char *name)
271 buf = tbGetBuffer(7);
273 strncpy(&buf[1], name, 4);
282 static const char *siMatchText[5] = {
283 "NoneOf", /* XkbSI_NoneOf */
284 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
285 "AnyOf", /* XkbSI_AnyOf */
286 "AllOf", /* XkbSI_AllOf */
287 "Exactly" /* XkbSI_Exactly */
291 XkbcSIMatchText(unsigned type)
295 switch (type & XkbSI_OpMask) {
297 return siMatchText[0];
298 case XkbSI_AnyOfOrNone:
299 return siMatchText[1];
301 return siMatchText[2];
303 return siMatchText[3];
305 return siMatchText[4];
307 buf = tbGetBuffer(40);
308 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);