action: add a common CheckBooleanFlag function Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index 018d4a8..dbb57a9 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -230,30 +230,23 @@ HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
}
static bool
-CheckLatchLockFlags(struct xkb_context *ctx, enum xkb_action_type action,
- enum action_field field, const ExprDef *array_ndx,
- const ExprDef *value, enum xkb_action_flags *flags_inout)
+CheckBooleanFlag(struct xkb_context *ctx, enum xkb_action_type action,
+ enum action_field field, enum xkb_action_flags flag,
+ const ExprDef *array_ndx, const ExprDef *value,
+ enum xkb_action_flags *flags_inout)
{
- enum xkb_action_flags tmp;
- bool result;
+ bool set;
if (array_ndx)
return ReportActionNotArray(ctx, action, field);
- if (field == ACTION_FIELD_CLEAR_LOCKS)
- tmp = ACTION_LOCK_CLEAR;
- else if (field == ACTION_FIELD_LATCH_TO_LOCK)
- tmp = ACTION_LATCH_TO_LOCK;
- else
- return false; /* WSGO! */
-
- if (!ExprResolveBoolean(ctx, value, &result))
+ if (!ExprResolveBoolean(ctx, value, &set))
return ReportMismatch(ctx, action, field, "boolean");
- if (result)
- *flags_inout |= tmp;
+ if (set)
+ *flags_inout |= flag;
else
- *flags_inout &= ~tmp;
+ *flags_inout &= ~flag;
return true;
}
@@ -292,11 +285,15 @@ HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
{
struct xkb_mod_action *act = &action->mods;
- if (field == ACTION_FIELD_CLEAR_LOCKS ||
- field == ACTION_FIELD_LATCH_TO_LOCK)
- return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
- value, &act->flags);
- else if (field == ACTION_FIELD_MODIFIERS)
+ if (field == ACTION_FIELD_CLEAR_LOCKS)
+ return CheckBooleanFlag(keymap->ctx, action->type, field,
+ ACTION_LOCK_CLEAR, array_ndx, value,
+ &act->flags);
+ if (field == ACTION_FIELD_LATCH_TO_LOCK)
+ return CheckBooleanFlag(keymap->ctx, action->type, field,
+ ACTION_LATCH_TO_LOCK, array_ndx, value,
+ &act->flags);
+ if (field == ACTION_FIELD_MODIFIERS)
return CheckModifierField(keymap, action->type, array_ndx, value,
&act->flags, &act->mods.mods);
@@ -392,11 +389,15 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
{
struct xkb_group_action *act = &action->group;
- if (field == ACTION_FIELD_CLEAR_LOCKS ||
- field == ACTION_FIELD_LATCH_TO_LOCK)
- return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
- value, &act->flags);
- else if (field == ACTION_FIELD_GROUP)
+ if (field == ACTION_FIELD_CLEAR_LOCKS)
+ return CheckBooleanFlag(keymap->ctx, action->type, field,
+ ACTION_LOCK_CLEAR, array_ndx, value,
+ &act->flags);
+ if (field == ACTION_FIELD_LATCH_TO_LOCK)
+ return CheckBooleanFlag(keymap->ctx, action->type, field,
+ ACTION_LATCH_TO_LOCK, array_ndx, value,
+ &act->flags);
+ if (field == ACTION_FIELD_GROUP)
return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
&act->flags, &act->group);
@@ -458,18 +459,8 @@ HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
return true;
}
else if (field == ACTION_FIELD_ACCEL) {
- bool set;
-
- if (array_ndx)
- return ReportActionNotArray(keymap->ctx, action->type, field);
-
- if (!ExprResolveBoolean(keymap->ctx, value, &set))
- return ReportMismatch(keymap->ctx, action->type, field, "boolean");
-
- if (set)
- act->flags |= ACTION_ACCEL;
- else
- act->flags &= ~ACTION_ACCEL;
+ return CheckBooleanFlag(keymap->ctx, action->type, field,
+ ACTION_ACCEL, array_ndx, value, &act->flags);
}
return ReportIllegal(keymap->ctx, action->type, field);
@@ -635,20 +626,9 @@ HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
return true;
}
else if (field == ACTION_FIELD_SAME) {
- bool set;
-
- if (array_ndx)
- return ReportActionNotArray(keymap->ctx, action->type, field);
-
- if (!ExprResolveBoolean(keymap->ctx, value, &set))
- return ReportMismatch(keymap->ctx, action->type, field, "boolean");
-
- if (set)
- act->flags |= ACTION_SAME_SCREEN;
- else
- act->flags &= ~ACTION_SAME_SCREEN;
-
- return true;
+ return CheckBooleanFlag(keymap->ctx, action->type, field,
+ ACTION_SAME_SCREEN, array_ndx, value,
+ &act->flags);
}
return ReportIllegal(keymap->ctx, action->type, field);