********************************************************/
-#include "xkbcomp.h"
-#include "xkballoc.h"
-#include "xkbmisc.h"
-#include "expr.h"
+#include "xkbcomp-priv.h"
#include "parseutils.h"
-
-#include <X11/keysym.h>
-#include <stdlib.h>
-
-#include "expr.h"
-#include "vmod.h"
#include "action.h"
-#include "keycodes.h"
-#include "misc.h"
#include "alias.h"
+#include "keycodes.h"
+#include "vmod.h"
/***====================================================================***/
unsigned char symsDefined;
unsigned char actsDefined;
unsigned int numLevels[XkbNumKbdGroups];
+
+ /* syms[group] -> Single array for all the keysyms in the group. */
xkb_keysym_t *syms[XkbNumKbdGroups];
+ /* sizeSyms[group] -> The size of the syms[group] array. */
int sizeSyms[XkbNumKbdGroups];
+ /*
+ * symsMapIndex[group][level] -> The index from which the syms for
+ * the level begin in the syms[group] array. Remember each keycode
+ * can have multiple keysyms in each level (that is, each key press
+ * can result in multiple keysyms).
+ */
int *symsMapIndex[XkbNumKbdGroups];
+ /*
+ * symsMapNumEntries[group][level] -> How many syms are in
+ * syms[group][symsMapIndex[group][level]].
+ */
unsigned int *symsMapNumEntries[XkbNumKbdGroups];
+
union xkb_action *acts[XkbNumKbdGroups];
xkb_atom_t types[XkbNumKbdGroups];
unsigned repeat;
struct xkb_behavior behavior;
unsigned short vmodmap;
- unsigned long allowNone;
xkb_atom_t dfltType;
} KeyInfo;
InitKeyInfo(KeyInfo * info)
{
int i;
- static char dflt[4] = "*";
+ static const char dflt[4] = "*";
info->defs.defined = 0;
info->defs.fileID = 0;
info->behavior.data = 0;
info->vmodmap = 0;
info->repeat = RepeatUndefined;
- info->allowNone = 0;
}
/**
info->behavior.data = 0;
info->vmodmap = 0;
info->repeat = RepeatUndefined;
- info->allowNone = 0;
}
/**
* If old is reset, new simply re-uses old's memory. Otherwise, the memory is
* newly allocated and new points to the new memory areas.
*/
-static Bool
-CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
+static bool
+CopyKeyInfo(KeyInfo * old, KeyInfo * new, bool clearOld)
{
int i;
new->sizeSyms[i] = 0;
new->numLevels[i] = 0;
new->acts[i] = NULL;
- return False;
+ return false;
}
memcpy(new->syms[i], old->syms[i],
new->sizeSyms[i] * sizeof(xkb_keysym_t));
new->sizeSyms[i] = 0;
new->numLevels[i] = 0;
new->acts[i] = NULL;
- return False;
+ return false;
}
memcpy(new->symsMapIndex[i], old->symsMapIndex[i],
width * sizeof(int));
new->symsMapIndex[i] = NULL;
new->numLevels[i] = 0;
new->acts[i] = NULL;
- return False;
+ return false;
}
memcpy(new->symsMapNumEntries[i], old->symsMapNumEntries[i],
- sizeof(unsigned int));
+ width * sizeof(unsigned int));
}
if (old->acts[i] != NULL)
{
free(new->symsMapNumEntries[i]);
new->symsMapNumEntries[i] = NULL;
new->numLevels[i] = 0;
- return False;
+ return false;
}
memcpy(new->acts[i], old->acts[i],
width * sizeof(union xkb_action));
}
}
}
- return True;
+ return true;
}
/***====================================================================***/
typedef struct _ModMapEntry
{
CommonInfo defs;
- Bool haveSymbol;
+ bool haveSymbol;
int modifier;
union
{
} u;
} ModMapEntry;
-#define SYMBOLS_INIT_SIZE 110
-#define SYMBOLS_CHUNK 20
+#define SYMBOLS_INIT_SIZE 110
+
typedef struct _SymbolsInfo
{
char *name; /* e.g. pc+us+inet(evdev) */
unsigned fileID;
unsigned merge;
unsigned explicit_group;
- unsigned groupInfo;
- unsigned szKeys;
- unsigned nKeys;
- KeyInfo *keys;
+ darray(KeyInfo) keys;
KeyInfo dflt;
VModInfo vmods;
ActionInfo *action;
} SymbolsInfo;
static void
-InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap * xkb)
+InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap *keymap)
{
int i;
info->errorCount = 0;
info->fileID = 0;
info->merge = MergeOverride;
- info->groupInfo = 0;
- info->szKeys = SYMBOLS_INIT_SIZE;
- info->nKeys = 0;
- info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
+ darray_init(info->keys);
+ darray_growalloc(info->keys, SYMBOLS_INIT_SIZE);
info->modMap = NULL;
for (i = 0; i < XkbNumKbdGroups; i++)
info->groupNames[i] = XKB_ATOM_NONE;
InitKeyInfo(&info->dflt);
- InitVModInfo(&info->vmods, xkb);
+ InitVModInfo(&info->vmods, keymap);
info->action = NULL;
info->aliases = NULL;
}
static void
FreeSymbolsInfo(SymbolsInfo * info)
{
- unsigned int i;
+ KeyInfo *key;
free(info->name);
- if (info->keys)
- {
- for (i = 0; i < info->nKeys; i++)
- FreeKeyInfo(&info->keys[i]);
- free(info->keys);
- }
+ darray_foreach(key, info->keys)
+ FreeKeyInfo(key);
+ darray_free(info->keys);
if (info->modMap)
ClearCommonInfo(&info->modMap->defs);
if (info->aliases)
memset(info, 0, sizeof(SymbolsInfo));
}
-static Bool
+static bool
ResizeKeyGroup(KeyInfo * key, unsigned int group, unsigned int numLevels,
- unsigned sizeSyms, Bool forceActions)
+ unsigned sizeSyms, bool forceActions)
{
int i;
xkb_keysym_t);
if (!key->syms[group]) {
key->sizeSyms[group] = 0;
- return False;
+ return false;
}
key->sizeSyms[group] = sizeSyms;
}
numLevels,
int);
if (!key->symsMapIndex[group])
- return False;
+ return false;
for (i = key->numLevels[group]; i < numLevels; i++)
key->symsMapIndex[group][i] = -1;
}
numLevels,
unsigned int);
if (!key->symsMapNumEntries[group])
- return False;
+ return false;
}
if ((forceActions &&
(key->numLevels[group] < numLevels || (key->acts[group] == NULL))) ||
numLevels,
union xkb_action);
if (!key->acts[group])
- return False;
+ return false;
}
if (key->numLevels[group] < numLevels)
key->numLevels[group] = numLevels;
- return True;
+ return true;
}
-static Bool
+enum key_group_selector {
+ NONE = 0,
+ FROM = (1 << 0),
+ TO = (1 << 1),
+};
+
+static bool
MergeKeyGroups(SymbolsInfo * info,
KeyInfo * into, KeyInfo * from, unsigned group)
{
xkb_keysym_t *resultSyms = NULL;
+ enum key_group_selector using = NONE;
union xkb_action *resultActs;
unsigned int resultWidth;
unsigned int resultSize = 0;
int cur_idx = 0;
int i;
- Bool report, clobber;
+ bool report, clobber;
clobber = (from->defs.merge != MergeAugment);
report = (warningLevel > 9) ||
int);
into->symsMapNumEntries[group] =
uTypedRecalloc(into->symsMapNumEntries[group],
- from->numLevels[group],
into->numLevels[group],
+ from->numLevels[group],
unsigned int);
if (!into->symsMapIndex[group] || !into->symsMapNumEntries[group])
{
ACTION("Group %d of key %s not merged\n", group,
longText(into->name));
- return False;
+ return false;
}
for (i = into->numLevels[group]; i < from->numLevels[group]; i++)
into->symsMapIndex[group][i] = -1;
WSGO("Could not allocate actions for group merge\n");
ACTION("Group %d of key %s not merged\n", group,
longText(into->name));
- return False;
+ return false;
}
for (i = 0; i < resultWidth; i++)
{
if (into->symsMapNumEntries[group] && (i < into->numLevels[group]))
toSize = into->symsMapNumEntries[group][i];
- if (fromSize == 0 || fromSize == toSize || clobber)
+ if (fromSize == 0)
{
- fromSize += toSize;
+ resultSize += toSize;
+ using |= TO;
}
- else if (toSize == 0)
+ else if (toSize == 0 || clobber)
{
resultSize += fromSize;
+ using |= FROM;
+ }
+ else
+ {
+ resultSize += toSize;
+ using |= TO;
}
}
if (resultSize == 0)
goto out;
+ if (using == FROM)
+ {
+ resultSyms = from->syms[group];
+ goto out;
+ }
+ else if (using == TO)
+ {
+ resultSyms = into->syms[group];
+ goto out;
+ }
+
resultSyms = uTypedCalloc(resultSize, xkb_keysym_t);
if (!resultSyms)
{
WSGO("Could not allocate symbols for group merge\n");
ACTION("Group %d of key %s not merged\n", group, longText(into->name));
- return False;
+ return false;
}
for (i = 0; i < resultWidth; i++)
{
- enum { NONE, FROM, TO } use;
+ enum key_group_selector use = NONE;
unsigned int fromSize = 0;
unsigned int toSize = 0;
- if (from->symsMapNumEntries[group] && (i < from->numLevels[group]))
+ if (i < from->numLevels[group])
fromSize = from->symsMapNumEntries[group][i];
- if (into->symsMapNumEntries[group] && (i < into->numLevels[group]))
+ if (i < into->numLevels[group])
toSize = into->symsMapNumEntries[group][i];
- if (!fromSize && !toSize)
+ if (fromSize == 0 && toSize == 0)
{
into->symsMapIndex[group][i] = -1;
into->symsMapNumEntries[group][i] = 0;
continue;
}
- if ((fromSize && !toSize) || clobber)
+ if (fromSize == 0)
+ use = TO;
+ else if (toSize == 0 || clobber)
use = FROM;
else
use = TO;
else
{
memcpy(&resultSyms[cur_idx],
- &into->syms[group][from->symsMapIndex[group][i]],
+ &into->syms[group][into->symsMapIndex[group][i]],
into->symsMapNumEntries[group][i] * sizeof(xkb_keysym_t));
into->symsMapIndex[group][i] = cur_idx;
}
if (resultActs != from->acts[group])
free(from->acts[group]);
into->numLevels[group] = resultWidth;
- free(into->syms[group]);
+ if (resultSyms != into->syms[group])
+ free(into->syms[group]);
into->syms[group] = resultSyms;
- free(from->syms[group]);
+ if (resultSyms != from->syms[group])
+ free(from->syms[group]);
from->syms[group] = NULL;
from->sizeSyms[group] = 0;
into->sizeSyms[group] = resultSize;
from->symsMapNumEntries[group] = NULL;
into->acts[group] = resultActs;
from->acts[group] = NULL;
- into->symsDefined |= (1 << group);
+ if (into->syms[group])
+ into->symsDefined |= (1 << group);
from->symsDefined &= ~(1 << group);
into->actsDefined |= (1 << group);
from->actsDefined &= ~(1 << group);
- return True;
+ return true;
}
-static Bool
-MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
+static bool
+MergeKeys(SymbolsInfo *info, struct xkb_keymap *keymap,
+ KeyInfo *into, KeyInfo *from)
{
int i;
unsigned collide = 0;
- Bool report;
+ bool report;
if (from->defs.merge == MergeReplace)
{
}
*into = *from;
memset(from, 0, sizeof(KeyInfo));
- return True;
+ return true;
}
report = ((warningLevel > 9) ||
((into->defs.fileID == from->defs.fileID)
("Multiple definitions for group %d type of key %s\n",
i, longText(into->name));
ACTION("Using %s, ignoring %s\n",
- XkbcAtomText(use),
- XkbcAtomText(ignore));
+ xkb_atom_text(keymap->ctx, use),
+ xkb_atom_text(keymap->ctx, ignore));
}
if ((from->defs.merge != MergeAugment)
|| (into->types[i] == XKB_ATOM_NONE))
ACTION("Using %s definition for conflicting fields\n",
(from->defs.merge == MergeAugment ? "first" : "last"));
}
- return True;
+ return true;
}
-static Bool
-AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_keymap * xkb)
+static bool
+AddKeySymbols(SymbolsInfo *info, KeyInfo *key, struct xkb_keymap *keymap)
{
- unsigned int i;
unsigned long real_name;
+ KeyInfo *iter, *new;
- for (i = 0; i < info->nKeys; i++)
- {
- if (info->keys[i].name == key->name)
- return MergeKeys(info, &info->keys[i], key);
- }
- if (FindKeyNameForAlias(xkb, key->name, &real_name))
- {
- for (i = 0; i < info->nKeys; i++)
- {
- if (info->keys[i].name == real_name)
- return MergeKeys(info, &info->keys[i], key);
- }
- }
- if (info->nKeys >= info->szKeys)
- {
- info->szKeys += SYMBOLS_CHUNK;
- info->keys =
- uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
- if (!info->keys)
- {
- WSGO("Could not allocate key symbols descriptions\n");
- ACTION("Some key symbols definitions may be lost\n");
- return False;
- }
- }
- return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
+ darray_foreach(iter, info->keys)
+ if (iter->name == key->name)
+ return MergeKeys(info, keymap, iter, key);
+
+ if (FindKeyNameForAlias(keymap, key->name, &real_name))
+ darray_foreach(iter, info->keys)
+ if (iter->name == real_name)
+ return MergeKeys(info, keymap, iter, key);
+
+ darray_resize0(info->keys, darray_size(info->keys) + 1);
+ new = &darray_item(info->keys, darray_size(info->keys) - 1);
+ return CopyKeyInfo(key, new, true);
}
-static Bool
+static bool
AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
{
ModMapEntry *mm;
- Bool clobber;
+ bool clobber;
clobber = (new->defs.merge != MergeAugment);
for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
XkbcModIndexText(ignore));
mm->modifier = use;
}
- return True;
+ return true;
}
if ((!new->haveSymbol) && (!mm->haveSymbol) &&
(new->u.keyName == mm->u.keyName))
XkbcModIndexText(ignore));
mm->modifier = use;
}
- return True;
+ return true;
}
}
mm = uTypedAlloc(ModMapEntry);
WSGO("Could not allocate modifier map entry\n");
ACTION("Modifier map for %s will be incomplete\n",
XkbcModIndexText(new->modifier));
- return False;
+ return false;
}
*mm = *new;
mm->defs.next = &info->modMap->defs;
info->modMap = mm;
- return True;
+ return true;
}
/***====================================================================***/
static void
-MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
- unsigned merge, struct xkb_keymap * xkb)
+MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
+ unsigned merge, struct xkb_keymap *keymap)
{
unsigned int i;
KeyInfo *key;
into->groupNames[i] = from->groupNames[i];
}
}
- for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
- {
+
+ darray_foreach(key, from->keys) {
if (merge != MergeDefault)
key->defs.merge = merge;
- if (!AddKeySymbols(into, key, xkb))
+
+ if (!AddKeySymbols(into, key, keymap))
into->errorCount++;
}
+
if (from->modMap != NULL)
{
ModMapEntry *mm, *next;
into->errorCount++;
}
-typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
- struct xkb_keymap * /* xkb */ ,
- unsigned /* merge */ ,
- SymbolsInfo * /* included */
- );
+static void
+HandleSymbolsFile(XkbFile *file, struct xkb_keymap *keymap,
+ unsigned merge, SymbolsInfo *info);
-static Bool
-HandleIncludeSymbols(IncludeStmt * stmt,
- struct xkb_keymap * xkb, SymbolsInfo * info, FileHandler hndlr)
+static bool
+HandleIncludeSymbols(IncludeStmt *stmt, struct xkb_keymap *keymap,
+ SymbolsInfo *info)
{
unsigned newMerge;
XkbFile *rtrn;
SymbolsInfo included;
- Bool haveSelf;
+ bool haveSelf;
- haveSelf = False;
+ haveSelf = false;
if ((stmt->file == NULL) && (stmt->map == NULL))
{
- haveSelf = True;
+ haveSelf = true;
included = *info;
memset(info, 0, sizeof(SymbolsInfo));
}
- else if (ProcessIncludeFile(xkb->context, stmt, XkmSymbolsIndex, &rtrn,
+ else if (ProcessIncludeFile(keymap->ctx, stmt, XkmSymbolsIndex, &rtrn,
&newMerge))
{
- InitSymbolsInfo(&included, xkb);
+ InitSymbolsInfo(&included, keymap);
included.fileID = included.dflt.defs.fileID = rtrn->id;
included.merge = included.dflt.defs.merge = MergeOverride;
if (stmt->modifier)
{
included.explicit_group = info->explicit_group;
}
- (*hndlr) (rtrn, xkb, MergeOverride, &included);
+ HandleSymbolsFile(rtrn, keymap, MergeOverride, &included);
if (stmt->stmt != NULL)
{
free(included.name);
else
{
info->errorCount += 10;
- return False;
+ return false;
}
if ((stmt->next != NULL) && (included.errorCount < 1))
{
{
if ((next->file == NULL) && (next->map == NULL))
{
- haveSelf = True;
- MergeIncludedSymbols(&included, info, next->merge, xkb);
+ haveSelf = true;
+ MergeIncludedSymbols(&included, info, next->merge, keymap);
FreeSymbolsInfo(info);
}
- else if (ProcessIncludeFile(xkb->context, next, XkmSymbolsIndex,
+ else if (ProcessIncludeFile(keymap->ctx, next, XkmSymbolsIndex,
&rtrn, &op))
{
- InitSymbolsInfo(&next_incl, xkb);
+ InitSymbolsInfo(&next_incl, keymap);
next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
if (next->modifier)
{
next_incl.explicit_group = info->explicit_group;
}
- (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
- MergeIncludedSymbols(&included, &next_incl, op, xkb);
+ HandleSymbolsFile(rtrn, keymap, MergeOverride, &next_incl);
+ MergeIncludedSymbols(&included, &next_incl, op, keymap);
FreeSymbolsInfo(&next_incl);
FreeXKBFile(rtrn);
}
{
info->errorCount += 10;
FreeSymbolsInfo(&included);
- return False;
+ return false;
}
}
}
*info = included;
else
{
- MergeIncludedSymbols(info, &included, newMerge, xkb);
+ MergeIncludedSymbols(info, &included, newMerge, keymap);
FreeSymbolsInfo(&included);
}
return (info->errorCount == 0);
#define SYMBOLS 1
#define ACTIONS 2
-static Bool
-GetGroupIndex(KeyInfo * key,
+static bool
+GetGroupIndex(KeyInfo *key, struct xkb_keymap *keymap,
ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
{
const char *name;
if ((defined & (1 << i)) == 0)
{
*ndx_rtrn = i;
- return True;
+ return true;
}
}
ERROR("Too many groups of %s for key %s (max %d)\n", name,
longText(key->name), XkbNumKbdGroups + 1);
ACTION("Ignoring %s defined for extra groups\n", name);
- return False;
+ return false;
}
- if (!ExprResolveGroup(arrayNdx, &tmp))
+ if (!ExprResolveGroup(keymap->ctx, arrayNdx, &tmp))
{
ERROR("Illegal group index for %s of key %s\n", name,
longText(key->name));
ACTION("Definition with non-integer array index ignored\n");
- return False;
+ return false;
}
*ndx_rtrn = tmp.uval - 1;
- return True;
+ return true;
}
-static Bool
-AddSymbolsToKey(KeyInfo * key,
- struct xkb_keymap * xkb,
- char *field,
- ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
+static bool
+AddSymbolsToKey(KeyInfo *key, struct xkb_keymap *keymap,
+ ExprDef *arrayNdx, ExprDef *value, SymbolsInfo *info)
{
unsigned ndx, nSyms, nLevels;
unsigned int i;
long j;
- if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
- return False;
+ if (!GetGroupIndex(key, keymap, arrayNdx, SYMBOLS, &ndx))
+ return false;
if (value == NULL)
{
key->symsDefined |= (1 << ndx);
- return True;
+ return true;
}
if (value->op != ExprKeysymList)
{
ERROR("Expected a list of symbols, found %s\n", exprOpText(value->op));
ACTION("Ignoring symbols for group %d of %s\n", ndx + 1,
longText(key->name));
- return False;
+ return false;
}
if (key->sizeSyms[ndx] != 0)
{
ERROR("Symbols for key %s, group %d already defined\n",
longText(key->name), ndx + 1);
ACTION("Ignoring duplicate definition\n");
- return False;
+ return false;
}
- nSyms = value->value.list.nSyms;
- nLevels = value->value.list.nLevels;
+ nSyms = darray_size(value->value.list.syms);
+ nLevels = darray_size(value->value.list.symsMapIndex);
if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
- (!ResizeKeyGroup(key, ndx, nLevels, nSyms, False)))
+ (!ResizeKeyGroup(key, ndx, nLevels, nSyms, false)))
{
WSGO("Could not resize group %d of key %s to contain %d levels\n",
ndx + 1, longText(key->name), nSyms);
ACTION("Symbols lost\n");
- return False;
+ return false;
}
key->symsDefined |= (1 << ndx);
for (i = 0; i < nLevels; i++) {
- key->symsMapIndex[ndx][i] = value->value.list.symsMapIndex[i];
- key->symsMapNumEntries[ndx][i] = value->value.list.symsNumEntries[i];
+ key->symsMapIndex[ndx][i] =
+ darray_item(value->value.list.symsMapIndex, i);
+ key->symsMapNumEntries[ndx][i] =
+ darray_item(value->value.list.symsNumEntries, i);
+
for (j = 0; j < key->symsMapNumEntries[ndx][i]; j++) {
if (key->symsMapIndex[ndx][i] + j >= nSyms)
abort();
- if (!LookupKeysym(value->value.list.syms[value->value.list.symsMapIndex[i] + j],
+ if (!LookupKeysym(darray_item(value->value.list.syms,
+ darray_item(value->value.list.symsMapIndex, i) + j),
&key->syms[ndx][key->symsMapIndex[ndx][i] + j])) {
WARN("Could not resolve keysym %s for key %s, group %d (%s), level %d\n",
- value->value.list.syms[i], longText(key->name), ndx + 1,
- XkbcAtomText(info->groupNames[ndx]), nSyms);
+ darray_item(value->value.list.syms, i),
+ longText(key->name),
+ ndx + 1,
+ xkb_atom_text(keymap->ctx, info->groupNames[ndx]), nSyms);
while (--j >= 0)
- key->syms[ndx][key->symsMapIndex[ndx][i] + j] = NoSymbol;
+ key->syms[ndx][key->symsMapIndex[ndx][i] + j] = XKB_KEY_NoSymbol;
key->symsMapIndex[ndx][i] = -1;
key->symsMapNumEntries[ndx][i] = 0;
break;
}
+ if (key->symsMapNumEntries[ndx][i] == 1 &&
+ key->syms[ndx][key->symsMapIndex[ndx][i] + j] == XKB_KEY_NoSymbol) {
+ key->symsMapIndex[ndx][i] = -1;
+ key->symsMapNumEntries[ndx][i] = 0;
+ }
}
}
for (j = key->numLevels[ndx] - 1;
j >= 0 && key->symsMapNumEntries[ndx][j] == 0; j--)
key->numLevels[ndx]--;
- return True;
+ return true;
}
-static Bool
-AddActionsToKey(KeyInfo * key,
- struct xkb_keymap * xkb,
- char *field,
- ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
+static bool
+AddActionsToKey(KeyInfo *key, struct xkb_keymap *keymap, ExprDef *arrayNdx,
+ ExprDef *value, SymbolsInfo *info)
{
unsigned int i;
unsigned ndx, nActs;
ExprDef *act;
struct xkb_any_action *toAct;
- if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
- return False;
+ if (!GetGroupIndex(key, keymap, arrayNdx, ACTIONS, &ndx))
+ return false;
if (value == NULL)
{
key->actsDefined |= (1 << ndx);
- return True;
+ return true;
}
if (value->op != ExprActionList)
{
WSGO("Bad expression type (%d) for action list value\n", value->op);
ACTION("Ignoring actions for group %d of %s\n", ndx,
longText(key->name));
- return False;
+ return false;
}
if (key->acts[ndx] != NULL)
{
WSGO("Actions for key %s, group %d already defined\n",
longText(key->name), ndx);
- return False;
+ return false;
}
for (nActs = 0, act = value->value.child; act != NULL; nActs++)
{
if (nActs < 1)
{
WSGO("Action list but not actions in AddActionsToKey\n");
- return False;
+ return false;
}
if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
- (!ResizeKeyGroup(key, ndx, nActs, nActs, True)))
+ (!ResizeKeyGroup(key, ndx, nActs, nActs, true)))
{
WSGO("Could not resize group %d of key %s\n", ndx,
longText(key->name));
ACTION("Actions lost\n");
- return False;
+ return false;
}
key->actsDefined |= (1 << ndx);
act = value->value.child;
for (i = 0; i < nActs; i++, toAct++)
{
- if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
+ if (!HandleActionDef(act, keymap, toAct, info->action))
{
ERROR("Illegal action definition for %s\n",
longText(key->name));
}
act = (ExprDef *) act->common.next;
}
- return True;
+ return true;
}
static const LookupEntry lockingEntries[] = {
{NULL, 0}
};
-static Bool
-SetSymbolsField(KeyInfo * key,
- struct xkb_keymap * xkb,
- char *field,
- ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
+static bool
+SetSymbolsField(KeyInfo *key, struct xkb_keymap *keymap, char *field,
+ ExprDef *arrayNdx, ExprDef *value, SymbolsInfo *info)
{
- Bool ok = True;
+ bool ok = true;
ExprResult tmp;
if (strcasecmp(field, "type") == 0)
{
ExprResult ndx;
- if ((!ExprResolveString(value, &tmp))
+ if ((!ExprResolveString(keymap->ctx, value, &tmp))
&& (warningLevel > 0))
{
WARN("The type field of a key symbol map must be a string\n");
}
if (arrayNdx == NULL)
{
- key->dfltType = xkb_intern_atom(tmp.str);
+ key->dfltType = xkb_atom_intern(keymap->ctx, tmp.str);
key->defs.defined |= _Key_Type_Dflt;
}
- else if (!ExprResolveGroup(arrayNdx, &ndx))
+ else if (!ExprResolveGroup(keymap->ctx, arrayNdx, &ndx))
{
ERROR("Illegal group index for type of key %s\n",
longText(key->name));
ACTION("Definition with non-integer array index ignored\n");
free(tmp.str);
- return False;
+ return false;
}
else
{
- key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
+ key->types[ndx.uval - 1] = xkb_atom_intern(keymap->ctx, tmp.str);
key->typesDefined |= (1 << (ndx.uval - 1));
}
free(tmp.str);
}
else if (strcasecmp(field, "symbols") == 0)
- return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
+ return AddSymbolsToKey(key, keymap, arrayNdx, value, info);
else if (strcasecmp(field, "actions") == 0)
- return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
+ return AddActionsToKey(key, keymap, arrayNdx, value, info);
else if ((strcasecmp(field, "vmods") == 0) ||
(strcasecmp(field, "virtualmods") == 0) ||
(strcasecmp(field, "virtualmodifiers") == 0))
{
- ok = ExprResolveVModMask(value, &tmp, xkb);
+ ok = ExprResolveVModMask(value, &tmp, keymap);
if (ok)
{
key->vmodmap = (tmp.uval >> 8);
(strcasecmp(field, "lock") == 0) ||
(strcasecmp(field, "locks") == 0))
{
- ok = ExprResolveEnum(value, &tmp, lockingEntries);
+ ok = ExprResolveEnum(keymap->ctx, value, &tmp, lockingEntries);
if (ok)
key->behavior.type = tmp.uval;
key->defs.defined |= _Key_Behavior;
{
ERROR("Radio groups not supported\n");
ACTION("Ignoring radio group specification for key %s\n", longText(key->name));
- return False;
+ return false;
}
else if (uStrCasePrefix("overlay", field) ||
uStrCasePrefix("permanentoverlay", field))
(strcasecmp(field, "repeats") == 0) ||
(strcasecmp(field, "repeat") == 0))
{
- ok = ExprResolveEnum(value, &tmp, repeatEntries);
+ ok = ExprResolveEnum(keymap->ctx, value, &tmp, repeatEntries);
if (!ok)
{
ERROR("Illegal repeat setting for %s\n",
longText(key->name));
ACTION("Non-boolean repeat setting ignored\n");
- return False;
+ return false;
}
key->repeat = tmp.uval;
key->defs.defined |= _Key_Repeat;
else if ((strcasecmp(field, "groupswrap") == 0) ||
(strcasecmp(field, "wrapgroups") == 0))
{
- ok = ExprResolveBoolean(value, &tmp);
+ ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
if (!ok)
{
ERROR("Illegal groupsWrap setting for %s\n",
longText(key->name));
ACTION("Non-boolean value ignored\n");
- return False;
+ return false;
}
if (tmp.uval)
key->groupInfo = XkbWrapIntoRange;
else if ((strcasecmp(field, "groupsclamp") == 0) ||
(strcasecmp(field, "clampgroups") == 0))
{
- ok = ExprResolveBoolean(value, &tmp);
+ ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
if (!ok)
{
ERROR("Illegal groupsClamp setting for %s\n",
longText(key->name));
ACTION("Non-boolean value ignored\n");
- return False;
+ return false;
}
if (tmp.uval)
key->groupInfo = XkbClampIntoRange;
else if ((strcasecmp(field, "groupsredirect") == 0) ||
(strcasecmp(field, "redirectgroups") == 0))
{
- if (!ExprResolveGroup(value, &tmp))
+ if (!ExprResolveGroup(keymap->ctx, value, &tmp))
{
ERROR("Illegal group index for redirect of key %s\n",
longText(key->name));
ACTION("Definition with non-integer group ignored\n");
- return False;
+ return false;
}
key->groupInfo =
XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
{
ERROR("Unknown field %s in a symbol interpretation\n", field);
ACTION("Definition ignored\n");
- ok = False;
+ ok = false;
}
return ok;
}
static int
-SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
+SetGroupName(SymbolsInfo *info, struct xkb_keymap *keymap, ExprDef *arrayNdx,
+ ExprDef *value)
{
ExprResult tmp, name;
{
WARN("You must specify an index when specifying a group name\n");
ACTION("Group name definition without array subscript ignored\n");
- return False;
+ return false;
}
- if (!ExprResolveGroup(arrayNdx, &tmp))
+ if (!ExprResolveGroup(keymap->ctx, arrayNdx, &tmp))
{
ERROR("Illegal index in group name definition\n");
ACTION("Definition with non-integer array index ignored\n");
- return False;
+ return false;
}
- if (!ExprResolveString(value, &name))
+ if (!ExprResolveString(keymap->ctx, value, &name))
{
ERROR("Group name must be a string\n");
ACTION("Illegal name for group %d ignored\n", tmp.uval);
- return False;
+ return false;
}
info->groupNames[tmp.uval - 1 + info->explicit_group] =
- xkb_intern_atom(name.str);
+ xkb_atom_intern(keymap->ctx, name.str);
free(name.str);
- return True;
+ return true;
}
static int
-HandleSymbolsVar(VarDef * stmt, struct xkb_keymap * xkb, SymbolsInfo * info)
+HandleSymbolsVar(VarDef *stmt, struct xkb_keymap *keymap, SymbolsInfo *info)
{
- ExprResult elem, field, tmp;
+ ExprResult elem, field;
ExprDef *arrayNdx;
- Bool ret;
+ bool ret;
- if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
+ if (ExprResolveLhs(keymap, stmt->name, &elem, &field, &arrayNdx) == 0)
return 0; /* internal error, already reported */
if (elem.str && (strcasecmp(elem.str, "key") == 0))
{
- ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
+ ret = SetSymbolsField(&info->dflt, keymap, field.str, arrayNdx,
stmt->value, info);
}
else if ((elem.str == NULL) && ((strcasecmp(field.str, "name") == 0) ||
(strcasecmp(field.str, "groupname") ==
0)))
{
- ret = SetGroupName(info, arrayNdx, stmt->value);
+ ret = SetGroupName(info, keymap, arrayNdx, stmt->value);
}
else if ((elem.str == NULL)
&& ((strcasecmp(field.str, "groupswrap") == 0) ||
(strcasecmp(field.str, "wrapgroups") == 0)))
{
- if (!ExprResolveBoolean(stmt->value, &tmp))
- {
- ERROR("Illegal setting for global groupsWrap\n");
- ACTION("Non-boolean value ignored\n");
- ret = False;
- }
- else {
- if (tmp.uval)
- info->groupInfo = XkbWrapIntoRange;
- else
- info->groupInfo = XkbClampIntoRange;
- ret = True;
- }
+ ERROR("Global \"groupswrap\" not supported\n");
+ ACTION("Ignored\n");
+ ret = true;
}
else if ((elem.str == NULL)
&& ((strcasecmp(field.str, "groupsclamp") == 0) ||
(strcasecmp(field.str, "clampgroups") == 0)))
{
- if (!ExprResolveBoolean(stmt->value, &tmp))
- {
- ERROR("Illegal setting for global groupsClamp\n");
- ACTION("Non-boolean value ignored\n");
- return False;
- }
- else {
- if (tmp.uval)
- info->groupInfo = XkbClampIntoRange;
- else
- info->groupInfo = XkbWrapIntoRange;
- ret = True;
- }
+ ERROR("Global \"groupsclamp\" not supported\n");
+ ACTION("Ignored\n");
+ ret = true;
}
else if ((elem.str == NULL)
&& ((strcasecmp(field.str, "groupsredirect") == 0) ||
(strcasecmp(field.str, "redirectgroups") == 0)))
{
- if (!ExprResolveGroup(stmt->value, &tmp))
- {
- ERROR("Illegal group index for global groupsRedirect\n");
- ACTION("Definition with non-integer group ignored\n");
- ret = False;
- }
- else {
- info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
- tmp.uval);
- ret = True;
- }
+ ERROR("Global \"groupsredirect\" not supported\n");
+ ACTION("Ignored\n");
+ ret = true;
}
else if ((elem.str == NULL) && (strcasecmp(field.str, "allownone") == 0))
{
ERROR("Radio groups not supported\n");
- ACTION("Ignoring \"allow none\" specification\n");
- ret = False;
+ ACTION("Ignoring \"allownone\" specification\n");
+ ret = true;
}
else {
- ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
- &info->action);
+ ret = SetActionField(keymap, elem.str, field.str, arrayNdx,
+ stmt->value, &info->action);
}
free(elem.str);
return ret;
}
-static Bool
-HandleSymbolsBody(VarDef * def,
- struct xkb_keymap * xkb, KeyInfo * key, SymbolsInfo * info)
+static bool
+HandleSymbolsBody(VarDef *def, struct xkb_keymap *keymap, KeyInfo *key,
+ SymbolsInfo *info)
{
- Bool ok = True;
+ bool ok = true;
ExprResult tmp, field;
ExprDef *arrayNdx;
{
if ((def->name) && (def->name->type == ExprFieldRef))
{
- ok = HandleSymbolsVar(def, xkb, info);
+ ok = HandleSymbolsVar(def, keymap, info);
continue;
}
else
}
else
{
- ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
+ ok = ExprResolveLhs(keymap, def->name, &tmp, &field,
+ &arrayNdx);
}
if (ok)
- ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
+ ok = SetSymbolsField(key, keymap, field.str, arrayNdx,
def->value, info);
free(field.str);
}
return ok;
}
-static Bool
-SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
+static bool
+SetExplicitGroup(SymbolsInfo *info, KeyInfo *key)
{
unsigned group = info->explicit_group;
if (group == 0)
- return True;
+ return true;
if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
{
key->acts[0] = NULL;
key->types[group] = key->types[0];
key->types[0] = 0;
- return True;
+ return true;
}
static int
-HandleSymbolsDef(SymbolsDef * stmt,
- struct xkb_keymap * xkb, unsigned merge, SymbolsInfo * info)
+HandleSymbolsDef(SymbolsDef *stmt, struct xkb_keymap *keymap,
+ SymbolsInfo *info)
{
KeyInfo key;
InitKeyInfo(&key);
- CopyKeyInfo(&info->dflt, &key, False);
+ CopyKeyInfo(&info->dflt, &key, false);
key.defs.merge = stmt->merge;
key.name = KeyNameToLong(stmt->keyName);
- if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
+ if (!HandleSymbolsBody((VarDef *) stmt->symbols, keymap, &key, info))
{
info->errorCount++;
- return False;
+ return false;
}
if (!SetExplicitGroup(info, &key))
{
info->errorCount++;
- return False;
+ return false;
}
- if (!AddKeySymbols(info, &key, xkb))
+ if (!AddKeySymbols(info, &key, keymap))
{
info->errorCount++;
- return False;
+ return false;
}
- return True;
+ return true;
}
-static Bool
-HandleModMapDef(ModMapDef * def,
- struct xkb_keymap * xkb, unsigned merge, SymbolsInfo * info)
+static bool
+HandleModMapDef(ModMapDef *def, struct xkb_keymap *keymap, SymbolsInfo *info)
{
ExprDef *key;
ModMapEntry tmp;
ExprResult rtrn;
- Bool ok;
+ bool ok;
- if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
+ if (!LookupModIndex(keymap->ctx, NULL, def->modifier, TypeInt, &rtrn))
{
ERROR("Illegal modifier map definition\n");
ACTION("Ignoring map for non-modifier \"%s\"\n",
- XkbcAtomText(def->modifier));
- return False;
+ xkb_atom_text(keymap->ctx, def->modifier));
+ return false;
}
- ok = True;
+ ok = true;
tmp.modifier = rtrn.uval;
for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
{
if ((key->op == ExprValue) && (key->type == TypeKeyName))
{
- tmp.haveSymbol = False;
+ tmp.haveSymbol = false;
tmp.u.keyName = KeyNameToLong(key->value.keyName);
}
- else if (ExprResolveKeySym(key, &rtrn))
+ else if (ExprResolveKeySym(keymap->ctx, key, &rtrn))
{
- tmp.haveSymbol = True;
+ tmp.haveSymbol = true;
tmp.u.keySym = rtrn.uval;
}
else
}
static void
-HandleSymbolsFile(XkbFile * file,
- struct xkb_keymap * xkb, unsigned merge, SymbolsInfo * info)
+HandleSymbolsFile(XkbFile *file, struct xkb_keymap *keymap,
+ unsigned merge, SymbolsInfo *info)
{
ParseCommon *stmt;
switch (stmt->stmtType)
{
case StmtInclude:
- if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
- HandleSymbolsFile))
+ if (!HandleIncludeSymbols((IncludeStmt *) stmt, keymap, info))
info->errorCount++;
break;
case StmtSymbolsDef:
- if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
+ if (!HandleSymbolsDef((SymbolsDef *) stmt, keymap, info))
info->errorCount++;
break;
case StmtVarDef:
- if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
+ if (!HandleSymbolsVar((VarDef *) stmt, keymap, info))
info->errorCount++;
break;
case StmtVModDef:
- if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
+ if (!HandleVModDef((VModDef *) stmt, keymap, merge, &info->vmods))
info->errorCount++;
break;
case StmtInterpDef:
info->errorCount++;
break;
case StmtModMapDef:
- if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
+ if (!HandleModMapDef((ModMapDef *) stmt, keymap, info))
info->errorCount++;
break;
default:
}
}
-static Bool
-FindKeyForSymbol(struct xkb_keymap * xkb, xkb_keysym_t sym, xkb_keycode_t *kc_rtrn)
+static bool
+FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym,
+ xkb_keycode_t *kc_rtrn)
{
xkb_keycode_t key;
unsigned int group, level;
- for (key = xkb->min_key_code; key <= xkb->max_key_code; key++)
+ for (key = keymap->min_key_code; key <= keymap->max_key_code; key++)
{
- for (group = 0; group < XkbKeyNumGroups(xkb, key); group++)
+ for (group = 0; group < XkbKeyNumGroups(keymap, key); group++)
{
- for (level = 0; level < XkbKeyGroupWidth(xkb, key, group); level++)
+ for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
+ level++)
{
- if (XkbKeyNumSyms(xkb, key, group, level) != 1 ||
- (XkbKeySymEntry(xkb, key, group, level))[0] != sym)
+ if (XkbKeyNumSyms(keymap, key, group, level) != 1 ||
+ (XkbKeySymEntry(keymap, key, group, level))[0] != sym)
continue;
*kc_rtrn = key;
- return True;
+ return true;
}
}
}
- return False;
+ return false;
}
/**
- * Find the given name in the xkb->map->types and return its index.
+ * Find the given name in the keymap->map->types and return its index.
*
* @param atom The atom to search for.
* @param type_rtrn Set to the index of the name if found.
*
- * @return True if found, False otherwise.
+ * @return true if found, false otherwise.
*/
-static Bool
-FindNamedType(struct xkb_keymap * xkb, xkb_atom_t atom, unsigned *type_rtrn)
+static bool
+FindNamedType(struct xkb_keymap *keymap, xkb_atom_t atom, unsigned *type_rtrn)
{
- unsigned n;
- const char *name = XkbcAtomText(atom);
+ unsigned n = 0;
+ const char *name = xkb_atom_text(keymap->ctx, atom);
+ struct xkb_key_type *type;
- if (xkb && xkb->map && xkb->map->types)
- {
- for (n = 0; n < xkb->map->num_types; n++)
- {
- if (strcmp(xkb->map->types[n].name, name) == 0)
- {
+ if (keymap && keymap->map) {
+ darray_foreach(type, keymap->map->types) {
+ if (strcmp(type->name, name) == 0) {
*type_rtrn = n;
- return True;
+ return true;
}
+ n++;
}
}
- return False;
+ return false;
}
/**
* @param syms The keysyms for the given key (must be size width).
* @param typeNameRtrn Set to the Atom of the type name.
*
- * @returns True if a type could be found, False otherwise.
+ * @returns true if a type could be found, false otherwise.
*/
-static Bool
-FindAutomaticType(int width, xkb_keysym_t * syms, xkb_atom_t * typeNameRtrn,
- Bool * autoType)
+static bool
+FindAutomaticType(struct xkb_keymap *keymap, int width, xkb_keysym_t *syms,
+ xkb_atom_t *typeNameRtrn, bool *autoType)
{
- *autoType = False;
+ *autoType = false;
if ((width == 1) || (width == 0))
{
- *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
- *autoType = True;
+ *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
+ *autoType = true;
}
else if (width == 2)
{
if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
{
- *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
+ *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
}
else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
{
- *typeNameRtrn = xkb_intern_atom("KEYPAD");
- *autoType = True;
+ *typeNameRtrn = xkb_atom_intern(keymap->ctx, "KEYPAD");
+ *autoType = true;
}
else
{
- *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
- *autoType = True;
+ *typeNameRtrn = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
+ *autoType = true;
}
}
else if (width <= 4)
if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
*typeNameRtrn =
- xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
+ xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_ALPHABETIC");
else
- *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
+ *typeNameRtrn = xkb_atom_intern(keymap->ctx,
+ "FOUR_LEVEL_SEMIALPHABETIC");
else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
- *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
+ *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_KEYPAD");
else
- *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
+ *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL");
/* XXX: why not set autoType here? */
}
return ((width >= 0) && (width <= 4));
PrepareKeyDef(KeyInfo * key)
{
int i, j, width, defined, lastGroup;
- Bool identical;
+ bool identical;
defined = key->symsDefined | key->actsDefined | key->typesDefined;
/* get highest group number */
}
/* If all groups are completely identical remove them all */
/* exept the first one. */
- identical = True;
+ identical = true;
for (i = lastGroup; i > 0; i--)
{
if ((key->numLevels[i] != key->numLevels[0]) ||
(key->types[i] != key->types[0]))
{
- identical = False;
+ identical = false;
break;
}
if ((key->syms[i] != key->syms[0]) &&
memcmp(key->syms[i], key->syms[0],
sizeof(xkb_keysym_t) * key->sizeSyms[0])))
{
- identical = False;
+ identical = false;
break;
}
- if ((key->symsMapIndex[i] != key->symsMapIndex[i]) &&
+ if ((key->symsMapIndex[i] != key->symsMapIndex[0]) &&
(key->symsMapIndex[i] == NULL || key->symsMapIndex[0] == NULL ||
memcmp(key->symsMapIndex[i], key->symsMapIndex[0],
key->numLevels[0] * sizeof(int))))
{
- identical = False;
+ identical = false;
continue;
}
- if ((key->symsMapNumEntries[i] != key->symsMapNumEntries[i]) &&
+ if ((key->symsMapNumEntries[i] != key->symsMapNumEntries[0]) &&
(key->symsMapNumEntries[i] == NULL ||
key->symsMapNumEntries[0] == NULL ||
memcmp(key->symsMapNumEntries[i], key->symsMapNumEntries[0],
key->numLevels[0] * sizeof(int))))
{
- identical = False;
+ identical = false;
continue;
}
if ((key->acts[i] != key->acts[0]) &&
memcmp(key->acts[i], key->acts[0],
sizeof(union xkb_action) * key->numLevels[0])))
{
- identical = False;
+ identical = false;
break;
}
}
*
* This function recurses.
*/
-static Bool
-CopySymbolsDef(struct xkb_keymap * xkb, KeyInfo *key, int start_from)
+static bool
+CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
{
unsigned int i;
xkb_keycode_t kc;
unsigned int sizeSyms = 0;
unsigned width, tmp, nGroups;
struct xkb_key_type * type;
- Bool haveActions, autoType, useAlias;
- xkb_atom_t types[XkbNumKbdGroups];
+ bool haveActions, autoType, useAlias;
+ unsigned types[XkbNumKbdGroups];
union xkb_action *outActs;
-
unsigned int symIndex = 0;
+ struct xkb_sym_map *sym_map;
useAlias = (start_from == 0);
/* get the keycode for the key. */
- if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
- start_from))
+ if (!FindNamedKey(keymap, key->name, &kc, useAlias,
+ CreateKeyNames(keymap), start_from))
{
if ((start_from == 0) && (warningLevel >= 5))
{
WARN("Key %s not found in keycodes\n", longText(key->name));
ACTION("Symbols ignored\n");
}
- return False;
+ return false;
}
- haveActions = False;
+ haveActions = false;
for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
{
if (((i + 1) > nGroups)
|| (key->typesDefined) & (1 << i)))
nGroups = i + 1;
if (key->acts[i])
- haveActions = True;
- autoType = False;
+ haveActions = true;
+ autoType = false;
/* Assign the type to the key, if it is missing. */
if (key->types[i] == XKB_ATOM_NONE)
{
if (key->dfltType != XKB_ATOM_NONE)
key->types[i] = key->dfltType;
- else if (FindAutomaticType(key->numLevels[i], key->syms[i],
+ else if (FindAutomaticType(keymap, key->numLevels[i], key->syms[i],
&key->types[i], &autoType))
{
}
WARN("No automatic type for %d symbols\n",
(unsigned int) key->numLevels[i]);
ACTION("Using %s for the %s key (keycode %d)\n",
- XkbcAtomText(key->types[i]),
+ xkb_atom_text(keymap->ctx, key->types[i]),
longText(key->name), kc);
}
}
}
- if (FindNamedType(xkb, key->types[i], &types[i]))
+ if (FindNamedType(keymap, key->types[i], &types[i]))
{
if (!autoType || key->numLevels[i] > 2)
- xkb->server->explicit[kc] |= (1 << i);
+ keymap->server->explicit[kc] |= (1 << i);
}
else
{
if (warningLevel >= 3)
{
WARN("Type \"%s\" is not defined\n",
- XkbcAtomText(key->types[i]));
+ xkb_atom_text(keymap->ctx, key->types[i]));
ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
longText(key->name), kc);
}
types[i] = XkbTwoLevelIndex;
}
/* if the type specifies fewer levels than the key has, shrink the key */
- type = &xkb->map->types[types[i]];
+ type = &darray_item(keymap->map->types, types[i]);
if (type->num_levels < key->numLevels[i])
{
if (warningLevel > 0)
{
WARN("Type \"%s\" has %d levels, but %s has %d symbols\n",
type->name, type->num_levels,
- XkbcAtomText(key->name), key->numLevels[i]);
+ xkb_atom_text(keymap->ctx, key->name), key->numLevels[i]);
ACTION("Ignoring extra symbols\n");
}
key->numLevels[i] = type->num_levels;
sizeSyms += key->sizeSyms[i];
}
- if (!XkbcResizeKeySyms(xkb, kc, sizeSyms))
+ if (!XkbcResizeKeySyms(keymap, kc, sizeSyms))
{
WSGO("Could not enlarge symbols for %s (keycode %d)\n",
longText(key->name), kc);
- return False;
+ return false;
}
if (haveActions)
{
- outActs = XkbcResizeKeyActions(xkb, kc, width * nGroups);
+ outActs = XkbcResizeKeyActions(keymap, kc, width * nGroups);
if (outActs == NULL)
{
WSGO("Could not enlarge actions for %s (key %d)\n",
longText(key->name), kc);
- return False;
+ return false;
}
- xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
+ keymap->server->explicit[kc] |= XkbExplicitInterpretMask;
}
else
outActs = NULL;
+
+ sym_map = &darray_item(keymap->map->key_sym_map, kc);
+
if (key->defs.defined & _Key_GroupInfo)
i = key->groupInfo;
else
- i = xkb->map->key_sym_map[kc].group_info;
+ i = sym_map->group_info;
+
+ sym_map->group_info = XkbSetNumGroups(i, nGroups);
+ sym_map->width = width;
+ sym_map->sym_index = uTypedCalloc(nGroups * width, int);
+ sym_map->num_syms = uTypedCalloc(nGroups * width, unsigned int);
- xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
- xkb->map->key_sym_map[kc].width = width;
- xkb->map->key_sym_map[kc].sym_index = uTypedCalloc(nGroups * width, int);
- xkb->map->key_sym_map[kc].num_syms = uTypedCalloc(nGroups * width,
- unsigned int);
for (i = 0; i < nGroups; i++)
{
/* assign kt_index[i] to the index of the type in map->types.
* FIXME: There should be a better fix for this.
*/
if (key->numLevels[i])
- xkb->map->key_sym_map[kc].kt_index[i] = types[i];
+ sym_map->kt_index[i] = types[i];
if (key->sizeSyms[i] != 0)
{
/* fill key to "width" symbols*/
{
if (tmp < key->numLevels[i] && key->symsMapNumEntries[i][tmp])
{
- memcpy(&xkb->map->key_sym_map[kc].syms[symIndex],
+ memcpy(&sym_map->syms[symIndex],
&key->syms[i][key->symsMapIndex[i][tmp]],
key->symsMapNumEntries[i][tmp] *
sizeof(xkb_keysym_t));
- xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] =
- symIndex;
- xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] =
+ sym_map->sym_index[(i * width) + tmp] = symIndex;
+ sym_map->num_syms[(i * width) + tmp] =
key->symsMapNumEntries[i][tmp];
- symIndex +=
- xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp];
+ symIndex += sym_map->num_syms[(i * width) + tmp];
}
else
{
- xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] = -1;
- xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] = 0;
+ sym_map->sym_index[(i * width) + tmp] = -1;
+ sym_map->num_syms[(i * width) + tmp] = 0;
}
if ((outActs != NULL) && (key->acts[i] != NULL))
{
case XkbKB_Default:
break;
default:
- xkb->server->behaviors[kc] = key->behavior;
- xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
+ keymap->server->behaviors[kc] = key->behavior;
+ keymap->server->explicit[kc] |= XkbExplicitBehaviorMask;
break;
}
if (key->defs.defined & _Key_VModMap)
{
- xkb->server->vmodmap[kc] = key->vmodmap;
- xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
+ keymap->server->vmodmap[kc] = key->vmodmap;
+ keymap->server->explicit[kc] |= XkbExplicitVModMapMask;
}
if (key->repeat != RepeatUndefined)
{
if (key->repeat == RepeatYes)
- xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
+ keymap->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
else
- xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
- xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
+ keymap->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
+ keymap->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
}
- if (nGroups > xkb->ctrls->num_groups)
- xkb->ctrls->num_groups = nGroups;
+ if (nGroups > keymap->ctrls->num_groups)
+ keymap->ctrls->num_groups = nGroups;
/* do the same thing for the next key */
- CopySymbolsDef(xkb, key, kc + 1);
- return True;
+ CopySymbolsDef(keymap, key, kc + 1);
+ return true;
}
-static Bool
-CopyModMapDef(struct xkb_keymap * xkb, ModMapEntry *entry)
+static bool
+CopyModMapDef(struct xkb_keymap *keymap, ModMapEntry *entry)
{
xkb_keycode_t kc;
- if ((!entry->haveSymbol)
- &&
- (!FindNamedKey
- (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
+ if (!entry->haveSymbol &&
+ !FindNamedKey(keymap, entry->u.keyName, &kc, true,
+ CreateKeyNames(keymap), 0))
{
if (warningLevel >= 5)
{
ACTION("Modifier map entry for %s not updated\n",
XkbcModIndexText(entry->modifier));
}
- return False;
+ return false;
}
- else if (entry->haveSymbol
- && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
+ else if (entry->haveSymbol &&
+ !FindKeyForSymbol(keymap, entry->u.keySym, &kc))
{
if (warningLevel > 5)
{
ACTION("Modifier map entry for %s not updated\n",
XkbcModIndexText(entry->modifier));
}
- return False;
+ return false;
}
- xkb->map->modmap[kc] |= (1 << entry->modifier);
- return True;
+ keymap->map->modmap[kc] |= (1 << entry->modifier);
+ return true;
}
/**
* Handle the xkb_symbols section of an xkb file.
*
* @param file The parsed xkb_symbols section of the xkb file.
- * @param xkb Handle to the keyboard description to store the symbols in.
+ * @param keymap Handle to the keyboard description to store the symbols in.
* @param merge Merge strategy (e.g. MergeOverride).
*/
-Bool
-CompileSymbols(XkbFile *file, struct xkb_keymap * xkb, unsigned merge)
+bool
+CompileSymbols(XkbFile *file, struct xkb_keymap *keymap, unsigned merge)
{
unsigned int i;
SymbolsInfo info;
+ KeyInfo *key;
- InitSymbolsInfo(&info, xkb);
+ InitSymbolsInfo(&info, keymap);
info.dflt.defs.fileID = file->id;
info.dflt.defs.merge = merge;
- HandleSymbolsFile(file, xkb, merge, &info);
- if (info.nKeys == 0) {
- FreeSymbolsInfo(&info);
- return False;
+ HandleSymbolsFile(file, keymap, merge, &info);
+
+ if (darray_empty(info.keys))
+ goto err_info;
+
+ if (info.errorCount != 0)
+ goto err_info;
+
+ /* alloc memory in the xkb struct */
+ if (XkbcAllocNames(keymap, XkbGroupNamesMask, 0) != Success) {
+ WSGO("Can not allocate names in CompileSymbols\n");
+ ACTION("Symbols not added\n");
+ goto err_info;
}
- if (info.errorCount == 0)
- {
- KeyInfo *key;
+ if (XkbcAllocClientMap(keymap, XkbKeySymsMask | XkbModifierMapMask, 0)
+ != Success) {
+ WSGO("Could not allocate client map in CompileSymbols\n");
+ ACTION("Symbols not added\n");
+ goto err_info;
+ }
- /* alloc memory in the xkb struct */
- if (XkbcAllocNames(xkb, XkbGroupNamesMask, 0) != Success)
- {
- WSGO("Can not allocate names in CompileSymbols\n");
- ACTION("Symbols not added\n");
- return False;
- }
- if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
- != Success)
- {
- WSGO("Could not allocate client map in CompileSymbols\n");
- ACTION("Symbols not added\n");
- return False;
- }
- if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
- {
- WSGO("Could not allocate server map in CompileSymbols\n");
- ACTION("Symbols not added\n");
- return False;
- }
- if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
- {
- WSGO("Could not allocate controls in CompileSymbols\n");
- ACTION("Symbols not added\n");
- return False;
+ if (XkbcAllocServerMap(keymap, XkbAllServerInfoMask, 32) != Success) {
+ WSGO("Could not allocate server map in CompileSymbols\n");
+ ACTION("Symbols not added\n");
+ goto err_info;
+ }
+
+ if (XkbcAllocControls(keymap) != Success) {
+ WSGO("Could not allocate controls in CompileSymbols\n");
+ ACTION("Symbols not added\n");
+ goto err_info;
+ }
+
+ /* now copy info into xkb. */
+ ApplyAliases(keymap, &info.aliases);
+
+ for (i = 0; i < XkbNumKbdGroups; i++) {
+ if (info.groupNames[i] != XKB_ATOM_NONE) {
+ free(keymap->names->groups[i]);
+ keymap->names->groups[i] = xkb_atom_strdup(keymap->ctx,
+ info.groupNames[i]);
}
+ }
- /* now copy info into xkb. */
- if (info.aliases)
- ApplyAliases(xkb, &info.aliases);
- for (i = 0; i < XkbNumKbdGroups; i++)
- {
- if (info.groupNames[i] != XKB_ATOM_NONE)
- {
- free(UNCONSTIFY(xkb->names->groups[i]));
- xkb->names->groups[i] = XkbcAtomGetString(info.groupNames[i]);
+ /* sanitize keys */
+ darray_foreach(key, info.keys)
+ PrepareKeyDef(key);
+
+ /* copy! */
+ darray_foreach(key, info.keys)
+ if (!CopySymbolsDef(keymap, key, 0))
+ info.errorCount++;
+
+ if (warningLevel > 3) {
+ for (i = keymap->min_key_code; i <= keymap->max_key_code; i++) {
+ if (darray_item(keymap->names->keys, i).name[0] == '\0')
+ continue;
+
+ if (XkbKeyNumGroups(keymap, i) < 1) {
+ char buf[5];
+ memcpy(buf, darray_item(keymap->names->keys, i).name, 4);
+ buf[4] = '\0';
+ WARN("No symbols defined for <%s> (keycode %d)\n", buf, i);
}
}
- /* sanitize keys */
- for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
- {
- PrepareKeyDef(key);
- }
- /* copy! */
- for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
- {
- if (!CopySymbolsDef(xkb, key, 0))
+ }
+
+ if (info.modMap) {
+ ModMapEntry *mm, *next;
+ for (mm = info.modMap; mm != NULL; mm = next) {
+ if (!CopyModMapDef(keymap, mm))
info.errorCount++;
+ next = (ModMapEntry *) mm->defs.next;
}
- if (warningLevel > 3)
- {
- for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
- {
- if (xkb->names->keys[i].name[0] == '\0')
- continue;
- if (XkbKeyNumGroups(xkb, i) < 1)
- {
- char buf[5];
- memcpy(buf, xkb->names->keys[i].name, 4);
- buf[4] = '\0';
- WARN
- ("No symbols defined for <%s> (keycode %d)\n",
- buf, i);
- }
- }
- }
- if (info.modMap)
- {
- ModMapEntry *mm, *next;
- for (mm = info.modMap; mm != NULL; mm = next)
- {
- if (!CopyModMapDef(xkb, mm))
- info.errorCount++;
- next = (ModMapEntry *) mm->defs.next;
- }
- }
- FreeSymbolsInfo(&info);
- return True;
}
FreeSymbolsInfo(&info);
- return False;
+ return true;
+
+err_info:
+ FreeSymbolsInfo(&info);
+ return false;
}