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 ********************************************************/
29 #define BUFFER_SIZE 1024
32 GetBuffer(size_t size)
34 static char buffer[BUFFER_SIZE];
38 if (size >= BUFFER_SIZE)
41 if (BUFFER_SIZE - next <= size)
51 VModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
55 const char *tmp = NULL;
58 if (ndx >= XkbNumVirtualMods)
61 tmp = keymap->vmod_names[ndx];
64 snprintf(buf, sizeof(buf) - 1, "%d", ndx);
68 len = strlen(tmp) + 1;
69 if (len >= BUFFER_SIZE)
70 len = BUFFER_SIZE - 1;
72 rtrn = GetBuffer(len);
73 strncpy(rtrn, tmp, len);
79 VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t modMask,
85 const char *mm = NULL;
87 char buf[BUFFER_SIZE];
89 if (modMask == 0 && mask == 0)
93 mm = ModMaskText(modMask, false);
100 for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<=
105 len = snprintf(str, rem, "%s%s",
106 (str != buf) ? "+" : "",
107 VModIndexText(keymap, i));
117 len = (str ? strlen(str) : 0) + (mm ? strlen(mm) : 0) +
119 if (len >= BUFFER_SIZE)
120 len = BUFFER_SIZE - 1;
122 rtrn = GetBuffer(len + 1);
125 snprintf(rtrn, len + 1, "%s%s%s", (mm ? mm : ""),
126 (mm && str ? "+" : ""), (str ? str : ""));
133 * The indices used for the legacy core modifiers is derived from
134 * the order of the names in this table. It matches the values
135 * ShiftMapIndex, LockMapIndex, etc. from X11/X.h. Take note before
138 static const char *modNames[XkbNumModifiers] = {
150 ModNameToIndex(const char *name)
154 for (i = 0; i < XkbNumModifiers; i++)
155 if (istreq(name, modNames[i]))
158 return XKB_MOD_INVALID;
162 ModIndexToName(xkb_mod_index_t ndx)
164 if (ndx < XkbNumModifiers)
165 return modNames[ndx];
170 ModIndexText(xkb_mod_index_t ndx)
175 name = ModIndexToName(ndx);
179 if (ndx == XkbNoModifier)
183 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
189 ModMaskText(xkb_mod_mask_t mask, bool cFormat)
195 if ((mask & 0xff) == 0xff)
196 return (cFormat ? "0xff" : "all");
198 if ((mask & 0xff) == 0)
199 return (cFormat ? "0" : "none");
202 buf = GetBuffer(rem);
205 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
211 len = snprintf(str, rem, "%s%s%s",
212 (str != buf) ? (cFormat ? "|" : "+") : "",
214 cFormat ? "Mask" : "");
223 FileTypeText(enum xkb_file_type type)
226 case FILE_TYPE_KEYMAP:
228 case FILE_TYPE_TYPES:
230 case FILE_TYPE_COMPAT:
231 return "xkb_compatability";
232 case FILE_TYPE_SYMBOLS:
233 return "xkb_symbols";
234 case FILE_TYPE_KEYCODES:
235 return "xkb_keycodes";
236 case FILE_TYPE_RULES:
243 static const char *actionTypeNames[XkbSA_NumActions] = {
244 [XkbSA_NoAction] = "NoAction",
245 [XkbSA_SetMods] = "SetMods",
246 [XkbSA_LatchMods] = "LatchMods",
247 [XkbSA_LockMods] = "LockMods",
248 [XkbSA_SetGroup] = "SetGroup",
249 [XkbSA_LatchGroup] = "LatchGroup",
250 [XkbSA_LockGroup] = "LockGroup",
251 [XkbSA_MovePtr] = "MovePtr",
252 [XkbSA_PtrBtn] = "PtrBtn",
253 [XkbSA_LockPtrBtn] = "LockPtrBtn",
254 [XkbSA_SetPtrDflt] = "SetPtrDflt",
255 [XkbSA_ISOLock] = "ISOLock",
256 [XkbSA_Terminate] = "Terminate",
257 [XkbSA_SwitchScreen] = "SwitchScreen",
258 [XkbSA_SetControls] = "SetControls",
259 [XkbSA_LockControls] = "LockControls",
260 [XkbSA_ActionMessage] = "ActionMessage",
261 [XkbSA_RedirectKey] = "RedirectKey",
262 [XkbSA_DeviceBtn] = "DeviceBtn",
263 [XkbSA_LockDeviceBtn] = "LockDeviceBtn",
264 [XkbSA_DeviceValuator] = "DeviceValuator"
268 ActionTypeText(unsigned type)
270 if (type <= XkbSA_LastAction)
271 return actionTypeNames[type];
276 KeysymText(xkb_keysym_t sym)
278 static char buffer[64];
280 xkb_keysym_get_name(sym, buffer, sizeof buffer);
286 KeyNameText(const char name[XkbKeyNameLength])
293 strncpy(&buf[1], name, 4);
302 static const char *siMatchText[5] = {
303 "NoneOf", /* XkbSI_NoneOf */
304 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
305 "AnyOf", /* XkbSI_AnyOf */
306 "AllOf", /* XkbSI_AllOf */
307 "Exactly" /* XkbSI_Exactly */
311 SIMatchText(unsigned type)
315 switch (type & XkbSI_OpMask) {
317 return siMatchText[0];
318 case XkbSI_AnyOfOrNone:
319 return siMatchText[1];
321 return siMatchText[2];
323 return siMatchText[3];
325 return siMatchText[4];
328 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);