compat: small changes

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-08-14 15:06:11 +03:00
parent 4fec91cbbc
commit e9aa84f311
3 changed files with 130 additions and 128 deletions

View File

@ -1237,7 +1237,7 @@ ApplyActionFactoryDefaults(union xkb_action * action)
} }
} }
int bool
HandleActionDef(ExprDef * def, HandleActionDef(ExprDef * def,
struct xkb_keymap *keymap, struct xkb_keymap *keymap,
union xkb_action *action, ActionInfo *info) union xkb_action *action, ActionInfo *info)
@ -1322,7 +1322,7 @@ HandleActionDef(ExprDef * def,
/***====================================================================***/ /***====================================================================***/
int bool
SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field, SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn) ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
{ {

View File

@ -32,11 +32,11 @@ typedef struct _ActionInfo ActionInfo;
void void
FreeActionInfo(ActionInfo *info); FreeActionInfo(ActionInfo *info);
int bool
HandleActionDef(ExprDef *def, struct xkb_keymap *keymap, HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
union xkb_action *action, ActionInfo *info); union xkb_action *action, ActionInfo *info);
int bool
SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field, SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
ExprDef *index, ExprDef *value, ActionInfo **info_rtrn); ExprDef *index, ExprDef *value, ActionInfo **info_rtrn);

View File

