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] = {
143 ModIndexText(xkb_mod_index_t ndx)
147 if (ndx < XkbNumModifiers)
148 return modNames[ndx];
149 else if (ndx == XkbNoModifier)
153 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
159 ModMaskText(xkb_mod_mask_t mask, bool cFormat)
165 if ((mask & 0xff) == 0xff)
166 return (cFormat ? "0xff" : "all");
168 if ((mask & 0xff) == 0)
169 return (cFormat ? "0" : "none");
172 buf = GetBuffer(rem);
175 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
181 len = snprintf(str, rem, "%s%s%s",
182 (str != buf) ? (cFormat ? "|" : "+") : "",
184 cFormat ? "Mask" : "");
193 FileTypeText(enum xkb_file_type type)
196 case FILE_TYPE_KEYMAP:
198 case FILE_TYPE_TYPES:
200 case FILE_TYPE_COMPAT:
202 case FILE_TYPE_SYMBOLS:
204 case FILE_TYPE_KEYCODES:
206 case FILE_TYPE_RULES:
213 static const char *actionTypeNames[XkbSA_NumActions] = {
214 "NoAction", /* XkbSA_NoAction */
215 "SetMods", /* XkbSA_SetMods */
216 "LatchMods", /* XkbSA_LatchMods */
217 "LockMods", /* XkbSA_LockMods */
218 "SetGroup", /* XkbSA_SetGroup */
219 "LatchGroup", /* XkbSA_LatchGroup */
220 "LockGroup", /* XkbSA_LockGroup */
221 "MovePtr", /* XkbSA_MovePtr */
222 "PtrBtn", /* XkbSA_PtrBtn */
223 "LockPtrBtn", /* XkbSA_LockPtrBtn */
224 "SetPtrDflt", /* XkbSA_SetPtrDflt */
225 "ISOLock", /* XkbSA_ISOLock */
226 "Terminate", /* XkbSA_Terminate */
227 "SwitchScreen", /* XkbSA_SwitchScreen */
228 "SetControls", /* XkbSA_SetControls */
229 "LockControls", /* XkbSA_LockControls */
230 "ActionMessage", /* XkbSA_ActionMessage */
231 "RedirectKey", /* XkbSA_RedirectKey */
232 "DeviceBtn", /* XkbSA_DeviceBtn */
233 "LockDeviceBtn", /* XkbSA_LockDeviceBtn */
234 "DeviceValuator" /* XkbSA_DeviceValuator */
238 ActionTypeText(unsigned type)
240 if (type <= XkbSA_LastAction)
241 return actionTypeNames[type];
246 KeysymText(xkb_keysym_t sym)
248 static char buffer[64];
250 xkb_keysym_get_name(sym, buffer, sizeof buffer);
256 KeyNameText(char *name)
263 strncpy(&buf[1], name, 4);
272 static const char *siMatchText[5] = {
273 "NoneOf", /* XkbSI_NoneOf */
274 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
275 "AnyOf", /* XkbSI_AnyOf */
276 "AllOf", /* XkbSI_AllOf */
277 "Exactly" /* XkbSI_Exactly */
281 SIMatchText(unsigned type)
285 switch (type & XkbSI_OpMask) {
287 return siMatchText[0];
288 case XkbSI_AnyOfOrNone:
289 return siMatchText[1];
291 return siMatchText[2];
293 return siMatchText[3];
295 return siMatchText[4];
298 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);