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 ********************************************************/
31 #include "X11/extensions/XKBcommon.h"
32 #include "XKBcommonint.h"
33 #include <X11/extensions/XKM.h>
38 #define BUFFER_SIZE 512
39 static char textBuffer[BUFFER_SIZE];
40 static int tbNext = 0;
43 tbGetBuffer(unsigned size)
47 if (size >= BUFFER_SIZE)
50 if ((BUFFER_SIZE - tbNext) <= size)
53 rtrn = &textBuffer[tbNext];
60 XkbStringText(char *str)
72 /* Find if there are any non-printable characters */
73 for (ok = True, len = 0, in = str; *in != '\0'; in++, len++) {
79 case '\n': case '\t': case '\v':
80 case '\b': case '\r': case '\f':
93 /* Cleanup non-printable characters */
94 buf = tbGetBuffer(len + 1);
95 for (in = str, out = buf; *in != '\0'; in++) {
123 snprintf(out, 3, "%o", *in);
134 XkbcAtomText(Atom atm)
139 tmp = XkbcAtomGetString(atm);
144 len = strlen(tmp) + 1;
145 if (len >= BUFFER_SIZE)
146 len = BUFFER_SIZE - 2;
148 rtrn = tbGetBuffer(len);
149 strncpy(rtrn, tmp, len);
154 return XkbStringText(rtrn);
158 XkbcVModIndexText(XkbcDescPtr xkb, unsigned ndx)
162 char *rtrn, *tmp = NULL;
164 if (xkb && xkb->names)
165 vmodNames = xkb->names->vmods;
169 if (ndx >= XkbNumVirtualMods)
170 tmp = strdup("illegal");
171 else if (vmodNames && (vmodNames[ndx] != None))
172 tmp = XkbcAtomGetString(vmodNames[ndx]);
175 tmp = _XkbAlloc(20 * sizeof(char));
176 snprintf(tmp, 20, "%d", ndx);
179 len = strlen(tmp) + 1;
180 if (len >= BUFFER_SIZE)
181 len = BUFFER_SIZE - 1;
183 rtrn = tbGetBuffer(len);
184 strncpy(rtrn, tmp, len);
192 XkbcVModMaskText(XkbcDescPtr xkb, unsigned modMask, unsigned mask)
194 int i, bit, len, rem;
195 char *mm = NULL, *rtrn, *str;
196 char buf[BUFFER_SIZE];
198 if ((modMask == 0) && (mask == 0))
202 mm = XkbcModMaskText(modMask, False);
209 for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<= 1)
214 len = snprintf(str, rem, "%s%s",
215 (str != buf) ? "+" : "",
216 XkbcVModIndexText(xkb, i));
226 len = ((str) ? strlen(str) : 0) + ((mm) ? strlen(mm) : 0) +
227 ((str && mm) ? 1 : 0);
228 if (len >= BUFFER_SIZE)
229 len = BUFFER_SIZE - 1;
231 rtrn = tbGetBuffer(len + 1);
234 snprintf(rtrn, len + 1, "%s%s%s", (mm) ? mm : "",
235 (mm && str) ? "+" : "", (str) ? str : "");
240 static char *modNames[XkbNumModifiers] = {
252 XkbcModIndexText(unsigned ndx)
256 if (ndx < XkbNumModifiers)
257 return modNames[ndx];
258 else if (ndx == XkbNoModifier)
261 buf = tbGetBuffer(32);
262 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
268 XkbcModMaskText(unsigned mask, Bool cFormat)
273 if ((mask & 0xff) == 0xff)
274 return (cFormat ? "0xff" : "all");
276 if ((mask & 0xff) == 0)
277 return (cFormat ? "0" : "none");
280 buf = tbGetBuffer(rem);
283 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
289 len = snprintf(str, rem, "%s%s%s",
290 (str != buf) ? (cFormat ? "|" : "+") : "",
292 cFormat ? "Mask" : "");
301 XkbcConfigText(unsigned config)
304 case XkmSemanticsFile:
310 case XkmGeometryFile:
311 case XkmGeometryIndex:
315 case XkmCompatMapIndex:
317 case XkmSymbolsIndex:
319 case XkmIndicatorsIndex:
321 case XkmKeyNamesIndex:
323 case XkmVirtualModsIndex:
324 return "VirtualMods";
331 XkbcGeomFPText(int val)
336 buf = tbGetBuffer(12);
337 whole = val / XkbGeomPtsPerMM;
338 frac = val % XkbGeomPtsPerMM;
341 snprintf(buf, 12, "%d.%d", whole, frac);
343 snprintf(buf, 12, "%d", whole);
348 static char *actionTypeNames[XkbSA_NumActions]= {
349 "NoAction", /* XkbSA_NoAction */
350 "SetMods", /* XkbSA_SetMods */
351 "LatchMods", /* XkbSA_LatchMods */
352 "LockMods", /* XkbSA_LockMods */
353 "SetGroup", /* XkbSA_SetGroup */
354 "LatchGroup", /* XkbSA_LatchGroup */
355 "LockGroup", /* XkbSA_LockGroup */
356 "MovePtr", /* XkbSA_MovePtr */
357 "PtrBtn", /* XkbSA_PtrBtn */
358 "LockPtrBtn", /* XkbSA_LockPtrBtn */
359 "SetPtrDflt", /* XkbSA_SetPtrDflt */
360 "ISOLock", /* XkbSA_ISOLock */
361 "Terminate", /* XkbSA_Terminate */
362 "SwitchScreen", /* XkbSA_SwitchScreen */
363 "SetControls", /* XkbSA_SetControls */
364 "LockControls", /* XkbSA_LockControls */
365 "ActionMessage", /* XkbSA_ActionMessage */
366 "RedirectKey", /* XkbSA_RedirectKey */
367 "DeviceBtn", /* XkbSA_DeviceBtn */
368 "LockDeviceBtn", /* XkbSA_LockDeviceBtn */
369 "DeviceValuator" /* XkbSA_DeviceValuator */
373 XkbcActionTypeText(unsigned type)
375 if (type <= XkbSA_LastAction)
376 return actionTypeNames[type];
381 XkbcKeysymText(KeySym sym)
388 if ((buf = XkbcKeysymToString(sym)))
391 buf = tbGetBuffer(32);
392 snprintf(buf, 32, "0x%lx", (long)sym);
397 XkbcKeyNameText(char *name)
402 buf = tbGetBuffer(7);
404 strncpy(&buf[1], name, 4);
413 static char *siMatchText[5] = {
414 "NoneOf", /* XkbSI_NoneOf */
415 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
416 "AnyOf", /* XkbSI_AnyOf */
417 "AllOf", /* XkbSI_AllOf */
418 "Exactly" /* XkbSI_Exactly */
422 XkbcSIMatchText(unsigned type)
426 switch (type & XkbSI_OpMask) {
428 return siMatchText[0];
429 case XkbSI_AnyOfOrNone:
430 return siMatchText[1];
432 return siMatchText[2];
434 return siMatchText[3];
436 return siMatchText[4];
438 buf = tbGetBuffer(40);
439 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);