action: simplify Check* functions

Instead of using those t1 t2 variables, pass the final destinations
directly (while making sure they are not modified in case of error).

This also ensures the types are right, e.g. in CheckGroupField it should
be int32_t, not xkb_layout_index_t (and indeed it takes a negation!).

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2014-02-13 23:11:31 +02:00
parent d3d55f1c4e
commit 6248b09feb
1 changed files with 34 additions and 68 deletions

View File

@ -284,10 +284,8 @@ HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
const ExprDef *value) const ExprDef *value)
{ {
struct xkb_mod_action *act = &action->mods; struct xkb_mod_action *act = &action->mods;
enum xkb_action_flags rtrn, t1;
xkb_mod_mask_t t2;
if (array_ndx != NULL) { if (array_ndx) {
switch (field) { switch (field) {
case ACTION_FIELD_CLEAR_LOCKS: case ACTION_FIELD_CLEAR_LOCKS:
case ACTION_FIELD_LATCH_TO_LOCK: case ACTION_FIELD_LATCH_TO_LOCK:
@ -301,22 +299,11 @@ HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
switch (field) { switch (field) {
case ACTION_FIELD_CLEAR_LOCKS: case ACTION_FIELD_CLEAR_LOCKS:
case ACTION_FIELD_LATCH_TO_LOCK: case ACTION_FIELD_LATCH_TO_LOCK:
rtrn = act->flags; return CheckLatchLockFlags(keymap, action->type, field, value,
if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) { &act->flags);
act->flags = rtrn;
return true;
}
return false;
case ACTION_FIELD_MODIFIERS: case ACTION_FIELD_MODIFIERS:
t1 = act->flags; return CheckModifierField(keymap, action->type, value,
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) { &act->flags, &act->mods.mods);
act->flags = t1;
act->mods.mods = t2;
return true;
}
return false;
default: default:
break; break;
} }
@ -330,22 +317,14 @@ HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
const ExprDef *value) const ExprDef *value)
{ {
struct xkb_mod_action *act = &action->mods; struct xkb_mod_action *act = &action->mods;
enum xkb_action_flags t1;
xkb_mod_mask_t t2;
if (array_ndx && field == ACTION_FIELD_MODIFIERS) if (array_ndx && field == ACTION_FIELD_MODIFIERS)
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
switch (field) { switch (field) {
case ACTION_FIELD_MODIFIERS: case ACTION_FIELD_MODIFIERS:
t1 = act->flags; return CheckModifierField(keymap, action->type, value,
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) { &act->flags, &act->mods.mods);
act->flags = t1;
act->mods.mods = t2;
return true;
}
return false;
default: default:
break; break;
} }
@ -356,28 +335,35 @@ HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
static bool static bool
CheckGroupField(struct xkb_keymap *keymap, unsigned action, CheckGroupField(struct xkb_keymap *keymap, unsigned action,
const ExprDef *value, enum xkb_action_flags *flags_inout, const ExprDef *value, enum xkb_action_flags *flags_inout,
xkb_layout_index_t *grp_rtrn) int32_t *group_rtrn)
{ {
const ExprDef *spec; const ExprDef *spec;
xkb_layout_index_t idx;
enum xkb_action_flags flags = *flags_inout;
if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) { if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
*flags_inout &= ~ACTION_ABSOLUTE_SWITCH; flags &= ~ACTION_ABSOLUTE_SWITCH;
spec = value->unary.child; spec = value->unary.child;
} }
else { else {
*flags_inout |= ACTION_ABSOLUTE_SWITCH; flags |= ACTION_ABSOLUTE_SWITCH;
spec = value; spec = value;
} }
if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn)) if (!ExprResolveGroup(keymap->ctx, spec, &idx))
return ReportMismatch(keymap, action, ACTION_FIELD_GROUP, return ReportMismatch(keymap, action, ACTION_FIELD_GROUP,
"integer (range 1..8)"); "integer (range 1..8)");
if (value->expr.op == EXPR_NEGATE) /* +n, -n are relative, n is absolute. */
*grp_rtrn = -*grp_rtrn; if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
else if (value->expr.op != EXPR_UNARY_PLUS) *group_rtrn = (int32_t) idx;
(*grp_rtrn)--; if (value->expr.op == EXPR_NEGATE)
*group_rtrn = -*group_rtrn;
}
else {
*group_rtrn = (int32_t) (idx - 1);
}
*flags_inout = flags;
return true; return true;
} }
@ -387,16 +373,13 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
const ExprDef *value) const ExprDef *value)
{ {
struct xkb_group_action *act = &action->group; struct xkb_group_action *act = &action->group;
enum xkb_action_flags rtrn, t1;
xkb_layout_index_t t2;
if (array_ndx != NULL) { if (array_ndx) {
switch (field) { switch (field) {
case ACTION_FIELD_CLEAR_LOCKS: case ACTION_FIELD_CLEAR_LOCKS:
case ACTION_FIELD_LATCH_TO_LOCK: case ACTION_FIELD_LATCH_TO_LOCK:
case ACTION_FIELD_GROUP: case ACTION_FIELD_GROUP:
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
default: default:
break; break;
} }
@ -405,22 +388,11 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
switch (field) { switch (field) {
case ACTION_FIELD_CLEAR_LOCKS: case ACTION_FIELD_CLEAR_LOCKS:
case ACTION_FIELD_LATCH_TO_LOCK: case ACTION_FIELD_LATCH_TO_LOCK:
rtrn = act->flags; return CheckLatchLockFlags(keymap, action->type, field, value,
if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) { &act->flags);
act->flags = rtrn;
return true;
}
return false;
case ACTION_FIELD_GROUP: case ACTION_FIELD_GROUP:
t1 = act->flags; return CheckGroupField(keymap, action->type, value,
if (CheckGroupField(keymap, action->type, value, &t1, &t2)) { &act->flags, &act->group);
act->flags = t1;
act->group = t2;
return true;
}
return false;
default: default:
break; break;
} }
@ -434,20 +406,14 @@ HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
const ExprDef *value) const ExprDef *value)
{ {
struct xkb_group_action *act = &action->group; struct xkb_group_action *act = &action->group;
enum xkb_action_flags t1;
xkb_layout_index_t t2;
if ((array_ndx != NULL) && (field == ACTION_FIELD_GROUP)) if (array_ndx && field == ACTION_FIELD_GROUP)
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (field == ACTION_FIELD_GROUP) {
t1 = act->flags; if (field == ACTION_FIELD_GROUP)
if (CheckGroupField(keymap, action->type, value, &t1, &t2)) { return CheckGroupField(keymap, action->type, value,
act->flags = t1; &act->flags, &act->group);
act->group = t2;
return true;
}
return false;
}
return ReportIllegal(keymap, action->type, field); return ReportIllegal(keymap, action->type, field);
} }