keycodes: use darray in KeyNamesInfo
Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
07c88b551b
commit
89c5e88603
|
@ -69,10 +69,9 @@ typedef struct _KeyNamesInfo
|
||||||
xkb_keycode_t computedMax; /* highest keycode stored */
|
xkb_keycode_t computedMax; /* highest keycode stored */
|
||||||
xkb_keycode_t explicitMin;
|
xkb_keycode_t explicitMin;
|
||||||
xkb_keycode_t explicitMax;
|
xkb_keycode_t explicitMax;
|
||||||
xkb_keycode_t arraySize;
|
darray(unsigned long) names;
|
||||||
unsigned long *names;
|
darray(unsigned int) files;
|
||||||
unsigned *files;
|
darray(unsigned char) has_alt_forms;
|
||||||
unsigned char *has_alt_forms;
|
|
||||||
IndicatorNameInfo *leds;
|
IndicatorNameInfo *leds;
|
||||||
AliasInfo *aliases;
|
AliasInfo *aliases;
|
||||||
} KeyNamesInfo;
|
} KeyNamesInfo;
|
||||||
|
@ -80,51 +79,15 @@ typedef struct _KeyNamesInfo
|
||||||
static void HandleKeycodesFile(XkbFile *file, struct xkb_keymap *keymap,
|
static void HandleKeycodesFile(XkbFile *file, struct xkb_keymap *keymap,
|
||||||
unsigned merge, KeyNamesInfo *info);
|
unsigned merge, KeyNamesInfo *info);
|
||||||
|
|
||||||
static int
|
static void
|
||||||
ResizeKeyNameArrays(KeyNamesInfo *info, int newMax)
|
ResizeKeyNameArrays(KeyNamesInfo *info, int newMax)
|
||||||
{
|
{
|
||||||
void *tmp;
|
if (newMax < darray_size(info->names))
|
||||||
int i;
|
return;
|
||||||
|
|
||||||
tmp = uTypedRealloc(info->names, newMax + 1, unsigned long);
|
darray_resize0(info->names, newMax + 1);
|
||||||
if (!tmp) {
|
darray_resize0(info->files, newMax + 1);
|
||||||
ERROR
|
darray_resize0(info->has_alt_forms, newMax + 1);
|
||||||
("Couldn't reallocate for larger maximum keycode (%d)\n",
|
|
||||||
newMax);
|
|
||||||
ACTION("Maximum key value not changed\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
info->names = tmp;
|
|
||||||
for (i = info->arraySize + 1; i <= newMax; i++)
|
|
||||||
info->names[i] = 0;
|
|
||||||
|
|
||||||
tmp = uTypedRealloc(info->files, newMax + 1, unsigned);
|
|
||||||
if (!tmp) {
|
|
||||||
ERROR
|
|
||||||
("Couldn't reallocate for larger maximum keycode (%d)\n",
|
|
||||||
newMax);
|
|
||||||
ACTION("Maximum key value not changed\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
info->files = tmp;
|
|
||||||
for (i = info->arraySize + 1; i <= newMax; i++)
|
|
||||||
info->files[i] = 0;
|
|
||||||
|
|
||||||
tmp = uTypedRealloc(info->has_alt_forms, newMax + 1, unsigned char);
|
|
||||||
if (!tmp) {
|
|
||||||
ERROR
|
|
||||||
("Couldn't reallocate for larger maximum keycode (%d)\n",
|
|
||||||
newMax);
|
|
||||||
ACTION("Maximum key value not changed\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
info->has_alt_forms = tmp;
|
|
||||||
for (i = info->arraySize + 1; i <= newMax; i++)
|
|
||||||
info->has_alt_forms[i] = 0;
|
|
||||||
|
|
||||||
info->arraySize = newMax;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -318,13 +281,12 @@ ClearKeyNamesInfo(KeyNamesInfo * info)
|
||||||
info->name = NULL;
|
info->name = NULL;
|
||||||
info->computedMax = info->explicitMax = info->explicitMin = 0;
|
info->computedMax = info->explicitMax = info->explicitMin = 0;
|
||||||
info->computedMin = XKB_KEYCODE_MAX;
|
info->computedMin = XKB_KEYCODE_MAX;
|
||||||
info->arraySize = 0;
|
darray_free(info->names);
|
||||||
free(info->names);
|
darray_init(info->names);
|
||||||
info->names = NULL;
|
darray_free(info->files);
|
||||||
free(info->files);
|
darray_init(info->files);
|
||||||
info->files = NULL;
|
darray_free(info->has_alt_forms);
|
||||||
free(info->has_alt_forms);
|
darray_init(info->has_alt_forms);
|
||||||
info->has_alt_forms = NULL;
|
|
||||||
if (info->leds)
|
if (info->leds)
|
||||||
ClearIndicatorNameInfo(info->leds, info);
|
ClearIndicatorNameInfo(info->leds, info);
|
||||||
if (info->aliases)
|
if (info->aliases)
|
||||||
|
@ -337,9 +299,9 @@ InitKeyNamesInfo(KeyNamesInfo * info)
|
||||||
info->name = NULL;
|
info->name = NULL;
|
||||||
info->leds = NULL;
|
info->leds = NULL;
|
||||||
info->aliases = NULL;
|
info->aliases = NULL;
|
||||||
info->names = NULL;
|
darray_init(info->names);
|
||||||
info->files = NULL;
|
darray_init(info->files);
|
||||||
info->has_alt_forms = NULL;
|
darray_init(info->has_alt_forms);
|
||||||
ClearKeyNamesInfo(info);
|
ClearKeyNamesInfo(info);
|
||||||
info->errorCount = 0;
|
info->errorCount = 0;
|
||||||
}
|
}
|
||||||
|
@ -350,10 +312,9 @@ FindKeyByLong(KeyNamesInfo * info, unsigned long name)
|
||||||
uint64_t i;
|
uint64_t i;
|
||||||
|
|
||||||
for (i = info->computedMin; i <= info->computedMax; i++)
|
for (i = info->computedMin; i <= info->computedMax; i++)
|
||||||
{
|
if (darray_item(info->names, i) == name)
|
||||||
if (info->names[i] == name)
|
|
||||||
return i;
|
return i;
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,11 +331,8 @@ AddKeyName(KeyNamesInfo * info,
|
||||||
xkb_keycode_t old;
|
xkb_keycode_t old;
|
||||||
unsigned long lval;
|
unsigned long lval;
|
||||||
|
|
||||||
if (kc > info->arraySize && !ResizeKeyNameArrays(info, kc)) {
|
ResizeKeyNameArrays(info, kc);
|
||||||
ERROR("Couldn't resize KeyNames arrays for keycode %d\n", kc);
|
|
||||||
ACTION("Ignoring key %d\n", kc);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (kc < info->computedMin)
|
if (kc < info->computedMin)
|
||||||
info->computedMin = kc;
|
info->computedMin = kc;
|
||||||
if (kc > info->computedMax)
|
if (kc > info->computedMax)
|
||||||
|
@ -383,25 +341,23 @@ AddKeyName(KeyNamesInfo * info,
|
||||||
|
|
||||||
if (reportCollisions)
|
if (reportCollisions)
|
||||||
{
|
{
|
||||||
reportCollisions = ((warningLevel > 7) ||
|
reportCollisions = (warningLevel > 7 ||
|
||||||
((warningLevel > 0)
|
(warningLevel > 0 &&
|
||||||
&& (fileID == info->files[kc])));
|
fileID == darray_item(info->files, kc)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->names[kc] != 0)
|
if (darray_item(info->names, kc) != 0)
|
||||||
{
|
{
|
||||||
char buf[6];
|
char buf[6];
|
||||||
|
|
||||||
LongToKeyName(info->names[kc], buf);
|
LongToKeyName(darray_item(info->names, kc), buf);
|
||||||
buf[4] = '\0';
|
buf[4] = '\0';
|
||||||
if (info->names[kc] == lval)
|
if (darray_item(info->names, kc) == lval)
|
||||||
{
|
{
|
||||||
if (info->has_alt_forms[kc] || (merge == MergeAltForm))
|
if (darray_item(info->has_alt_forms, kc) || (merge == MergeAltForm)) {
|
||||||
{
|
darray_item(info->has_alt_forms, kc) = true;
|
||||||
info->has_alt_forms[kc] = true;
|
|
||||||
}
|
}
|
||||||
else if (reportCollisions)
|
else if (reportCollisions) {
|
||||||
{
|
|
||||||
WARN("Multiple identical key name definitions\n");
|
WARN("Multiple identical key name definitions\n");
|
||||||
ACTION("Later occurences of \"<%s> = %d\" ignored\n",
|
ACTION("Later occurences of \"<%s> = %d\" ignored\n",
|
||||||
buf, kc);
|
buf, kc);
|
||||||
|
@ -424,8 +380,8 @@ AddKeyName(KeyNamesInfo * info,
|
||||||
WARN("Multiple names for keycode %d\n", kc);
|
WARN("Multiple names for keycode %d\n", kc);
|
||||||
ACTION("Using <%s>, ignoring <%s>\n", name, buf);
|
ACTION("Using <%s>, ignoring <%s>\n", name, buf);
|
||||||
}
|
}
|
||||||
info->names[kc] = 0;
|
darray_item(info->names, kc) = 0;
|
||||||
info->files[kc] = 0;
|
darray_item(info->files, kc) = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
old = FindKeyByLong(info, lval);
|
old = FindKeyByLong(info, lval);
|
||||||
|
@ -433,9 +389,9 @@ AddKeyName(KeyNamesInfo * info,
|
||||||
{
|
{
|
||||||
if (merge == MergeOverride)
|
if (merge == MergeOverride)
|
||||||
{
|
{
|
||||||
info->names[old] = 0;
|
darray_item(info->names, old) = 0;
|
||||||
info->files[old] = 0;
|
darray_item(info->files, old) = 0;
|
||||||
info->has_alt_forms[old] = true;
|
darray_item(info->has_alt_forms, old) = true;
|
||||||
if (reportCollisions)
|
if (reportCollisions)
|
||||||
{
|
{
|
||||||
WARN("Key name <%s> assigned to multiple keys\n", name);
|
WARN("Key name <%s> assigned to multiple keys\n", name);
|
||||||
|
@ -455,12 +411,12 @@ AddKeyName(KeyNamesInfo * info,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
info->has_alt_forms[old] = true;
|
darray_item(info->has_alt_forms, old) = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info->names[kc] = lval;
|
darray_item(info->names, kc) = lval;
|
||||||
info->files[kc] = fileID;
|
darray_item(info->files, kc) = fileID;
|
||||||
info->has_alt_forms[kc] = (merge == MergeAltForm);
|
darray_item(info->has_alt_forms, kc) = (merge == MergeAltForm);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,22 +439,17 @@ MergeIncludedKeycodes(KeyNamesInfo *into, struct xkb_keymap *keymap,
|
||||||
into->name = from->name;
|
into->name = from->name;
|
||||||
from->name = NULL;
|
from->name = NULL;
|
||||||
}
|
}
|
||||||
if (from->computedMax > into->arraySize &&
|
|
||||||
!ResizeKeyNameArrays(into, from->computedMax)) {
|
ResizeKeyNameArrays(into, from->computedMax);
|
||||||
ERROR("Couldn't resize KeyNames arrays for key %d\n",
|
|
||||||
from->computedMax);
|
|
||||||
ACTION("Ignoring include file %s\n", from->name);
|
|
||||||
into->errorCount += 10;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (i = from->computedMin; i <= from->computedMax; i++)
|
for (i = from->computedMin; i <= from->computedMax; i++)
|
||||||
{
|
{
|
||||||
unsigned thisMerge;
|
unsigned thisMerge;
|
||||||
if (from->names[i] == 0)
|
if (darray_item(from->names, i) == 0)
|
||||||
continue;
|
continue;
|
||||||
LongToKeyName(from->names[i], buf);
|
LongToKeyName(darray_item(from->names, i), buf);
|
||||||
buf[4] = '\0';
|
buf[4] = '\0';
|
||||||
if (from->has_alt_forms[i])
|
if (darray_item(from->has_alt_forms, i))
|
||||||
thisMerge = MergeAltForm;
|
thisMerge = MergeAltForm;
|
||||||
else
|
else
|
||||||
thisMerge = merge;
|
thisMerge = merge;
|
||||||
|
@ -897,7 +848,7 @@ CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap, unsigned merge)
|
||||||
== Success) {
|
== Success) {
|
||||||
uint64_t i;
|
uint64_t i;
|
||||||
for (i = info.computedMin; i <= info.computedMax; i++)
|
for (i = info.computedMin; i <= info.computedMax; i++)
|
||||||
LongToKeyName(info.names[i],
|
LongToKeyName(darray_item(info.names, i),
|
||||||
darray_item(keymap->names->keys, i).name);
|
darray_item(keymap->names->keys, i).name);
|
||||||
} else {
|
} else {
|
||||||
WSGO("Cannot create struct xkb_names in CompileKeycodes\n");
|
WSGO("Cannot create struct xkb_names in CompileKeycodes\n");
|
||||||
|
|
Loading…
Reference in New Issue