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
30 static char textBuffer[BUFFER_SIZE];
31 static unsigned int tbNext = 0;
34 tbGetBuffer(unsigned int size)
38 if (size >= BUFFER_SIZE)
41 if ((BUFFER_SIZE - tbNext) <= size)
44 rtrn = &textBuffer[tbNext];
51 XkbcVModIndexText(struct xkb_keymap *keymap, unsigned 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 = tbGetBuffer(len);
73 strncpy(rtrn, tmp, len);
79 XkbcVModMaskText(struct xkb_keymap *keymap, unsigned modMask, unsigned mask)
82 const char *mm = NULL;
84 char buf[BUFFER_SIZE];
86 if ((modMask == 0) && (mask == 0))
90 mm = XkbcModMaskText(modMask, false);
97 for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<=
102 len = snprintf(str, rem, "%s%s",
103 (str != buf) ? "+" : "",
104 XkbcVModIndexText(keymap, i));
114 len = ((str) ? strlen(str) : 0) + ((mm) ? strlen(mm) : 0) +
115 ((str && mm) ? 1 : 0);
116 if (len >= BUFFER_SIZE)
117 len = BUFFER_SIZE - 1;
119 rtrn = tbGetBuffer(len + 1);
122 snprintf(rtrn, len + 1, "%s%s%s", (mm) ? mm : "",
123 (mm && str) ? "+" : "", (str) ? str : "");
128 static const char *modNames[XkbNumModifiers] = {
140 XkbcModIndexText(unsigned ndx)
144 if (ndx < XkbNumModifiers)
145 return modNames[ndx];
146 else if (ndx == XkbNoModifier)
149 buf = tbGetBuffer(32);
150 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
156 XkbcModMaskText(unsigned mask, bool cFormat)
161 if ((mask & 0xff) == 0xff)
162 return (cFormat ? "0xff" : "all");
164 if ((mask & 0xff) == 0)
165 return (cFormat ? "0" : "none");
168 buf = tbGetBuffer(rem);
171 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
177 len = snprintf(str, rem, "%s%s%s",
178 (str != buf) ? (cFormat ? "|" : "+") : "",
180 cFormat ? "Mask" : "");
189 XkbcFileTypeText(enum xkb_file_type type)
192 case FILE_TYPE_KEYMAP:
194 case FILE_TYPE_TYPES:
196 case FILE_TYPE_COMPAT:
198 case FILE_TYPE_SYMBOLS:
200 case FILE_TYPE_KEYCODES:
202 case FILE_TYPE_RULES:
209 static const char *actionTypeNames[XkbSA_NumActions] = {
210 "NoAction", /* XkbSA_NoAction */
211 "SetMods", /* XkbSA_SetMods */
212 "LatchMods", /* XkbSA_LatchMods */
213 "LockMods", /* XkbSA_LockMods */
214 "SetGroup", /* XkbSA_SetGroup */
215 "LatchGroup", /* XkbSA_LatchGroup */
216 "LockGroup", /* XkbSA_LockGroup */
217 "MovePtr", /* XkbSA_MovePtr */
218 "PtrBtn", /* XkbSA_PtrBtn */
219 "LockPtrBtn", /* XkbSA_LockPtrBtn */
220 "SetPtrDflt", /* XkbSA_SetPtrDflt */
221 "ISOLock", /* XkbSA_ISOLock */
222 "Terminate", /* XkbSA_Terminate */
223 "SwitchScreen", /* XkbSA_SwitchScreen */
224 "SetControls", /* XkbSA_SetControls */
225 "LockControls", /* XkbSA_LockControls */
226 "ActionMessage", /* XkbSA_ActionMessage */
227 "RedirectKey", /* XkbSA_RedirectKey */
228 "DeviceBtn", /* XkbSA_DeviceBtn */
229 "LockDeviceBtn", /* XkbSA_LockDeviceBtn */
230 "DeviceValuator" /* XkbSA_DeviceValuator */
234 XkbcActionTypeText(unsigned type)
236 if (type <= XkbSA_LastAction)
237 return actionTypeNames[type];
242 XkbcKeysymText(xkb_keysym_t sym)
244 static char buffer[64];
246 xkb_keysym_get_name(sym, buffer, sizeof buffer);
252 XkbcKeyNameText(char *name)
257 buf = tbGetBuffer(7);
259 strncpy(&buf[1], name, 4);
268 static const char *siMatchText[5] = {
269 "NoneOf", /* XkbSI_NoneOf */
270 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
271 "AnyOf", /* XkbSI_AnyOf */
272 "AllOf", /* XkbSI_AllOf */
273 "Exactly" /* XkbSI_Exactly */
277 XkbcSIMatchText(unsigned type)
281 switch (type & XkbSI_OpMask) {
283 return siMatchText[0];
284 case XkbSI_AnyOfOrNone:
285 return siMatchText[1];
287 return siMatchText[2];
289 return siMatchText[3];
291 return siMatchText[4];
293 buf = tbGetBuffer(40);
294 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);