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 : ""));
131 static const char *modNames[XkbNumModifiers] = {
132 [ShiftMapIndex] = "Shift",
133 [LockMapIndex] = "Lock",
134 [ControlMapIndex] = "Control",
135 [Mod1MapIndex] = "Mod1",
136 [Mod2MapIndex] = "Mod2",
137 [Mod3MapIndex] = "Mod3",
138 [Mod4MapIndex] = "Mod4",
139 [Mod5MapIndex] = "Mod5",
143 ModNameToIndex(const char *name)
147 for (i = 0; i < XkbNumModifiers; i++)
148 if (istreq(name, modNames[i]))
151 return XKB_MOD_INVALID;
155 ModIndexToName(xkb_mod_index_t ndx)
157 if (ndx < XkbNumModifiers)
158 return modNames[ndx];
163 ModIndexText(xkb_mod_index_t ndx)
168 name = ModIndexToName(ndx);
172 if (ndx == XkbNoModifier)
176 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
182 ModMaskText(xkb_mod_mask_t mask, bool cFormat)
188 if ((mask & 0xff) == 0xff)
189 return (cFormat ? "0xff" : "all");
191 if ((mask & 0xff) == 0)
192 return (cFormat ? "0" : "none");
195 buf = GetBuffer(rem);
198 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
204 len = snprintf(str, rem, "%s%s%s",
205 (str != buf) ? (cFormat ? "|" : "+") : "",
207 cFormat ? "Mask" : "");
216 FileTypeText(enum xkb_file_type type)
219 case FILE_TYPE_KEYMAP:
221 case FILE_TYPE_TYPES:
223 case FILE_TYPE_COMPAT:
224 return "xkb_compatability";
225 case FILE_TYPE_SYMBOLS:
226 return "xkb_symbols";
227 case FILE_TYPE_KEYCODES:
228 return "xkb_keycodes";
229 case FILE_TYPE_RULES:
236 static const char *actionTypeNames[XkbSA_NumActions] = {
237 [XkbSA_NoAction] = "NoAction",
238 [XkbSA_SetMods] = "SetMods",
239 [XkbSA_LatchMods] = "LatchMods",
240 [XkbSA_LockMods] = "LockMods",
241 [XkbSA_SetGroup] = "SetGroup",
242 [XkbSA_LatchGroup] = "LatchGroup",
243 [XkbSA_LockGroup] = "LockGroup",
244 [XkbSA_MovePtr] = "MovePtr",
245 [XkbSA_PtrBtn] = "PtrBtn",
246 [XkbSA_LockPtrBtn] = "LockPtrBtn",
247 [XkbSA_SetPtrDflt] = "SetPtrDflt",
248 [XkbSA_ISOLock] = "ISOLock",
249 [XkbSA_Terminate] = "Terminate",
250 [XkbSA_SwitchScreen] = "SwitchScreen",
251 [XkbSA_SetControls] = "SetControls",
252 [XkbSA_LockControls] = "LockControls",
253 [XkbSA_ActionMessage] = "ActionMessage",
254 [XkbSA_RedirectKey] = "RedirectKey",
255 [XkbSA_DeviceBtn] = "DeviceBtn",
256 [XkbSA_LockDeviceBtn] = "LockDeviceBtn",
257 [XkbSA_DeviceValuator] = "DeviceValuator"
261 ActionTypeText(unsigned type)
263 if (type <= XkbSA_LastAction)
264 return actionTypeNames[type];
269 KeysymText(xkb_keysym_t sym)
271 static char buffer[64];
273 xkb_keysym_get_name(sym, buffer, sizeof buffer);
279 KeyNameText(char *name)
286 strncpy(&buf[1], name, 4);
295 static const char *siMatchText[5] = {
296 "NoneOf", /* XkbSI_NoneOf */
297 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
298 "AnyOf", /* XkbSI_AnyOf */
299 "AllOf", /* XkbSI_AllOf */
300 "Exactly" /* XkbSI_Exactly */
304 SIMatchText(unsigned type)
308 switch (type & XkbSI_OpMask) {
310 return siMatchText[0];
311 case XkbSI_AnyOfOrNone:
312 return siMatchText[1];
314 return siMatchText[2];
316 return siMatchText[3];
318 return siMatchText[4];
321 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);