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 XkbcModMaskText(unsigned mask, Bool cFormat)
256 if ((mask & 0xff) == 0xff)
257 return (cFormat ? "0xff" : "all");
259 if ((mask & 0xff) == 0)
260 return (cFormat ? "0" : "none");
263 buf = tbGetBuffer(rem);
266 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
272 len = snprintf(str, rem, "%s%s%s",
273 (str != buf) ? (cFormat ? "|" : "+") : "",
275 cFormat ? "Mask" : "");
284 XkbcConfigText(unsigned config)
287 case XkmSemanticsFile:
293 case XkmGeometryFile:
294 case XkmGeometryIndex:
298 case XkmCompatMapIndex:
300 case XkmSymbolsIndex:
302 case XkmIndicatorsIndex:
304 case XkmKeyNamesIndex:
306 case XkmVirtualModsIndex:
307 return "VirtualMods";
314 XkbcGeomFPText(int val)
319 buf = tbGetBuffer(12);
320 whole = val / XkbGeomPtsPerMM;
321 frac = val % XkbGeomPtsPerMM;
324 snprintf(buf, 12, "%d.%d", whole, frac);
326 snprintf(buf, 12, "%d", whole);
331 static char *actionTypeNames[XkbSA_NumActions]= {
332 "NoAction", /* XkbSA_NoAction */
333 "SetMods", /* XkbSA_SetMods */
334 "LatchMods", /* XkbSA_LatchMods */
335 "LockMods", /* XkbSA_LockMods */
336 "SetGroup", /* XkbSA_SetGroup */
337 "LatchGroup", /* XkbSA_LatchGroup */
338 "LockGroup", /* XkbSA_LockGroup */
339 "MovePtr", /* XkbSA_MovePtr */
340 "PtrBtn", /* XkbSA_PtrBtn */
341 "LockPtrBtn", /* XkbSA_LockPtrBtn */
342 "SetPtrDflt", /* XkbSA_SetPtrDflt */
343 "ISOLock", /* XkbSA_ISOLock */
344 "Terminate", /* XkbSA_Terminate */
345 "SwitchScreen", /* XkbSA_SwitchScreen */
346 "SetControls", /* XkbSA_SetControls */
347 "LockControls", /* XkbSA_LockControls */
348 "ActionMessage", /* XkbSA_ActionMessage */
349 "RedirectKey", /* XkbSA_RedirectKey */
350 "DeviceBtn", /* XkbSA_DeviceBtn */
351 "LockDeviceBtn", /* XkbSA_LockDeviceBtn */
352 "DeviceValuator" /* XkbSA_DeviceValuator */
356 XkbcActionTypeText(unsigned type)
358 if (type <= XkbSA_LastAction)
359 return actionTypeNames[type];
364 XkbcKeysymText(KeySym sym)
371 if ((buf = XkbcKeysymToString(sym)))
374 buf = tbGetBuffer(32);
375 snprintf(buf, 32, "0x%lx", (long)sym);
380 XkbcKeyNameText(char *name)
385 buf = tbGetBuffer(7);
387 strncpy(&buf[1], name, 4);
396 static char *siMatchText[5] = {
397 "NoneOf", /* XkbSI_NoneOf */
398 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
399 "AnyOf", /* XkbSI_AnyOf */
400 "AllOf", /* XkbSI_AllOf */
401 "Exactly" /* XkbSI_Exactly */
405 XkbcSIMatchText(unsigned type)
409 switch (type & XkbSI_OpMask) {
411 return siMatchText[0];
412 case XkbSI_AnyOfOrNone:
413 return siMatchText[1];
415 return siMatchText[2];
417 return siMatchText[3];
419 return siMatchText[4];
421 buf = tbGetBuffer(40);
422 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);