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 ********************************************************/
30 #include "X11/extensions/XKBcommon.h"
31 #include "XKBcommonint.h"
32 #include <X11/extensions/XKM.h>
37 #define BUFFER_SIZE 512
38 static char textBuffer[BUFFER_SIZE];
39 static int tbNext = 0;
42 tbGetBuffer(unsigned size)
46 if (size >= BUFFER_SIZE)
49 if ((BUFFER_SIZE - tbNext) <= size)
52 rtrn = &textBuffer[tbNext];
59 XkbStringText(char *str)
71 /* Find if there are any non-printable characters */
72 for (ok = True, len = 0, in = str; *in != '\0'; in++, len++) {
78 case '\n': case '\t': case '\v':
79 case '\b': case '\r': case '\f':
92 /* Cleanup non-printable characters */
93 buf = tbGetBuffer(len + 1);
94 for (in = str, out = buf; *in != '\0'; in++) {
122 snprintf(out, 3, "%o", *in);
133 XkbcAtomText(Atom atm)
138 tmp = XkbcAtomGetString(atm);
143 len = strlen(tmp) + 1;
144 if (len >= BUFFER_SIZE)
145 len = BUFFER_SIZE - 2;
147 rtrn = tbGetBuffer(len);
148 strncpy(rtrn, tmp, len);
153 return XkbStringText(rtrn);
157 XkbcVModIndexText(XkbcDescPtr xkb, unsigned ndx)
161 char *rtrn, *tmp = NULL;
163 if (xkb && xkb->names)
164 vmodNames = xkb->names->vmods;
168 if (ndx >= XkbNumVirtualMods)
169 tmp = strdup("illegal");
170 else if (vmodNames && (vmodNames[ndx] != None))
171 tmp = XkbcAtomGetString(vmodNames[ndx]);
174 tmp = _XkbAlloc(20 * sizeof(char));
175 snprintf(tmp, 20, "%d", ndx);
178 len = strlen(tmp) + 1;
179 if (len >= BUFFER_SIZE)
180 len = BUFFER_SIZE - 1;
182 rtrn = tbGetBuffer(len);
183 strncpy(rtrn, tmp, len);
191 XkbcVModMaskText(XkbcDescPtr xkb, unsigned modMask, unsigned mask)
193 int i, bit, len, rem;
194 char *mm = NULL, *rtrn, *str;
195 char buf[BUFFER_SIZE];
197 if ((modMask == 0) && (mask == 0))
201 mm = XkbcModMaskText(modMask, False);
208 for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<= 1)
213 len = snprintf(str, rem, "%s%s",
214 (str != buf) ? "+" : "",
215 XkbcVModIndexText(xkb, i));
225 len = ((str) ? strlen(str) : 0) + ((mm) ? strlen(mm) : 0) +
226 ((str && mm) ? 1 : 0);
227 if (len >= BUFFER_SIZE)
228 len = BUFFER_SIZE - 1;
230 rtrn = tbGetBuffer(len + 1);
233 snprintf(rtrn, len + 1, "%s%s%s", (mm) ? mm : "",
234 (mm && str) ? "+" : "", (str) ? str : "");
239 static char *modNames[XkbNumModifiers] = {
251 XkbcModIndexText(unsigned ndx)
255 if (ndx < XkbNumModifiers)
256 return modNames[ndx];
257 else if (ndx == XkbNoModifier)
260 buf = tbGetBuffer(32);
261 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
267 XkbcModMaskText(unsigned mask, Bool cFormat)
272 if ((mask & 0xff) == 0xff)
273 return (cFormat ? "0xff" : "all");
275 if ((mask & 0xff) == 0)
276 return (cFormat ? "0" : "none");
279 buf = tbGetBuffer(rem);
282 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
288 len = snprintf(str, rem, "%s%s%s",
289 (str != buf) ? (cFormat ? "|" : "+") : "",
291 cFormat ? "Mask" : "");
300 XkbcConfigText(unsigned config)
303 case XkmSemanticsFile:
309 case XkmGeometryFile:
310 case XkmGeometryIndex:
314 case XkmCompatMapIndex:
316 case XkmSymbolsIndex:
318 case XkmIndicatorsIndex:
320 case XkmKeyNamesIndex:
322 case XkmVirtualModsIndex:
323 return "VirtualMods";
330 XkbcGeomFPText(int val)
335 buf = tbGetBuffer(12);
336 whole = val / XkbGeomPtsPerMM;
337 frac = val % XkbGeomPtsPerMM;
340 snprintf(buf, 12, "%d.%d", whole, frac);
342 snprintf(buf, 12, "%d", whole);
347 static char *actionTypeNames[XkbSA_NumActions]= {
348 "NoAction", /* XkbSA_NoAction */
349 "SetMods", /* XkbSA_SetMods */
350 "LatchMods", /* XkbSA_LatchMods */
351 "LockMods", /* XkbSA_LockMods */
352 "SetGroup", /* XkbSA_SetGroup */
353 "LatchGroup", /* XkbSA_LatchGroup */
354 "LockGroup", /* XkbSA_LockGroup */
355 "MovePtr", /* XkbSA_MovePtr */
356 "PtrBtn", /* XkbSA_PtrBtn */
357 "LockPtrBtn", /* XkbSA_LockPtrBtn */
358 "SetPtrDflt", /* XkbSA_SetPtrDflt */
359 "ISOLock", /* XkbSA_ISOLock */
360 "Terminate", /* XkbSA_Terminate */
361 "SwitchScreen", /* XkbSA_SwitchScreen */
362 "SetControls", /* XkbSA_SetControls */
363 "LockControls", /* XkbSA_LockControls */
364 "ActionMessage", /* XkbSA_ActionMessage */
365 "RedirectKey", /* XkbSA_RedirectKey */
366 "DeviceBtn", /* XkbSA_DeviceBtn */
367 "LockDeviceBtn", /* XkbSA_LockDeviceBtn */
368 "DeviceValuator" /* XkbSA_DeviceValuator */
372 XkbcActionTypeText(unsigned type)
374 if (type <= XkbSA_LastAction)
375 return actionTypeNames[type];
380 XkbcKeysymText(KeySym sym)
387 if ((buf = XkbcKeysymToString(sym)))
390 buf = tbGetBuffer(32);
391 snprintf(buf, 32, "0x%lx", (long)sym);
396 XkbcKeyNameText(char *name)
401 buf = tbGetBuffer(7);
403 strncpy(&buf[1], name, 4);
412 static char *siMatchText[5] = {
413 "NoneOf", /* XkbSI_NoneOf */
414 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
415 "AnyOf", /* XkbSI_AnyOf */
416 "AllOf", /* XkbSI_AllOf */
417 "Exactly" /* XkbSI_Exactly */
421 XkbcSIMatchText(unsigned type)
425 switch (type & XkbSI_OpMask) {
427 return siMatchText[0];
428 case XkbSI_AnyOfOrNone:
429 return siMatchText[1];
431 return siMatchText[2];
433 return siMatchText[3];
435 return siMatchText[4];
437 buf = tbGetBuffer(40);
438 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);