xkbcomp: seperate keymap-copying code from Compile functions

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-08-15 10:10:44 +03:00
parent 6738d30036
commit eaa50c450b
3 changed files with 87 additions and 72 deletions

View File

@ -1006,7 +1006,7 @@ CopyInterps(CompatInfo *info, bool needSymbol, unsigned pred)
}
}
static bool
static void
CopyIndicatorMapDefs(CompatInfo *info)
{
LEDInfo *led;
@ -1066,6 +1066,25 @@ CopyIndicatorMapDefs(CompatInfo *info)
im->mods.mods = led->mods;
im->ctrls = led->ctrls;
}
}
static bool
CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
{
keymap->compat_section_name = strdup_safe(info->name);
if (!darray_empty(info->interps)) {
CopyInterps(info, true, XkbSI_Exactly);
CopyInterps(info, true, XkbSI_AllOf | XkbSI_NoneOf);
CopyInterps(info, true, XkbSI_AnyOf);
CopyInterps(info, true, XkbSI_AnyOfOrNone);
CopyInterps(info, false, XkbSI_Exactly);
CopyInterps(info, false, XkbSI_AllOf | XkbSI_NoneOf);
CopyInterps(info, false, XkbSI_AnyOf);
CopyInterps(info, false, XkbSI_AnyOfOrNone);
}
CopyIndicatorMapDefs(info);
return true;
}
@ -1081,26 +1100,11 @@ CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
info.ledDflt.merge = merge;
HandleCompatMapFile(&info, file, merge);
if (info.errorCount != 0)
goto err_info;
if (info.name)
keymap->compat_section_name = strdup(info.name);
if (!darray_empty(info.interps)) {
CopyInterps(&info, true, XkbSI_Exactly);
CopyInterps(&info, true, XkbSI_AllOf | XkbSI_NoneOf);
CopyInterps(&info, true, XkbSI_AnyOf);
CopyInterps(&info, true, XkbSI_AnyOfOrNone);
CopyInterps(&info, false, XkbSI_Exactly);
CopyInterps(&info, false, XkbSI_AllOf | XkbSI_NoneOf);
CopyInterps(&info, false, XkbSI_AnyOf);
CopyInterps(&info, false, XkbSI_AnyOfOrNone);
}
if (!CopyIndicatorMapDefs(&info))
info.errorCount++;
if (!CopyCompatToKeymap(keymap, &info))
goto err_info;
ClearCompatInfo(&info);
return true;

View File

@ -860,7 +860,7 @@ HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
}
}
static int
static void
ApplyAliases(KeyNamesInfo *info, struct xkb_keymap *keymap)
{
int i;
@ -932,6 +932,37 @@ out:
list_foreach_safe(alias, next, &info->aliases, entry)
free(alias);
list_init(&info->aliases);
}
static bool
CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
{
xkb_keycode_t kc;
IndicatorNameInfo *ii;
if (info->explicitMin > 0)
keymap->min_key_code = info->explicitMin;
else
keymap->min_key_code = info->computedMin;
if (info->explicitMax > 0)
keymap->max_key_code = info->explicitMax;
else
keymap->max_key_code = info->computedMax;
darray_resize0(keymap->keys, keymap->max_key_code + 1);
for (kc = info->computedMin; kc <= info->computedMax; kc++)
LongToKeyName(darray_item(info->names, kc),
XkbKey(keymap, kc)->name);
keymap->keycodes_section_name = strdup_safe(info->name);
list_foreach(ii, &info->leds, entry)
keymap->indicator_names[ii->ndx - 1] =
xkb_atom_text(keymap->ctx, ii->name);
ApplyAliases(info, keymap);
return true;
}
@ -949,41 +980,16 @@ bool
CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
enum merge_mode merge)
{
xkb_keycode_t kc;
KeyNamesInfo info; /* contains all the info after parsing */
IndicatorNameInfo *ii;
KeyNamesInfo info;
InitKeyNamesInfo(&info, keymap->ctx, file->id);
HandleKeycodesFile(&info, file, merge);
/* all the keys are now stored in info */
if (info.errorCount != 0)
goto err_info;
if (info.explicitMin > 0) /* if "minimum" statement was present */
keymap->min_key_code = info.explicitMin;
else
keymap->min_key_code = info.computedMin;
if (info.explicitMax > 0) /* if "maximum" statement was present */
keymap->max_key_code = info.explicitMax;
else
keymap->max_key_code = info.computedMax;
darray_resize0(keymap->keys, keymap->max_key_code + 1);
for (kc = info.computedMin; kc <= info.computedMax; kc++)
LongToKeyName(darray_item(info.names, kc),
XkbKey(keymap, kc)->name);
keymap->keycodes_section_name = strdup_safe(info.name);
list_foreach(ii, &info.leds, entry)
keymap->indicator_names[ii->ndx - 1] =
xkb_atom_text(keymap->ctx, ii->name);
ApplyAliases(&info, keymap);
if (!CopyKeyNamesToKeymap(keymap, &info))
goto err_info;
ClearKeyNamesInfo(&info);
return true;

View File

@ -847,7 +847,7 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
}
}
static bool
static void
CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
struct xkb_key_type *type)
{
@ -859,40 +859,27 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
type->name = def->name;
type->level_names = darray_mem(def->level_names, 0);
darray_init(def->level_names);
return true;
}
bool
CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
enum merge_mode merge)
static bool
CopyKeyTypesToKeymap(struct xkb_keymap *keymap, KeyTypesInfo *info)
{
unsigned int i;
unsigned int num_types;
KeyTypesInfo info;
KeyTypeInfo *def;
InitKeyTypesInfo(&info, keymap, file->id);
HandleKeyTypesFile(&info, file, merge);
if (info.errorCount != 0)
goto err_info;
if (info.name)
keymap->types_section_name = strdup(info.name);
num_types = info.num_types ? info.num_types : 1;
num_types = info->num_types ? info->num_types : 1;
keymap->types = calloc(num_types, sizeof(*keymap->types));
if (!keymap->types)
goto err_info;
return false;
keymap->num_types = num_types;
/*
* If no types were specified, a default unnamed one-level type is
* used for all keys.
*/
if (info.num_types == 0) {
if (info->num_types == 0) {
KeyTypeInfo dflt = {
.name = xkb_atom_intern(keymap->ctx, "default"),
.mods = 0,
@ -901,15 +888,33 @@ CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
.level_names = darray_new(),
};
if (!CopyDefToKeyType(&info, &dflt, &keymap->types[0]))
goto err_info;
CopyDefToKeyType(info, &dflt, &keymap->types[0]);
} else {
i = 0;
list_foreach(def, &info.types, entry)
if (!CopyDefToKeyType(&info, def, &keymap->types[i++]))
goto err_info;
list_foreach(def, &info->types, entry)
CopyDefToKeyType(info, def, &keymap->types[i++]);
}
keymap->types_section_name = strdup_safe(info->name);
return true;
}
bool
CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
enum merge_mode merge)
{
KeyTypesInfo info;
InitKeyTypesInfo(&info, keymap, file->id);
HandleKeyTypesFile(&info, file, merge);
if (info.errorCount != 0)
goto err_info;
if (!CopyKeyTypesToKeymap(keymap, &info))
goto err_info;
FreeKeyTypesInfo(&info);
return true;