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 * Get a vmod name's text, where the vmod index is zero based
52 * (0..XkbNumVirtualMods-1).
55 VModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
59 const char *tmp = NULL;
62 if (ndx >= XkbNumVirtualMods)
65 tmp = keymap->vmod_names[ndx];
68 snprintf(buf, sizeof(buf) - 1, "%d", ndx);
72 len = strlen(tmp) + 1;
73 if (len >= BUFFER_SIZE)
74 len = BUFFER_SIZE - 1;
76 rtrn = GetBuffer(len);
77 strncpy(rtrn, tmp, len);
82 /* Get a mod mask's text, where the mask is in rmods+vmods format. */
84 VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
88 xkb_mod_mask_t rmask, vmask;
90 const char *mm = NULL;
92 char buf[BUFFER_SIZE];
95 vmask = cmask >> XkbNumModifiers;
97 if (rmask == 0 && vmask == 0)
101 mm = ModMaskText(rmask);
108 for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<=
113 len = snprintf(str, rem, "%s%s",
114 (str != buf) ? "+" : "",
115 VModIndexText(keymap, i));
125 len = (str ? strlen(str) : 0) + (mm ? strlen(mm) : 0) +
127 if (len >= BUFFER_SIZE)
128 len = BUFFER_SIZE - 1;
130 rtrn = GetBuffer(len + 1);
133 snprintf(rtrn, len + 1, "%s%s%s", (mm ? mm : ""),
134 (mm && str ? "+" : ""), (str ? str : ""));
141 * The indices used for the legacy core modifiers is derived from
142 * the order of the names in this table. It matches the values
143 * ShiftMapIndex, LockMapIndex, etc. from X11/X.h. Take note before
146 static const char *modNames[XkbNumModifiers] = {
158 ModNameToIndex(const char *name)
162 for (i = 0; i < XkbNumModifiers; i++)
163 if (istreq(name, modNames[i]))
166 return XKB_MOD_INVALID;
170 ModIndexToName(xkb_mod_index_t ndx)
172 if (ndx < XkbNumModifiers)
173 return modNames[ndx];
178 ModIndexText(xkb_mod_index_t ndx)
183 name = ModIndexToName(ndx);
187 if (ndx == XkbNoModifier)
191 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
196 /* Gets the text for the real modifiers only. */
198 ModMaskText(xkb_mod_mask_t mask)
204 if ((mask & 0xff) == 0xff)
207 if ((mask & 0xff) == 0)
211 buf = GetBuffer(rem);
214 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
220 len = snprintf(str, rem, "%s%s",
221 (str != buf ? "+" : ""), modNames[i]);
229 static const char *xkb_file_type_strings[_FILE_TYPE_NUM_ENTRIES] = {
230 [FILE_TYPE_KEYMAP] = "xkb_keymap",
231 [FILE_TYPE_TYPES] = "xkb_types",
232 [FILE_TYPE_COMPAT] = "xkb_compatibility",
233 [FILE_TYPE_SYMBOLS] = "xkb_symbols",
234 [FILE_TYPE_KEYCODES] = "xkb_keycodes",
235 [FILE_TYPE_RULES] = "rules",
239 FileTypeText(enum xkb_file_type type)
241 if (type > _FILE_TYPE_NUM_ENTRIES)
243 return xkb_file_type_strings[type];
246 static const char *actionTypeNames[XkbSA_NumActions] = {
247 [XkbSA_NoAction] = "NoAction",
248 [XkbSA_SetMods] = "SetMods",
249 [XkbSA_LatchMods] = "LatchMods",
250 [XkbSA_LockMods] = "LockMods",
251 [XkbSA_SetGroup] = "SetGroup",
252 [XkbSA_LatchGroup] = "LatchGroup",
253 [XkbSA_LockGroup] = "LockGroup",
254 [XkbSA_MovePtr] = "MovePtr",
255 [XkbSA_PtrBtn] = "PtrBtn",
256 [XkbSA_LockPtrBtn] = "LockPtrBtn",
257 [XkbSA_SetPtrDflt] = "SetPtrDflt",
258 [XkbSA_ISOLock] = "ISOLock",
259 [XkbSA_Terminate] = "Terminate",
260 [XkbSA_SwitchScreen] = "SwitchScreen",
261 [XkbSA_SetControls] = "SetControls",
262 [XkbSA_LockControls] = "LockControls",
263 [XkbSA_ActionMessage] = "ActionMessage",
264 [XkbSA_RedirectKey] = "RedirectKey",
265 [XkbSA_DeviceBtn] = "DeviceBtn",
266 [XkbSA_LockDeviceBtn] = "LockDeviceBtn",
267 [XkbSA_DeviceValuator] = "DeviceValuator"
271 ActionTypeText(unsigned type)
273 if (type <= XkbSA_LastAction)
274 return actionTypeNames[type];
279 KeysymText(xkb_keysym_t sym)
281 static char buffer[64];
283 xkb_keysym_get_name(sym, buffer, sizeof buffer);
289 KeyNameText(const char name[XkbKeyNameLength])
296 strncpy(&buf[1], name, 4);
305 static const char *siMatchText[5] = {
306 "NoneOf", /* XkbSI_NoneOf */
307 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
308 "AnyOf", /* XkbSI_AnyOf */
309 "AllOf", /* XkbSI_AllOf */
310 "Exactly" /* XkbSI_Exactly */
314 SIMatchText(unsigned type)
318 switch (type & XkbSI_OpMask) {
320 return siMatchText[0];
321 case XkbSI_AnyOfOrNone:
322 return siMatchText[1];
324 return siMatchText[2];
326 return siMatchText[3];
328 return siMatchText[4];
331 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);