/* Needed to work with the typechecker. */
typedef darray(xkb_keysym_t) darray_xkb_keysym_t;
+typedef darray(union xkb_action) darray_xkb_action;
#define RepeatYes 1
#define RepeatNo 0
*/
darray(size_t) symsMapNumEntries[XkbNumKbdGroups];
- union xkb_action *acts[XkbNumKbdGroups];
+ darray_xkb_action acts[XkbNumKbdGroups];
+
xkb_atom_t types[XkbNumKbdGroups];
unsigned repeat;
struct xkb_behavior behavior;
darray_init(info->syms[i]);
darray_init(info->symsMapIndex[i]);
darray_init(info->symsMapNumEntries[i]);
- info->acts[i] = NULL;
+ darray_init(info->acts[i]);
}
info->dfltType = XKB_ATOM_NONE;
info->behavior.type = XkbKB_Default;
darray_free(info->syms[i]);
darray_free(info->symsMapIndex[i]);
darray_free(info->symsMapNumEntries[i]);
- free(info->acts[i]);
- info->acts[i] = NULL;
+ darray_free(info->acts[i]);
}
info->dfltType = XKB_ATOM_NONE;
info->behavior.type = XkbKB_Default;
*new = *old;
new->defs.next = NULL;
- if (clearOld)
- {
- for (i = 0; i < XkbNumKbdGroups; i++)
- {
+
+ if (clearOld) {
+ for (i = 0; i < XkbNumKbdGroups; i++) {
old->numLevels[i] = 0;
darray_init(old->symsMapIndex[i]);
darray_init(old->symsMapNumEntries[i]);
darray_init(old->syms[i]);
- old->acts[i] = NULL;
+ darray_init(old->acts[i]);
}
}
- else
- {
- unsigned int width;
- for (i = 0; i < XkbNumKbdGroups; i++)
- {
- width = new->numLevels[i];
-
+ else {
+ for (i = 0; i < XkbNumKbdGroups; i++) {
darray_copy(new->syms[i], old->syms[i]);
darray_copy(new->symsMapIndex[i], old->symsMapIndex[i]);
darray_copy(new->symsMapNumEntries[i], old->symsMapNumEntries[i]);
-
- if (old->acts[i] != NULL)
- {
- new->acts[i] = uTypedCalloc(width, union xkb_action);
- if (!new->acts[i])
- {
- darray_free(new->syms[i]);
- darray_free(new->symsMapIndex[i]);
- darray_free(new->symsMapNumEntries[i]);
- new->numLevels[i] = 0;
- return false;
- }
- memcpy(new->acts[i], old->acts[i],
- width * sizeof(union xkb_action));
- }
+ darray_copy(new->acts[i], old->acts[i]);
}
}
+
return true;
}
darray_resize0(key->syms[group], sizeSyms);
if (darray_empty(key->symsMapIndex[group]) ||
- key->numLevels[group] < numLevels)
- {
+ key->numLevels[group] < numLevels) {
darray_resize(key->symsMapIndex[group], numLevels);
for (i = key->numLevels[group]; i < numLevels; i++)
darray_item(key->symsMapIndex[group], i) = -1;
key->numLevels[group] < numLevels)
darray_resize0(key->symsMapNumEntries[group], numLevels);
- if ((forceActions &&
- (key->numLevels[group] < numLevels || (key->acts[group] == NULL))) ||
- (key->numLevels[group] < numLevels && (key->acts[group] != NULL)))
- {
- key->acts[group] = uTypedRecalloc(key->acts[group],
- key->numLevels[group],
- numLevels,
- union xkb_action);
- if (!key->acts[group])
- return false;
- }
+ if ((forceActions && (key->numLevels[group] < numLevels ||
+ darray_empty(key->acts[group]))) ||
+ (key->numLevels[group] < numLevels && !darray_empty(key->acts[group])))
+ darray_resize0(key->acts[group], numLevels);
+
if (key->numLevels[group] < numLevels)
key->numLevels[group] = numLevels;
+
return true;
}
{
darray_xkb_keysym_t resultSyms;
enum key_group_selector using = NONE;
- union xkb_action *resultActs;
+ darray_xkb_action resultActs;
unsigned int resultWidth;
unsigned int resultSize = 0;
int cur_idx = 0;
darray_item(into->symsMapIndex[group], i) = -1;
}
- if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
+ if (darray_empty(resultActs) && (!darray_empty(into->acts[group]) ||
+ !darray_empty(from->acts[group])))
{
- resultActs = uTypedCalloc(resultWidth, union xkb_action);
- if (!resultActs)
- {
- WSGO("Could not allocate actions for group merge\n");
- ACTION("Group %d of key %s not merged\n", group,
- longText(into->name));
- return false;
- }
+ darray_resize0(resultActs, resultWidth);
for (i = 0; i < resultWidth; i++)
{
- union xkb_action *fromAct, *toAct;
- fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
- toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
+ union xkb_action *fromAct = NULL, *toAct = NULL;
+
+ if (!darray_empty(from->acts[group]))
+ fromAct = &darray_item(from->acts[group], i);
+
+ if (!darray_empty(into->acts[group]))
+ toAct = &darray_item(into->acts[group], i);
+
if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
&& (toAct != NULL))
{
- resultActs[i] = *toAct;
+ darray_item(resultActs, i) = *toAct;
}
else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
&& (fromAct != NULL))
{
- resultActs[i] = *fromAct;
+ darray_item(resultActs, i) = *fromAct;
}
else
{
XkbcActionTypeText(ignore->type));
}
if (use)
- resultActs[i] = *use;
+ darray_item(resultActs, i) = *use;
}
}
}
}
out:
- if (resultActs != into->acts[group])
- free(into->acts[group]);
- if (resultActs != from->acts[group])
- free(from->acts[group]);
+ if (!darray_same(resultActs, into->acts[group]))
+ darray_free(into->acts[group]);
+ if (!darray_same(resultActs, from->acts[group]))
+ darray_free(from->acts[group]);
into->numLevels[group] = resultWidth;
if (!darray_same(resultSyms, into->syms[group]))
darray_free(into->syms[group]);
darray_free(from->symsMapIndex[group]);
darray_free(from->symsMapNumEntries[group]);
into->acts[group] = resultActs;
- from->acts[group] = NULL;
+ darray_init(from->acts[group]);
if (!darray_empty(into->syms[group]))
into->symsDefined |= (1 << group);
from->symsDefined &= ~(1 << group);
if (into->numLevels[i] != 0)
{
darray_free(into->syms[i]);
- free(into->acts[i]);
+ darray_free(into->acts[i]);
}
}
*into = *from;
darray_init(from->syms[i]);
darray_init(from->symsMapIndex[i]);
darray_init(from->symsMapNumEntries[i]);
- from->acts[i] = NULL;
+ darray_init(from->acts[i]);
from->numLevels[i] = 0;
from->symsDefined &= ~(1 << i);
if (!darray_empty(into->syms[i]))
into->defs.defined |= _Key_Syms;
- if (into->acts[i])
+ if (!darray_empty(into->acts[i]))
into->defs.defined |= _Key_Acts;
}
else
{
if (!darray_empty(into->syms[i]))
collide |= _Key_Syms;
- if (into->acts[i])
+ if (!darray_empty(into->acts[i]))
collide |= _Key_Acts;
}
MergeKeyGroups(info, into, from, (unsigned) i);
longText(key->name));
return false;
}
- if (key->acts[ndx] != NULL)
+ if (!darray_empty(key->acts[ndx]))
{
WSGO("Actions for key %s, group %d already defined\n",
longText(key->name), ndx);
WSGO("Action list but not actions in AddActionsToKey\n");
return false;
}
- if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
- (!ResizeKeyGroup(key, ndx, nActs, nActs, true)))
+ if ((key->numLevels[ndx] < nActs || darray_empty(key->acts[ndx])) &&
+ !ResizeKeyGroup(key, ndx, nActs, nActs, true))
{
WSGO("Could not resize group %d of key %s\n", ndx,
longText(key->name));
}
key->actsDefined |= (1 << ndx);
- toAct = (struct xkb_any_action *) key->acts[ndx];
+ toAct = (struct xkb_any_action *) darray_mem(key->acts[ndx], 0);
act = value->value.child;
for (i = 0; i < nActs; i++, toAct++)
{
{
key->numLevels[i] = 0;
darray_free(key->syms[i]);
- free(key->acts[i]);
- key->acts[i] = NULL;
+ darray_free(key->acts[i]);
key->types[i] = 0;
}
}
key->symsMapNumEntries[group] = key->symsMapNumEntries[0];
darray_init(key->symsMapNumEntries[0]);
key->acts[group] = key->acts[0];
- key->acts[0] = NULL;
+ darray_init(key->acts[0]);
key->types[group] = key->types[0];
key->types[0] = 0;
return true;
}
key->typesDefined |= 1 << i;
}
- if ((key->actsDefined & 1) && key->acts[0])
+ if ((key->actsDefined & 1) && !darray_empty(key->acts[0]))
{
- key->acts[i] = uTypedCalloc(width, union xkb_action);
- if (key->acts[i] == NULL)
- continue;
- memcpy(key->acts[i], key->acts[0],
- width * sizeof(union xkb_action));
+ darray_copy(key->acts[i], key->acts[0]);
key->actsDefined |= 1 << i;
}
if ((key->symsDefined & 1) && !darray_empty(key->syms[0]))
identical = false;
continue;
}
- if ((key->acts[i] != key->acts[0]) &&
- (key->acts[i] == NULL || key->acts[0] == NULL ||
- memcmp(key->acts[i], key->acts[0],
- sizeof(union xkb_action) * key->numLevels[0])))
+ if (!darray_same(key->acts[i], key->acts[0]) &&
+ (darray_empty(key->acts[i]) || darray_empty(key->acts[0]) ||
+ memcmp(darray_mem(key->acts[i], 0),
+ darray_mem(key->acts[0], 0),
+ key->numLevels[0] * sizeof(union xkb_action))))
{
identical = false;
break;
darray_free(key->syms[i]);
darray_free(key->symsMapIndex[i]);
darray_free(key->symsMapNumEntries[i]);
- free(key->acts[i]);
- key->acts[i] = NULL;
+ darray_free(key->acts[i]);
key->types[i] = 0;
}
key->symsDefined &= 1;
&& (((key->symsDefined | key->actsDefined) & (1 << i))
|| (key->typesDefined) & (1 << i)))
nGroups = i + 1;
- if (key->acts[i])
+ if (!darray_empty(key->acts[i]))
haveActions = true;
autoType = false;
/* Assign the type to the key, if it is missing. */
sym_map->sym_index[(i * width) + tmp] = -1;
sym_map->num_syms[(i * width) + tmp] = 0;
}
- if ((outActs != NULL) && (key->acts[i] != NULL))
+ if (outActs != NULL && !darray_empty(key->acts[i]))
{
if (tmp < key->numLevels[i])
- outActs[tmp] = key->acts[i][tmp];
+ outActs[tmp] = darray_item(key->acts[i], tmp);
else
outActs[tmp].type = XkbSA_NoAction;
}