types: use list instead of CommonInfo in PreserveInfo
Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
85abd36bf4
commit
730c2bc34f
|
@ -29,7 +29,7 @@
|
||||||
#include "vmod.h"
|
#include "vmod.h"
|
||||||
|
|
||||||
typedef struct _PreserveInfo {
|
typedef struct _PreserveInfo {
|
||||||
CommonInfo defs;
|
struct list entry;
|
||||||
short matchingMapIndex;
|
short matchingMapIndex;
|
||||||
unsigned char indexMods;
|
unsigned char indexMods;
|
||||||
unsigned char preMods;
|
unsigned char preMods;
|
||||||
|
@ -51,7 +51,7 @@ typedef struct _KeyTypeInfo {
|
||||||
unsigned vmask;
|
unsigned vmask;
|
||||||
unsigned numLevels;
|
unsigned numLevels;
|
||||||
darray(struct xkb_kt_map_entry) entries;
|
darray(struct xkb_kt_map_entry) entries;
|
||||||
PreserveInfo *preserve;
|
struct list preserves;
|
||||||
darray(xkb_atom_t) lvlNames;
|
darray(xkb_atom_t) lvlNames;
|
||||||
} KeyTypeInfo;
|
} KeyTypeInfo;
|
||||||
|
|
||||||
|
@ -123,6 +123,8 @@ static void
|
||||||
InitKeyTypesInfo(KeyTypesInfo *info, struct xkb_keymap *keymap,
|
InitKeyTypesInfo(KeyTypesInfo *info, struct xkb_keymap *keymap,
|
||||||
KeyTypesInfo *from, unsigned file_id)
|
KeyTypesInfo *from, unsigned file_id)
|
||||||
{
|
{
|
||||||
|
PreserveInfo *old, *new;
|
||||||
|
|
||||||
info->tok_ONE_LEVEL = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
|
info->tok_ONE_LEVEL = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
|
||||||
info->tok_TWO_LEVEL = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
|
info->tok_TWO_LEVEL = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
|
||||||
info->tok_ALPHABETIC = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
|
info->tok_ALPHABETIC = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
|
||||||
|
@ -143,43 +145,37 @@ InitKeyTypesInfo(KeyTypesInfo *info, struct xkb_keymap *keymap,
|
||||||
info->dflt.numLevels = 1;
|
info->dflt.numLevels = 1;
|
||||||
darray_init(info->dflt.entries);
|
darray_init(info->dflt.entries);
|
||||||
darray_init(info->dflt.lvlNames);
|
darray_init(info->dflt.lvlNames);
|
||||||
info->dflt.preserve = NULL;
|
list_init(&info->dflt.preserves);
|
||||||
InitVModInfo(&info->vmods, keymap);
|
InitVModInfo(&info->vmods, keymap);
|
||||||
if (from != NULL) {
|
|
||||||
info->dflt = from->dflt;
|
|
||||||
|
|
||||||
darray_copy(info->dflt.entries, from->dflt.entries);
|
if (!from)
|
||||||
darray_copy(info->dflt.lvlNames, from->dflt.lvlNames);
|
return;
|
||||||
|
|
||||||
if (from->dflt.preserve) {
|
info->dflt = from->dflt;
|
||||||
PreserveInfo *old, *new, *last;
|
|
||||||
last = NULL;
|
darray_copy(info->dflt.entries, from->dflt.entries);
|
||||||
old = from->dflt.preserve;
|
darray_copy(info->dflt.lvlNames, from->dflt.lvlNames);
|
||||||
for (; old; old = (PreserveInfo *) old->defs.next) {
|
|
||||||
new = uTypedAlloc(PreserveInfo);
|
list_init(&info->dflt.preserves);
|
||||||
if (!new)
|
list_foreach(old, &from->dflt.preserves, entry) {
|
||||||
return;
|
new = malloc(sizeof(*new));
|
||||||
*new = *old;
|
if (!new)
|
||||||
new->defs.next = NULL;
|
return;
|
||||||
if (last)
|
|
||||||
last->defs.next = (CommonInfo *) new;
|
*new = *old;
|
||||||
else
|
list_append(&new->entry, &info->dflt.preserves);
|
||||||
info->dflt.preserve = new;
|
|
||||||
last = new;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
FreeKeyTypeInfo(KeyTypeInfo * type)
|
FreeKeyTypeInfo(KeyTypeInfo * type)
|
||||||
{
|
{
|
||||||
|
PreserveInfo *pi, *next_pi;
|
||||||
darray_free(type->entries);
|
darray_free(type->entries);
|
||||||
darray_free(type->lvlNames);
|
darray_free(type->lvlNames);
|
||||||
if (type->preserve != NULL) {
|
list_foreach_safe(pi, next_pi, &type->preserves, entry)
|
||||||
ClearCommonInfo(&type->preserve->defs);
|
free(pi);
|
||||||
type->preserve = NULL;
|
list_init(&type->preserves);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -206,6 +202,7 @@ NextKeyType(KeyTypesInfo * info)
|
||||||
type = uTypedAlloc(KeyTypeInfo);
|
type = uTypedAlloc(KeyTypeInfo);
|
||||||
if (type != NULL) {
|
if (type != NULL) {
|
||||||
memset(type, 0, sizeof(KeyTypeInfo));
|
memset(type, 0, sizeof(KeyTypeInfo));
|
||||||
|
list_init(&type->preserves);
|
||||||
type->defs.file_id = info->file_id;
|
type->defs.file_id = info->file_id;
|
||||||
info->types = AddCommonInfo(&info->types->defs, &type->defs);
|
info->types = AddCommonInfo(&info->types->defs, &type->defs);
|
||||||
info->nTypes++;
|
info->nTypes++;
|
||||||
|
@ -237,6 +234,7 @@ static bool
|
||||||
AddKeyType(struct xkb_keymap *keymap, KeyTypesInfo *info, KeyTypeInfo *new)
|
AddKeyType(struct xkb_keymap *keymap, KeyTypesInfo *info, KeyTypeInfo *new)
|
||||||
{
|
{
|
||||||
KeyTypeInfo *old;
|
KeyTypeInfo *old;
|
||||||
|
struct list entry;
|
||||||
|
|
||||||
if (new->name == info->tok_ONE_LEVEL) {
|
if (new->name == info->tok_ONE_LEVEL) {
|
||||||
if (new->numLevels > 1)
|
if (new->numLevels > 1)
|
||||||
|
@ -281,7 +279,7 @@ AddKeyType(struct xkb_keymap *keymap, KeyTypesInfo *info, KeyTypeInfo *new)
|
||||||
*old = *new;
|
*old = *new;
|
||||||
darray_init(new->entries);
|
darray_init(new->entries);
|
||||||
darray_init(new->lvlNames);
|
darray_init(new->lvlNames);
|
||||||
new->preserve = NULL;
|
list_init(&new->preserves);
|
||||||
old->defs.next = &next->defs;
|
old->defs.next = &next->defs;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -298,11 +296,14 @@ AddKeyType(struct xkb_keymap *keymap, KeyTypesInfo *info, KeyTypeInfo *new)
|
||||||
old = NextKeyType(info);
|
old = NextKeyType(info);
|
||||||
if (old == NULL)
|
if (old == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
list_replace(&new->preserves, &old->preserves);
|
||||||
|
entry = old->preserves;
|
||||||
*old = *new;
|
*old = *new;
|
||||||
|
old->preserves = entry;
|
||||||
old->defs.next = NULL;
|
old->defs.next = NULL;
|
||||||
darray_init(new->entries);
|
darray_init(new->entries);
|
||||||
darray_init(new->lvlNames);
|
darray_init(new->lvlNames);
|
||||||
new->preserve = NULL;
|
list_init(&new->preserves);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,16 +448,12 @@ AddPreserve(struct xkb_keymap *keymap, KeyTypeInfo *type,
|
||||||
{
|
{
|
||||||
PreserveInfo *old;
|
PreserveInfo *old;
|
||||||
|
|
||||||
old = type->preserve;
|
list_foreach(old, &type->preserves, entry) {
|
||||||
while (old != NULL)
|
if (old->indexMods != new->indexMods ||
|
||||||
{
|
old->indexVMods != new->indexVMods)
|
||||||
if ((old->indexMods != new->indexMods) ||
|
|
||||||
(old->indexVMods != new->indexVMods)) {
|
|
||||||
old = (PreserveInfo *) old->defs.next;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if ((old->preMods == new->preMods)
|
if (old->preMods == new->preMods && old->preVMods == new->preVMods) {
|
||||||
&& (old->preVMods == new->preVMods)) {
|
|
||||||
if (warningLevel > 9) {
|
if (warningLevel > 9) {
|
||||||
WARN("Identical definitions for preserve[%s] in %s\n",
|
WARN("Identical definitions for preserve[%s] in %s\n",
|
||||||
PreserveIndexTxt(keymap, old), TypeTxt(keymap, type));
|
PreserveIndexTxt(keymap, old), TypeTxt(keymap, type));
|
||||||
|
@ -464,37 +461,36 @@ AddPreserve(struct xkb_keymap *keymap, KeyTypeInfo *type,
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (report && (warningLevel > 0)) {
|
|
||||||
|
if (report && warningLevel > 0) {
|
||||||
const char *str;
|
const char *str;
|
||||||
WARN("Multiple definitions for preserve[%s] in %s\n",
|
WARN("Multiple definitions for preserve[%s] in %s\n",
|
||||||
PreserveIndexTxt(keymap, old), TypeTxt(keymap, type));
|
PreserveIndexTxt(keymap, old), TypeTxt(keymap, type));
|
||||||
|
str = PreserveTxt(keymap, clobber ? new : old);
|
||||||
if (clobber)
|
|
||||||
str = PreserveTxt(keymap, new);
|
|
||||||
else
|
|
||||||
str = PreserveTxt(keymap, old);
|
|
||||||
ACTION("Using %s, ", str);
|
ACTION("Using %s, ", str);
|
||||||
if (clobber)
|
str = PreserveTxt(keymap, clobber ? old : new);
|
||||||
str = PreserveTxt(keymap, old);
|
|
||||||
else
|
|
||||||
str = PreserveTxt(keymap, new);
|
|
||||||
INFO("ignoring %s\n", str);
|
INFO("ignoring %s\n", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clobber) {
|
if (clobber) {
|
||||||
old->preMods = new->preMods;
|
old->preMods = new->preMods;
|
||||||
old->preVMods = new->preVMods;
|
old->preVMods = new->preVMods;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
old = uTypedAlloc(PreserveInfo);
|
|
||||||
|
old = malloc(sizeof(*old));
|
||||||
if (!old) {
|
if (!old) {
|
||||||
WSGO("Couldn't allocate preserve in %s\n", TypeTxt(keymap, type));
|
WSGO("Couldn't allocate preserve in %s\n", TypeTxt(keymap, type));
|
||||||
ACTION("Preserve[%s] lost\n", PreserveIndexTxt(keymap, new));
|
ACTION("Preserve[%s] lost\n", PreserveIndexTxt(keymap, new));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*old = *new;
|
*old = *new;
|
||||||
old->matchingMapIndex = -1;
|
old->matchingMapIndex = -1;
|
||||||
type->preserve = AddCommonInfo(&type->preserve->defs, &old->defs);
|
list_append(&old->entry, &type->preserves);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,8 +595,6 @@ SetPreserve(KeyTypeInfo *type, struct xkb_keymap *keymap,
|
||||||
if (!ExprResolveVModMask(arrayNdx, &rtrn, keymap))
|
if (!ExprResolveVModMask(arrayNdx, &rtrn, keymap))
|
||||||
return ReportTypeBadType(keymap, type, "preserve entry",
|
return ReportTypeBadType(keymap, type, "preserve entry",
|
||||||
"modifier mask");
|
"modifier mask");
|
||||||
new.defs = type->defs;
|
|
||||||
new.defs.next = NULL;
|
|
||||||
new.indexMods = rtrn.uval & 0xff;
|
new.indexMods = rtrn.uval & 0xff;
|
||||||
new.indexVMods = (rtrn.uval >> 8) & 0xffff;
|
new.indexVMods = (rtrn.uval >> 8) & 0xffff;
|
||||||
if ((new.indexMods & (~type->mask)) ||
|
if ((new.indexMods & (~type->mask)) ||
|
||||||
|
@ -817,6 +811,7 @@ HandleKeyTypeDef(KeyTypeDef *def, struct xkb_keymap *keymap,
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
KeyTypeInfo type;
|
KeyTypeInfo type;
|
||||||
struct xkb_kt_map_entry *entry;
|
struct xkb_kt_map_entry *entry;
|
||||||
|
PreserveInfo *pi, *pi_next;
|
||||||
|
|
||||||
if (def->merge != MERGE_DEFAULT)
|
if (def->merge != MERGE_DEFAULT)
|
||||||
merge = def->merge;
|
merge = def->merge;
|
||||||
|
@ -831,7 +826,7 @@ HandleKeyTypeDef(KeyTypeDef *def, struct xkb_keymap *keymap,
|
||||||
type.numLevels = 1;
|
type.numLevels = 1;
|
||||||
darray_init(type.entries);
|
darray_init(type.entries);
|
||||||
darray_init(type.lvlNames);
|
darray_init(type.lvlNames);
|
||||||
type.preserve = NULL;
|
list_init(&type.preserves);
|
||||||
|
|
||||||
/* Parse the actual content. */
|
/* Parse the actual content. */
|
||||||
if (!HandleKeyTypeBody(def->body, keymap, &type, info)) {
|
if (!HandleKeyTypeBody(def->body, keymap, &type, info)) {
|
||||||
|
@ -846,16 +841,11 @@ HandleKeyTypeDef(KeyTypeDef *def, struct xkb_keymap *keymap,
|
||||||
(entry->mods.vmods & type.vmask) == entry->mods.vmods)
|
(entry->mods.vmods & type.vmask) == entry->mods.vmods)
|
||||||
AddMapEntry(keymap, &type, entry, false, false);
|
AddMapEntry(keymap, &type, entry, false, false);
|
||||||
}
|
}
|
||||||
if (info->dflt.preserve) {
|
|
||||||
PreserveInfo *dflt = info->dflt.preserve;
|
list_foreach_safe(pi, pi_next, &info->dflt.preserves, entry) {
|
||||||
while (dflt)
|
if ((pi->indexMods & type.mask) == pi->indexMods &&
|
||||||
{
|
(pi->indexVMods & type.vmask) == pi->indexVMods)
|
||||||
if (((dflt->indexMods & type.mask) == dflt->indexMods) &&
|
AddPreserve(keymap, &type, pi, false, false);
|
||||||
((dflt->indexVMods & type.vmask) == dflt->indexVMods)) {
|
|
||||||
AddPreserve(keymap, &type, dflt, false, false);
|
|
||||||
}
|
|
||||||
dflt = (PreserveInfo *) dflt->defs.next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < darray_size(info->dflt.lvlNames); i++) {
|
for (i = 0; i < darray_size(info->dflt.lvlNames); i++) {
|
||||||
|
@ -973,8 +963,7 @@ CopyDefToKeyType(struct xkb_keymap *keymap, struct xkb_key_type *type,
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
PreserveInfo *pre;
|
PreserveInfo *pre;
|
||||||
|
|
||||||
for (pre = def->preserve; pre != NULL;
|
list_foreach(pre, &def->preserves, entry) {
|
||||||
pre = (PreserveInfo *) pre->defs.next) {
|
|
||||||
struct xkb_kt_map_entry * match;
|
struct xkb_kt_map_entry * match;
|
||||||
struct xkb_kt_map_entry tmp;
|
struct xkb_kt_map_entry tmp;
|
||||||
tmp.mods.real_mods = pre->indexMods;
|
tmp.mods.real_mods = pre->indexMods;
|
||||||
|
@ -993,7 +982,7 @@ CopyDefToKeyType(struct xkb_keymap *keymap, struct xkb_key_type *type,
|
||||||
type->mods.vmods = def->vmask;
|
type->mods.vmods = def->vmask;
|
||||||
type->num_levels = def->numLevels;
|
type->num_levels = def->numLevels;
|
||||||
memcpy(&type->map, &def->entries, sizeof(def->entries));
|
memcpy(&type->map, &def->entries, sizeof(def->entries));
|
||||||
if (def->preserve) {
|
if (!list_empty(&def->preserves)) {
|
||||||
type->preserve = uTypedCalloc(darray_size(type->map), struct xkb_mods);
|
type->preserve = uTypedCalloc(darray_size(type->map), struct xkb_mods);
|
||||||
if (!type->preserve) {
|
if (!type->preserve) {
|
||||||
WARN("Couldn't allocate preserve array in CopyDefToKeyType\n");
|
WARN("Couldn't allocate preserve array in CopyDefToKeyType\n");
|
||||||
|
@ -1001,8 +990,7 @@ CopyDefToKeyType(struct xkb_keymap *keymap, struct xkb_key_type *type,
|
||||||
xkb_atom_text(keymap->ctx, def->name));
|
xkb_atom_text(keymap->ctx, def->name));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pre = def->preserve;
|
list_foreach(pre, &def->preserves, entry) {
|
||||||
for (; pre != NULL; pre = (PreserveInfo *) pre->defs.next) {
|
|
||||||
int ndx = pre->matchingMapIndex;
|
int ndx = pre->matchingMapIndex;
|
||||||
type->preserve[ndx].mask = pre->preMods;
|
type->preserve[ndx].mask = pre->preMods;
|
||||||
type->preserve[ndx].real_mods = pre->preMods;
|
type->preserve[ndx].real_mods = pre->preMods;
|
||||||
|
|
Loading…
Reference in New Issue