@ -201,19 +201,17 @@ typedef struct _CompatInfo {
} CompatInfo; } CompatInfo;
static const char * static const char *
siText(SymInterpInfo * si, CompatInfo * info) siText(SymInterpInfo *si, CompatInfo *info)
{ {
static char buf[128]; static char buf[128];
if (si == &info->dflt) { if (si == &info->dflt)
snprintf(buf, sizeof(buf), "default"); return "default";
}
else { snprintf(buf, sizeof(buf), "%s+%s(%s)",
snprintf(buf, sizeof(buf), "%s+%s(%s)", KeysymText(si->interp.sym),
KeysymText(si->interp.sym), SIMatchText(si->interp.match),
SIMatchText(si->interp.match), ModMaskText(si->interp.mods));
ModMaskText(si->interp.mods));
}
return buf; return buf;
} }
@ -250,7 +248,7 @@ ReportIndicatorNotArray(CompatInfo *info, LEDInfo *led,
} }
static void static void
ClearIndicatorMapInfo(struct xkb_context *ctx, LEDInfo * info) ClearIndicatorMapInfo(struct xkb_context *ctx, LEDInfo *info)
{ {
info->name = xkb_atom_intern(ctx, "default"); info->name = xkb_atom_intern(ctx, "default");
info->indicator = XKB_LED_INVALID; info->indicator = XKB_LED_INVALID;
@ -318,7 +316,7 @@ ClearCompatInfo(CompatInfo *info)
} }
static SymInterpInfo * static SymInterpInfo *
NextInterp(CompatInfo * info) NextInterp(CompatInfo *info)
{ {
SymInterpInfo *si; SymInterpInfo *si;
@ -333,7 +331,7 @@ NextInterp(CompatInfo * info)
} }
static SymInterpInfo * static SymInterpInfo *
FindMatchingInterp(CompatInfo * info, SymInterpInfo * new) FindMatchingInterp(CompatInfo *info, SymInterpInfo *new)
{ {
SymInterpInfo *old; SymInterpInfo *old;
@ -365,7 +363,7 @@ UseNewInterpField(enum si_field field, SymInterpInfo *old, SymInterpInfo *new,
} }
static bool static bool
AddInterp(CompatInfo * info, SymInterpInfo * new) AddInterp(CompatInfo *info, SymInterpInfo *new)
{ {
enum si_field collide; enum si_field collide;
SymInterpInfo *old; SymInterpInfo *old;
@ -429,7 +427,8 @@ AddInterp(CompatInfo * info, SymInterpInfo * new)
} }
old = new; old = new;
if ((new = NextInterp(info)) == NULL) new = NextInterp(info);
if (!new)
return false; return false;
entry = new->entry; entry = new->entry;
*new = *old; *new = *old;
@ -462,9 +461,8 @@ AddGroupCompat(CompatInfo *info, xkb_group_index_t group, GroupCompatInfo *new)
/***====================================================================***/ /***====================================================================***/
static bool static bool
ResolveStateAndPredicate(ExprDef * expr, ResolveStateAndPredicate(ExprDef *expr, unsigned *pred_rtrn,
unsigned *pred_rtrn, xkb_mod_mask_t *mods_rtrn, CompatInfo *info)
xkb_mod_mask_t *mods_rtrn, CompatInfo * info)
{ {
if (expr == NULL) { if (expr == NULL) {
*pred_rtrn = XkbSI_AnyOfOrNone; *pred_rtrn = XkbSI_AnyOfOrNone;
@ -535,84 +533,84 @@ AddIndicatorMap(CompatInfo *info, LEDInfo *new)
int verbosity = xkb_get_log_verbosity(ctx); int verbosity = xkb_get_log_verbosity(ctx);
list_foreach(old, &info->leds, entry) { list_foreach(old, &info->leds, entry) {
if (old->name == new->name) { if (old->name != new->name)
if ((old->mods == new->mods) && continue;
(old->groups == new->groups) &&
(old->ctrls == new->ctrls) &&
(old->which_mods == new->which_mods) &&
(old->which_groups == new->which_groups)) {
old->defined |= new->defined;
return true;
}
if (new->merge == MERGE_REPLACE) {
struct list entry = old->entry;
if ((old->file_id == new->file_id && verbosity > 0) ||
verbosity > 9)
log_warn(info->keymap->ctx,
"Map for indicator %s redefined; "
"Earlier definition ignored\n",
xkb_atom_text(ctx, old->name));
*old = *new;
old->entry = entry;
return true;
}
collide = 0;
if (UseNewLEDField(LED_FIELD_INDEX, old, new, verbosity,
&collide)) {
old->indicator = new->indicator;
old->defined |= LED_FIELD_INDEX;
}
if (UseNewLEDField(LED_FIELD_MODS, old, new, verbosity,
&collide)) {
old->which_mods = new->which_mods;
old->mods = new->mods;
old->defined |= LED_FIELD_MODS;
}
if (UseNewLEDField(LED_FIELD_GROUPS, old, new, verbosity,
&collide)) {
old->which_groups = new->which_groups;
old->groups = new->groups;
old->defined |= LED_FIELD_GROUPS;
}
if (UseNewLEDField(LED_FIELD_CTRLS, old, new, verbosity,
&collide)) {
old->ctrls = new->ctrls;
old->defined |= LED_FIELD_CTRLS;
}
if (UseNewLEDField(LED_FIELD_EXPLICIT, old, new, verbosity,
&collide)) {
old->flags &= ~XkbIM_NoExplicit;
old->flags |= (new->flags & XkbIM_NoExplicit);
old->defined |= LED_FIELD_EXPLICIT;
}
if (UseNewLEDField(LED_FIELD_AUTOMATIC, old, new, verbosity,
&collide)) {
old->flags &= ~XkbIM_NoAutomatic;
old->flags |= (new->flags & XkbIM_NoAutomatic);
old->defined |= LED_FIELD_AUTOMATIC;
}
if (UseNewLEDField(LED_FIELD_DRIVES_KBD, old, new, verbosity,
&collide)) {
old->flags &= ~XkbIM_LEDDrivesKB;
old->flags |= (new->flags & XkbIM_LEDDrivesKB);
old->defined |= LED_FIELD_DRIVES_KBD;
}
if (collide) {
log_warn(info->keymap->ctx,
"Map for indicator %s redefined; "
"Using %s definition for duplicate fields\n",
xkb_atom_text(ctx, old->name),
(new->merge == MERGE_AUGMENT ? "first" : "last"));
}
if (old->mods == new->mods &&
old->groups == new->groups &&
old->ctrls == new->ctrls &&
old->which_mods == new->which_mods &&
old->which_groups == new->which_groups) {
old->defined |= new->defined;
return true; return true;
} }
if (new->merge == MERGE_REPLACE) {
struct list entry = old->entry;
if ((old->file_id == new->file_id && verbosity > 0) ||
verbosity > 9)
log_warn(info->keymap->ctx,
"Map for indicator %s redefined; "
"Earlier definition ignored\n",
xkb_atom_text(ctx, old->name));
*old = *new;
old->entry = entry;
return true;
}
collide = 0;
if (UseNewLEDField(LED_FIELD_INDEX, old, new, verbosity,
&collide)) {
old->indicator = new->indicator;
old->defined |= LED_FIELD_INDEX;
}
if (UseNewLEDField(LED_FIELD_MODS, old, new, verbosity,
&collide)) {
old->which_mods = new->which_mods;
old->mods = new->mods;
old->defined |= LED_FIELD_MODS;
}
if (UseNewLEDField(LED_FIELD_GROUPS, old, new, verbosity,
&collide)) {
old->which_groups = new->which_groups;
old->groups = new->groups;
old->defined |= LED_FIELD_GROUPS;
}
if (UseNewLEDField(LED_FIELD_CTRLS, old, new, verbosity,
&collide)) {
old->ctrls = new->ctrls;
old->defined |= LED_FIELD_CTRLS;
}
if (UseNewLEDField(LED_FIELD_EXPLICIT, old, new, verbosity,
&collide)) {
old->flags &= ~XkbIM_NoExplicit;
old->flags |= (new->flags & XkbIM_NoExplicit);
old->defined |= LED_FIELD_EXPLICIT;
}
if (UseNewLEDField(LED_FIELD_AUTOMATIC, old, new, verbosity,
&collide)) {
old->flags &= ~XkbIM_NoAutomatic;
old->flags |= (new->flags & XkbIM_NoAutomatic);
old->defined |= LED_FIELD_AUTOMATIC;
}
if (UseNewLEDField(LED_FIELD_DRIVES_KBD, old, new, verbosity,
&collide)) {
old->flags &= ~XkbIM_LEDDrivesKB;
old->flags |= (new->flags & XkbIM_LEDDrivesKB);
old->defined |= LED_FIELD_DRIVES_KBD;
}
if (collide) {
log_warn(info->keymap->ctx,
"Map for indicator %s redefined; "
"Using %s definition for duplicate fields\n",
xkb_atom_text(ctx, old->name),
(new->merge == MERGE_AUGMENT ? "first" : "last"));
}
return true;
} }
/* new definition */
old = malloc(sizeof(*old)); old = malloc(sizeof(*old));
if (!old) { if (!old) {
log_wsgo(info->keymap->ctx, log_wsgo(info->keymap->ctx,
@ -629,10 +627,10 @@ AddIndicatorMap(CompatInfo *info, LEDInfo *new)
} }
static void static void
MergeIncludedCompatMaps(CompatInfo * into, CompatInfo * from, MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
enum merge_mode merge) enum merge_mode merge)
{ {
SymInterpInfo *si; SymInterpInfo *si, *next_si;
LEDInfo *led, *next_led; LEDInfo *led, *next_led;
GroupCompatInfo *gcm; GroupCompatInfo *gcm;
xkb_group_index_t i; xkb_group_index_t i;
@ -641,22 +639,21 @@ MergeIncludedCompatMaps(CompatInfo * into, CompatInfo * from,
into->errorCount += from->errorCount; into->errorCount += from->errorCount;
return; return;
} }
if (into->name == NULL) { if (into->name == NULL) {
into->name = from->name; into->name = from->name;
from->name = NULL; from->name = NULL;
} }
list_foreach(si, &from->interps, entry) { list_foreach_safe(si, next_si, &from->interps, entry) {
if (merge != MERGE_DEFAULT) si->merge = (merge == MERGE_DEFAULT ? si->merge : merge);
si->merge = merge;
if (!AddInterp(into, si)) if (!AddInterp(into, si))
into->errorCount++; into->errorCount++;
} }
for (i = 0, gcm = &from->groupCompat[0]; i < XkbNumKbdGroups; for (i = 0; i < XkbNumKbdGroups; i++) {
i++, gcm++) { gcm = &from->groupCompat[i];
if (merge != MERGE_DEFAULT) gcm->merge = (merge == MERGE_DEFAULT ? gcm->merge : merge);
gcm->merge = merge;
if (!AddGroupCompat(into, i, gcm)) if (!AddGroupCompat(into, i, gcm))
into->errorCount++; into->errorCount++;
} }
@ -726,7 +723,7 @@ static const LookupEntry useModMapValues[] = {
{ NULL, 0 } { NULL, 0 }
}; };
static int static bool
SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field, SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
ExprDef *arrayNdx, ExprDef *value) ExprDef *arrayNdx, ExprDef *value)
{ {
@ -820,6 +817,7 @@ static const LookupEntry modComponentNames[] = {
{"none", 0}, {"none", 0},
{NULL, 0} {NULL, 0}
}; };
static const LookupEntry groupComponentNames[] = { static const LookupEntry groupComponentNames[] = {
{"base", XkbIM_UseBase}, {"base", XkbIM_UseBase},
{"latched", XkbIM_UseLatched}, {"latched", XkbIM_UseLatched},
@ -844,7 +842,7 @@ static const LookupEntry groupNames[] = {
{NULL, 0} {NULL, 0}
}; };
static int static bool
SetIndicatorMapField(CompatInfo *info, LEDInfo *led, SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
const char *field, ExprDef *arrayNdx, ExprDef *value) const char *field, ExprDef *arrayNdx, ExprDef *value)
{ {
@ -957,7 +955,7 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
return ReportIndicatorBadType(info, led, field, return ReportIndicatorBadType(info, led, field,
"indicator index"); "indicator index");
if (ndx < 1 || ndx > 32) { if (ndx < 1 || ndx > XkbNumIndicators) {
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Illegal indicator index %d (range 1..%d); " "Illegal indicator index %d (range 1..%d); "
"Index definition for %s indicator ignored\n", "Index definition for %s indicator ignored\n",
@ -980,15 +978,15 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
return ok; return ok;
} }
static int static bool
HandleInterpVar(CompatInfo *info, VarDef *stmt) HandleInterpVar(CompatInfo *info, VarDef *stmt)
{ {
const char *elem, *field; const char *elem, *field;
ExprDef *ndx; ExprDef *ndx;
int ret; bool ret;
if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, &ndx)) if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, &ndx))
ret = 0; /* internal error, already reported */ ret = false;
else if (elem && istreq(elem, "interpret")) else if (elem && istreq(elem, "interpret"))
ret = SetInterpField(info, &info->dflt, field, ndx, stmt->value); ret = SetInterpField(info, &info->dflt, field, ndx, stmt->value);
else if (elem && istreq(elem, "indicator")) else if (elem && istreq(elem, "indicator"))
@ -1000,28 +998,31 @@ HandleInterpVar(CompatInfo *info, VarDef *stmt)
return ret; return ret;
} }
static int static bool
HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si) HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si)
{ {
int ok = 1; bool ok = true;
const char *elem, *field; const char *elem, *field;
ExprDef *arrayNdx; ExprDef *arrayNdx;
for (; def != NULL; def = (VarDef *) def->common.next) { for (; def; def = (VarDef *) def->common.next) {
if (def->name && def->name->op == EXPR_FIELD_REF) { if (def->name && def->name->op == EXPR_FIELD_REF) {
ok = HandleInterpVar(info, def); ok = HandleInterpVar(info, def);
continue; continue;
} }
ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field, ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
&arrayNdx); &arrayNdx);
if (ok) { if (!ok)
ok = SetInterpField(info, si, field, arrayNdx, def->value); continue;
}
ok = SetInterpField(info, si, field, arrayNdx, def->value);
} }
return ok; return ok;
} }
static int static bool
HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge) HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
{ {
unsigned pred, mods; unsigned pred, mods;
@ -1033,11 +1034,11 @@ HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
"Symbol interpretation ignored\n"); "Symbol interpretation ignored\n");
return false; return false;
} }
if (def->merge != MERGE_DEFAULT)
merge = def->merge;
si = info->dflt; si = info->dflt;
si.merge = merge;
si.merge = merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
if (!LookupKeysym(def->sym, &si.interp.sym)) { if (!LookupKeysym(def->sym, &si.interp.sym)) {
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Could not resolve keysym %s; " "Could not resolve keysym %s; "
@ -1045,8 +1046,11 @@ HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
def->sym); def->sym);
return false; return false;
} }
si.interp.match = pred & XkbSI_OpMask; si.interp.match = pred & XkbSI_OpMask;
si.interp.mods = mods; si.interp.mods = mods;
if (!HandleInterpBody(info, def->def, &si)) { if (!HandleInterpBody(info, def->def, &si)) {
info->errorCount++; info->errorCount++;
return false; return false;
@ -1056,10 +1060,11 @@ HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
info->errorCount++; info->errorCount++;
return false; return false;
} }
return true; return true;
} }
static int static bool
HandleGroupCompatDef(CompatInfo *info, GroupCompatDef *def, HandleGroupCompatDef(CompatInfo *info, GroupCompatDef *def,
enum merge_mode merge) enum merge_mode merge)
{ {
@ -1329,13 +1334,12 @@ CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
if (info.errorCount != 0) if (info.errorCount != 0)
goto err_info; goto err_info;
darray_init(keymap->sym_interpret);
darray_growalloc(keymap->sym_interpret, info.nInterps);
if (info.name) if (info.name)
keymap->compat_section_name = strdup(info.name); keymap->compat_section_name = strdup(info.name);
darray_init(keymap->sym_interpret);
if (info.nInterps > 0) { if (info.nInterps > 0) {
darray_growalloc(keymap->sym_interpret, info.nInterps);
CopyInterps(&info, true, XkbSI_Exactly); CopyInterps(&info, true, XkbSI_Exactly);
CopyInterps(&info, true, XkbSI_AllOf | XkbSI_NoneOf); CopyInterps(&info, true, XkbSI_AllOf | XkbSI_NoneOf);
CopyInterps(&info, true, XkbSI_AnyOf); CopyInterps(&info, true, XkbSI_AnyOf);
@ -1346,8 +1350,8 @@ CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
CopyInterps(&info, false, XkbSI_AnyOfOrNone); CopyInterps(&info, false, XkbSI_AnyOfOrNone);
} }
for (i = 0, gcm = &info.groupCompat[0]; i < XkbNumKbdGroups; for (i = 0; i < XkbNumKbdGroups; i++) {
i++, gcm++) { gcm = &info.groupCompat[i];
if (gcm->file_id != 0 || gcm->mods != 0) if (gcm->file_id != 0 || gcm->mods != 0)
keymap->groups[i].mods = gcm->mods; keymap->groups[i].mods = gcm->mods;
} }
@ -1472,8 +1476,6 @@ FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key,
return ret; return ret;
} }
/**
*/
static bool static bool
ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key) ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
{ {