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);
156 static char *modNames[XkbNumModifiers] = {
168 XkbcModMaskText(unsigned mask, Bool cFormat)
173 if ((mask & 0xff) == 0xff)
174 return (cFormat ? "0xff" : "all");
176 if ((mask & 0xff) == 0)
177 return (cFormat ? "0" : "none");
180 buf = tbGetBuffer(rem);
183 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
189 len = snprintf(str, rem, "%s%s%s",
190 (str != buf) ? (cFormat ? "|" : "+") : "",
192 cFormat ? "Mask" : "");
201 XkbcConfigText(unsigned config)
204 case XkmSemanticsFile:
210 case XkmGeometryFile:
211 case XkmGeometryIndex:
215 case XkmCompatMapIndex:
217 case XkmSymbolsIndex:
219 case XkmIndicatorsIndex:
221 case XkmKeyNamesIndex:
223 case XkmVirtualModsIndex:
224 return "VirtualMods";
231 XkbcGeomFPText(int val)
236 buf = tbGetBuffer(12);
237 whole = val / XkbGeomPtsPerMM;
238 frac = val % XkbGeomPtsPerMM;
241 snprintf(buf, 12, "%d.%d", whole, frac);
243 snprintf(buf, 12, "%d", whole);
248 static char *actionTypeNames[XkbSA_NumActions]= {
249 "NoAction", /* XkbSA_NoAction */
250 "SetMods", /* XkbSA_SetMods */
251 "LatchMods", /* XkbSA_LatchMods */
252 "LockMods", /* XkbSA_LockMods */
253 "SetGroup", /* XkbSA_SetGroup */
254 "LatchGroup", /* XkbSA_LatchGroup */
255 "LockGroup", /* XkbSA_LockGroup */
256 "MovePtr", /* XkbSA_MovePtr */
257 "PtrBtn", /* XkbSA_PtrBtn */
258 "LockPtrBtn", /* XkbSA_LockPtrBtn */
259 "SetPtrDflt", /* XkbSA_SetPtrDflt */
260 "ISOLock", /* XkbSA_ISOLock */
261 "Terminate", /* XkbSA_Terminate */
262 "SwitchScreen", /* XkbSA_SwitchScreen */
263 "SetControls", /* XkbSA_SetControls */
264 "LockControls", /* XkbSA_LockControls */
265 "ActionMessage", /* XkbSA_ActionMessage */
266 "RedirectKey", /* XkbSA_RedirectKey */
267 "DeviceBtn", /* XkbSA_DeviceBtn */
268 "LockDeviceBtn", /* XkbSA_LockDeviceBtn */
269 "DeviceValuator" /* XkbSA_DeviceValuator */
273 XkbcActionTypeText(unsigned type)
275 if (type <= XkbSA_LastAction)
276 return actionTypeNames[type];
281 XkbcKeysymText(KeySym sym)
288 if ((buf = XkbcKeysymToString(sym)))
291 buf = tbGetBuffer(32);
292 snprintf(buf, 32, "0x%lx", (long)sym);
297 XkbcKeyNameText(char *name)
302 buf = tbGetBuffer(7);
304 strncpy(&buf[1], name, 4);
313 static char *siMatchText[5] = {
314 "NoneOf", /* XkbSI_NoneOf */
315 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
316 "AnyOf", /* XkbSI_AnyOf */
317 "AllOf", /* XkbSI_AllOf */
318 "Exactly" /* XkbSI_Exactly */
322 XkbcSIMatchText(unsigned type)
326 switch (type & XkbSI_OpMask) {
328 return siMatchText[0];
329 case XkbSI_AnyOfOrNone:
330 return siMatchText[1];
332 return siMatchText[2];
334 return siMatchText[3];
336 return siMatchText[4];
338 buf = tbGetBuffer(40);
339 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);