/************************************************************
- Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
-
- Permission to use, copy, modify, and distribute this
- software and its documentation for any purpose and without
- fee is hereby granted, provided that the above copyright
- notice appear in all copies and that both that copyright
- notice and this permission notice appear in supporting
- documentation, and that the name of Silicon Graphics not be
- used in advertising or publicity pertaining to distribution
- of the software without specific prior written permission.
- Silicon Graphics makes no representation about the suitability
- of this software for any purpose. It is provided "as is"
- without any express or implied warranty.
-
- SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
- THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
+ * Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of Silicon Graphics not be
+ * used in advertising or publicity pertaining to distribution
+ * of the software without specific prior written permission.
+ * Silicon Graphics makes no representation about the suitability
+ * of this software for any purpose. It is provided "as is"
+ * without any express or implied warranty.
+ *
+ * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+ * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
+ * THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
********************************************************/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "xkbmisc.h"
-#include "X11/extensions/XKBcommon.h"
-#include "XKBcommonint.h"
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
+#include "text.h"
#define BUFFER_SIZE 1024
-static char textBuffer[BUFFER_SIZE];
-static int tbNext = 0;
static char *
-tbGetBuffer(unsigned int size)
+GetBuffer(size_t size)
{
+ static char buffer[BUFFER_SIZE];
+ static size_t next;
char *rtrn;
if (size >= BUFFER_SIZE)
return NULL;
- if ((BUFFER_SIZE - tbNext) <= size)
- tbNext = 0;
+ if (BUFFER_SIZE - next <= size)
+ next = 0;
- rtrn = &textBuffer[tbNext];
- tbNext += size;
+ rtrn = &buffer[next];
+ next += size;
return rtrn;
}
-static char *
-XkbcVModIndexText(struct xkb_desc * xkb, unsigned ndx)
+static const char *
+VModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
{
int len;
- uint32_t *vmodNames;
- char *rtrn, *tmp = NULL;
-
- if (xkb && xkb->names)
- vmodNames = xkb->names->vmods;
- else
- vmodNames = NULL;
+ char *rtrn;
+ const char *tmp = NULL;
+ char buf[20];
if (ndx >= XkbNumVirtualMods)
- tmp = strdup("illegal");
- else if (vmodNames && (vmodNames[ndx] != None))
- tmp = XkbcAtomGetString(vmodNames[ndx]);
+ tmp = "illegal";
+ else
+ tmp = keymap->vmod_names[ndx];
if (!tmp) {
- tmp = malloc(20 * sizeof(char));
- snprintf(tmp, 20, "%d", ndx);
+ snprintf(buf, sizeof(buf) - 1, "%d", ndx);
+ tmp = buf;
}
len = strlen(tmp) + 1;
if (len >= BUFFER_SIZE)
len = BUFFER_SIZE - 1;
- rtrn = tbGetBuffer(len);
+ rtrn = GetBuffer(len);
strncpy(rtrn, tmp, len);
- free(tmp);
-
return rtrn;
}
-char *
-XkbcVModMaskText(struct xkb_desc * xkb, unsigned modMask, unsigned mask)
+const char *
+VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t modMask,
+ xkb_mod_mask_t mask)
{
- int i, bit, len, rem;
- char *mm = NULL, *rtrn, *str;
+ xkb_mod_index_t i;
+ xkb_mod_mask_t bit;
+ int len, rem;
+ const char *mm = NULL;
+ char *rtrn, *str;
char buf[BUFFER_SIZE];
- if ((modMask == 0) && (mask == 0))
+ if (modMask == 0 && mask == 0)
return "none";
if (modMask != 0)
- mm = XkbcModMaskText(modMask, False);
+ mm = ModMaskText(modMask, false);
str = buf;
- buf[0]= '\0';
+ buf[0] = '\0';
rem = BUFFER_SIZE;
if (mask) {
- for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<= 1)
- {
+ for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<=
+ 1) {
if (!(mask & bit))
continue;
len = snprintf(str, rem, "%s%s",
(str != buf) ? "+" : "",
- XkbcVModIndexText(xkb, i));
+ VModIndexText(keymap, i));
rem -= len;
str += len;
}
else
str = NULL;
- len = ((str) ? strlen(str) : 0) + ((mm) ? strlen(mm) : 0) +
- ((str && mm) ? 1 : 0);
+ len = (str ? strlen(str) : 0) + (mm ? strlen(mm) : 0) +
+ (str && mm ? 1 : 0);
if (len >= BUFFER_SIZE)
len = BUFFER_SIZE - 1;
- rtrn = tbGetBuffer(len + 1);
+ rtrn = GetBuffer(len + 1);
rtrn[0] = '\0';
- snprintf(rtrn, len + 1, "%s%s%s", (mm) ? mm : "",
- (mm && str) ? "+" : "", (str) ? str : "");
+ snprintf(rtrn, len + 1, "%s%s%s", (mm ? mm : ""),
+ (mm && str ? "+" : ""), (str ? str : ""));
return rtrn;
}
-static char *modNames[XkbNumModifiers] = {
+static const char *modNames[XkbNumModifiers] = {
"Shift",
"Lock",
"Control",
"Mod5"
};
-char *
-XkbcModIndexText(unsigned ndx)
+const char *
+ModIndexText(xkb_mod_index_t ndx)
{
char *buf;
else if (ndx == XkbNoModifier)
return "none";
- buf = tbGetBuffer(32);
+ buf = GetBuffer(32);
snprintf(buf, 32, "ILLEGAL_%02x", ndx);
return buf;
}
-char *
-XkbcModMaskText(unsigned mask, Bool cFormat)
+const char *
+ModMaskText(xkb_mod_mask_t mask, bool cFormat)
{
- int i, rem, bit;
+ int i, rem;
+ xkb_mod_index_t bit;
char *str, *buf;
if ((mask & 0xff) == 0xff)
return (cFormat ? "0" : "none");
rem = 64;
- buf = tbGetBuffer(rem);
+ buf = GetBuffer(rem);
str = buf;
buf[0] = '\0';
for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
return buf;
}
-char *
-XkbcConfigText(unsigned config)
+const char *
+FileTypeText(enum xkb_file_type type)
{
- switch (config) {
- case XkmSemanticsFile:
- return "Semantics";
- case XkmLayoutFile:
- return "Layout";
- case XkmKeymapFile:
+ switch (type) {
+ case FILE_TYPE_KEYMAP:
return "Keymap";
- case XkmGeometryFile:
- case XkmGeometryIndex:
- return "Geometry";
- case XkmTypesIndex:
+ case FILE_TYPE_TYPES:
return "Types";
- case XkmCompatMapIndex:
+ case FILE_TYPE_COMPAT:
return "CompatMap";
- case XkmSymbolsIndex:
+ case FILE_TYPE_SYMBOLS:
return "Symbols";
- case XkmIndicatorsIndex:
- return "Indicators";
- case XkmKeyNamesIndex:
+ case FILE_TYPE_KEYCODES:
return "KeyNames";
- case XkmVirtualModsIndex:
- return "VirtualMods";
+ case FILE_TYPE_RULES:
+ return "Rules";
default:
return "unknown";
}
}
-char *
-XkbcGeomFPText(int val)
-{
- char *buf;
- int whole, frac;
-
- buf = tbGetBuffer(12);
- whole = val / XkbGeomPtsPerMM;
- frac = val % XkbGeomPtsPerMM;
-
- if (frac != 0)
- snprintf(buf, 12, "%d.%d", whole, frac);
- else
- snprintf(buf, 12, "%d", whole);
-
- return buf;
-}
-
-static char *actionTypeNames[XkbSA_NumActions]= {
- "NoAction", /* XkbSA_NoAction */
- "SetMods", /* XkbSA_SetMods */
- "LatchMods", /* XkbSA_LatchMods */
- "LockMods", /* XkbSA_LockMods */
- "SetGroup", /* XkbSA_SetGroup */
- "LatchGroup", /* XkbSA_LatchGroup */
- "LockGroup", /* XkbSA_LockGroup */
- "MovePtr", /* XkbSA_MovePtr */
- "PtrBtn", /* XkbSA_PtrBtn */
- "LockPtrBtn", /* XkbSA_LockPtrBtn */
- "SetPtrDflt", /* XkbSA_SetPtrDflt */
- "ISOLock", /* XkbSA_ISOLock */
- "Terminate", /* XkbSA_Terminate */
- "SwitchScreen", /* XkbSA_SwitchScreen */
- "SetControls", /* XkbSA_SetControls */
- "LockControls", /* XkbSA_LockControls */
- "ActionMessage", /* XkbSA_ActionMessage */
- "RedirectKey", /* XkbSA_RedirectKey */
- "DeviceBtn", /* XkbSA_DeviceBtn */
- "LockDeviceBtn", /* XkbSA_LockDeviceBtn */
- "DeviceValuator" /* XkbSA_DeviceValuator */
+static const char *actionTypeNames[XkbSA_NumActions] = {
+ [XkbSA_NoAction] = "NoAction",
+ [XkbSA_SetMods] = "SetMods",
+ [XkbSA_LatchMods] = "LatchMods",
+ [XkbSA_LockMods] = "LockMods",
+ [XkbSA_SetGroup] = "SetGroup",
+ [XkbSA_LatchGroup] = "LatchGroup",
+ [XkbSA_LockGroup] = "LockGroup",
+ [XkbSA_MovePtr] = "MovePtr",
+ [XkbSA_PtrBtn] = "PtrBtn",
+ [XkbSA_LockPtrBtn] = "LockPtrBtn",
+ [XkbSA_SetPtrDflt] = "SetPtrDflt",
+ [XkbSA_ISOLock] = "ISOLock",
+ [XkbSA_Terminate] = "Terminate",
+ [XkbSA_SwitchScreen] = "SwitchScreen",
+ [XkbSA_SetControls] = "SetControls",
+ [XkbSA_LockControls] = "LockControls",
+ [XkbSA_ActionMessage] = "ActionMessage",
+ [XkbSA_RedirectKey] = "RedirectKey",
+ [XkbSA_DeviceBtn] = "DeviceBtn",
+ [XkbSA_LockDeviceBtn] = "LockDeviceBtn",
+ [XkbSA_DeviceValuator] = "DeviceValuator"
};
-char *
-XkbcActionTypeText(unsigned type)
+const char *
+ActionTypeText(unsigned type)
{
if (type <= XkbSA_LastAction)
return actionTypeNames[type];
return "Private";
}
-char *
-XkbcKeysymText(uint32_t sym)
+const char *
+KeysymText(xkb_keysym_t sym)
{
- static char buffer[16];
+ static char buffer[64];
- xkb_keysym_to_string(sym, buffer, sizeof buffer);
+ xkb_keysym_get_name(sym, buffer, sizeof buffer);
return buffer;
}
-char *
-XkbcKeyNameText(char *name)
+const char *
+KeyNameText(char *name)
{
char *buf;
int len;
- buf = tbGetBuffer(7);
+ buf = GetBuffer(7);
buf[0] = '<';
strncpy(&buf[1], name, 4);
buf[5] = '\0';
return buf;
}
-static char *siMatchText[5] = {
+static const char *siMatchText[5] = {
"NoneOf", /* XkbSI_NoneOf */
"AnyOfOrNone", /* XkbSI_AnyOfOrNone */
"AnyOf", /* XkbSI_AnyOf */
"Exactly" /* XkbSI_Exactly */
};
-char *
-XkbcSIMatchText(unsigned type)
+const char *
+SIMatchText(unsigned type)
{
char *buf;
case XkbSI_Exactly:
return siMatchText[4];
default:
- buf = tbGetBuffer(40);
+ buf = GetBuffer(40);
snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);
return buf;
}